* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(circle at 50% 0%, #1a1430 0%, #050409 70%);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 430px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem calc(env(safe-area-inset-bottom) + 0.5rem);
  gap: 0.5rem;
}

button { touch-action: manipulation; cursor: pointer; }

/* ---------- HUD ---------- */
.hud {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  align-items: center;
  gap: 0.5rem;
}
.score {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35rem 0.2rem;
  border-radius: 0.7rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}
.score .lbl { font-size: 0.62rem; letter-spacing: 0.15em; opacity: 0.6; }
.score .val { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.score.you .val { color: #5ad1ff; }
.score.ai .val { color: #ff8aa8; }
.score.active { box-shadow: 0 0 0 2px rgba(255,255,255,0.18) inset; background: rgba(255,255,255,0.07); }

.turn {
  text-align: center;
}
.turn-label {
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.45rem 0.6rem;
  border-radius: 0.7rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
}
.turn.you .turn-label { color: #5ad1ff; }
.turn.ai .turn-label { color: #ff8aa8; }

/* ---------- Board ---------- */
.board-wrap {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  display: grid;
  place-items: center;
  min-height: 0;
}
.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 2px;
  width: min(100%, 58vh);
  aspect-ratio: 1 / 1;
  background: rgba(255,255,255,0.05);
  border-radius: 0.8rem;
  padding: 2px;
  border: 1px solid rgba(255,255,255,0.08);
}
.cell {
  background: #15122a;
  border-radius: 3px;
  display: grid;
  place-items: center;
  font-size: clamp(0.7rem, 3.4vw, 1.05rem);
  font-weight: 800;
  color: rgba(255,255,255,0.85);
  position: relative;
}
.cell.filled { color: #fff; }
.cell.s { color: #5ad1ff; }
.cell.o { color: #ffce5a; }
.cell.flash {
  animation: pop 0.4s ease;
  background: #2a2148;
}
@keyframes pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.cell.win {
  background: rgba(90,209,255,0.18);
  box-shadow: 0 0 0 2px rgba(90,209,255,0.4) inset;
}
.cell.win.ai {
  background: rgba(255,138,168,0.18);
  box-shadow: 0 0 0 2px rgba(255,138,168,0.4) inset;
}
.board.locked .cell:not(.filled) { opacity: 0.45; }

/* ---------- flash overlay ---------- */
.flash {
  position: absolute;
  pointer-events: none;
  font-weight: 800;
  font-size: 1.6rem;
  opacity: 0;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.flash.show {
  animation: fly 0.7s ease forwards;
}
@keyframes fly {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.7); }
  30% { opacity: 1; transform: translate(-50%, -14px) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -40px) scale(1); }
}

/* ---------- Controls ---------- */
.controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}
.letter-pick {
  display: flex;
  gap: 0.5rem;
}
.letter {
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 0.8rem;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 800;
}
.letter.active {
  background: linear-gradient(160deg, #5ad1ff, #3a7bff);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(90,209,255,0.4);
}
.restart-btn {
  height: 3.2rem;
  padding: 0 1.1rem;
  border-radius: 0.8rem;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

/* ---------- Game over overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5,4,9,0.82);
  backdrop-filter: blur(4px);
  z-index: 5;
}
.overlay .card {
  text-align: center;
  padding: 1.6rem 2rem;
  border-radius: 1.2rem;
  background: linear-gradient(160deg, #1c1738, #0d0a1c);
  border: 1px solid rgba(255,255,255,0.1);
}
.overlay h2 { margin: 0 0 0.4rem; font-size: 1.8rem; }
.overlay p { margin: 0 0 1.2rem; opacity: 0.75; font-size: 0.95rem; }
.overlay button {
  padding: 0.8rem 1.6rem;
  border-radius: 0.8rem;
  border: none;
  background: linear-gradient(160deg, #5ad1ff, #3a7bff);
  color: #06121f;
  font-weight: 800;
  font-size: 1rem;
}
