*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --lime:   #c8f135;
  --white:  #ffffff;
  --bg:     #0d0d0d;
  --line:   #2a2a2a;
  --hud-h:  60px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  touch-action: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  display: flex;
  flex-direction: column;
}

/* =====================================================
   HUD
   ===================================================== */
#hud {
  position: relative;
  z-index: 2;
  width: 100%;
  height: var(--hud-h);
  flex: 0 0 var(--hud-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.score-side {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 80px;
}

#score-x { justify-content: flex-start; }
#score-o { justify-content: flex-end; }

.score-sym {
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
}

.score-num {
  font-size: 20px;
  font-weight: 300;
  color: #2e2e2e;
  width: 28px;
  text-align: center;
  transition: color 0.3s;
  font-variant-numeric: tabular-nums;
}

.score-num.highlight { color: #666; }

.sym-x { color: var(--lime); }
.sym-o { color: var(--white); }

#hud-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#reset-btn {
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  opacity: 0.18;
  color: var(--white);
  transition: opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#reset-btn:hover,
#reset-btn:active { opacity: 0.55; }
#reset-btn svg { width: 20px; height: 20px; display: block; }

/* =====================================================
   ÁREA DE JUEGO
   ===================================================== */
#game-area {
  position: relative;
  flex: 1;
  min-height: 0;
}

/* ─── TABLERO ─────────────────────────────────────────
   position:absolute + grid-template-rows explícito:
   las filas no crecen con el contenido → sin saltos.
   ─────────────────────────────────────────────────── */
#board {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);  /* ← fix principal */
  overflow: hidden;
  /* width y height fijados por JS una sola vez */
}

/* =====================================================
   CELLS
   ===================================================== */
.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.line-v {
  position: absolute;
  right: 0;
  top: 10%;
  height: 80%;
  width: 1px;
  background: var(--line);
  pointer-events: none;
}

.line-h {
  position: absolute;
  bottom: 0;
  left: 10%;
  width: 80%;
  height: 1px;
  background: var(--line);
  pointer-events: none;
}

/* =====================================================
   SÍMBOLOS
   ===================================================== */
.sym {
  font-size: var(--sym-size, 52px);
  font-weight: 300;
  line-height: 1;
  pointer-events: none;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.sym-x { transform: scale(1.18); }
.sym.vanishing { opacity: 0.15; }

.sym.win-flash {
  animation: flash 0.5s ease infinite alternate;
}

@keyframes flash {
  from { opacity: 1;   }
  to   { opacity: 0.2; }
}

/* =====================================================
   GEAR
   ===================================================== */
#gear-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  opacity: 0.15;
  color: var(--white);
  transition: opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#gear-btn:hover,
#gear-btn:active { opacity: 0.5; }
#gear-btn svg { width: 20px; height: 20px; display: block; }

/* =====================================================
   WIN OVERLAY
   ===================================================== */
#win-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13,13,13,0.88);
  cursor: pointer;
  z-index: 10;
  animation: fade-in 0.3s ease;
  touch-action: manipulation;
}

#win-overlay.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#win-symbol {
  font-size: 30vmin;
  font-weight: 300;
  line-height: 1;
  animation: pop 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes pop {
  from { transform: scale(0.2); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* =====================================================
   CONFIG SCREEN
   ===================================================== */
#config-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 32px;
  z-index: 20;
  animation: slide-in 0.2s ease;
}

#config-screen.hidden { display: none; }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

#config-back {
  position: fixed;
  top: 24px;
  left: 24px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  opacity: 0.22;
  color: var(--white);
  transition: opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
#config-back:hover { opacity: 0.6; }
#config-back svg { width: 22px; height: 22px; display: block; }

#config-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 280px;
}

.mode-option {
  width: 100%;
  padding: 18px 20px;
  border: 1px solid #1c1c1c;
  border-radius: 14px;
  background: none;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.mode-option:hover  { border-color: #2a2a2a; }
.mode-option.selected { border-color: #333; }

.m-name {
  font-size: 15px;
  font-weight: 400;
  color: #2e2e2e;
  display: block;
  transition: color 0.2s;
}
.mode-option.selected .m-name { color: #777; }

.god-label { color: #1e1e1e; }
.mode-option[data-mode="god"].selected .god-label { color: var(--lime); }

.m-desc {
  font-size: 11px;
  color: #1e1e1e;
  display: block;
}
.mode-option.selected .m-desc { color: #2a2a2a; }

.mode-divider {
  height: 1px;
  background: #181818;
  margin: 4px 0;
}

/* =====================================================
   DESKTOP
   ===================================================== */
@media (min-width: 769px) {
  #app {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    width: 480px;
  }
}
