:root {
  --bg: #f4efe6;
  --bg-accent: #d8e3d2;
  --bg-glow-1: rgba(255, 122, 89, 0.24);
  --bg-glow-2: rgba(94, 140, 106, 0.28);
  --surface: rgba(16, 32, 39, 0.9);
  --surface-soft: rgba(255, 255, 255, 0.08);
  --text: #f6f3ec;
  --muted: #d8d2c7;
  --ink: #102027;
  --accent: #ff7a59;
  --accent-dark: #d85636;
  --line: rgba(255, 255, 255, 0.12);
  --topbar: rgba(16, 32, 39, 0.82);
  --link: #ffd1c6;
  --footer: rgba(16, 32, 39, 0.7);
  --eyebrow: #f5b39d;
  --toggle-bg: rgba(255, 255, 255, 0.08);
  --toggle-border: rgba(255, 255, 255, 0.14);
}

:root[data-theme="nightfall"] {
  --bg: #09131d;
  --bg-accent: #16273a;
  --bg-glow-1: rgba(46, 212, 191, 0.18);
  --bg-glow-2: rgba(255, 212, 102, 0.14);
  --surface: rgba(6, 15, 24, 0.88);
  --surface-soft: rgba(151, 212, 255, 0.08);
  --text: #eef6ff;
  --muted: #a8c0d5;
  --ink: #d6e4f0;
  --accent: #2ed4bf;
  --accent-dark: #1aa896;
  --line: rgba(151, 212, 255, 0.14);
  --topbar: rgba(4, 11, 18, 0.88);
  --link: #8ae5d8;
  --footer: rgba(220, 236, 250, 0.68);
  --eyebrow: #7ae7d7;
  --toggle-bg: rgba(46, 212, 191, 0.12);
  --toggle-border: rgba(46, 212, 191, 0.3);
}

html {
  font-size: 16px;
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, var(--bg-glow-1), transparent 28%),
    radial-gradient(circle at bottom right, var(--bg-glow-2), transparent 30%),
    linear-gradient(135deg, var(--bg), var(--bg-accent));
}

.page-shell {
  padding-bottom: 4rem;
}

.topbar {
  background: var(--topbar);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.navbar-brand,
.nav-link {
  color: var(--text) !important;
}

.nav-link {
  opacity: 0.85;
}

.nav-link:hover {
  opacity: 1;
}

.theme-toggle {
  border: 1px solid var(--toggle-border);
  background: var(--toggle-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  line-height: 1;
  min-width: 112px;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.hero-panel,
.surface-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 30px 80px rgba(16, 32, 39, 0.18);
}

.hero-panel {
  padding: 3rem;
  display: grid;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.hero-panel h1,
.page-head h1 {
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1;
  margin: 0;
  max-width: 12ch;
}

.hero-copy,
.subtle-copy,
.stack-item span,
.session-meta span,
.session-meta small,
.empty-state {
  color: var(--muted);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.8rem;
  color: var(--eyebrow);
  margin-bottom: 0.5rem;
}

.hero-actions,
.section-heading,
.page-head,
.player-strip,
.session-row {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.dashboard-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.lobby-grid,
.game-grid {
  align-items: start;
}

.surface-card {
  padding: 1.5rem;
}

.stack-list {
  display: grid;
  gap: 0.9rem;
}

.stack-item,
.session-row {
  padding: 1rem 1.1rem;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stack-item,
.session-meta {
  display: grid;
  gap: 0.2rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.btn-accent,
.btn-accent:hover,
.btn-accent:focus {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.btn-outline-light {
  border-color: rgba(255, 255, 255, 0.4);
}

.form-stack,
.inline-join-form {
  display: grid;
  gap: 0.9rem;
}

.inline-join-form {
  grid-template-columns: minmax(120px, 1fr) auto;
  align-items: center;
}

.form-control {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
}

.form-control::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.form-control:focus,
.btn:focus,
.btn:active:focus {
  box-shadow: 0 0 0 0.2rem rgba(255, 122, 89, 0.3);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 110px));
  gap: 0.8rem;
  margin-top: 1.25rem;
  justify-content: center;
}

.board-cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: clamp(2rem, 7vw, 3.4rem);
  font-weight: 700;
  transition: transform 140ms ease, background 140ms ease;
}

.board-cell:not(:disabled):hover {
  transform: translateY(-2px);
  background: rgba(255, 122, 89, 0.2);
}

.board-cell:disabled {
  cursor: default;
  opacity: 0.92;
}

.history-list {
  padding-left: 1.2rem;
  display: grid;
  gap: 0.75rem;
}

.spectator-panel {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.game-finish-panel {
  margin-top: 1.5rem;
  padding: 1.25rem;
  border-radius: 20px;
  background: rgba(255, 122, 89, 0.12);
  border: 1px solid rgba(255, 122, 89, 0.28);
}

.finish-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.is-hidden {
  display: none;
}

.session-badges {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.leaderboard-table {
  color: var(--text);
  margin: 0;
}

.leaderboard-table th,
.leaderboard-table td {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.08);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: white;
}

.footer {
  padding: 1.5rem 0 2rem;
  color: var(--footer);
}

@media (max-width: 767px) {
  .page-shell {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .hero-panel,
  .surface-card {
    border-radius: 22px;
    padding: 1.15rem;
  }

  .hero-panel,
  .surface-card,
  .session-row,
  .page-head,
  .player-strip,
  .section-heading,
  .inline-join-form {
    display: grid;
  }

  .board-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .board-cell {
    min-height: 84px;
    border-radius: 18px;
    font-size: clamp(2rem, 12vw, 3rem);
  }

  .inline-join-form,
  .finish-actions {
    grid-template-columns: 1fr;
  }

  .finish-actions .btn,
  .inline-join-form .btn,
  .inline-join-form .form-control {
    width: 100%;
  }

  .page-head h1,
  .hero-panel h1 {
    max-width: none;
  }

  .status-pill,
  .session-badges {
    justify-content: flex-start;
  }

  .theme-toggle {
    margin-top: 0.5rem;
    width: 100%;
  }
}
