/* ── Reset & Base ────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  overflow-x: clip;
}

.hidden {
  display: none !important;
}

/* ── Loading Spinner ─────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.4rem;
  flex-shrink: 0;
}

.spinner-sm {
  width: 10px;
  height: 10px;
  border-width: 1.5px;
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Confirm Modal (shared) ───────────────────────── */
.confirm-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.confirm-modal-overlay.hidden {
  display: none;
}

.confirm-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.confirm-modal-message {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.confirm-modal-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
}

.confirm-modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.confirm-leave-btn {
  background: var(--red) !important;
  border-color: var(--red) !important;
  color: #fff !important;
}

/* ── Form Inputs ────────────────────────────────── */
.text-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-family: var(--font);
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  transition: border-color 0.2s;
}

.text-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 8px var(--red-faint);
}

.text-input option {
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
}

select.text-input {
  color: var(--text);
  font-family: var(--font);
}

/* ── Shared Form Styles ──────────────────────────── */
.input-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  letter-spacing: 0.05em;
}

.input-subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
}

.input-row-half {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.input-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.input-with-btn {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.input-with-btn .text-input {
  flex: 1;
}

:root {
  --red: #ff0a2b;
  --red-dim: #cc0822;
  --red-glow: rgba(255, 10, 43, 0.6);
  --red-subtle: rgba(255, 10, 43, 0.15);
  --red-faint: rgba(255, 10, 43, 0.06);
  --bg: #0a0a0c;
  --bg-card: #0f0f13;
  --bg-elevated: #141418;
  --border: rgba(255, 10, 43, 0.12);
  --border-hover: rgba(255, 10, 43, 0.3);
  --text: #e8e6e3;
  --text-dim: #6b6a6a;
  --text-muted: #3a3939;
  --font: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  /* Board square colors (overridden by board themes) */
  --sq-light: #2a2836;
  --sq-dark: #1a1824;
  --sq-highlight: rgba(255, 10, 43, 0.18);
}

/* ── Board Themes ───────────────────────────────── */
.board-theme-classic { --sq-light: #eeeed2; --sq-dark: #769656; --sq-highlight: rgba(255, 255, 0, 0.4); }
.board-theme-wood { --sq-light: #e8c99b; --sq-dark: #a67c52; --sq-highlight: rgba(255, 200, 0, 0.35); }
.board-theme-ice { --sq-light: #d6e4f0; --sq-dark: #7ea8c8; --sq-highlight: rgba(100, 200, 255, 0.35); }
.board-theme-monokai { --sq-light: #3e3d32; --sq-dark: #272822; --sq-highlight: rgba(166, 226, 46, 0.25); }
.board-theme-walnut { --sq-light: #c9a66b; --sq-dark: #6b4226; --sq-highlight: rgba(255, 180, 0, 0.35); }

/* ── Piece Color Schemes ───────────────────────── */
/* default: no filter — uses native SVG colors (red/white for cburnett) */

/* Midnight: black / silver */
.piece-colors-midnight .black-piece  { filter: saturate(0) brightness(0.25) drop-shadow(0 1px 3px rgba(0,0,0,0.4)) !important; }
.piece-colors-midnight .piece-img:not(.black-piece) { filter: saturate(0) brightness(1.4) drop-shadow(0 1px 3px rgba(0,0,0,0.5)) !important; }

/* Ocean: blue / ivory */
.piece-colors-ocean .black-piece  { filter: hue-rotate(200deg) saturate(1.8) brightness(0.9) drop-shadow(0 1px 3px rgba(0,0,0,0.4)) !important; }
.piece-colors-ocean .piece-img:not(.black-piece) { filter: sepia(0.3) saturate(0.3) brightness(1.4) drop-shadow(0 1px 3px rgba(0,0,0,0.5)) !important; }

/* Emerald: green / cream */
.piece-colors-emerald .black-piece  { filter: hue-rotate(130deg) saturate(1.4) brightness(0.85) drop-shadow(0 1px 3px rgba(0,0,0,0.4)) !important; }
.piece-colors-emerald .piece-img:not(.black-piece) { filter: sepia(0.4) saturate(0.4) brightness(1.4) drop-shadow(0 1px 3px rgba(0,0,0,0.5)) !important; }

/* Royal: purple / gold */
.piece-colors-royal .black-piece  { filter: hue-rotate(280deg) saturate(1.6) brightness(0.9) drop-shadow(0 1px 3px rgba(0,0,0,0.4)) !important; }
.piece-colors-royal .piece-img:not(.black-piece) { filter: sepia(1) saturate(3) hue-rotate(15deg) brightness(1.1) drop-shadow(0 1px 3px rgba(0,0,0,0.5)) !important; }

/* Gold: gold / ebony */
.piece-colors-gold .black-piece  { filter: sepia(1) saturate(3) hue-rotate(15deg) brightness(1.1) drop-shadow(0 1px 3px rgba(0,0,0,0.4)) !important; }
.piece-colors-gold .piece-img:not(.black-piece) { filter: saturate(0) brightness(0.3) drop-shadow(0 1px 3px rgba(0,0,0,0.5)) !important; }

/* Light theme overrides */
.light-theme {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-elevated: #eaeaea;
  --border: rgba(200, 20, 40, 0.15);
  --border-hover: rgba(200, 20, 40, 0.35);
  --text: #1a1a1a;
  --text-dim: #555555;
  --text-muted: #999999;
  --red: #cc0822;
  --red-dim: #a00618;
  --red-glow: rgba(200, 10, 35, 0.3);
  --red-subtle: rgba(200, 10, 35, 0.08);
  --red-faint: rgba(200, 10, 35, 0.04);
}

.light-theme .scanlines,
.light-theme .vignette {
  display: none;
}

.light-theme .nav {
  background: rgba(245, 245, 245, 0.92);
  border-bottom-color: rgba(0, 0, 0, 0.1);
}

.light-theme .nav-link {
  color: var(--text-dim);
}

.light-theme .nav-link.nav-link-active {
  color: var(--red);
}

.light-theme .nav-user-toggle {
  color: var(--text);
}

.light-theme .nav-logo .logo-text {
  color: var(--text);
}

.light-theme .nav-dropdown {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.light-theme .nav-dropdown-item {
  color: var(--text);
}

.light-theme .nav-dropdown-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.light-theme .nav-dropdown-item.nav-link-active {
  color: var(--red);
}

.light-theme .nav-hamburger {
  color: var(--text);
}

@media (max-width: 768px) {
  .light-theme .nav-links {
    background: rgba(245, 245, 245, 0.97);
    border-bottom-color: rgba(0, 0, 0, 0.1);
  }
}

/* Light theme: hero and general overrides */
.light-theme .hero::before {
  opacity: 0.3;
}

.light-theme .hero-review {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.1);
}

.light-theme .game-card-glow {
  display: none;
}

.light-theme .hero-title {
  color: var(--red);
  text-shadow: none;
}

.light-theme .glitch::before,
.light-theme .glitch::after {
  display: none;
}

.light-theme .hero-comment {
  background: rgba(0, 0, 0, 0.03);
}

.light-theme .board-btn {
  background: var(--bg-card);
  color: var(--text-dim);
  border-color: rgba(0, 0, 0, 0.15);
}

.light-theme .btn-primary {
  background: var(--red);
  color: #fff;
}

.light-theme .btn-ghost {
  color: var(--text-dim);
  border-color: rgba(0, 0, 0, 0.15);
}

.light-theme .game-header {
  background: var(--bg-elevated);
}

.light-theme .eval-bar,
.light-theme .hero-eval-bar,
.light-theme .coach-eval-bar,
.light-theme .analysis-eval-bar {
  background: #ddd;
  border-color: rgba(0, 0, 0, 0.1);
}

.light-theme .feature-card {
  background: var(--bg-card);
  border-color: rgba(0, 0, 0, 0.08);
}

.light-theme .feature-icon {
  color: var(--red);
}

.light-theme .pipeline-step .step-number {
  color: var(--red);
}

.light-theme .footer {
  border-top-color: rgba(0, 0, 0, 0.1);
}

.light-theme .text-dim {
  color: var(--text-dim);
}

.light-theme a:not(.btn):not(.nav-link):not(.nav-logo):not(.nav-dropdown-item) {
  color: var(--text-dim);
}

.light-theme a:not(.btn):not(.nav-link):not(.nav-logo):not(.nav-dropdown-item):hover {
  color: var(--red);
}

/* Light theme uses classic board by default, but board-theme-* classes take precedence */
.light-theme:not([class*="board-theme-"]) { --sq-light: #eeeed2; --sq-dark: #769656; --sq-highlight: rgba(255, 255, 0, 0.4); }

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow-x: clip;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Overlays ────────────────────────────────────── */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(0, 0, 0, 0.5) 100%
  );
}

/* ── Navigation ──────────────────────────────────── */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 3rem;
  background: rgba(10, 10, 12, 0.95);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
  max-width: 100vw;
  overflow: visible;
}

.nav-logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-decoration: none;
}

.logo-bracket {
  color: var(--red);
  text-shadow: 0 0 20px var(--red-glow);
}

.logo-text {
  color: var(--text);
  margin: 0 0.3rem;
}

.logo-version {
  font-size: 0.55em;
  font-weight: 400;
  color: var(--text-dim);
  margin-left: 0.3rem;
  letter-spacing: 0.05em;
  vertical-align: super;
}

.nav-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
}

.nav-links {
  display: flex;
  align-items: baseline;
  gap: 2rem;
}

.nav-link {
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  transition: color 0.3s, text-shadow 0.3s;
}


.nav-link:hover {
  color: var(--red);
  text-shadow: 0 0 15px var(--red-glow);
}

.nav-link.nav-link-active {
  color: var(--red);
  text-shadow: 0 0 10px var(--red-glow);
}

.nav-user-dropdown {
  position: relative;
}

.nav-user-toggle {
  background: none;
  border: none;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}

.nav-user-toggle:hover {
  color: var(--red);
}

.nav-caret {
  font-size: 0.6rem;
  margin-left: 0.1rem;
}

.nav-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: #141418;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0;
  min-width: 140px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 200;
}

.nav-dropdown.hidden {
  display: none;
}

.nav-dropdown-item {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  transition: color 0.2s, background 0.2s;
}

.nav-dropdown-item:hover {
  color: var(--red);
  background: rgba(255, 255, 255, 0.03);
}

.nav-dropdown-item.nav-link-active {
  color: var(--red);
}

/* ── Auth Modal ─────────────────────────────────── */

.auth-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.auth-modal-overlay.hidden {
  display: none;
}

.auth-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  width: 380px;
  max-width: 90vw;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px var(--red-faint);
}

.auth-modal-close {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.auth-modal-close:hover {
  color: var(--text);
}

.auth-modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.2rem;
  letter-spacing: 0.05em;
}

.auth-modal-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  padding: 0.5rem 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.auth-tab.active {
  color: var(--red);
  border-bottom-color: var(--red);
}

.auth-tab:hover {
  color: var(--text);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-field label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  letter-spacing: 0.05em;
}

.password-input-wrap {
  position: relative;
  display: flex;
}

.password-input-wrap .text-input {
  flex: 1;
  padding-right: 2.5rem;
}

.password-toggle {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem;
  color: var(--text-dim);
  opacity: 0.5;
  transition: opacity 0.2s, color 0.2s;
  line-height: 1;
}

.password-toggle:hover {
  opacity: 1;
  color: var(--red);
}

.auth-hint {
  font-size: 0.68rem;
  margin-top: 0.25rem;
}

.auth-hint-error {
  color: var(--red);
}

.auth-password-strength {
  font-size: 0.68rem;
  margin-top: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.strength-bar {
  display: inline-block;
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.strength-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  transition: width 0.2s, background 0.2s;
}

.auth-error {
  color: var(--red);
  font-size: 0.72rem;
  padding: 0.5rem;
  border: 1px solid var(--red-dim);
  background: var(--red-faint);
  border-radius: 4px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
}

/* Inline link-style buttons used in the post-register recovery copy
   ("Resend" / "Log in instead"). Visually a link, semantically a
   button so click handlers attach cleanly. */
.auth-link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--red);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.auth-link-btn:hover:not(:disabled) {
  filter: brightness(1.15);
}

.auth-link-btn:disabled {
  opacity: 0.6;
  cursor: default;
  text-decoration: none;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.2rem 0;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-oauth {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-oauth-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  font-size: 0.75rem;
  padding: 0.6rem;
  text-decoration: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  transition: border-color 0.2s, color 0.2s;
}

.oauth-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  position: relative;
  top: -1px;
}

.auth-oauth-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* ── Hero ────────────────────────────────────────── */
.hero {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 8rem 3rem 4rem;
  gap: 4rem;
  position: relative;
}

.hero::before {
  content: '';
  position: absolute;
  top: 20%;
  left: -10%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, var(--red-subtle) 0%, transparent 70%);
  filter: blur(80px);
  pointer-events: none;
}


/* ── Glitch Title ─────────────────────────────────── */
.hero-title {
  font-size: clamp(4rem, 10vw, 8rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.05em;
  margin-bottom: 1.5rem;
  position: relative;
  color: var(--red);
  text-shadow:
    0 0 40px var(--red-glow),
    0 0 80px rgba(255, 10, 43, 0.3);
}

.glitch {
  animation: glitch-pulse 6s ease-in-out infinite;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.glitch::before {
  color: #ff0a2b;
  text-shadow: none;
  animation: glitch-top 3s infinite linear alternate-reverse;
  clip-path: inset(0 0 65% 0);
}

.glitch::after {
  color: #ff0a2b;
  text-shadow: none;
  animation: glitch-bottom 2.5s infinite linear alternate-reverse;
  clip-path: inset(65% 0 0 0);
}

@keyframes glitch-top {
  0%, 90%, 100% { transform: translate(0); }
  91% { transform: translate(-3px, -1px); }
  92% { transform: translate(3px, 1px); }
  93% { transform: translate(-2px, 0); }
  94% { transform: translate(0); }
}

@keyframes glitch-bottom {
  0%, 88%, 100% { transform: translate(0); }
  89% { transform: translate(4px, 1px); }
  90% { transform: translate(-3px, -1px); }
  91% { transform: translate(2px, 0); }
  92% { transform: translate(0); }
}

@keyframes glitch-pulse {
  0%, 100% {
    text-shadow:
      0 0 40px var(--red-glow),
      0 0 80px rgba(255, 10, 43, 0.3);
  }
  50% {
    text-shadow:
      0 0 60px var(--red-glow),
      0 0 120px rgba(255, 10, 43, 0.4),
      0 0 200px rgba(255, 10, 43, 0.15);
  }
}

/* Periodic heavy glitch burst */
.glitch-line {
  display: block;
  position: relative;
  animation: glitch-skew 4s infinite;
}

@keyframes glitch-skew {
  0%, 95%, 100% { transform: skew(0deg); filter: none; }
  96% { transform: skew(-2deg); filter: brightness(1.5) saturate(2); }
  97% { transform: skew(3deg); filter: brightness(0.8); }
  98% { transform: skew(-1deg); filter: brightness(1.3) hue-rotate(10deg); }
  99% { transform: skew(0deg); filter: none; }
}

/* Heavy glitch burst — triggered by JS */
.glitch-burst {
  animation: glitch-heavy 0.2s steps(2) !important;
}

.glitch-burst::before {
  animation: glitch-burst-before 0.2s steps(3) !important;
  text-shadow: none !important;
}

.glitch-burst::after {
  animation: glitch-burst-after 0.2s steps(3) !important;
  text-shadow: none !important;
}

@keyframes glitch-heavy {
  0% { transform: translate(0) skew(0deg); }
  25% { transform: translate(-5px, 2px) skew(-3deg); }
  50% { transform: translate(5px, -2px) skew(2deg); }
  75% { transform: translate(-3px, 1px) skew(-1deg); }
  100% { transform: translate(0) skew(0deg); }
}

@keyframes glitch-burst-before {
  0% { clip-path: inset(0 0 80% 0); transform: translate(-4px, -2px); }
  33% { clip-path: inset(20% 0 50% 0); transform: translate(4px, 1px); }
  66% { clip-path: inset(40% 0 20% 0); transform: translate(-3px, 0); }
  100% { clip-path: inset(0 0 65% 0); transform: translate(0); }
}

@keyframes glitch-burst-after {
  0% { clip-path: inset(70% 0 0 0); transform: translate(4px, 2px); }
  33% { clip-path: inset(50% 0 10% 0); transform: translate(-5px, -1px); }
  66% { clip-path: inset(60% 0 0 0); transform: translate(3px, 0); }
  100% { clip-path: inset(65% 0 0 0); transform: translate(0); }
}

.hero-subtitle {
  font-size: 1.1rem;
  font-weight: 300;
  color: var(--text-dim);
  margin-bottom: 2.5rem;
  line-height: 1.8;
}

.hero-subtitle .hero-line:last-child {
  display: block;
}

.text-dim {
  color: var(--text-dim);
}

.text-accent {
  color: var(--red);
  font-weight: 500;
  text-shadow: 0 0 10px var(--red-glow);
}

/* Stats */
.hero-stats {
  display: flex;
  gap: 2.5rem;
  margin-bottom: 2.5rem;
  padding: 1.2rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--red);
  text-shadow: 0 0 15px var(--red-glow);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Buttons */
.hero-actions {
  display: flex;
  gap: 1rem;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0.8rem 2rem;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

@media (hover: none), (pointer: coarse) {
  .btn:focus {
    outline: none;
    border-color: var(--border);
    box-shadow: none;
  }
}

.btn:focus-visible {
  border-color: var(--red);
}

.btn-primary {
  background: var(--red-faint);
  color: var(--red);
  border-color: var(--red-dim);
}

.btn-primary:hover {
  background: rgba(255, 10, 43, 0.15);
  border-color: var(--red);
  box-shadow:
    0 0 20px rgba(255, 10, 43, 0.3),
    inset 0 0 20px rgba(255, 10, 43, 0.05);
}

.btn-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--red-subtle), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
}

.btn-primary:hover .btn-glow {
  opacity: 1;
}

.btn-text {
  position: relative;
  z-index: 1;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-hover);
}

/* Compact button sized to sit next to a text input (Browse, Editor,
   etc.). Padding/font-size override the default .btn so the combo
   reads as "one input with an inline action". */
.btn-compact-input {
  white-space: nowrap;
  padding: 0.5rem 0.8rem;
  font-size: 0.7rem;
}

/* ── Collapsible "Settings" panel ─────────────────── */
/* Shared between the Review, Position Analysis, and Coach setup pages. Wraps
   secondary inputs (provider, depth, API key) behind a single
   full-width toggle button so the primary action (Analyze) stays
   prominent. Collapsed by default; open state rotates the caret
   and reveals the body. */
.primary-action-stack,
.review-sticky-actions {
  position: sticky;
  bottom: 1rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

.llm-config {
  width: 100%;
}

.llm-config-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.9rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.llm-config-toggle:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--red-faint);
}

.llm-config-caret {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.llm-config:not(.collapsed) .llm-config-caret {
  transform: rotate(90deg);
}

.llm-config:not(.collapsed) .llm-config-body {
  margin-top: 0.6rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.llm-config.collapsed .llm-config-body {
  display: none;
}

/* Primary submit button that spans the form width with centered text. */
.btn-primary-action,
.btn-analyze {
  width: 100%;
  justify-content: center;
  padding: 0.9rem;
  font-size: 0.9rem;
}

/* ── Top-level mode tabs ──────────────────────────── */
/* Sits just under the page title on the unified review page. Two-option
   segmented switcher (Game / Position) — JS toggles the matching panel
   without a reload. On the standalone analysis.html fallback, the
   inactive tab is still a plain link back to review.html. */
.mode-tabs {
  display: flex;
  gap: 0.4rem;
  margin: 0 0 1rem;
}

.mode-tab {
  flex: 1;
  padding: 0.6rem 1rem;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-align: center;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.mode-tab:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--red-faint);
}

.mode-tab.active {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-faint);
  cursor: default;
}

.mode-tab.active:hover {
  background: var(--red-faint);
}

/* ── Game Card Visual ─────────────────────────────── */
.hero-visual {
  display: flex;
  justify-content: center;
  align-items: center;
}

@media (min-width: 901px) and (max-width: 1300px) {
  .hero-content {
    padding-left: 0;
  }
  .hero-visual {
    padding-right: 0;
  }
  .hero-review {
    width: clamp(300px, calc(50vw - 6rem), 480px);
  }
}

@media (min-width: 1301px) {
  .hero-content {
    padding-left: 30%;
  }
  .hero-visual {
    padding-right: 30%;
  }
}

/* Shrink the hero panel only on genuinely short viewports, and keep the
   shrink mild so the board and text remain legible. Previously this
   kicked in at max-height: 1100px with zoom: 0.85, which affected
   virtually every laptop/desktop monitor. */
@media (min-width: 901px) and (max-height: 900px) {
  .hero-review { zoom: 0.9; }
}
@media (min-width: 901px) and (max-height: 750px) {
  .hero-review { zoom: 0.8; }
}
@media (min-width: 901px) and (max-height: 650px) {
  .hero-review { zoom: 0.7; }
}

.game-card {
  position: relative;
  width: 460px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 40px var(--red-faint),
    0 0 80px rgba(255, 10, 43, 0.05);
  animation: card-float 6s ease-in-out infinite;
}

/* Custom scrollbar */
.game-card::-webkit-scrollbar {
  width: 4px;
}
.game-card::-webkit-scrollbar-track {
  background: transparent;
}
.game-card::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 2px;
}

@keyframes card-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.game-card-glow {
  position: absolute;
  inset: -40px;
  background: radial-gradient(circle, var(--red-subtle) 0%, transparent 70%);
  filter: blur(50px);
  pointer-events: none;
  z-index: -1;
  animation: glow-breathe 5s ease-in-out infinite;
}

@keyframes glow-breathe {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.7; }
}

/* Card top accent line */
.game-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--red), transparent);
  border-radius: 8px 8px 0 0;
}

/* ── Hero Interactive Review ─────────────────────── */
.hero-review {
  position: relative;
  width: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 40px var(--red-faint);
}

.hero-game-selector {
  display: flex;
  gap: 0;
  margin-bottom: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.hero-game-tab {
  flex: 1;
  padding: 0.45rem 0.3rem;
  font-family: var(--font);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}

.hero-game-tab:last-child {
  border-right: none;
}

.hero-game-tab.active {
  background: var(--red-faint);
  color: var(--red);
}

.hero-game-tab:hover:not(.active) {
  background: var(--bg-elevated);
  color: var(--text);
}

.hero-review-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.hero-captured {
  display: inline-flex;
  align-items: center;
  gap: 1px;
}

.hero-captured-piece {
  width: 14px;
  height: 14px;
  object-fit: contain;
  opacity: 0.7;
}

.hero-review-players {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

/* Bump shared game-meta text sizes inside the hero demo so they read
   comfortably on desktop. Mobile overrides (around the 900px media
   query) already apply ellipsis truncation, so this is safe. */
.hero-review-header .game-tag {
  font-size: 0.7rem;
}

.hero-review-header .game-opening,
.hero-review-header .game-date {
  font-size: 0.75rem;
}

.hero-board-wrap {
  display: flex;
  gap: 0;
}

.hero-eval-bar {
  width: 16px;
  align-self: stretch;
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 3px 0 0 3px;
  overflow: hidden;
  position: relative;
}

.hero-eval-bar .eval-bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: #d4d0c8;
  transition: height 0.4s ease;
}

.hero-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  touch-action: manipulation;
}

.hero-controls .board-btn {
  padding: 0.4rem 0.8rem;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.hero-controls .board-btn:hover:not(:disabled) {
  color: var(--red);
  border-color: var(--border-hover);
}

.hero-controls .board-btn:disabled {
  cursor: default;
  opacity: 0.3;
}

.hero-controls .move-indicator {
  font-size: 0.85rem;
  color: var(--text-dim);
  min-width: 80px;
  text-align: center;
}

.hero-comment {
  margin-top: 0.6rem;
  padding: 0.5rem 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  border-left: 2px solid var(--red);
  border-radius: 0 4px 4px 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  height: 5rem;
  overflow-y: auto;
}

.hero-comment-move {
  font-weight: 600;
  color: var(--red);
  margin-right: 0.4rem;
}

.hero-qa {
  margin-top: 0.6rem;
  padding: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.hero-qa .qa-messages {
  max-height: 150px;
  overflow-y: auto;
  margin-bottom: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.hero-qa .qa-msg {
  padding: 0.4rem 0.6rem;
  border-radius: 5px;
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 92%;
  word-wrap: break-word;
}

.hero-qa .qa-msg-user {
  align-self: flex-end;
  background: rgba(255, 10, 43, 0.1);
  border: 1px solid rgba(255, 10, 43, 0.15);
  color: var(--text);
}

.hero-qa .qa-msg-ai {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}

.hero-qa .qa-input-row {
  display: flex;
  gap: 0.4rem;
}

.hero-qa .qa-input {
  flex: 1;
  font-size: 0.85rem;
  padding: 0.35rem 0.6rem;
}

.hero-qa .qa-send {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.hero-qa .qa-thinking {
  color: var(--text-dim);
  font-style: italic;
}

.hero-qa .hero-qa-trigger-wrap { display: none; }

.hero-qa-trigger {
  width: 100%;
  font-size: 0.85rem;
  padding: 0.4rem;
}

.hero-qa-trigger:disabled {
  opacity: 0.4;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (max-width: 768px) {
  .hero-qa .qa-input-row { display: none; }
  .hero-qa .hero-qa-trigger-wrap { display: block; }
}

.hero-review-link {
  display: block;
  text-align: center;
  margin-top: 0.8rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.2s;
}

.hero-review-link:hover {
  color: var(--red);
}

@media (max-width: 900px) {
  .hero-review {
    width: 100%;
    /* Size the board purely off the viewport width on mobile. Using a
       height-based constraint (svh/vh) caused the board to resize as
       the browser's URL bar showed/hid during scroll — see #243. */
    max-width: calc(100vw - 2rem);
    margin: 0 auto;
    /* Simplify rendering for mobile performance */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  }

  .game-card-glow {
    display: none;
  }

  /* Disable transitions on board squares for snappy navigation */
  .mini-board .sq,
  .mini-board .sq .piece-img,
  .hero-controls .board-btn {
    transition: none !important;
  }

  /* Remove expensive inset box-shadow on highlights */
  .mini-board .sq.highlight {
    box-shadow: none;
  }

  .mini-board {
    box-shadow: none;
    will-change: contents;
  }

  .hero-captured {
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .hero-captured-piece {
    width: 10px;
    height: 10px;
  }
}

/* ── Mini Board ──────────────────────────────────── */
.game-board-wrap {
  padding: 1rem 1.5rem 0;
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
}

.mini-board .sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  position: relative;
}

.mini-board .sq.light {
  background: var(--sq-light);
}

.mini-board .sq.dark {
  background: var(--sq-dark);
}

.mini-board .sq.highlight {
  background: var(--sq-highlight) !important;
  box-shadow: inset 0 0 8px var(--sq-highlight);
}

.mini-board .sq .piece-img {
  width: 85%;
  height: 85%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.mini-board .sq .piece-img.black-piece {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.board-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
}

.board-label-text {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-style: italic;
}

.board-eval {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--red);
  text-shadow: 0 0 8px var(--red-glow);
  padding: 0.1rem 0.4rem;
  background: var(--red-faint);
  border: 1px solid rgba(255, 10, 43, 0.15);
  border-radius: 3px;
}

/* ── Game Header ─────────────────────────────────── */
.game-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: 8px 8px 0 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.game-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.game-tag {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
}

.tag-eco {
  color: var(--red);
  border-color: rgba(255, 10, 43, 0.25);
  background: var(--red-faint);
}

.game-opening {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-style: italic;
}

.game-date {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-left: auto;
}

.game-players {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.player {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.player-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

.player-color.white {
  background: #d4d0c8;
}

.player-color.black {
  background: #1a1a1a;
}

.player-name {
  font-size: 0.8rem;
  font-weight: 600;
}

.player-accuracy {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-left: 0.3rem;
}

.player-elo {
  font-size: 0.65rem;
  color: var(--text-dim);
}

/* Accuracy summary */
.accuracy-summary {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}

.accuracy-bar-wrap {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  margin-bottom: 0.6rem;
  overflow: hidden;
}

.accuracy-bar-white {
  height: 100%;
  background: linear-gradient(90deg, var(--red-dim), var(--red));
  border-radius: 2px;
  transition: width 0.5s ease;
}

.accuracy-details {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.accuracy-detail-col {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.6rem;
}

.acc-label {
  width: 100%;
  font-weight: 600;
  font-size: 0.65rem;
  color: var(--text);
  margin-bottom: 0.1rem;
}

.acc-good { color: #4caf50; }
.acc-inaccuracy { color: #ffc107; }
.acc-mistake { color: #ff9800; }
.acc-blunder { color: var(--red); }

.vs {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-style: italic;
}

.game-result {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--red);
  text-shadow: 0 0 10px var(--red-glow);
}

/* ── Game Body ───────────────────────────────────── */
.game-body {
  padding: 1.2rem 1.5rem;
}

.move-group {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
  line-height: 1.8;
}

.move-num {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
  min-width: fit-content;
}

.move {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  position: relative;
}

.move-bad {
  color: #ff6b6b;
}

.move-good {
  color: #51cf66;
}

.move-blunder {
  color: var(--red);
  text-shadow: 0 0 8px var(--red-glow);
}

.nag {
  font-weight: 700;
  font-size: 0.75rem;
  margin-left: 1px;
}

.move-bad .nag {
  color: #ff6b6b;
}

.move-good .nag {
  color: #51cf66;
}

.move-blunder .nag {
  color: var(--red);
  text-shadow: 0 0 8px var(--red-glow);
}

.move-novelty {
  color: #ffa726;
}

.novelty-badge {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 700;
  color: #ffa726;
  background: rgba(255, 167, 38, 0.15);
  border: 1px solid rgba(255, 167, 38, 0.3);
  border-radius: 3px;
  padding: 0 0.2em;
  margin-left: 0.2em;
  vertical-align: super;
  line-height: 1;
  cursor: help;
}

.move-ellip {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.game-result-inline {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--red);
  text-shadow: 0 0 8px var(--red-glow);
  margin-left: 0.3rem;
}

/* ── Comments ────────────────────────────────────── */
.game-comment {
  position: relative;
  margin: 0.5rem 0 1rem;
  padding: 0.8rem 1rem 0.8rem 1.2rem;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.comment-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--text-muted);
  border-radius: 2px;
}

.comment-critical .comment-bar {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
}

.comment-critical {
  background: var(--red-faint);
  border-color: rgba(255, 10, 43, 0.1);
}

.game-comment.active-comment {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.05);
}

.game-comment.active-comment .comment-bar {
  background: var(--text);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.3);
}

.game-comment.active-comment.comment-critical {
  border-color: rgba(255, 10, 43, 0.35);
  background: rgba(255, 10, 43, 0.15);
  box-shadow: 0 0 12px rgba(255, 10, 43, 0.1);
}

.game-comment.active-comment.comment-critical .comment-bar {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
}

.game-comment p {
  font-size: 0.72rem;
  line-height: 1.7;
  color: var(--text-dim);
  font-weight: 300;
  font-style: italic;
}

.game-comment p strong {
  color: var(--text);
  font-weight: 600;
  font-style: normal;
}

.eval-badge {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  letter-spacing: 0.05em;
}

.eval-blunder {
  color: var(--red);
  background: var(--red-faint);
  border-color: rgba(255, 10, 43, 0.15);
  text-shadow: 0 0 6px var(--red-glow);
}

/* Tablebase eval badges */
.eval-tablebase {
  font-weight: 700;
  letter-spacing: 0.03em;
}
.eval-tablebase.tb-win {
  color: #66bb6a;
  background: rgba(102, 187, 106, 0.1);
  border-color: rgba(102, 187, 106, 0.25);
}
.eval-tablebase.tb-draw {
  color: #78909c;
  background: rgba(120, 144, 156, 0.1);
  border-color: rgba(120, 144, 156, 0.25);
}
.eval-tablebase.tb-loss {
  color: #ef5350;
  background: rgba(239, 83, 80, 0.1);
  border-color: rgba(239, 83, 80, 0.25);
}

/* ── Section Common ──────────────────────────────── */
.section {
  padding: 6rem 3rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* Collapsible sections */
.section-collapsible {
  border: none;
}

.section-collapsible > summary {
  list-style: none;
}

.section-collapsible > summary::-webkit-details-marker,
.section-collapsible > summary::marker {
  display: none;
  content: '';
}

.section-title {
  font-size: 1.8rem;
  font-weight: 600;
  margin-bottom: 3rem;
  letter-spacing: 0.05em;
}

.section-marker {
  color: var(--red);
  text-shadow: 0 0 10px var(--red-glow);
}

/* ── Features Grid ───────────────────────────────── */
.features-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.feature-card {
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.4s;
  position: relative;
  overflow: hidden;
}

.feature-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--red), transparent);
  opacity: 0;
  transition: opacity 0.4s;
}

.feature-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-elevated);
  transform: translateY(-2px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3), 0 0 30px var(--red-faint);
}

.feature-card:hover::before {
  opacity: 1;
}

.feature-icon {
  width: 40px;
  height: 40px;
  color: var(--red);
  margin-bottom: 1.2rem;
  filter: drop-shadow(0 0 8px var(--red-glow));
}

.feature-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  letter-spacing: 0.03em;
}

.feature-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.7;
  font-weight: 300;
}

/* ── Demo Gallery ────────────────────────────────── */

.demo-gallery-desc {
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.demo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.demo-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.3s, transform 0.3s, box-shadow 0.3s;
  cursor: pointer;
}

.demo-card:hover {
  border-color: var(--red);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 20px var(--red-faint);
}

.demo-card-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  font-size: 0.75rem;
}

.demo-card-players {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
}

.demo-card-opening {
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
}

.demo-card-moves {
  font-size: 0.7rem;
}

/* ── Pipeline ────────────────────────────────────── */
.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
  padding-left: 3rem;
}

.pipeline::before {
  content: '';
  position: absolute;
  left: 1.15rem;
  top: 1.2rem;
  bottom: 1.2rem;
  width: 1px;
  background: linear-gradient(to bottom, var(--red), var(--red-dim), transparent);
  box-shadow: 0 0 8px var(--red-glow);
}

.pipeline-step {
  position: relative;
  padding: 1.5rem 0;
}

.step-number {
  position: absolute;
  left: -3rem;
  top: 1.5rem;
  width: 2.3rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--red);
  text-shadow: 0 0 10px var(--red-glow);
  background: var(--bg);
  padding: 0.2rem 0;
}

.step-content h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  letter-spacing: 0.03em;
}

.step-content p {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.7;
  font-weight: 300;
  max-width: 600px;
}

/* ── Demo Terminal ───────────────────────────────── */
.demo-terminal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), 0 0 40px var(--red-faint);
}

.terminal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1.2rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.terminal-dots {
  display: flex;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-red { background: #ff5f57; }
.dot-yellow { background: #ffbd2e; }
.dot-green { background: #28c840; }

.terminal-title {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.terminal-body {
  padding: 1.5rem 2rem;
  overflow-x: auto;
}

.terminal-body pre {
  font-family: var(--font);
  font-size: 0.8rem;
  line-height: 1.8;
}

.t-dim { color: var(--text-muted); }
.t-red {
  color: var(--red);
  text-shadow: 0 0 8px var(--red-glow);
  font-weight: 600;
}
.t-comment {
  color: #5a8a5a;
  font-style: italic;
}

/* ── Chess Notation Highlighting ─────────────────── */
/* Base style shared by all chess notation references */
.comment-move-ref,
.move-ref-sq,
.move-ref-move {
  font-family: 'JetBrains Mono', monospace;
  font-size: inherit;
  font-style: normal;
  font-weight: 600;
  color: #e8c547;
}

/* Interactive notation — clickable */
.move-ref-interactive {
  cursor: pointer;
  transition: color 0.15s;
}

.move-ref-interactive:hover {
  color: #f5d76e;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.move-ref-interactive:focus-visible {
  color: #f5d76e;
  outline: 2px solid #f5d76e;
  outline-offset: 2px;
}

/* Named pawn structures / strategic motifs surfaced by the feature
 * extractor. Distinct colour so it's obvious when the LLM uses them. */
.move-ref-structure {
  font-family: inherit;
  font-style: italic;
  font-weight: 600;
  color: #7ec8a4;
}

/* Auto-generated pawn-formation commentary — appears at the move where
 * a named structure first shows up, independent of the LLM. */
.structure-comment {
  color: #c8e4d0;
  font-size: 0.93em;
  line-height: 1.5;
  padding: 8px 10px;
  margin: 0 0 8px 0;
  background: rgba(126, 200, 164, 0.08);
  border-left: 3px solid #7ec8a4;
  border-radius: 3px;
}

.structure-comment strong {
  color: #9fd9b6;
}

/* Auto-generated trending-line commentary — appears at the move where
 * the player picks a line that's currently hot in TWIC master games.
 * Orange to distinguish from the green structure block. */
.trending-comment {
  color: #f3d8b8;
  font-size: 0.93em;
  line-height: 1.5;
  padding: 8px 10px;
  margin: 0 0 8px 0;
  background: rgba(232, 165, 71, 0.08);
  border-left: 3px solid #e8a547;
  border-radius: 3px;
}

.trending-comment strong {
  color: #f5b76e;
}

/* Inline link to a TWIC game (generated by [twic_game:ID|label] tags). */
.move-ref-game {
  color: #f5b76e;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}
.move-ref-game:hover {
  color: #ffd59a;
}

/* Board square highlight when a [sq:] or move is clicked */
.sq-ref-highlight {
  outline: 2px solid #e8c547 !important;
  outline-offset: -2px;
  box-shadow: inset 0 0 12px rgba(232, 197, 71, 0.4);
}

/* ── Board coordinate labels (a-h, 1-8) ────────── */
.board-with-coords {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 1fr auto;
}

.board-editor .board-with-coords {
  max-width: fit-content;
  margin: 0 auto;
}
.board-coords-ranks {
  display: flex;
  flex-direction: column;
  padding-right: 4px;
}
.board-coords-ranks .coord-label,
.board-coords-files .coord-label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim, rgba(255, 255, 255, 0.6));
  user-select: none;
}
.board-coords-files {
  grid-column: 2;
  display: flex;
  padding-top: 2px;
}



/* ── Q&A Modal (shared across pages) ────────────── */
.qa-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100%;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.qa-modal-overlay.hidden { display: none; }

.qa-modal {
  background: var(--bg);
  width: 100%;
  height: 100%;
  padding: 0.75rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.qa-modal-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.qa-modal-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  width: min(280px, 70vw);
  margin: 0 auto 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}

.qa-modal-board .sq {
  display: flex;
  align-items: center;
  justify-content: center;
}

.qa-modal-board .sq.light { background: var(--sq-light); }
.qa-modal-board .sq.dark { background: var(--sq-dark); }

.qa-modal-board .sq img {
  width: 85%;
  height: 85%;
  object-fit: contain;
  pointer-events: none;
}

.qa-modal-comment {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text);
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  border-left: 3px solid var(--red);
  max-height: 10rem;
  overflow-y: auto;
}

.qa-modal-comment:empty { display: none; }

.qa-modal-comment-move {
  font-weight: 600;
  color: var(--red);
}
.qa-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
.qa-modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}
/* Inside the modal the outer .qa-modal-scroll already handles scrolling.
   Keep the messages list in flow so there's only one scroll surface. */
.qa-modal .qa-messages {
  overflow-y: visible;
  margin-bottom: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.qa-modal .qa-input-row { display: flex; gap: 0.4rem; }
.qa-modal .qa-input { flex: 1; font-size: 0.85rem; padding: 0.5rem 0.6rem; }
.qa-modal .qa-send { padding: 0.5rem 0.75rem; font-size: 0.8rem; }
.qa-modal .qa-msg {
  padding: 0.4rem 0.6rem;
  border-radius: 5px;
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 92%;
  word-wrap: break-word;
}
.qa-modal .qa-msg-user {
  align-self: flex-end;
  background: rgba(255, 10, 43, 0.1);
  border: 1px solid rgba(255, 10, 43, 0.15);
  color: var(--text);
}
.qa-modal .qa-msg-ai {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}
.qa-modal .qa-thinking {
  color: var(--text-dim);
  font-style: italic;
}

/* ── Footer ──────────────────────────────────────── */
.footer {
  padding: 2rem 1rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-logo-wrap {
  text-align: center;
  margin-bottom: 1rem;
}

.footer-logo-link {
  display: inline-block;
}

.footer-logo {
  height: 48px;
  width: auto;
  opacity: 0.85;
  transition: opacity 0.2s;
  /* black → DeepRed red (#ff0a2b) */
  filter: invert(9%) sepia(95%) saturate(6932%) hue-rotate(353deg) brightness(102%) contrast(110%);
}

.footer-logo-link:hover .footer-logo {
  opacity: 1;
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
}

.footer-sep {
  color: var(--red);
}

.footer-text {
  color: var(--text-dim);
}

.footer-link {
  text-decoration: none;
  transition: color 0.2s;
}

.footer-link:hover {
  color: var(--red);
}

.footer-legal {
  margin-top: 0.4rem;
  gap: 0.5rem;
}

.footer-legal-dot {
  color: var(--text-muted);
}

.footer-legal-link {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-legal-link:hover {
  color: var(--red);
}

.light-theme .footer-logo {
  /* In light mode, keep the logo dark (original black art) */
  filter: none;
  opacity: 0.7;
}

.light-theme .footer-logo-link:hover .footer-logo {
  opacity: 0.9;
}


/* Mobile demo scroll link — hidden on desktop */
.hero-demo-scroll {
  display: none;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
    text-align: center;
    padding: 0 1rem 2rem;
    overflow-x: clip;
  }

  .hero-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100svh;
    padding-top: 3.5rem; /* offset for fixed navbar */
    padding-bottom: 2rem;
  }

  .hero-actions {
    margin-top: auto;
  }

  .hero-title {
    word-spacing: -0.15em;
    margin-top: auto;
  }

  .hero-subtitle {
    font-size: 1.3rem;
    color: var(--text);
    margin-bottom: 3rem;
  }

  .hero-subtitle .text-dim {
    display: block;
    font-size: 0.9rem;
    margin-top: 0.75rem;
    letter-spacing: 0.03em;
  }

  .hero-subtitle .hero-line {
    display: block;
  }

  /* Hide desktop demo button, show scroll link on mobile */
  .hero-demo-btn {
    display: none !important;
  }

  .hero-review-btn {
    order: -1;
    background: var(--red-faint);
    color: var(--red);
    border-color: var(--red-dim);
  }

  .hero-demo-scroll {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text-dim);
    width: 100%;
    -webkit-tap-highlight-color: transparent;
    outline: none;
  }

  .hero-demo-scroll:active {
    color: var(--red);
    text-shadow: 0 0 8px var(--red-glow);
  }

  .hero-demo-scroll-text {
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0.03em;
  }

  .hero-demo-scroll-arrow {
    opacity: 0.5;
    animation: hero-bounce 2s ease-in-out infinite;
  }

  .hero-visual {
    scroll-margin-top: 4rem;
  }

  .hero::before {
    display: none;
  }

  .hero-stats {
    justify-content: center;
  }

  .hero-actions {
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
  }

  .hero-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .hero-review-players {
    width: 100%;
    flex-wrap: nowrap;
    min-width: 0;
  }

  .hero-review-header {
    width: 100%;
    flex-wrap: nowrap;
    min-width: 0;
  }

  .hero-review-header .game-tag:not(.tag-eco),
  .hero-review-header .game-opening {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hero-review-header .game-tag:not(.tag-eco) {
    flex: 0 1 auto;
  }

  .hero-review-header .game-opening {
    flex: 1 1 0;
  }

  .hero-review-header .tag-eco,
  .hero-review-header .game-date {
    flex: 0 0 auto;
  }

  .hero-review-header .game-date {
    margin-left: 0;
  }

  .hero-review-players .player-name {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hero-review-players .player-color,
  .hero-review-players .vs,
  .hero-review-players .game-result {
    flex: 0 0 auto;
  }

  .hero-review-players .hero-captured {
    flex: 0 1 auto;
    min-width: 0;
  }

  .hero-review-players .game-result {
    margin-left: 0;
  }

  .game-card {
    width: 100%;
    max-width: 100%;
    animation: none;
  }

  .features-grid {
    grid-template-columns: 1fr;
  }

  /* Collapse sections on mobile by default */
  .section-collapsible:not([open]) > .section-title {
    margin-bottom: 0;
  }

  .section-collapsible > .section-title {
    cursor: pointer;
    position: relative;
    padding-right: 1.5rem;
  }

  .section-collapsible > .section-title::after {
    content: '+';
    position: absolute;
    right: 0;
    color: var(--red);
    font-weight: 300;
    font-size: 1.4rem;
  }

  .section-collapsible[open] > .section-title::after {
    content: '\2013';
  }

  .nav {
    padding: 1rem 1.5rem;
  }

  .nav-hamburger {
    display: block;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 1rem;
    left: auto;
    width: min(18rem, calc(100vw - 2rem));
    flex-direction: column;
    align-items: stretch;
    background: rgba(10, 10, 12, 0.97);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    gap: 0.5rem;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  }

  .nav-links.nav-open {
    display: flex;
  }

  .nav-user-dropdown {
    width: 100%;
  }

  .nav-link,
  .nav-user-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    padding: 0.75rem 0.9rem;
    border: 1px solid transparent;
    border-radius: 6px;
    box-sizing: border-box;
    text-align: left;
  }

  .nav-caret {
    margin-left: auto;
  }

  .section {
    padding: 4rem 1.5rem;
  }

  /* Auth modal: ensure it fits on phones */
  .auth-modal {
    padding: 1.5rem;
  }

  .auth-tab {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .nav-dropdown {
    position: static;
    right: auto;
    left: auto;
    width: 100%;
    min-width: 0;
    margin-top: 0.35rem;
    padding: 0.35rem 0;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: none;
  }

  .nav-dropdown-item {
    padding: 0.75rem 0.9rem;
    min-height: 44px;
  }

  /* Terminal code: prevent horizontal scroll */
  .terminal-body {
    padding: 1rem;
  }

  .terminal-body pre {
    white-space: pre-wrap;
    word-break: break-word;
  }
}

@media (max-width: 600px) {
  .nav {
    padding: 0.75rem 1rem;
  }

  /* Prevent iOS auto-zoom on input focus */
  .text-input,
  .text-input:focus {
    font-size: 16px;
  }

  /* Touch-friendly form inputs */
  .text-input {
    min-height: 44px;
    padding: 0.5rem 0.75rem;
  }

  .btn {
    min-height: 44px;
  }

  /* Game picker items need bigger touch targets */
  .game-picker-item {
    min-height: 44px;
    padding: 0.75rem;
  }
}

/* ── Animations ──────────────────────────────────── */
@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-content > * {
  animation: fade-in-up 0.8s ease-out backwards;
}

.hero-content > :nth-child(1) { animation-delay: 0.1s; }
.hero-content > :nth-child(2) { animation-delay: 0.3s; }
.hero-content > :nth-child(3) { animation-delay: 0.5s; }
.hero-content > :nth-child(4) { animation-delay: 0.7s; }

@keyframes hero-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

.feature-card {
  animation: fade-in-up 0.6s ease-out backwards;
}

.feature-card:nth-child(1) { animation-delay: 0.1s; }
.feature-card:nth-child(2) { animation-delay: 0.2s; }
.feature-card:nth-child(3) { animation-delay: 0.3s; }
.feature-card:nth-child(4) { animation-delay: 0.4s; }
.feature-card:nth-child(5) { animation-delay: 0.5s; }
.feature-card:nth-child(6) { animation-delay: 0.6s; }

/* ── Selection ───────────────────────────────────── */
::selection {
  background: var(--red-subtle);
  color: var(--text);
}
