:root {
  --bg: #161512;
  --panel: #211f1c;
  --card: #2c2a26;
  --line: #3a3733;
  --text: #d8d5d0;
  --muted: #8f8a83;
  /* Two colour pairs carry meaning, so both have to survive colour blindness
     and warm night-mode filters. Blue vs orange and green vs rose separate on
     the blue-yellow axis, which red-green deficiencies leave intact; the old
     blue/purple and green/red pairs collapsed to the same hue. Each pair has a
     light variant for the dark panel and a dark, saturated one for the light
     board, and app.js reads all of them from here so the arrow can't drift
     away from the button it belongs to. */
  --accent-1: #5aa9ff;
  --accent-2: #f0932f;
  --arrow-1: #1550c8;
  --arrow-2: #b3520a;
  --good: #56d364;
  --bad: #f0559b;
  --arrow-good: #15781b;
  --arrow-bad: #b3117a;
  /* Destructive actions, which never sit next to --good and can stay red. */
  --danger: #ff6b6b;
  --probe: #b07fd9;
  /* board (and mobile panel) edge length */
  --bw: min(100vw, 64vh, 520px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, sans-serif;
}

/* --- header ------------------------------------------------------------ */

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

#brand { font-weight: 700; font-size: 15px; white-space: nowrap; }

#topstats {
  margin-left: auto;
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
#topstats b { color: var(--text); font-size: 14px; }

.chip {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
#settings-btn { font-size: 16px; padding: 4px 10px; }

#user-name {
  display: inline-block;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

@media (max-width: 520px) {
  #topbar { gap: 8px; padding: 0 10px; }
  .brand-name { display: none; }
  #topstats { gap: 10px; }
  #user-name { max-width: 68px; }
}

/* --- layout ------------------------------------------------------------ */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0 40px;
}

#board-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }

#turn-banner {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
  min-height: 20px;
}
#turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: transparent;
}
#turn-dot.white { background: #e8e6e3; }
#turn-dot.black { background: #1a1917; }

#board { width: var(--bw); height: var(--bw); }

/* Vendored chessground nudges both coord rows off their own axis: the files
   by `left: 24px` on top of `width: 100%`, so half a square of letters hangs
   past the board — and where the board is viewport-wide, that hangover is a
   strip of page you can swipe to. Each row already centres itself (letters
   by text-align, digits by translateY), so the nudges only decentre them.
   Upstream's own fix is the same two zeroes (chessground#343, unmerged). */
.cg-wrap coords.files { left: 0; }
.cg-wrap coords.ranks { top: 0; }

/* Chessground dims every shape to 0.6, which suits a board users scribble on
   but not one where the two arrows are the trial: composited that far toward
   the board, the two hues wash out and lose the separation the palette buys.
   The brushes keep enough transparency to see the piece underneath. */
.cg-wrap .cg-shapes { opacity: 1; }

#panel { width: var(--bw); max-width: 100%; padding: 0 12px; }

@media (min-width: 900px) {
  :root { --bw: min(560px, 78vh); }
  main {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 28px;
    padding: 24px;
  }
  #board-col { position: sticky; top: 72px; }
  #panel {
    width: 360px;
    min-height: 420px;
    background: var(--panel);
    border-radius: 12px;
    padding: 18px 20px;
  }
}

/* hide keyboard hints where there's no keyboard */
@media (hover: none) and (pointer: coarse) {
  .kbd-hint { display: none; }
}

kbd {
  background: #333029;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  border: 1px solid var(--line);
}

/* --- choosing phase ----------------------------------------------------- */

#prompt { font-size: 14px; color: var(--muted); margin: 4px 0 8px; }

#choices { display: flex; gap: 10px; }

.choice {
  flex: 1;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font: inherit;
  font-size: 22px;
  font-weight: 600;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
#choice-1 { border-color: var(--accent-1); }
#choice-2 { border-color: var(--accent-2); }
.choice:hover { filter: brightness(1.2); }
.choice:disabled { cursor: default; opacity: 0.85; }
.choice .key,
.line-card .key {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 6px;
}

/* --- reveal phase -------------------------------------------------------- */

#verdict-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 4px 0 10px;
  min-height: 30px;
}
#verdict { font-size: 21px; font-weight: 700; }
#verdict.good { color: var(--good); }
#verdict.bad { color: var(--bad); }
#rating-delta { font-size: 13px; color: var(--muted); }

#controls-row { display: flex; gap: 8px; margin-bottom: 12px; }
.ctl {
  font: inherit;
  font-size: 18px;
  min-width: 52px;
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.ctl:active { filter: brightness(1.3); }
#next {
  flex: 1;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  min-height: 46px;
  border-radius: 8px;
  border: none;
  background: var(--accent-1);
  color: #0b1a2b;
  cursor: pointer;
}
#next:hover { filter: brightness(1.1); }
#next kbd { background: rgba(0, 0, 0, 0.15); border-color: transparent; color: inherit; }

#line-cards { display: flex; flex-direction: column; gap: 8px; }

.line-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.line-card .san { font-size: 17px; font-weight: 600; }
.line-card.good .san { color: var(--good); }
.line-card.bad .san { color: var(--bad); }
.line-card .tag { font-size: 12px; color: var(--muted); }
.line-card .nums {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}
.line-card .eval { font-size: 14px; }
.line-card .wp { font-size: 12px; color: var(--muted); }
.line-card.active { background: var(--card); }
.line-card.good.active { border-color: var(--good); }
.line-card.bad.active { border-color: var(--bad); }

#line-sans {
  font-size: 14px;
  min-height: 26px;
  margin: 8px 0 4px;
  color: var(--muted);
  line-height: 1.8;
}
#line-sans .ply { padding: 1px 4px; border-radius: 3px; }
/* Neutral: this marks position in the line, not one of the two moves. */
#line-sans .ply.current { background: #4a463f; color: var(--text); }

#detail { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
#detail a { color: var(--accent-1); }

#extra-actions { margin-top: 12px; }
#copy-btn {
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
#copy-btn:hover { color: var(--text); }

#repeat-note { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.repeat-badge {
  display: inline-block;
  background: var(--probe);
  color: #1c1425;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 4px;
  padding: 1px 7px;
  margin-right: 6px;
}

/* --- settings drawer ------------------------------------------------------ */

#settings {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: flex-end;
}
#settings[hidden] { display: none; }

#settings-sheet {
  background: var(--panel);
  width: min(340px, 100vw);
  padding: 18px 20px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (max-width: 640px) {
  #settings { align-items: flex-end; justify-content: stretch; }
  #settings-sheet {
    width: 100%;
    max-height: 85dvh;
    border-radius: 16px 16px 0 0;
  }
}

#settings-head { display: flex; align-items: center; justify-content: space-between; }
#settings-head h2 { margin: 0; font-size: 16px; }

.setting { display: flex; flex-direction: column; gap: 8px; }
.setting-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.setting-note { margin: 0; font-size: 12px; color: var(--muted); }

#speed-menu { display: flex; gap: 8px; }
#speed-menu button {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
#speed-menu button.active { color: var(--text); border-color: var(--accent-1); }

#auth-tabs { display: flex; gap: 8px; margin: 4px 0 2px; }
.auth-tab {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active { color: var(--text); border-color: var(--accent-1); }

.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-form[hidden] { display: none; }
.auth-form input {
  min-width: 0;
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
.auth-form button,
#logout-btn,
#delete-btn {
  font: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.auth-form button { border-color: var(--accent-1); }
/* Deletion erases responses with no undo, so it shouldn't look like Sign out.
   Carries the #id so it outranks the shared block above, which has one too. */
#delete-btn.danger,
.auth-form button.danger { border-color: var(--danger); color: var(--danger); }
.auth-form button:disabled,
#logout-btn:disabled,
#delete-btn:disabled { opacity: 0.6; cursor: default; }
#logout-btn, #delete-btn, #delete-cancel { align-self: flex-start; }

#account-guest, #account-user { display: flex; flex-direction: column; gap: 8px; }
#account-guest[hidden], #account-user[hidden] { display: none; }

#auth-error {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}
#auth-error[hidden] { display: none; }

#drawer-stats {
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 6px;
  font-size: 14px;
  color: var(--muted);
}
#drawer-stats b { color: var(--text); text-align: right; }

/* --- legal links and pages ------------------------------------------------ */

.legal-links { font-size: 13px; color: var(--muted); }
.setting-note a, .legal-links a { color: var(--accent-1); }

#page-footer {
  padding: 0 12px 16px;
  text-align: center;
}

.legal main {
  align-items: stretch;
  padding: 0 16px 24px;
}
.legal article {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}
.legal h1 { font-size: 24px; margin: 24px 0 4px; }
.legal h2 { font-size: 17px; margin: 28px 0 6px; }
.legal li { margin-bottom: 6px; }
.legal .updated { font-size: 13px; color: var(--muted); margin-top: 0; }
.legal a { color: var(--accent-1); }
.legal #brand a { color: inherit; text-decoration: none; }

#legal-nav { margin-left: auto; display: flex; gap: 10px; font-size: 13px; }
#legal-nav a { color: var(--muted); text-decoration: none; padding: 6px 4px; }
#legal-nav a:hover, #legal-nav a[aria-current] { color: var(--text); }

#legal-footer {
  padding: 20px 16px 28px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
#legal-footer a { color: var(--accent-1); }
