:root {
  /* Fix: light green/white chess.com-style theme (was a dark theme before).
     Variable NAMES kept the same so the rest of the stylesheet doesn't
     need touching — just the values changed from dark to light. */
  --ink: #FFFFFF;           /* main page background (was darkest, now white) */
  --ink-2: #F3F8F1;         /* card/panel background (soft green-white) */
  --ink-3: #E8F3E3;         /* hover/highlight background */
  --hair: #D3E5CB;          /* borders (light green) */
  --ivory: #1C2B1C;         /* main text (was light, now dark green-black) */
  --ivory-dim: #5C6E58;     /* secondary/dim text */
  --brass: #6B9B37;         /* accent — chess.com-style green (was gold) */
  --brass-dim: #558030;
  --brass-glow: rgba(107, 155, 55, 0.20);
  --teal: #2E8B7A;
  --teal-dim: #216257;
  --sage: #5C8A4E;
  --amber: #C77C1E;
  --rust: #C1483F;
  --green: #22c55e;
  /* Literal chess white/black — used for the eval bar and king avatars,
     which represent the actual White/Black sides of the game and must
     stay white/black regardless of the page theme. */
  --chess-white: #F7F7F2;
  --chess-dark: #1a1f1b;
  --display: 'Fraunces', serif;
  --body: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --radius: 4px;
  --shadow: 0 12px 40px rgba(60, 90, 50, 0.15);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  background: linear-gradient(180deg, #FFFFFF 0%, #F2F8EF 100%);
  color: var(--ivory);
  font-family: var(--body);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* prevent any horizontal scroll */
}
::selection { background: var(--brass); color: var(--ink); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--ink-3); border-radius: 10px; }
::-webkit-scrollbar-thumb { background: var(--brass); border-radius: 10px; }
button { font-family: var(--body); cursor: pointer; border: none; outline: none; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ── Nav ── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--hair);
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 18, 16, 0.97);
  backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 2px 20px rgba(0,0,0,0.3);
  gap: 8px;
  flex-wrap: nowrap;
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 1; min-width: 0; overflow: hidden; }
.logo-svg { width: 36px; height: 36px; flex-shrink: 0; }
.logo-text {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--ivory);
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
}
.logo-text .highlight { color: var(--brass); }
.logo-text .tagline {
  font-family: var(--body);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ivory-dim);
  background: var(--ink-3);
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--hair);
  margin-left: 2px;
  flex-shrink: 0;
}
.navlinks { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.navlink {
  font-size: 12px;
  font-weight: 600;
  color: var(--ivory-dim);
  background: transparent;
  padding: 7px 12px;
  border-radius: var(--radius);
  transition: var(--transition);
  white-space: nowrap;
}
.navlink.active { color: var(--ink); background: var(--brass); }
.navlink:not(.active):hover { color: var(--ivory); background: var(--ink-3); }
.soon-badge {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  background: var(--ink-3);
  color: var(--teal);
  border: 1px solid var(--hair);
  padding: 2px 6px;
  border-radius: 20px;
}

/* ── Stage ── */
.stage {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 24px 60px;
  overflow-x: hidden;  /* fix 1: prevent game-list overflow */
}
.setup-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: stretch; margin-bottom: 24px; }
.card {
  background: var(--ink-2);
  border: 1px solid var(--hair);
  border-radius: 8px;
  padding: 20px 22px;
  transition: border-color var(--transition);
  overflow: hidden; /* fix 1: clip any overflowing content */
}
.card:hover { border-color: rgba(201, 162, 39, 0.15); }
.source-card { flex: 2.2; min-width: 280px; max-width: 100%; }
.depth-card { flex: 1; min-width: 250px; }
.card h3 {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--ivory-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.game-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  background: var(--ink-3);
  border: 1px solid var(--hair);
  border-radius: 6px;
  padding: 8px 14px;
  margin-bottom: 16px;
  font-size: 11px;
  color: var(--ivory-dim);
  overflow: hidden;
}
.game-meta .meta-item { display: flex; align-items: center; gap: 6px; min-width: 0; }
.game-meta .meta-item strong { color: var(--ivory); font-weight: 600; white-space: nowrap; }
.game-meta .result {
  font-weight: 700;
  padding: 2px 12px;
  border-radius: 20px;
  font-size: 11px;
  white-space: nowrap;
}
.game-meta .result.white-win { color: var(--brass-dim); background: var(--brass-glow); }
.game-meta .result.black-win { color: var(--rust); background: rgba(193,72,63,0.15); }
.game-meta .result.draw { color: var(--ivory-dim); background: var(--ink-3); }

.tabs { display: flex; gap: 3px; margin-bottom: 14px; background: var(--ink); border-radius: 6px; padding: 3px; }
.tab {
  flex: 1; text-align: center; padding: 8px 4px; font-size: 11px; font-weight: 600;
  color: var(--ivory-dim); background: transparent; border: none; border-radius: 4px;
  transition: var(--transition); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tab.active { background: var(--ink-3); color: var(--brass); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.tab:hover:not(.active) { color: var(--ivory); }
.tab-panel { animation: fadeSlide 0.25s ease; }
@keyframes fadeSlide { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.field-row { display: flex; gap: 10px; }
.field-row input { flex: 1; min-width: 0; }

/* ── Fix 1: Game list overflow on mobile ── */
.game-list {
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: 12px;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  width: 100%;
}
.game-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--hair);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--mono);
  font-size: 12px;
  overflow: hidden;
  min-width: 0;
}
.game-list-item:last-child { border-bottom: none; }
.game-list-item:hover { background: var(--ink-3); }
.game-list-item.active { background: var(--ink-3); box-shadow: inset 3px 0 0 var(--brass); }
.game-list-item .glt-players {
  color: var(--ivory);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.game-list-item .glt-meta {
  color: var(--ivory-dim);
  font-size: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.game-list-empty { padding: 14px; color: var(--ivory-dim); font-size: 12px; text-align: center; }
input[type="text"], input[type="file"], textarea {
  background: var(--ink);
  border: 1px solid var(--hair);
  color: var(--ivory);
  padding: 11px 14px;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
  max-width: 100%;
}
input[type="text"]:focus, textarea:focus { border-color: var(--brass); box-shadow: 0 0 0 3px var(--brass-glow); }
textarea { width: 100%; min-height: 88px; resize: vertical; font-size: 12px; line-height: 1.6; }
input::placeholder, textarea::placeholder { color: #5D655E; }

.btn {
  border: none; border-radius: var(--radius); padding: 11px 22px;
  font-weight: 700; font-size: 13px; letter-spacing: 0.3px;
  color: var(--ink); background: var(--brass);
  transition: var(--transition); white-space: nowrap;
}
.btn:hover { background: #DCB646; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(201, 162, 39, 0.3); }
.btn:active { transform: scale(0.97) translateY(0); }
.btn.ghost { background: transparent; border: 1px solid var(--hair); color: var(--ivory); }
.btn.ghost:hover { border-color: var(--brass); color: var(--brass); background: rgba(201, 162, 39, 0.06); box-shadow: none; }
.btn.wide { width: 100%; margin-top: 14px; padding: 14px; }
.btn:disabled { opacity: 0.4; pointer-events: none; transform: none !important; }

.depth-options { display: flex; flex-direction: column; gap: 6px; }
.depth-opt {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border: 1px solid var(--hair); border-radius: var(--radius);
  cursor: pointer; transition: var(--transition);
}
.depth-opt:hover { border-color: var(--ivory-dim); }
.depth-opt.selected { border-color: var(--brass); background: rgba(201, 162, 39, 0.07); box-shadow: 0 0 0 1px var(--brass-glow); }
.depth-opt .name { font-size: 13px; font-weight: 600; }
.depth-opt .desc { font-size: 11px; color: var(--ivory-dim); margin-top: 2px; }
.depth-opt .dval { font-family: var(--mono); font-size: 12px; color: var(--teal); }
.custom-depth { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-size: 12px; color: var(--ivory-dim); }
.custom-depth input[type="range"] {
  flex: 1; accent-color: var(--brass); height: 4px; background: var(--hair);
  border-radius: 4px; -webkit-appearance: none;
}
.custom-depth input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--brass); cursor: pointer; border: 2px solid var(--ink);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.status-line { margin-top: 14px; font-size: 12px; color: var(--ivory-dim); font-family: var(--mono); min-height: 18px; display: flex; align-items: center; gap: 8px; }
.status-line .spinner-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--brass); animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } }
.status-line.err { color: var(--rust); }
.status-line.success { color: var(--sage); }

.progress-wrap { margin-top: 14px; }
.progress-bar { height: 4px; background: var(--ink-3); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--brass)); width: 0%; transition: width 0.4s ease; border-radius: 4px; }
.progress-text { font-family: var(--mono); font-size: 11px; color: var(--ivory-dim); margin-top: 8px; }

/* ── Review grid ── */
.review-grid { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.board-col { flex: 1.4; min-width: 340px; display: flex; flex-direction: column; gap: 0; }

/* ── Eval column (bar + player names) ── */
.eval-col {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 36px;
  flex-shrink: 0;
  gap: 0;
}

/* Player name labels at top (black) and bottom (white) of eval bar */
.eval-player-label {
  width: 36px;
  font-size: 8px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.3px;
  padding: 3px 1px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
  background: var(--ink-3);
  border: 1px solid var(--hair);
  border-radius: 3px 3px 0 0;
  color: var(--ivory-dim);
  text-transform: uppercase;
  cursor: default;
}
.eval-player-black { border-radius: 3px 3px 0 0; background: #1a1f1b; }
.eval-player-white { border-radius: 0 0 3px 3px; background: var(--ink-2); color: var(--ivory); }

/* ── Eval bar ── */
.eval-rail {
  flex: 1;
  background: var(--ink);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-left: 1px solid var(--hair);
  border-right: 1px solid var(--hair);
  position: relative;
  min-height: 200px;
}
#eval-fill {
  background: linear-gradient(to top, var(--chess-white) 0%, #ccc 100%);
  width: 100%;
  height: 50%;
  transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  position: relative;
}
/* The score label sits at the boundary between black/white in the bar */
.eval-label {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--brass);
  font-weight: 800;
  z-index: 2;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  pointer-events: none;
  /* Positioned dynamically via JS */
  bottom: 50%;
  transform: translateY(50%);
  transition: bottom 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.board-with-eval { display: flex; gap: 12px; width: 100%; }
.board-wrap { flex: 1; min-width: 0; }

/* ── Fix 1: Chess.com-style player rows (top = opponent, bottom = you) ── */
.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--ink-2);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  margin-bottom: 6px;
}
#player-row-bottom { margin-top: 6px; margin-bottom: 0; }
.player-avatar {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--ink-3);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  color: var(--brass);
}
.player-info { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.player-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--ivory);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-elo {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ivory-dim);
}
.opening-name {
  margin-left: auto;
  font-size: 11px;
  font-style: italic;
  color: var(--brass);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
}

/* ── Fix 1 & 3: Move classification callout, attributed to the mover ── */
.move-callout {
  --callout-color: var(--sage);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--ink-2);
  border: 1px solid var(--hair);
  border-left: 4px solid var(--callout-color);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.callout-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  border: 2px solid var(--callout-color);
}
.callout-avatar.callout-w { background: var(--chess-white); color: var(--chess-dark); }
.callout-avatar.callout-b { background: var(--chess-dark); color: var(--chess-white); }
.callout-body { flex: 1; min-width: 0; }
.callout-top-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.callout-player { font-weight: 700; font-size: 12px; color: var(--ivory-dim); }
.callout-label { font-weight: 800; font-size: 14px; color: var(--callout-color); }
.callout-score {
  margin-left: auto;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 13px;
  color: var(--ivory);
  background: var(--ink-3);
  padding: 2px 8px;
  border-radius: 4px;
}
.callout-desc { font-size: 12px; color: var(--ivory-dim); margin-top: 3px; line-height: 1.4; }

@media (max-width: 720px) {
  .board-with-eval { gap: 6px; }
  .player-name { font-size: 12px; max-width: 40vw; }
  .opening-name { max-width: 40%; font-size: 10px; }
  .callout-desc { display: none; } /* keep the mobile callout to one line */
  .callout-label { font-size: 12px; }
}

/* ── Fix 1: Touch drag + layout ── */
#myBoard {
  width: 100%;
  border-radius: 4px;
  box-shadow: var(--shadow);
  position: relative;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#myBoard img {
  touch-action: none;
  -webkit-user-drag: none;
  user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  /* Fix: long-press on a piece was triggering the browser's native
     "save/share image" menu — very disruptive since players naturally
     long-press pieces while thinking about a move. */
  -webkit-touch-callout: none;
  pointer-events: auto;
}

/* ── Board piece animations ── */
@keyframes blunderShake {
  0%, 100% { transform: translateX(0); }
  15%       { transform: translateX(-7px); }
  35%       { transform: translateX(7px); }
  55%       { transform: translateX(-5px); }
  75%       { transform: translateX(5px); }
  90%       { transform: translateX(-2px); }
}
@keyframes blunderFlash {
  0%, 100% { box-shadow: var(--shadow); }
  30%      { box-shadow: var(--shadow), 0 0 0 16px rgba(193,72,63,0.5); }
  60%      { box-shadow: var(--shadow), 0 0 0 8px rgba(193,72,63,0.25); }
}
@keyframes brilliantGlow {
  0%, 100% { box-shadow: var(--shadow); }
  25%      { box-shadow: var(--shadow), 0 0 40px 14px rgba(27,166,160,0.65); }
  60%      { box-shadow: var(--shadow), 0 0 20px 5px rgba(27,166,160,0.3); }
}
#myBoard.anim-brilliant { animation: brilliantGlow 1.0s ease-out forwards; }
#myBoard.anim-blunder   { animation: blunderShake 0.5s ease-out forwards, blunderFlash 0.5s ease-out forwards; }

/* ── Tap-to-select: selected square ── */
.square-selected {
  background: rgba(255, 215, 0, 0.38) !important;
  box-shadow: inset 0 0 0 3px rgba(255, 215, 0, 0.75) !important;
}

/* ── Fix 4: Legal move dots (click-to-move) ── */
.legal-dot {
  position: absolute;
  width: 32%;
  height: 32%;
  background: rgba(0, 0, 0, 0.30);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 8;
  animation: dotFadeIn 0.15s ease-out;
}
.legal-capture-ring {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 5px solid rgba(0, 0, 0, 0.28);
  pointer-events: none;
  z-index: 8;
  animation: dotFadeIn 0.15s ease-out;
}
@keyframes dotFadeIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1);   }
}
/* capture ring doesn't translate */
.legal-capture-ring { animation: ringFadeIn 0.15s ease-out; }
@keyframes ringFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Board badge (move classification) ── */
.board-badge {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-family: var(--mono);
  color: #fff;
  border: 2px solid rgba(0,0,0,0.5);
  box-shadow: 0 3px 10px rgba(0,0,0,0.6);
  z-index: 30;
  pointer-events: none;
  /* default size */
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  font-size: 11px;
  animation: badgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes badgePop {
  from { transform: scale(0.2); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* Brilliant and Blunder get special large animated badges */
.board-badge.badge-brilliant {
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  font-size: 14px;
  background: #1BA6A0;
  border-color: #0a4d4a;
  box-shadow: 0 0 0 0 rgba(27,166,160,0.8), 0 3px 12px rgba(0,0,0,0.7);
  animation: badgePop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), brilliantBadgePulse 1.4s 0.35s ease-out forwards;
}
@keyframes brilliantBadgePulse {
  0%   { box-shadow: 0 0 0 0 rgba(27,166,160,0.8), 0 3px 12px rgba(0,0,0,0.7); }
  40%  { box-shadow: 0 0 0 14px rgba(27,166,160,0), 0 3px 12px rgba(0,0,0,0.7); }
  100% { box-shadow: 0 0 0 0 rgba(27,166,160,0), 0 3px 12px rgba(0,0,0,0.7); }
}

.board-badge.badge-blunder {
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  font-size: 14px;
  background: var(--rust);
  border-color: #7a1e1e;
  animation: badgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), blunderBadgePulse 1.2s 0.3s ease-out forwards;
}
@keyframes blunderBadgePulse {
  0%   { box-shadow: 0 0 0 0 rgba(193,72,63,0.8), 0 3px 12px rgba(0,0,0,0.7); }
  40%  { box-shadow: 0 0 0 14px rgba(193,72,63,0), 0 3px 12px rgba(0,0,0,0.7); }
  100% { box-shadow: 0 0 0 0 rgba(193,72,63,0), 0 3px 12px rgba(0,0,0,0.7); }
}

.board-badge.badge-great     { background: #4FA8D8; width: 26px; height: 26px; margin: -13px 0 0 -13px; font-size: 12px; }
.board-badge.badge-best      { background: var(--sage); }
.board-badge.badge-excellent { background: #8FBF88; }
.board-badge.badge-good      { background: var(--teal); }
.board-badge.badge-book      { background: #8B6F3E; }
.board-badge.badge-inaccuracy{ background: var(--amber); width: 26px; height: 26px; margin: -13px 0 0 -13px; font-size: 12px; }
.board-badge.badge-mistake   { background: #E0873A; width: 26px; height: 26px; margin: -13px 0 0 -13px; font-size: 12px; }

/* ── Board arrows ── */
.board-arrow-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 25; }
.board-arrow-layer path.arrow-best   { stroke: var(--teal); stroke-width: 2.8; fill: none; opacity: 0.88; }
.board-arrow-layer path.arrow-played { stroke: var(--green); stroke-width: 2.4; fill: none; opacity: 0.75; }
.arrow-poly-best   { fill: var(--teal); }
.arrow-poly-played { fill: var(--green); }

/* ── Navigation controls ── */
.board-controls { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.board-controls .btn.ghost { flex: 1 1 30%; padding: 14px 6px; font-size: 14px; min-width: 0; min-height: 48px; text-align: center; }
#btn-prev, #btn-next { border-color: rgba(201, 162, 39, 0.3); }

.sandbox-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: rgba(58,166,160,0.12); border: 1px solid var(--teal-dim); color: var(--teal); font-size: 12px; padding: 8px 12px; border-radius: var(--radius); margin-top: 10px; }
.sandbox-banner .btn.ghost { padding: 6px 12px; font-size: 11px; flex: none; }

/* ── Engine Lines Panel ── */
.lines-panel { margin-top: 10px; background: var(--ink-2); border: 1px solid var(--hair); border-radius: 8px; overflow: hidden; }
.lines-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: var(--ink-3); border-bottom: 1px solid var(--hair); }
.lines-title { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--teal); letter-spacing: 0.5px; text-transform: uppercase; }
.lines-hint  { font-family: var(--mono); font-size: 10px; color: var(--ivory-dim); }
.lines-body  { padding: 4px 0; }
.lines-empty { padding: 10px 14px; font-size: 12px; color: var(--ivory-dim); font-family: var(--mono); text-align: center; }
.line-item { display: flex; align-items: center; gap: 10px; padding: 7px 14px; border-bottom: 1px solid rgba(42,50,43,0.5); transition: background var(--transition); overflow: hidden; }
.line-item:last-child { border-bottom: none; }
.line-item:hover { background: var(--ink-3); }
.line-rank { width: 18px; height: 18px; border-radius: 50%; background: var(--ink-3); border: 1px solid var(--hair); font-family: var(--mono); font-size: 10px; font-weight: 700; color: var(--ivory-dim); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.line-item.line-rank-1 .line-rank { background: rgba(58,166,160,0.18); border-color: var(--teal-dim); color: var(--teal); }
.line-moves { flex: 1; font-family: var(--mono); font-size: 12px; color: var(--ivory); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.line-item.line-rank-1 .line-moves { font-weight: 600; }
.line-item.line-rank-2 .line-moves, .line-item.line-rank-3 .line-moves { color: var(--ivory-dim); }
.line-score { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--ivory-dim); white-space: nowrap; }
.line-score.score-pos { color: #6fcf97; }
.line-score.score-neg { color: var(--rust); }

/* ── Panel col ── */
.panel-col { flex: 1; min-width: 340px; display: flex; flex-direction: column; gap: 16px; }
.summary-card { padding: 22px 24px; }
.summary-top { display: flex; justify-content: space-between; gap: 20px; align-items: stretch; }
.acc-block { text-align: center; flex: 1; padding: 6px 0; }
.acc-block .who { font-size: 11px; color: var(--ivory-dim); text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 4px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-block .num { font-family: var(--display); font-size: 38px; font-weight: 700; color: var(--brass); line-height: 1.2; }
.acc-block .num.white { color: var(--ivory); }
.acc-block .sub { font-size: 11px; color: var(--ivory-dim); margin-top: 2px; }
.acc-divider { width: 1px; background: var(--hair); }

/* Fix 3: per-side breakdown table (White | category | Black) */
.tally-table { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--hair); }
.tally-row {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 12px;
}
.tally-row .tw { text-align: center; font-family: var(--mono); font-weight: 700; font-size: 14px; }
.tally-row .tb { text-align: center; font-family: var(--mono); font-weight: 700; font-size: 14px; }
.tally-row .tc { text-align: center; color: var(--ivory-dim); font-size: 11px; white-space: nowrap; }
.tally-row.tally-head { border-bottom: 1px solid var(--hair); padding-bottom: 8px; margin-bottom: 4px; }
.tally-head .tw, .tally-head .tb {
  font-family: var(--sans, inherit); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px; color: var(--ivory-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ledger-card { flex: 1; padding: 0; overflow: hidden; display: flex; flex-direction: column; max-height: 480px; min-height: 300px; }
.ledger-head { padding: 14px 20px; border-bottom: 1px solid var(--hair); display: flex; justify-content: space-between; align-items: center; background: var(--ink-3); border-radius: 8px 8px 0 0; }
.ledger-head h3 { margin: 0; font-size: 12px; letter-spacing: 1.2px; }
.ledger-head .move-count { font-family: var(--mono); font-size: 11px; color: var(--ivory-dim); }
.ledger-body { overflow-y: auto; padding: 4px 0; flex: 1; }
.ledger-empty { padding: 50px 20px; text-align: center; color: var(--ivory-dim); font-size: 13px; }
.ledger-empty .icon { font-size: 32px; display: block; margin-bottom: 12px; opacity: 0.4; }

.move-row {
  display: grid; grid-template-columns: 36px 1fr auto 70px;
  align-items: center; gap: 10px; padding: 8px 18px;
  border-left: 3px solid transparent; cursor: pointer;
  transition: var(--transition);
}
.move-row:hover { background: var(--ink-3); }
.move-row.current { background: rgba(58, 166, 160, 0.08); border-left-color: var(--teal); }
.move-row .mno { font-family: var(--mono); font-size: 11px; color: #5D655E; text-align: right; }
.move-row .msan { font-family: var(--mono); font-size: 14px; font-weight: 500; }
.move-row .mside { font-size: 9px; color: #5D655E; margin-left: 6px; font-weight: 400; }
.move-row .meval { font-family: var(--mono); font-size: 11px; color: var(--ivory-dim); text-align: right; }
.move-row .mbest { font-size: 10px; color: var(--ivory-dim); grid-column: 1 / -1; padding: 0 0 4px 46px; font-family: var(--mono); }
.move-row .mbest strong { color: var(--sage); }
.move-row .mbest-line { color: var(--ivory-dim); opacity: 0.75; }

.stamp {
  font-size: 10px; font-weight: 700; letter-spacing: 0.3px;
  padding: 2px 8px; border-radius: 20px; text-align: center; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 3px;
  transition: var(--transition);
  font-family: var(--mono);
}
.stamp.brilliant { color: #1BA6A0; background: rgba(27,166,160,0.15); border: 1px solid rgba(27,166,160,0.4); }
.stamp.great     { color: #4FA8D8; background: rgba(79,168,216,0.15); border: 1px solid rgba(79,168,216,0.35); }
.stamp.best      { color: var(--sage); background: rgba(122,155,110,0.15); border: 1px solid rgba(122,155,110,0.3); }
.stamp.excellent { color: #8FBF88; background: rgba(122,155,110,0.08); border: 1px solid rgba(122,155,110,0.2); }
.stamp.good      { color: var(--teal); background: rgba(58,166,160,0.1); border: 1px solid rgba(58,166,160,0.25); }
.stamp.book      { color: var(--ivory-dim); background: var(--ink-3); border: 1px solid var(--hair); }
.stamp.inaccuracy{ color: var(--amber); background: rgba(214,145,44,0.12); border: 1px solid rgba(214,145,44,0.3); }
.stamp.mistake   { color: #E0873A; background: rgba(224,135,58,0.14); border: 1px solid rgba(224,135,58,0.35); }
.stamp.blunder   { color: var(--rust); background: rgba(193,72,63,0.16); border: 1px solid rgba(193,72,63,0.4); }

.ad-container {
  background: var(--ink-2); border: 1px dashed var(--hair); border-radius: 8px;
  padding: 16px; text-align: center; color: var(--ivory-dim); font-size: 12px;
  min-height: 90px; display: flex; align-items: center; justify-content: center; margin: 16px 0;
}
.ad-container .ad-label { text-transform: uppercase; letter-spacing: 2px; font-size: 10px; opacity: 0.4; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8, 10, 9, 0.8); backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--ink-2); border: 1px solid var(--hair); border-radius: 12px;
  max-width: 420px; width: 100%; padding: 40px 36px; text-align: center; box-shadow: var(--shadow);
  animation: modalIn 0.3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal .icon { font-size: 44px; color: var(--brass); margin-bottom: 16px; }
.modal h2 { font-family: var(--display); font-size: 22px; margin: 0 0 8px; }
.modal p { font-size: 14px; color: var(--ivory-dim); line-height: 1.7; margin: 0 0 24px; }
.modal .btn { padding: 12px 40px; }

/* Review-done modal extras */
.review-done-modal .review-done-icon {
  font-size: 52px;
  color: var(--sage);
  display: block;
  animation: doneIconPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes doneIconPop {
  from { transform: scale(0.4) rotate(-15deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px; max-width: 360px;
}
.toast {
  background: var(--ink-2); border: 1px solid var(--hair); border-radius: 8px;
  padding: 14px 20px; font-size: 13px; box-shadow: var(--shadow);
  animation: slideUp 0.4s ease; display: flex; align-items: center; gap: 12px;
}
.toast.success { border-left: 3px solid var(--sage); }
.toast.error   { border-left: 3px solid var(--rust); }
.toast.info    { border-left: 3px solid var(--teal); }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.toast .toast-close { background: none; border: none; color: var(--ivory-dim); font-size: 16px; padding: 0 4px; cursor: pointer; margin-left: auto; }

.footer-note { text-align: center; font-size: 11px; color: var(--ivory-dim); padding: 20px 0 0; opacity: 0.6; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .stage { padding: 20px 16px 60px; }
  .board-col { min-width: 280px; }
  .panel-col { min-width: 280px; }
}

@media (max-width: 768px) {
  /* Nav */
  .topnav { padding: 8px 12px; }
  .logo-text { font-size: 18px; }
  .logo-text .tagline { display: none; }
  .navlink { padding: 6px 10px; font-size: 11px; }
  .soon-badge { display: none; }

  /* Setup */
  .setup-row { flex-direction: column; }
  .source-card, .depth-card { min-width: 100%; max-width: 100%; width: 100%; }

  /* Fix 1: game list stays within bounds */
  .game-list { max-height: 200px; }
  .game-list-item { font-size: 11px; padding: 8px 10px; }
  .game-list-item .glt-meta { font-size: 9px; max-width: 100px; overflow: hidden; text-overflow: ellipsis; }

  .review-grid { flex-direction: column; }

  /* Board col: stack eval bar above board as thin horizontal strip.
     FIX: board-with-eval (eval-col + board-wrap) must also switch to a
     column stack on mobile — otherwise eval-col's width:100% below
     grabs the whole row and leaves board-wrap at 0 width (the board
     disappears entirely). */
  .board-col {
    width: 100%;
    min-width: 0;
    flex-direction: column;
    gap: 0;
  }
  .board-with-eval {
    flex-direction: column;
    width: 100%;
  }

  /* Fix 4: Eval bar becomes a horizontal strip on mobile, but tall enough
     (24px) to show the score number directly inside it — removing the need
     for the separate duplicate score row that used to sit below the board. */
  .eval-col {
    flex-direction: row;
    width: 100%;
    height: 24px;
    gap: 6px;
    align-items: center;
  }
  .eval-player-label {
    font-size: 10px;
  }
  .eval-rail {
    flex: 1;
    height: 24px;
    min-height: 0;
    flex-direction: row;
    justify-content: flex-start;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--hair);
    border-bottom: 1px solid var(--hair);
  }
  #eval-fill {
    height: 100% !important;
    width: var(--eval-pct, 50%);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  }
  /* Center the label vertically in the now-horizontal bar, overriding the
     JS-set "bottom: X%" (meant for the vertical desktop bar) with !important. */
  .eval-label {
    display: flex !important;
    align-items: center;
    justify-content: center;
    top: 0 !important;
    bottom: 0 !important;
    transform: none !important;
    font-size: 11px;
  }

  .board-wrap { width: 100%; }
  #myBoard { width: 100% !important; }

  .panel-col { min-width: 0; width: 100%; }
  .summary-top { flex-direction: row; gap: 8px; }
  .acc-block .num { font-size: 26px; }
  .ledger-card { max-height: 320px; min-height: 180px; }
  .move-row { grid-template-columns: 28px 1fr auto 50px; gap: 6px; padding: 6px 12px; }
  .move-row .msan { font-size: 12px; }
  .modal { padding: 28px 20px; margin: 16px; }
  .toast-container { bottom: 12px; right: 12px; left: 12px; max-width: 100%; }
  .ad-container { min-height: 60px; padding: 10px; }
  .lines-panel { margin-top: 8px; }
  .line-item { padding: 6px 10px; gap: 8px; }
  .line-moves { font-size: 11px; }
  .line-score { font-size: 10px; }
  .board-controls { gap: 6px; flex-wrap: wrap; }
  .board-controls .btn.ghost { font-size: 13px; padding: 14px 4px; flex: 1 1 30%; min-height: 48px; }
}

@media (max-width: 480px) {
  .stage { padding: 12px 8px 40px; }
  .card { padding: 14px 12px; }
  .field-row { flex-direction: column; }
  .btn { padding: 10px 16px; font-size: 12px; }
  .move-row { grid-template-columns: 24px 1fr auto 40px; gap: 4px; font-size: 11px; }
  .stamp { font-size: 9px; padding: 2px 6px; }
  .game-meta { font-size: 10px; gap: 6px; padding: 6px 10px; }
  .tally-row { font-size: 11px; grid-template-columns: 32px 1fr 32px; }
}
