/* ── Reset & tokens ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #5b8dee;
  --accent-dim: #3a5fbf;
  --x-color: #f0635a;
  --o-color: #5b8dee;
  --text: #e4e8ff;
  --muted: #7a82aa;
  --win-glow: #ffe066;
  --radius: 12px;
  --gap: 12px;
}

body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
}

/* ── Screens ──────────────────────────────────────────────────────────── */
.screen { display: none; flex-direction: column; align-items: center; gap: 24px; width: 100%; max-width: 440px; padding: 32px 20px; }
.screen.active { display: flex; }

/* ── Lobby ────────────────────────────────────────────────────────────── */
header { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.logo { width: 64px; height: 64px; }
h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.5px; }
.tagline { color: var(--muted); font-size: 0.95rem; }

.lobby-form {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

label { font-size: 0.85rem; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }

.input-row { display: flex; gap: 8px; }

input[type="text"] {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
input[type="text"]:focus { border-color: var(--accent); }

button { cursor: pointer; font-family: inherit; border: none; transition: opacity .15s, background .15s; }
button:active { opacity: .75; }

#random-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 1.2rem;
  padding: 0 14px;
}
#random-btn:hover { color: var(--text); }

.side-choice { display: flex; gap: 8px; }
.side-btn {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface2);
  border: 2px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}
.side-btn.active[data-side="X"] { border-color: var(--x-color); color: var(--x-color); background: #2a1616; }
.side-btn.active[data-side="O"] { border-color: var(--o-color); color: var(--o-color); background: #111d35; }

.primary-btn {
  padding: 12px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.primary-btn:hover { background: var(--accent-dim); }

.hint { color: var(--muted); font-size: 0.85rem; text-align: center; }

/* ── Game ─────────────────────────────────────────────────────────────── */
.game-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
}
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 1.1rem;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--text); }
.room-label {
  flex: 1;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-bar {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  min-height: 1.5em;
  color: var(--text);
  transition: color .2s;
}
.status-bar.your-turn { color: var(--accent); }
.status-bar.won-x { color: var(--x-color); }
.status-bar.won-o { color: var(--o-color); }
.status-bar.draw { color: var(--win-glow); }

/* ── Board ────────────────────────────────────────────────────────────── */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  width: 100%;
  aspect-ratio: 1;
  max-width: 360px;
}

.cell {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2rem, 10vw, 3.5rem);
  font-weight: 900;
  cursor: pointer;
  user-select: none;
  transition: background .1s, border-color .1s, transform .1s;
  color: transparent;
}
.cell:hover:not(.taken):not(.disabled) {
  background: var(--surface2);
  border-color: var(--accent);
  transform: scale(1.03);
}
.cell.x { color: var(--x-color); }
.cell.o { color: var(--o-color); }
.cell.taken, .cell.disabled { cursor: default; }
.cell.win-line {
  border-color: var(--win-glow);
  background: #22200a;
  box-shadow: 0 0 12px 2px color-mix(in srgb, var(--win-glow) 30%, transparent);
}

/* ── Scores ───────────────────────────────────────────────────────────── */
.scores {
  display: flex;
  gap: 12px;
  width: 100%;
}
.score-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.score-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.score-value { font-size: 1.4rem; font-weight: 700; }
#score-x .score-value { color: var(--x-color); }
#score-o .score-value { color: var(--o-color); }
#score-draw .score-value { color: var(--win-glow); }

.tab-hint { font-size: 0.78rem; color: var(--muted); text-align: center; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .screen { padding: 20px 12px; gap: 16px; }
  .lobby-form { padding: 16px; }
}
