:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --cell: #334155;
  --cell-hover: #475569;
  --x-color: #38bdf8;
  --o-color: #fb7185;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22c55e;
  --win: #facc15;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
}
h1 { font-size: 1.8rem; margin-bottom: 16px; letter-spacing: 2px; }
h1 .x { color: var(--x-color); }
h1 .o { color: var(--o-color); }

.controls {
  background: var(--panel);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  align-items: flex-end;
  margin-bottom: 20px;
  max-width: 640px;
}
.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
select, button {
  background: var(--cell);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.95rem;
  cursor: pointer;
}
select:hover, button:hover { background: var(--cell-hover); }
#newGameBtn { background: var(--accent); color: #052e16; font-weight: 700; padding: 10px 20px; }
#newGameBtn:hover { filter: brightness(1.1); background: var(--accent); }

.scoreboard {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.score {
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 18px;
  text-align: center;
  min-width: 90px;
}
.score .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.score .value { font-size: 1.4rem; font-weight: 700; }
.score.x .value { color: var(--x-color); }
.score.o .value { color: var(--o-color); }

#status {
  font-size: 1.1rem;
  margin-bottom: 16px;
  min-height: 1.5em;
  font-weight: 600;
}
#status .x { color: var(--x-color); }
#status .o { color: var(--o-color); }

.board {
  display: grid;
  grid-template-columns: repeat(3, 100px);
  grid-template-rows: repeat(3, 100px);
  gap: 8px;
}
.cell {
  background: var(--cell);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, transform 0.1s;
}
.cell:hover:not(.taken) { background: var(--cell-hover); }
.cell.taken { cursor: default; }
.cell.x { color: var(--x-color); }
.cell.o { color: var(--o-color); }
.cell.win { background: #423d10; box-shadow: 0 0 0 3px var(--win) inset; }
.cell.pop { animation: pop 0.18s ease-out; }
@keyframes pop {
  0% { transform: scale(0.6); }
  100% { transform: scale(1); }
}
.board.locked .cell { cursor: default; }

.hidden { display: none !important; }
footer { margin-top: 20px; color: var(--muted); font-size: 0.8rem; }

@media (max-width: 400px) {
  .board {
    grid-template-columns: repeat(3, 84px);
    grid-template-rows: repeat(3, 84px);
  }
  .cell { font-size: 2.4rem; }
}
