:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-end: #02070f;
  --bg-soft: #0e1727;
  --panel: rgba(10, 19, 34, 0.84);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f7fb;
  --muted: #93a1b8;
  --accent: #f5b942;
  --accent-strong: #ff7a18;
  --green: #4ade80;

  /* Board square colors -- "classic" (this site's original gray-blue
     pairing) is the default with no data attribute, so every board
     already using var(--square-light)/var(--square-dark) keeps looking
     exactly as it did before this existed. Set server-side via
     data-board-theme on <html> (see app.py's inject_appearance) so
     there's no flash of the wrong theme on load. */
  --square-light: #e8eaf0;
  --square-dark: #4b5266;
}

:root[data-board-theme="green"] {
  --square-light: #ebecd0;
  --square-dark: #779556;
}

:root[data-board-theme="brown"] {
  --square-light: #f0d9b5;
  --square-dark: #b58863;
}

:root[data-board-theme="blue"] {
  --square-light: #dee3e6;
  --square-dark: #8ca2ad;
}

:root[data-board-theme="walnut"] {
  --square-light: #d9c4a3;
  --square-dark: #7c5a3a;
}

:root[data-board-theme="coral"] {
  --square-light: #ffe8db;
  --square-dark: #e2725b;
}

:root[data-board-theme="ice"] {
  --square-light: #f2f9ff;
  --square-dark: #7fa8c9;
}

:root[data-board-theme="lavender"] {
  --square-light: #ece4f7;
  --square-dark: #8868b3;
}

:root[data-board-theme="sand"] {
  --square-light: #f0e6d2;
  --square-dark: #c19a6b;
}

:root[data-board-theme="mint"] {
  --square-light: #e3f7ee;
  --square-dark: #4f9a7d;
}

:root[data-board-theme="slate"] {
  --square-light: #d8dee3;
  --square-dark: #52616f;
}

:root[data-board-theme="rose"] {
  --square-light: #f8dde3;
  --square-dark: #b5495b;
}

:root[data-board-theme="midnight"] {
  --square-light: #3b4252;
  --square-dark: #1c212b;
}

:root[data-board-theme="sunset"] {
  --square-light: #ffd9a0;
  --square-dark: #d1652f;
}

/* Desk (page background) themes -- "classic" is this site's original
   near-black navy and is the default with no data attribute. Only
   --bg/--bg-end change: card/panel colors across the site (profile.css's
   --pf-card, admin.css's --admin-card, etc.) are already dark enough to
   read fine over any of these without their own per-theme overrides, so
   this stays scoped to the body gradient rather than a much larger
   refactor. Set server-side via data-desk-theme on <html> (see app.py's
   inject_appearance), same as data-board-theme above. */
:root[data-desk-theme="charcoal"] {
  --bg: #1c1c1c;
  --bg-end: #0a0a0a;
}

:root[data-desk-theme="forest"] {
  --bg: #0b1f16;
  --bg-end: #030a07;
}

:root[data-desk-theme="wine"] {
  --bg: #200c14;
  --bg-end: #0a0306;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(245, 185, 66, 0.18), transparent 25%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-end) 100%);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent);
  pointer-events: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(240px, 280px) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 30px 22px;
  border-right: 1px solid var(--border);
  background: rgba(5, 10, 18, 0.72);
  backdrop-filter: blur(24px);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* Mobile nav: hamburger (in .topbar) + off-canvas drawer + backdrop.
   All three are no-ops above the 960px breakpoint below, where the
   sidebar is already always visible as a real column -- see
   mobile-nav.js for the open/close toggle. */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.mobile-menu-btn:hover {
  border-color: var(--accent);
}

.sidebar-close-btn {
  display: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.sidebar-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 30px;
}

a.brand {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: opacity 150ms ease;
}

a.brand:hover {
  opacity: 0.85;
}

/* Topbar user chip is a link to /profile on every page except settings
   (which keeps the Log out button instead) -- see backend/templates/*.html
   and .user-chip's own box styling in dashboard.css. */
a.user-chip {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: opacity 150ms ease;
}

a.user-chip:hover {
  opacity: 0.75;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #111;
  font-size: 1.2rem;
  font-weight: 700;
  box-shadow: 0 14px 28px rgba(245, 185, 66, 0.25);
}

/* Fixed px, not %: the .brand-mark parent is display:grid with
   place-items:center, and percentage height doesn't reliably resolve
   against a grid item's box in that combination -- it was rendering
   taller than the parent itself and throwing off the centering. */
.brand-mark img {
  width: 33px;
  height: 33px;
  object-fit: contain;
  display: block;
}

.legal-brand .brand-mark img {
  width: 27px;
  height: 27px;
}

/* Already inherits font-weight:800 (Manrope's heaviest cut -- it has
   no 900) from the brand text around it, but red reads visually
   thinner than white at the same weight against a dark background.
   The stroke fakes extra weight to compensate. */
.brand-red {
  color: #ff0000;
  -webkit-text-stroke: 0.5px #ff0000;
}

.brand-gold {
  color: var(--text);
  text-transform: none;
  font-size: 0.7em;
  font-weight: 600;
}

.brand h1,
.legal-brand span {
  font-family: "Manrope", Inter, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1.3rem;
  font-weight: 800;
  text-transform: uppercase;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.brand h1 {
  margin: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: transform 180ms ease, background 180ms ease;
}

.nav-links a:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateX(2px);
}

.nav-icon {
  width: 24px;
  text-align: center;
  color: var(--accent);
}

.sidebar-footer {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.sidebar-legal {
  margin-top: 10px;
  font-size: 0.82rem;
}

.sidebar-legal a {
  color: var(--muted);
  text-decoration: none;
}

.sidebar-legal a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- Shared layout for standalone content pages (credits, privacy) ---------- */

.legal-shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.legal-back:hover {
  color: var(--accent);
}

.legal-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.legal-brand .brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.legal-brand span {
  color: var(--text);
}

.legal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 40px;
}

.legal-card h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
}

.legal-card .legal-updated {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 28px;
}

.legal-card h2 {
  font-size: 1.05rem;
  margin: 32px 0 10px;
}

.legal-card h2:first-of-type {
  margin-top: 0;
}

.legal-card p,
.legal-card li {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.65;
}

.legal-card ul {
  margin: 8px 0;
  padding-left: 20px;
}

.legal-card a {
  color: var(--accent);
}

.legal-card strong {
  color: var(--text);
}

.credit-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.credit-item:last-child {
  border-bottom: none;
}

.credit-item h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
}

.credit-item p {
  margin: 0;
}

.credit-item .credit-license {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(245, 185, 66, 0.14);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
}

.main-panel {
  display: flex;
  flex-direction: column;
  padding: 24px 36px 36px;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 28px;
}

.topbar-spacer {
  flex: 1;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 18px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #111;
  box-shadow: 0 15px 30px rgba(245, 185, 66, 0.2);
}

.secondary-btn,
.ghost-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}

.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
}

.hero {
  flex: 1;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  align-items: center;
  gap: 30px;
}

.hero-copy {
  max-width: 560px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.9rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  font-weight: 700;
}

.hero h2 {
  margin: 0 0 16px;
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 1.1;
}

.hero-text {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.75;
}

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

.hero-media {
  display: flex;
  justify-content: center;
}

.board-wrapper {
  position: relative;
  width: min(100%, 520px);
  padding: 18px;
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255,255,255,0.09), rgba(255,255,255,0.04));
  border: 1px solid var(--border);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.28);
}

.board-glow {
  position: absolute;
  inset: 20px;
  border-radius: 24px;
  background: radial-gradient(circle, rgba(245, 185, 66, 0.18), transparent 62%);
  z-index: 0;
  animation: glowPulse 3.2s ease-in-out infinite alternate;
}

.board {
  position: relative;
  aspect-ratio: 1;
  /* No overflow:hidden -- a rounded, clipped container with filtered/
     GPU-layered children (.piece-el below) is a confirmed real trigger
     for a Chromium/GPU-driver bug that paints the whole area solid black
     on some hardware -- see the matching fix in bots.css/puzzles.css. */
  border-radius: 14px;
  border: 4px solid #23262f;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 20px 40px rgba(0, 0, 0, 0.35);
  background: #23262f;
  z-index: 1;
}

/* Squares are built once and never resized/rescaled — only the pieces
   layer on top of them animates, so the grid stays perfectly stable. */
.squares-layer {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}

.square {
  position: relative;
  min-height: 0;
  min-width: 0;
}

.square.dark {
  background: var(--square-dark, #4b5266);
}

.square.light {
  background: var(--square-light, #e8eaf0);
}

.square.from-highlight::after,
.square.to-highlight::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(120, 190, 255, 0.22);
  pointer-events: none;
}

.square.to-highlight::after {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.4);
}

.coord-rank,
.coord-file {
  position: absolute;
  font-family: Inter, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  color: #8a99ad;
  pointer-events: none;
  line-height: 1;
}

.coord-rank {
  top: 4px;
  left: 5px;
}

.coord-file {
  bottom: 4px;
  right: 5px;
}

/* Pieces are persistent DOM nodes positioned by percentage, so a move
   just slides left/top — never a resize, never a re-render. */
.pieces-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* Piece look itself (background-image via "wK"/"bP" classes) comes from
   css/pieces-cburnett.css; this just handles position/slide/opacity. */
.piece-el {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  transition: left 0.5s cubic-bezier(0.22, 0.61, 0.36, 1), top 0.5s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.35s ease;
  /* No filter/drop-shadow -- see the matching removal in bots.css. */
}

.piece-el.is-resetting {
  opacity: 0;
}

.board-caption {
  position: relative;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
  font-size: 0.95rem;
  z-index: 1;
}

@keyframes glowPulse {
  from { transform: scale(0.97); opacity: 0.65; }
  to { transform: scale(1.02); opacity: 1; }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  /* Off-canvas drawer instead of stacking the full nav above the page
     content -- previously .sidebar just went position:static here,
     which meant every nav link (Play/Puzzles/Learn/Train/Watch/
     Profile/Leaderboard/Coaching/Other) plus the footer rendered in
     full before any actual page content, so reaching the board, the
     Resign button, or anything else meant scrolling past the entire
     nav first every time. */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(280px, 82vw);
    height: 100vh;
    height: 100dvh;
    border-right: 1px solid var(--border);
    border-bottom: none;
    transform: translateX(-100%);
    transition: transform 240ms ease;
    z-index: 100;
    overflow-y: auto;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .sidebar-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    width: 32px;
    height: 32px;
    margin-bottom: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
  }

  .sidebar-backdrop {
    display: block;
  }

  .hero {
    grid-template-columns: 1fr;
    padding-top: 10px;
  }

  .hero-copy {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .main-panel {
    padding: 20px;
  }

  .topbar {
    justify-content: flex-start;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .board-wrapper {
    padding: 10px;
  }
}

/* Shared #toast (see frontend/js/toast.js) -- every page that loads
   toast.js needs this. Previously only defined in auth.css, so every
   other page's <div class="toast"> rendered with no positioning/
   background at all: showToast() still ran, but the message appeared
   unstyled and out of flow at the bottom of the DOM instead of as a
   floating notification -- invisible in practice. styles.css loads on
   every page, so defining it once here covers all of them. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 12px);
  padding: 14px 22px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.4);
  opacity: 0;
  z-index: 2000;
  transition: opacity 220ms ease, transform 220ms ease;
}

.toast[hidden] {
  display: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
