:root {
  color-scheme: light;
  --bg: radial-gradient(circle at top left, #9ec0f8 0%, #c3defa 35%, #f8fbff 100%);
  --surface: rgba(255, 255, 255, 0.74);
  --surface-strong: rgba(227, 236, 251, 0.95);
  --text: #122033;
  --muted: #64748b;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-x: #2563eb;
  --accent-o: #f97316;
  --border: rgba(99, 102, 241, 0.16);
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: radial-gradient(circle at top left, #14213d 0%, #10182b 35%, #060b16 100%);
  --surface: rgba(9, 17, 33, 0.72);
  --surface-strong: rgba(15, 23, 42, 0.95);
  --text: #f8fafc;
  --muted: #c2cedb;
  --accent: #818cf8;
  --accent-2: #a78bfa;
  --accent-x: #60a5fa;
  --accent-o: #fb923c;
  --border: rgba(129, 140, 248, 0.2);
  --shadow: 0 22px 45px rgba(2, 6, 23, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background: var(--bg);
  transition: background 0.3s ease, color 0.3s ease;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 1120px);
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 1.5rem;
  align-items: stretch;
  min-height: 70vh;
}

.glass-panel {
  background: var(--surface);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 1.75rem;
  box-shadow: var(--shadow);
}

.info-panel {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.2rem;
  gap: 0.75rem;
  min-height: 0;
}

.brand-block h1 {
  margin: 0.2rem 0 0.4rem;
  font-size: clamp(2rem, 3vw, 2.8rem);
}

.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.subtitle {
  margin: 0;
  line-height: 1.65;
  color: var(--muted);
  max-width: 36rem;
}

.status-card {
  padding: 0.8rem 0.95rem;
  border-radius: 1rem;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.player-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.status-text {
  margin: 0;
  color: var(--text);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.score-card {
  padding: 0.7rem 0.6rem;
  border-radius: 0.9rem;
  text-align: center;
  background: var(--surface-strong);
  border: 1px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.score-card.active {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.score-card span {
  display: block;
  margin-bottom: 0.2rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.score-card strong {
  font-size: 1rem;
  color: var(--text);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.72rem 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.16);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
}

.btn-secondary {
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--border);
}

.game-panel {
  padding: 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 70vh;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel-head h2 {
  margin: 0.2rem 0 0;
  font-size: 1.2rem;
}

.theme-toggle {
  border: none;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.3s ease;
}

.theme-toggle:hover {
  transform: translateY(-2px);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  padding: 0.25rem;
}

.cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 1.1rem;
  background: var(--surface-strong);
  color: var(--text);
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 10px 24px rgba(15, 23, 42, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  cursor: pointer;
}

.cell:hover {
  transform: translateY(-2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 16px 28px rgba(15, 23, 42, 0.14);
}

.cell:active {
  transform: scale(0.96);
}

.cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.cell.x {
  color: var(--accent-x);
}

.cell.o {
  color: var(--accent-o);
}

.cell.winning {
  animation: pulse 0.7s ease-in-out infinite alternate;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.035);
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .game-panel {
    min-height: auto;
  }
}

@media (max-width: 580px) {
  body {
    padding: 1rem;
  }

  .info-panel,
  .game-panel {
    padding: 1rem;
  }

  .actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .scoreboard {
    grid-template-columns: 1fr;
  }
}
