/**
 * Tetris (G5) Stylesheet - Classic Endless Mode
 * Game Room v5.0.0
 * Compliance: Rules.md (Rule 3)
 */

/* ==========================================================================
   Screen Visibility & Isolation
   ========================================================================== */
#screen-tetris {
  display: none !important;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #0f172a 0%, #020617 100%);
  color: #f8fafc;
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#screen-tetris.active {
  display: flex !important;
  flex-direction: column;
}

.screen-tetris-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ==========================================================================
   1. Unified 3-Tier Header (.unified-game-header)
   ========================================================================== */
.tetris-header {
  flex-shrink: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 12px 6px 12px;
  z-index: 20;
}

/* Top Row: Navigation & Brand & Actions */
.tetris-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  gap: 8px;
}

.btn-tetris-help {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-tetris-help:hover {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  transform: translateY(-1px);
}

.btn-tetris-help svg {
  width: 16px;
  height: 16px;
}

/* Progress Row: Level-up Progress Bar */
.tetris-progress-bar-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.tetris-progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 500;
}

.tetris-progress-track {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.tetris-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #06b6d4, #3b82f6);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Stats Row: 4 Column Uniform Stats */
.tetris-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 6px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tetris-stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.tetris-stat-label {
  font-size: 0.65rem;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tetris-stat-val {
  font-size: 0.88rem;
  font-weight: 700;
  color: #f1f5f9;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.tetris-stat-val.gold {
  color: #facc15;
}

/* ==========================================================================
   2. Main Game Area & Layout
   ========================================================================== */
.tetris-main-area {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 8px;
  position: relative;
  gap: 10px;
}

/* Left & Right Side Panels */
.tetris-side-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 68px;
  flex-shrink: 0;
}

.tetris-box-card {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tetris-box-title {
  font-size: 0.68rem;
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  text-align: center;
}

.tetris-mini-canvas {
  width: 58px;
  height: 58px;
  display: block;
}

.tetris-next-canvas {
  width: 58px;
  height: 140px;
  display: block;
}

/* Center Board Canvas Wrapper */
.tetris-board-wrapper {
  height: 100%;
  max-height: calc(100dvh - 200px);
  aspect-ratio: 10 / 20;
  position: relative;
  background: #030712;
  border: 2px solid rgba(56, 189, 248, 0.3);
  border-radius: 8px;
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.15), inset 0 0 20px rgba(0, 0, 0, 0.8);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tetris-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ==========================================================================
   3. Touch Controls (Mobile Friendly / 100dvh Non-scroll)
   ========================================================================== */
.tetris-touch-controls {
  flex-shrink: 0;
  width: 100%;
  padding: 4px 10px 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.8);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 15;
}

.touch-ctrl-cluster {
  display: flex;
  gap: 6px;
  align-items: center;
}

.touch-ctrl-btn {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: #f1f5f9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.touch-ctrl-btn:active {
  background: rgba(56, 189, 248, 0.35);
  border-color: #38bdf8;
  transform: scale(0.92);
}

.touch-ctrl-btn.btn-sm {
  width: 44px;
  height: 44px;
}

.touch-ctrl-btn.btn-md {
  width: 48px;
  height: 48px;
}

.touch-ctrl-btn.btn-accent {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.25), rgba(37, 99, 235, 0.35));
  border-color: rgba(56, 189, 248, 0.4);
}

.touch-ctrl-btn.btn-gold {
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.25), rgba(245, 158, 11, 0.35));
  border-color: rgba(250, 204, 21, 0.4);
}

.touch-ctrl-btn svg {
  width: 22px;
  height: 22px;
}

.touch-ctrl-btn span {
  font-size: 0.6rem;
  font-weight: 700;
  margin-top: 1px;
}

/* ==========================================================================
   4. Modals (Controls Guide & Game Over)
   ========================================================================== */
.tetris-modal-card {
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.7);
  width: 90%;
  max-width: 420px;
  padding: 20px;
  color: #f8fafc;
  position: relative;
  animation: modalPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tetris-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
}

.tetris-modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f1f5f9;
}

.controls-guide-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.85rem;
}

.controls-guide-section {
  background: rgba(30, 41, 59, 0.5);
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.controls-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #38bdf8;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.controls-table {
  width: 100%;
  border-collapse: collapse;
}

.controls-table td {
  padding: 4px 0;
  vertical-align: middle;
}

.controls-key-badge {
  display: inline-block;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #e2e8f0;
  font-family: monospace;
}

/* Game Over Modal Content */
.gameover-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.gameover-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.15);
  border: 1.5px solid rgba(239, 68, 68, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.gameover-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: #f8fafc;
  margin-bottom: 4px;
}

.new-record-badge {
  display: inline-block;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 999px;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  animation: pulseGlow 1.2s infinite alternate;
}

.gameover-stats-card {
  width: 100%;
  background: rgba(30, 41, 59, 0.6);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 12px 0 16px 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.gameover-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.gameover-stat-row:last-child {
  border-bottom: none;
}

.gameover-stat-row .label {
  font-size: 0.8rem;
  color: #94a3b8;
}

.gameover-stat-row .val {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
}

.gameover-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.gameover-actions button {
  flex: 1;
}

/* ==========================================================================
   5. Responsive Breakpoints
   ========================================================================== */
@media (min-width: 768px) {
  .tetris-side-panel {
    width: 84px;
  }
  .tetris-mini-canvas {
    width: 72px;
    height: 72px;
  }
  .tetris-next-canvas {
    width: 72px;
    height: 180px;
  }
  .touch-ctrl-btn.btn-sm {
    width: 50px;
    height: 50px;
  }
  .touch-ctrl-btn.btn-md {
    width: 56px;
    height: 56px;
  }
}
