/* Brand tokens: keep in sync with brand/README.md and scripts/build-brand.mjs. */
:root {
  --ink: #14140f;
  --cream: #f4eee1;
  --emerald: #0e7a55;
  --emerald-bright: #2fa877;
  --bg: var(--cream);
  --fg: var(--ink);
  --accent: var(--emerald);
  --sq-light: #efe6d2;
  --sq-dark: #5e8f78;
  --sq-last: rgba(214, 186, 72, 0.5);
  --sq-selected: rgba(47, 168, 119, 0.55);
  --hint: rgba(20, 20, 15, 0.22);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--ink);
    --fg: var(--cream);
    --accent: var(--emerald-bright);
    --sq-light: #d9cfb9;
    --sq-dark: #4b7a64;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Board */
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  width: min(100%, 560px);
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.sq {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  aspect-ratio: 1;
  cursor: default;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last { box-shadow: inset 0 0 0 100vmax var(--sq-last); }
.sq.selected { box-shadow: inset 0 0 0 100vmax var(--sq-selected); }
.sq.movable, .sq.target, .sq.capture { cursor: pointer; }
.sq:focus-visible { outline: 3px solid var(--emerald-bright); outline-offset: -3px; z-index: 1; }
.sq .pc { position: absolute; inset: 4%; display: block; }
.sq .pc svg, .ghost svg, .promo svg { width: 100%; height: 100%; display: block; }
.sq.lifted .pc { opacity: 0.3; }
.sq.target::after {
  content: "";
  position: absolute;
  inset: 36%;
  border-radius: 50%;
  background: var(--hint);
}
.sq.capture::after {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  border: 0.35em solid var(--hint);
}
.coord {
  position: absolute;
  font-size: clamp(8px, 1.6vw, 11px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}
.coord.rank { top: 4%; left: 5%; }
.coord.file { bottom: 4%; right: 6%; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }
.ghost {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 10;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.25));
}
.board .arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.promo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2%;
  background: rgba(20, 20, 15, 0.55);
  z-index: 2;
}
.promo[hidden] { display: none; }
.promo button {
  width: 20%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: var(--cream);
  padding: 4%;
  cursor: pointer;
}
.promo button:focus-visible { outline: 3px solid var(--emerald-bright); }
@media (prefers-reduced-motion: no-preference) {
  .sq .pc { transition: opacity 0.1s; }
}

/* --- Page --------------------------------------------------------------- */
:root {
  --muted: rgba(20, 20, 15, 0.6);
  --line: rgba(20, 20, 15, 0.12);
  --surface: #fbf7ee;
  --mark-path: #a6a298;
  --g-best: #2fa877;
  --g-good: #e3b341;
  --g-inacc: #e8833a;
  --g-bad: #d64545;
  --g-time: #8a877d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --muted: rgba(244, 238, 225, 0.6);
    --line: rgba(244, 238, 225, 0.14);
    --surface: #1f1f19;
    --mark-path: #626058;
    --g-time: #6b6960;
  }
}
body { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; }
.top, main, .switch { width: 100%; max-width: 560px; padding-inline: 16px; }
.top { display: flex; align-items: center; justify-content: space-between; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: 6px; }
.logo { display: block; color: var(--fg); width: 210px; }
.logo svg { display: block; width: 100%; height: auto; }
.tools { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line); background: transparent;
  color: var(--fg); font-family: inherit; font-weight: 700; font-size: 17px; line-height: 1; cursor: pointer;
}
.switch { display: flex; gap: 4px; padding-bottom: 8px; }
.switch a {
  flex: 1; text-align: center; padding: 8px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 14px;
}
.switch a[aria-current="page"] { background: var(--surface); color: var(--fg); box-shadow: inset 0 0 0 1.5px var(--line); }
main { flex: 1; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.loading { text-align: center; color: var(--muted); margin-top: 30vh; }
.screen[hidden] { display: none; }
.kicker { font-size: 13px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 0; }
h1 { font-size: clamp(34px, 9vw, 48px); line-height: 1.05; margin: 10px 0 8px; letter-spacing: -0.02em; }
.rules { font-size: 18px; margin: 0 0 28px; }
.small { font-size: 14px; color: var(--muted); }
.sponsor { font-size: 13px; color: var(--muted); }
.primary {
  display: inline-flex; align-items: center; justify-content: center; min-width: 180px; min-height: 52px; padding: 0 28px;
  border: 0; border-radius: 14px; background: var(--fg); color: var(--bg); font-family: inherit; font-weight: 800; font-size: 18px; line-height: 1; letter-spacing: 0.02em; cursor: pointer;
}
.primary:active { transform: translateY(1px); }
.primary:focus-visible, .icon-btn:focus-visible, .link:focus-visible { outline: 3px solid var(--emerald-bright); outline-offset: 2px; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; }
a { color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#intro { padding-top: 12vh; text-align: center; }

/* --- Game --------------------------------------------------------------- */
.status { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 6px; }
.pips { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.pip { width: 26px; height: 26px; border-radius: 7px; background: var(--line); }
.pip.current { box-shadow: inset 0 0 0 2.5px var(--fg); background: transparent; }
.clock {
  min-width: 64px; height: 40px; padding: 0 12px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--line); font: 800 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.clock.urgent { background: var(--g-bad); color: #fff; box-shadow: none; }
@media (prefers-reduced-motion: no-preference) { .clock.urgent { animation: pulse 1s ease-in-out infinite; } }
@keyframes pulse { 50% { transform: scale(1.06); } }
.turn { margin: 0 0 6px; font-weight: 700; font-size: 15px; }
.board-wrap { position: relative; width: 100%; }
.board-wrap .board { width: 100%; }
.overlay {
  position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-radius: 6px; text-align: center; padding: 16px;
}
.overlay[hidden] { display: none; }
.overlay.reveal { background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: none; -webkit-backdrop-filter: none; }
.badge { margin: 0; padding: 12px 26px; border-radius: 16px; font-size: 32px; font-weight: 900; color: #fff; letter-spacing: -0.01em; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.points { margin: 0; font-size: 26px; font-weight: 800; padding: 6px 16px; border-radius: 12px; background: var(--bg); }
.bolt { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .overlay.reveal:not([hidden]) .badge { animation: pop 0.35s cubic-bezier(.2,1.4,.4,1); }
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.timebar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 10px; overflow: hidden; }
.timebar span { display: block; height: 100%; background: var(--accent); transform-origin: left; }

/* Grade colours, shared by pips, badges and tiles. */
.g-best, .g-excellent { --g: var(--g-best); }
.g-good { --g: var(--g-good); }
.g-inaccuracy { --g: var(--g-inacc); }
.g-mistake, .g-blunder { --g: var(--g-bad); }
.g-time { --g: var(--g-time); }
.pip[class*="g-"], .badge { background: var(--g); }
.badge.g-good { color: var(--ink); }

/* --- Results ------------------------------------------------------------ */
#results { text-align: center; padding-top: 16px; }
.score { margin: 10px 0 4px; font-size: clamp(72px, 22vw, 104px); font-weight: 900; line-height: 1; letter-spacing: -0.04em; }
.score .max { font-size: 0.32em; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.tiles { display: flex; justify-content: center; gap: 8px; list-style: none; padding: 0; margin: 18px 0 8px; }
.tile { width: 64px; }
.tile button {
  display: grid; justify-items: center; gap: 4px; width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer;
}
.tile button:focus-visible { outline: 3px solid var(--emerald-bright); outline-offset: 3px; border-radius: 12px; }
.tile-sq { position: relative; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
.tile-sq::after { content: "›"; position: absolute; right: 5px; bottom: 1px; font: 800 18px/1 system-ui, sans-serif; color: rgba(255, 255, 255, 0.9); }
.tile button:active .tile-sq { transform: translateY(1px); box-shadow: none; }
.tile-sq { width: 52px; height: 52px; border-radius: 12px; background: var(--g); }
.tile-label { font-size: 11px; font-weight: 700; color: var(--muted); }
.tile-pts { font-size: 15px; font-weight: 800; }
.dist { margin: 14px auto 0; max-width: 360px; }
.dist[hidden] { display: none; }
.dist-count { margin: 0 0 6px; font-size: 12px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.dist-count[hidden] { display: none; }
.dist-count b { color: var(--fg); }
.dist-empty { margin: 4px 0 0; font-size: 15px; font-weight: 700; color: var(--muted); }
.dist-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.dist .area { fill: color-mix(in srgb, var(--fg) 8%, transparent); }
.dist .curve { fill: none; stroke: color-mix(in srgb, var(--fg) 45%, transparent); stroke-width: 2; stroke-linejoin: round; }
.dist .you-line { stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.dist .you-dot { fill: var(--accent); stroke: var(--bg); stroke-width: 1.5; }
.dist .you-knight { fill: var(--accent); stroke: var(--bg); stroke-width: 10; stroke-linejoin: round; paint-order: stroke; }
.dist .axis { stroke: var(--line); stroke-width: 1; }
.dist .tick { font: 600 8px system-ui, sans-serif; fill: var(--muted); }
.dist .you-label rect { fill: var(--accent); }
.dist .you-label text { font: 800 8.5px system-ui, sans-serif; fill: var(--bg); }
.share-row { margin: 22px 0 8px; display: grid; justify-items: center; gap: 6px; }
.share-msg { margin: 0; min-height: 1.2em; font-weight: 700; color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 20px 0; padding: 14px 8px; border-radius: 14px; background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--line); }
.stats div { display: grid; gap: 2px; align-content: space-between; }
.stats dt { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stats dd { margin: 0; font-size: 24px; font-weight: 900; }
.next { margin: 8px 0; }
#countdown { font-variant-numeric: tabular-nums; }

/* --- Review ----------------------------------------------------------- */
.review { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; }
.review[hidden] { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .review:not([hidden]) { animation: sheet-up 0.25s cubic-bezier(.2, .8, .2, 1); }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
body.reviewing { overflow: hidden; }
.review-inner { max-width: 560px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.rv-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.rv-head .icon-btn { font-size: 22px; }
.rv-grade { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.rv-grade .badge { font-size: 20px; padding: 8px 16px; border-radius: 12px; box-shadow: none; }
.rv-pts { font-weight: 800; font-size: 18px; }
.rv-moves { list-style: none; padding: 0; margin: 12px 0 8px; display: grid; gap: 8px; }
.rv-moves li {
  display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 10px; padding: 10px 14px;
  border-radius: 12px; background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--line);
}
.rv-moves li.rv-found { grid-template-columns: 16px 1fr; }
.rv-moves b { display: block; font-size: 18px; }
.rv-lab { color: var(--muted); font-size: 13px; font-weight: 700; }
.rv-swatch { width: 16px; height: 6px; border-radius: 3px; }
.rv-also { font-size: 14px; color: var(--muted); margin: 0 0 14px; min-height: 1.2em; }
.rv-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rv-nav .primary, .rv-nav .quiet { min-width: 0; flex: 1; }
.quiet {
  display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 20px; border: 0; border-radius: 14px;
  background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); color: var(--fg); font-family: inherit; font-weight: 800; font-size: 18px; cursor: pointer;
}
.quiet:disabled { opacity: 0.35; cursor: default; }
.quiet:focus-visible { outline: 3px solid var(--emerald-bright); outline-offset: 2px; }
.rv-dots { display: flex; gap: 6px; }
.rv-dots button { width: 16px; height: 16px; padding: 0; border: 0; border-radius: 4px; background: var(--g); opacity: 0.35; cursor: pointer; }
.rv-dots button.on { opacity: 1; outline: 2px solid var(--fg); outline-offset: 1px; }

/* --- Help --------------------------------------------------------------- */
dialog {
  border: 0; border-radius: 18px; padding: 24px; max-width: min(440px, calc(100% - 32px));
  background: var(--bg); color: var(--fg); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(20, 20, 15, 0.55); }
dialog h2 { margin: 0 0 12px; font-size: 24px; }
.how { padding-left: 20px; line-height: 1.45; display: grid; gap: 8px; }
dialog form { text-align: center; margin-top: 16px; }
dialog .credit { font-size: 12px; margin-top: 4px; }

/* Short phones (iPhone SE): keep Share on screen (RS-7). */
@media (max-height: 700px) {
  #results { padding-top: 4px; }
  .score { font-size: 64px; }
  .tiles { margin: 10px 0 4px; }
  .share-row { margin: 12px 0 4px; }
  .stats { margin: 10px 0; padding: 10px 6px; }
  #intro { padding-top: 6vh; }
}

/* --- Archive ------------------------------------------------------------ */
.archive-title { font-size: 28px; margin: 12px 0 4px; }
.archive-list { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; }
.archive-list a {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; padding: 14px 16px;
  border-radius: 14px; background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--line); text-decoration: none;
}
.arc-num { font-weight: 900; }
.arc-date { color: var(--muted); font-size: 14px; }
.arc-tiles { font-size: 13px; letter-spacing: -1px; }
.arc-score { font-weight: 800; }
.arc-score small { color: var(--muted); font-weight: 600; }
.arc-play { grid-column: 3 / 5; justify-self: end; font-weight: 800; color: var(--accent); }
