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

:root {
  --bg: #07111f;
  --bg-glow: #12233d;
  --surface: rgba(15, 23, 42, 0.88);
  --surface-strong: rgba(30, 41, 59, 0.96);
  --border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --x-color: #fb7185;
  --o-color: #60a5fa;
  --accent: #8b5cf6;
  --success: #22c55e;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --cell-size: min(24vw, 112px);
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(96, 165, 250, 0.18), transparent 32%),
    radial-gradient(circle at bottom left, rgba(244, 114, 182, 0.14), transparent 28%),
    linear-gradient(160deg, var(--bg-glow), var(--bg));
  color: var(--text);
}

body {
  min-height: 100dvh;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.game-card {
  width: min(100%, 560px);
  padding: 28px;
  border-radius: 28px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.9));
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.hero {
  text-align: center;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--x-color), var(--accent), var(--o-color));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  margin: 12px auto 0;
  max-width: 44ch;
  color: var(--muted);
  line-height: 1.55;
}

.toolbar {
  display: grid;
  gap: 14px;
}

.control-block {
  display: grid;
  gap: 8px;
}

.control-label {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.segment-group {
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.segment {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.segment:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.segment.active {
  color: white;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.55), rgba(59, 130, 246, 0.4));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.meta-row {
  margin: 18px 0 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.status-chip {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}

.status-chip.subtle {
  color: var(--muted);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.score {
  padding: 16px 12px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  text-align: center;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.score.active-x {
  border-color: rgba(251, 113, 133, 0.65);
  box-shadow: 0 0 0 1px rgba(251, 113, 133, 0.25), 0 10px 28px rgba(251, 113, 133, 0.12);
}

.score.active-o {
  border-color: rgba(96, 165, 250, 0.65);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.25), 0 10px 28px rgba(96, 165, 250, 0.12);
}

.player-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.player-label.x {
  color: var(--x-color);
}

.player-label.o {
  color: var(--o-color);
}

.score-value {
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 800;
}

.status {
  min-height: 1.6rem;
  margin-bottom: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
}

.status.win {
  color: #86efac;
  font-weight: 700;
}

.status.draw {
  color: #cbd5e1;
}

.status.thinking {
  color: #bfdbfe;
}

.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, var(--cell-size));
  gap: 10px;
  padding: 12px;
  border-radius: 24px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.96));
  color: var(--text);
  font-size: calc(var(--cell-size) * 0.42);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
}

.cell:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(139, 92, 246, 0.45);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.35);
}

.cell:active:not(:disabled) {
  transform: scale(0.97);
}

.cell[data-mark="X"] {
  color: var(--x-color);
  text-shadow: 0 0 22px rgba(251, 113, 133, 0.16);
}

.cell[data-mark="O"] {
  color: var(--o-color);
  text-shadow: 0 0 22px rgba(96, 165, 250, 0.16);
}

.cell.winning {
  border-color: rgba(34, 197, 94, 0.75);
  background: linear-gradient(180deg, rgba(20, 83, 45, 0.95), rgba(22, 101, 52, 0.8));
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.28), 0 0 28px rgba(34, 197, 94, 0.15);
}

.action-row {
  display: flex;
  gap: 12px;
}

.restart-btn {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 16px;
  color: var(--text);
  background: rgba(30, 41, 59, 0.9);
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}

.restart-btn:hover {
  transform: translateY(-1px);
  background: rgba(51, 65, 85, 0.95);
}

.restart-btn.primary {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.92), rgba(59, 130, 246, 0.92));
  border-color: transparent;
}

.hidden {
  display: none;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 16px;
  }

  .game-card {
    padding: 20px;
    border-radius: 22px;
  }

  .scoreboard {
    gap: 10px;
  }

  .action-row {
    flex-direction: column;
  }

  :root {
    --cell-size: min(26vw, 94px);
  }
}
