/* =====================================================================================
   SHARED DESIGN SYSTEM  (used by Play, Editor and Dashboard: link /static/style.css first,
   then the page's own css; load /static/theme.js in <head> for the theme toggle)
   -------------------------------------------------------------------------------------
   Tokens (CSS custom properties, light + dark):
     surfaces  --bg --panel --panel-2 --border --border-strong
     text      --ink --ink-2 --ink-3
     brand     --accent --accent-ink --accent-soft --grad --grad-agent --focus
     status    --good --bad --warn  (+ --good-soft --bad-soft --warn-soft)
     board     --cell --cell-edge --wall --bridge --cp --cp-ink --cp-ring --legal --heat --island-0..7
     shape     --radius-sm --radius --radius-lg --shadow --shadow-lg
     type      --font --font-mono
     layout    --topbar-h
   Base components: .topbar .brand .logo .nav .nav-link .icon-btn .btn(.primary .agent .ghost .sm .block)
     .card .card-head .seg .chip .pill .switch .row .lbl .check .muted .tiny .mono .modal .modal-card
     kbd .sr-only .skip-link .spinner .toast
   ===================================================================================== */
[hidden] { display: none !important; }
:root {
  --bg: #f6f4f0;
  --panel: #ffffff;
  --panel-2: #f9f7f3;
  --border: #e7e2d9;
  --border-strong: #d3ccbf;
  --ink: #1d1c1a;
  --ink-2: #55514a;
  --ink-3: #7c776d;
  --accent: #6d4ae0;
  --accent-ink: #ffffff;
  --accent-soft: #eee9ff;
  --focus: #6d4ae0;
  --grad: linear-gradient(90deg, #ff9f1c, #ff5a4e 28%, #d63a8f 52%, #7b3fd6 76%, #2f6fe0);
  --grad-agent: linear-gradient(120deg, #d63a8f, #7b3fd6 55%, #2f6fe0);
  --cell: #f1ede6;
  --cell-edge: #ddd5c8;
  --wall: #25252b;
  --bridge: #8b909a;
  --cp: #141414;
  --cp-ink: #ffffff;
  --cp-ring: #141414;
  --good: #1a7f45;
  --bad: #cf3535;
  --warn: #b86a12;
  --good-soft: #e3f4ea;
  --bad-soft: #fde8e8;
  --warn-soft: #fcf0de;
  --legal: #6d4ae0;
  --heat: #0e9f9a;
  --shadow: 0 1px 2px rgba(20, 16, 8, .05), 0 6px 24px rgba(20, 16, 8, .06);
  --shadow-lg: 0 2px 6px rgba(20, 16, 8, .08), 0 24px 60px rgba(20, 16, 8, .18);
  --radius-sm: 9px;
  --radius: 14px;
  --radius-lg: 20px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --topbar-h: 56px;
  --island-0: #e3eefc; --island-1: #fde8dc; --island-2: #e2f3e2; --island-3: #f1e6fa;
  --island-4: #fbf3d2; --island-5: #dff3f3; --island-6: #fbe3ec; --island-7: #ececec;
  /* island puzzles: sea, beaches, land tints, plank bridges */
  --water-1: #8fdcec; --water-2: #3fa6cf; --water-deep: #1c6b93; --foam: #ffffff;
  --sand: #f4e2b3; --sand-2: #e5c98d; --tile: rgba(255, 255, 255, .42); --tile-edge: rgba(52, 84, 36, .16);
  --land-0: #9fd57f; --land-1: #bcdc72; --land-2: #86cfa4; --land-3: #cfd98a; --land-4: #a6d6a0; --land-5: #d7cf8f;
  --wood: #c08a55; --wood-2: #8f6034; --rope: #6b4a2b; --leaf: #3f9a4f; --rock: #9aa0a6; --rock-2: #c3c7cb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131418; --panel: #1b1d23; --panel-2: #22252c; --border: #2f323a; --border-strong: #454954;
    --ink: #ecebe7; --ink-2: #b9b6ae; --ink-3: #8c8981;
    --accent: #9d86ff; --accent-ink: #14121c; --accent-soft: #2b2545; --focus: #b3a2ff;
    --cell: #2a2d35; --cell-edge: #393d47; --wall: #e9e6df; --bridge: #8b909a;
    --cp: #0b0b0d; --cp-ink: #ffffff; --cp-ring: #f2f0ea;
    --good: #4cc27f; --bad: #ff6b6b; --warn: #f0a24a; --legal: #b7a4ff; --heat: #36d1c4;
    --good-soft: #1d3527; --bad-soft: #3d2224; --warn-soft: #3a2d1b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.25);
    --shadow-lg: 0 2px 6px rgba(0,0,0,.4), 0 24px 70px rgba(0,0,0,.55);
    --island-0: #25334a; --island-1: #45302a; --island-2: #253d2c; --island-3: #3a2d48;
    --island-4: #433d23; --island-5: #213e40; --island-6: #472a37; --island-7: #34363b;
    --water-1: #173e5c; --water-2: #0b1f33; --water-deep: #02070f; --foam: #a9d4ff;
    --sand: #8a7a58; --sand-2: #6d5f42; --tile: rgba(255, 255, 255, .10); --tile-edge: rgba(0, 0, 0, .25);
    --land-0: #3e6b45; --land-1: #52703d; --land-2: #37695a; --land-3: #5e6a3b; --land-4: #466f52; --land-5: #65653f;
    --wood: #8a6340; --wood-2: #5b3d22; --rope: #3a2715; --leaf: #2f6b3a; --rock: #5d636b; --rock-2: #7b828a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131418; --panel: #1b1d23; --panel-2: #22252c; --border: #2f323a; --border-strong: #454954;
  --ink: #ecebe7; --ink-2: #b9b6ae; --ink-3: #8c8981;
  --accent: #9d86ff; --accent-ink: #14121c; --accent-soft: #2b2545; --focus: #b3a2ff;
  --cell: #2a2d35; --cell-edge: #393d47; --wall: #e9e6df; --bridge: #8b909a;
  --cp: #0b0b0d; --cp-ink: #ffffff; --cp-ring: #f2f0ea;
  --good: #4cc27f; --bad: #ff6b6b; --warn: #f0a24a; --legal: #b7a4ff; --heat: #36d1c4;
  --good-soft: #1d3527; --bad-soft: #3d2224; --warn-soft: #3a2d1b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.25);
  --shadow-lg: 0 2px 6px rgba(0,0,0,.4), 0 24px 70px rgba(0,0,0,.55);
  --island-0: #25334a; --island-1: #45302a; --island-2: #253d2c; --island-3: #3a2d48;
  --island-4: #433d23; --island-5: #213e40; --island-6: #472a37; --island-7: #34363b;
  --water-1: #173e5c; --water-2: #0b1f33; --water-deep: #02070f; --foam: #a9d4ff;
  --sand: #8a7a58; --sand-2: #6d5f42; --tile: rgba(255, 255, 255, .10); --tile-edge: rgba(0, 0, 0, .25);
  --land-0: #3e6b45; --land-1: #52703d; --land-2: #37695a; --land-3: #5e6a3b; --land-4: #466f52; --land-5: #65653f;
  --wood: #8a6340; --wood-2: #5b3d22; --rope: #3a2715; --leaf: #2f6b3a; --rock: #5d636b; --rock-2: #7b828a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code { font-family: var(--font-mono); font-size: .92em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -40px; z-index: 100; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px; }
.skip-link:focus { top: 8px; }
.ic { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: -3px; }
.muted { color: var(--ink-3); font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.good-txt { color: var(--good); } .bad-txt { color: var(--bad); } .warn-txt { color: var(--warn); }

/* ---- top bar + navigation ---- */
.topbar {
  display: flex; align-items: center; gap: 14px; height: var(--topbar-h);
  padding: 0 20px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); }
.logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #ff9f1c, #ff5a4e 30%, #d63a8f 55%, #7b3fd6 80%, #2f6fe0);
  color: #fff; font-weight: 800; box-shadow: 0 2px 8px rgba(214, 58, 143, .3);
}
.logo svg { width: 22px; height: 22px; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -.3px; }
.nav { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; }
.nav-link {
  text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 13.5px;
  padding: 5px 12px; border-radius: 8px; line-height: 20px;
}
.nav-link:hover { color: var(--ink); background: var(--panel); }
.nav-link.active, .nav-link[aria-current="page"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--border); }
.topbar .spacer, .spacer { flex: 1; }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px;
  height: 34px; min-width: 34px; padding: 0 8px; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; color: var(--ink-2);
}
.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.icon-btn .ic { width: 17px; height: 17px; }
.icon-btn.sm { height: 28px; min-width: 28px; padding: 0 6px; border-radius: 8px; }

/* ---- buttons ---- */
.btn {
  height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel);
  padding: 0 13px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center;
  justify-content: center; gap: 7px; white-space: nowrap; color: var(--ink);
  transition: transform .08s ease, background .15s, border-color .15s, box-shadow .15s;
  box-shadow: 0 1px 1px rgba(0,0,0,.03);
}
.btn:hover:not(:disabled) { border-color: var(--border-strong); background: var(--panel-2); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover:not(:disabled) { background: var(--ink); opacity: .9; }
.btn.agent { background: var(--grad-agent); color: #fff; border: none; box-shadow: 0 4px 14px rgba(123, 63, 214, .28); }
.btn.agent:hover:not(:disabled) { background: var(--grad-agent); filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.sm { height: 30px; font-size: 12.5px; padding: 0 10px; border-radius: 8px; gap: 5px; }
.btn.sm .ic { width: 14px; height: 14px; }
.btn.block { width: 100%; }
.btn.toggle.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* ---- cards, forms ---- */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 14px 12px;
}
.card h2, .card-head h2 {
  font-size: 11px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 10px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 9px; flex-wrap: wrap; }
.row > label.lbl, .lbl { width: 92px; color: var(--ink-2); font-size: 13px; flex: none; }
.row .grow { flex: 1; min-width: 0; }
select, input[type=number], input[type=text], textarea {
  height: 34px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2);
  padding: 0 10px; min-width: 0; width: 100%;
}
select:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input[type=range] { accent-color: var(--accent); width: 100%; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; flex: none; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.note { font-size: 12px; color: var(--warn); margin: -2px 0 8px; }
.note.muted { color: var(--ink-3); margin: 6px 0 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; width: 100%; background: var(--panel-2); padding: 2px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; height: 30px; cursor: pointer; color: var(--ink-2); font-weight: 650; font-size: 12.5px; white-space: nowrap; padding: 0 6px; border-radius: 8px; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 40%; }
.seg.small { width: auto; }
.seg.small button { height: 26px; font-size: 12px; padding: 0 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel); color: var(--ink-2); font-weight: 650; cursor: pointer;
  white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { color: var(--ink); border-color: var(--border-strong); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span[aria-hidden] { width: 38px; height: 22px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .18s; }
.switch span[aria-hidden]::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span[aria-hidden] { background: var(--accent); }
.switch input:checked + span[aria-hidden]::after { transform: translateX(16px); }
.switch input:focus-visible + span[aria-hidden] { outline: 2px solid var(--focus); outline-offset: 2px; }
kbd {
  display: inline-block; min-width: 20px; padding: 0 5px; height: 20px; line-height: 19px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; text-align: center;
  font: 600 11px var(--font-mono); color: var(--ink-2); background: var(--panel-2);
}
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; flex: none; }
.spinner.sm { width: 12px; height: 12px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.modal { position: fixed; inset: 0; display: none; place-items: center; background: rgba(10, 10, 14, .45); z-index: 50; padding: 16px; backdrop-filter: blur(3px); }
.modal.show { display: grid; animation: fadein .18s ease; }
.modal-card { position: relative; max-width: 440px; width: 100%; padding: 26px 24px 22px; box-shadow: var(--shadow-lg); border-radius: var(--radius-lg); max-height: calc(100vh - 32px); overflow: auto; }
.modal.show .modal-card { animation: popin .28s cubic-bezier(.2, 1.4, .4, 1); }
.modal h2 { font-size: 22px; color: var(--ink); letter-spacing: -.3px; text-transform: none; margin: 4px 0 10px; }
.modal .close { position: absolute; right: 12px; top: 12px; }
@keyframes fadein { from { opacity: 0; } }
@keyframes popin { from { transform: translateY(10px) scale(.96); opacity: 0; } }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-weight: 600; z-index: 70;
  transition: opacity .2s, transform .2s; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 720px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .brand-name { display: none; }
  .nav-link { padding: 5px 9px; font-size: 13px; }
  .top-actions { gap: 4px; }
  .top-actions .icon-btn { min-width: 32px; height: 32px; padding: 0 6px; }
}
@media (max-width: 440px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .logo { width: 28px; height: 28px; }
  .nav { padding: 2px; }
  .nav-link { padding: 4px 7px; font-size: 12.5px; }
  .top-actions .icon-btn { min-width: 30px; height: 30px; padding: 0 5px; }
  #keysBtn { display: none; }
}
@media (max-width: 360px) { #helpBtn { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
/* ============================================================ end of shared section */


/* =====================================================================================
   PLAY PAGE
   ===================================================================================== */
.play {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px;
  padding: 16px 20px 28px; max-width: 1640px; margin: 0 auto; align-items: start;
}
@media (max-width: 1080px) { .play { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 720px) { .play { padding: 10px 10px 24px; gap: 12px; } }
.stage { min-width: 0; display: flex; flex-direction: column; gap: 12px; }

/* mode bar: daily + difficulty chips */
.modebar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.daily-chip { background: var(--panel); border-color: var(--border); }
.daily-chip.on { background: var(--grad-agent); border-color: transparent; color: #fff; }
.daily-chip .tick { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--good); color: #fff; }
.daily-chip .tick .ic { width: 12px; height: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.d-easy { background: #3bb273; } .d-medium { background: #e0a100; } .d-hard { background: #ef6b2f; }
.d-expert { background: #d63a8f; } .d-insane { background: #7b3fd6; }
.chip.on .dot { box-shadow: 0 0 0 2px var(--bg); }
@media (max-width: 720px) {
  .modebar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -10px; padding: 0 10px 2px; }
  .modebar::-webkit-scrollbar { display: none; }
  .chips { flex-wrap: nowrap; }
  .chip { height: 32px; padding: 0 11px; }
}

/* board card */
.board-card { position: relative; padding: 16px 18px 14px; }
@media (max-width: 720px) { .board-card { padding: 12px 10px 12px; border-radius: 12px; } }
.board-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 10px; }
.title-block { flex: 1; min-width: 0; }
.kicker { font-size: 11.5px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; color: var(--accent); }
.board-head h1 { margin: 1px 0 0; font-size: 21px; letter-spacing: -.4px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-head .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.hud { display: flex; gap: 6px; }
.hud-item { background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px; padding: 5px 11px 5px; min-width: 64px; text-align: right; }
.hud-item .k { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.hud-item .v { display: block; font-size: 19px; font-weight: 750; letter-spacing: -.3px; line-height: 1.15; }
.hud-item.dim .v { color: var(--ink-3); }
body.no-timer .hud-item:first-child { display: none; }
@media (max-width: 720px) {
  .board-head { flex-wrap: wrap; align-items: flex-start; }
  .board-head h1 { font-size: 18px; }
  .board-head .sub { display: none; }
  .hud-item { min-width: 54px; padding: 4px 8px; }
  .hud-item .v { font-size: 16px; }
}
.progress { height: 5px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
.progress i { display: block; height: 100%; width: 0; transition: width .18s ease; background: var(--grad); border-radius: 3px; }
.progress.thin { height: 4px; margin: 8px 0 6px; }
.view-toggle { margin: -2px 0 10px; }

.banner {
  display: none; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 11px; padding: 8px 10px 8px 12px; margin-bottom: 10px; font-size: 13.5px;
}
.banner.show { display: flex; animation: slidein .2s ease; }
.banner.good { border-left-color: var(--good); background: var(--good-soft); }
.banner.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.banner.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.banner .msg { flex: 1; min-width: 180px; }
.banner .actions { display: flex; gap: 6px; flex-wrap: wrap; }
@keyframes slidein { from { opacity: 0; transform: translateY(-4px); } }

/* search replay HUD */
.trace-hud {
  display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin-bottom: 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px; padding: 7px 10px; font-size: 12.5px;
}
.th-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--accent); }
.th-stat b { font-size: 13.5px; }
.th-bar { flex: 1; min-width: 60px; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.th-bar i { display: block; height: 100%; background: var(--grad-agent); }
.th-speed { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-3); }
.th-speed input { width: 90px; }

/* arena: main board (+3D view) (+race mini board) */
.arena { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.arena.racing { grid-template-columns: minmax(0, 1fr) minmax(150px, 30%); }
@media (max-width: 720px) { .arena.racing { grid-template-columns: minmax(0, 1fr); } }
.views { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0; }
.views.with3d { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
@media (max-width: 1250px) { .views.with3d { grid-template-columns: minmax(0, 1fr); } }
.view3d {
  position: relative; min-height: 360px; height: 100%; border-radius: 12px; overflow: hidden;
  background: var(--panel-2); border: 1px solid var(--border);
}
.view3d canvas { display: block; width: 100%; height: 100%; }
.view3d .overlay-label { position: absolute; left: 10px; top: 8px; font-size: 12px; color: var(--ink-3); pointer-events: none; z-index: 1; }
.view3d .fallback { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); font-size: 13px; padding: 20px; text-align: center; }
.board { position: relative; min-width: 0; display: flex; justify-content: center; }

/* the SVG board */
.zboard { touch-action: none; user-select: none; -webkit-user-select: none; display: block; max-width: 100%; height: auto; overflow: visible; }
.zboard:focus { outline: none; }
.zboard:focus-visible { outline: 2px solid var(--focus); outline-offset: 6px; border-radius: 8px; }
.zboard .cell { cursor: pointer; transition: stroke .2s; }
.zboard.mini .cell { cursor: default; }
.zboard .shake { animation: shake .28s; transform-box: fill-box; transform-origin: center; }
@keyframes shake { 20% { transform: translateX(-3px); } 40% { transform: translateX(3px); } 60% { transform: translateX(-2px); } 80% { transform: translateX(2px); } }
.zboard .tint { opacity: 0; transition: opacity .22s ease; pointer-events: none; transform-box: fill-box; transform-origin: center; }
.zboard .tint.on { opacity: .2; }
.zboard .tint.pop { animation: tintpop .32s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes tintpop { 0% { transform: scale(.55); opacity: .5; } 100% { transform: scale(1); } }
.zboard .g-path, .zboard .g-marks, .zboard .g-cp, .zboard .g-head, .zboard .g-fx, .zboard .g-heat, .zboard .g-tried { pointer-events: none; }
.zboard .seg-in { stroke-dasharray: 1 1; animation: segin .1s linear forwards; }
.zboard .seg-out { stroke-dasharray: 1 1; animation: segout .16s ease-in forwards; }
@keyframes segin { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes segout { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 1; } }
.zboard .head.glide { transition: transform .1s ease-out; }
.zboard .head-glow { animation: glow 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes glow { 0%, 100% { opacity: .55; transform: scale(.92); } 50% { opacity: .95; transform: scale(1.08); } }
.zboard .cp-inner { transform-box: fill-box; transform-origin: center; }
.zboard .cp-inner.pop { animation: cppop .45s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes cppop { 0% { transform: scale(1); } 35% { transform: scale(1.28); } 100% { transform: scale(1); } }
.zboard .burst { transform-box: fill-box; transform-origin: center; animation: burst .6s ease-out forwards; }
@keyframes burst { from { transform: scale(1); opacity: .9; } to { transform: scale(2.3); opacity: 0; } }
.zboard .next-ring { animation: breathe 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes breathe { 0%, 100% { opacity: .35; transform: scale(1); } 50% { opacity: .8; transform: scale(1.06); } }
.zboard .pulse { animation: pulse 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(1.12); } }
.zboard .heat { transition: fill-opacity .25s ease; }
.zboard .pol-top { animation: breathe 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.zboard .pol-txt { font-family: var(--font); }
.zboard.won .seg { animation: wonglow 1.2s ease-out; }
/* island puzzles: animated sea, foam, swaying palms, splash when the line crosses a bridge */
.zboard .sea .waves { animation: waves 9s linear infinite; }
.zboard .sea .waves.w-b { animation-duration: 14s; animation-direction: reverse; opacity: .8; }
@keyframes waves { from { transform: translateX(0); } to { transform: translateX(var(--wl)); } }
.zboard .caustic { animation: caustic 6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes caustic { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.12); } }
.zboard .foam { animation: foam 4s ease-in-out infinite; }
@keyframes foam { 0%, 100% { opacity: .25; } 50% { opacity: .6; } }
.zboard .scenery .sway { animation: sway 3.2s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(4deg); } }
.zboard .scenery, .zboard .plank-bridge, .zboard .sea { pointer-events: none; }
.zboard .splash { transform-box: fill-box; transform-origin: center; animation: splash .8s ease-out forwards; opacity: 0; }
@keyframes splash { 0% { transform: scale(.3); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }
.zboard .drop { animation: drop .6s cubic-bezier(.3, .6, .5, 1) forwards; }
@keyframes drop { 0% { transform: translate(0, 0); opacity: 1; } 60% { transform: translate(calc(var(--dx) * .8), var(--dy)); opacity: 1; } 100% { transform: translate(var(--dx), 0); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .zboard .sea *, .zboard .foam, .zboard .scenery * { animation: none !important; } }
@keyframes wonglow { 0% { filter: brightness(1); } 30% { filter: brightness(1.35) saturate(1.2); } 100% { filter: brightness(1); } }

.controls { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.controls .btn .ic { width: 16px; height: 16px; }
@media (max-width: 720px) {
  .controls { gap: 6px; }
  .controls .btn { padding: 0 10px; flex: 1 1 auto; }
  .controls .spacer { display: none; }
}
@media (max-width: 420px) { .controls .btn span { display: none; } .controls .btn { min-width: 44px; } }

/* AI vision insight strip */
.insight { margin-top: 12px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--panel-2); transition: opacity .2s; }
.insight.stale { opacity: .75; }
.ins-head { display: flex; align-items: center; gap: 7px; font-size: 13px; margin-bottom: 8px; }
.ins-head .ic { color: var(--accent); }
.ins-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ins-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 10px 16px; align-items: center; }
@media (max-width: 720px) { .ins-grid { grid-template-columns: minmax(0, 1fr); } }
.meter-label { font-size: 13.5px; margin-bottom: 5px; }
.meter { height: 9px; border-radius: 5px; background: var(--border); overflow: hidden; margin-bottom: 5px; }
.meter i { display: block; height: 100%; border-radius: 5px; background: var(--accent); transition: width .35s ease; }
.meter.good i { background: var(--good); } .meter.warn i { background: var(--warn); } .meter.bad i { background: var(--bad); }
.ins-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ichip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--ink-2); }
.ichip .ic { width: 13px; height: 13px; }
.ichip.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }
.ichip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.ichip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }

.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink-3); margin-top: 12px; }

.busy {
  position: absolute; inset: 0; display: none; place-items: center; background: color-mix(in srgb, var(--panel) 65%, transparent);
  border-radius: var(--radius); z-index: 5; backdrop-filter: blur(1.5px);
}
.busy.show { display: grid; animation: fadein .2s ease .15s both; }
.busy .box { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--border); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); }

/* race side */
.race-side { border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: var(--panel-2); min-width: 0; }
.race-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 13px; }
.race-name { font-weight: 750; display: inline-flex; align-items: center; gap: 6px; }
.race-status { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap; }
.race-status.good { color: var(--good); } .race-status.bad { color: var(--bad); } .race-status.warn { color: var(--warn); }
.race-board { display: flex; justify-content: center; }
.countdown { position: fixed; left: 50%; top: 45%; width: 180px; height: 180px; margin: -90px 0 0 -90px; border-radius: 50%; display: none; place-items: center; z-index: 55; pointer-events: none;
  font-size: 92px; font-weight: 850; letter-spacing: -3px; color: #fff; background: var(--grad-agent); box-shadow: 0 20px 60px rgba(123, 63, 214, .45), 0 0 0 10px color-mix(in srgb, var(--panel) 70%, transparent); }
.countdown.go { font-size: 60px; letter-spacing: -1px; }
.countdown.show { display: grid; animation: countpop .6s ease; }
@keyframes countpop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } }

/* side panel */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; position: sticky; top: calc(var(--topbar-h) + 12px); max-height: calc(100vh - var(--topbar-h) - 24px); overflow: auto; padding-bottom: 4px; scrollbar-width: thin; }
@media (max-width: 1080px) { .side { position: static; max-height: none; overflow: visible; } }
.tabs { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; position: sticky; top: 0; z-index: 2; }
.tabs button { flex: 1; border: 0; background: transparent; height: 34px; border-radius: 9px; font-weight: 700; color: var(--ink-2); cursor: pointer; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--border); }
.pane { display: flex; flex-direction: column; gap: 12px; }
.pane p.muted { margin: 0 0 10px; line-height: 1.45; }

.streak { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: 12.5px; color: #e8590c; }
.daily-grid { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 10px; }
.daily-tile {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left;
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px; padding: 8px 11px; cursor: pointer; font-weight: 650;
}
.daily-tile:hover { border-color: var(--border-strong); }
.daily-tile.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.daily-tile .dl { display: inline-flex; align-items: center; gap: 8px; }
.daily-tile .dv { font-size: 12.5px; }
.daily-tile.done .dv { color: var(--good); font-weight: 750; }
.daily-tile .dv .ic { width: 14px; height: 14px; }
table.records { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 6px; }
table.records th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 700; text-align: right; padding: 3px 4px; }
table.records td { padding: 5px 4px; border-top: 1px solid var(--border); text-align: right; }
table.records td:first-child, table.records th:first-child { text-align: left; }
table.records td:first-child .dot { margin-right: 8px; }
details.advanced summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; }
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary h2 { margin: 0; }
details.advanced summary::after { content: "▾"; margin-left: auto; color: var(--ink-3); transition: transform .2s; }
details.advanced[open] summary::after { transform: rotate(180deg); }
details.advanced .adv-body { margin-top: 12px; }
.opt-val { width: 38px; text-align: right; }

.model-info { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.model-info .pill .ic { width: 13px; height: 13px; }

table.cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.cmp th, table.cmp td { text-align: right; padding: 4px 4px; border-bottom: 1px solid var(--border); }
table.cmp th:first-child, table.cmp td:first-child { text-align: left; color: var(--ink-3); font-weight: 500; }
table.cmp th { font-size: 11px; color: var(--ink-2); font-weight: 700; white-space: nowrap; }
table.cmp td { white-space: nowrap; }
table.cmp td.wrap { white-space: normal; text-align: left; padding-left: 10px; }
.ok { color: var(--good); font-weight: 700; }
.fail { color: var(--bad); font-weight: 700; }
.conf-block { margin-top: 10px; }
.conf-title { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.cand { display: grid; grid-template-columns: 54px 1fr 44px; gap: 6px; align-items: center; font-size: 12px; margin: 3px 0; }
.cand .bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.cand .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.cand .bar i.chosen { background: linear-gradient(90deg, #d63a8f, #7b3fd6); }
.cand .p { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.spark-wrap { position: relative; }
.spark { width: 100%; height: 56px; display: block; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 11px; padding: 3px 7px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); display: none; }

.cmp-models { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; max-height: 172px; overflow: auto; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.cmp-model { font-size: 12.5px; }
.cmp-model .muted { margin-left: auto; font-size: 11.5px; }
.cmp-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 10px; }
.cmp-card { border: 1px solid var(--border); border-radius: 11px; padding: 8px; background: var(--panel-2); cursor: pointer; min-width: 0; transition: border-color .15s, transform .1s; }
.cmp-card:hover { border-color: var(--border-strong); }
.cmp-card.best { border-color: var(--good); box-shadow: 0 0 0 1px var(--good) inset; }
.cmp-card.loading { cursor: progress; opacity: .8; }
.cmp-card-head { display: flex; flex-direction: column; gap: 1px; font-size: 12px; margin-bottom: 6px; min-width: 0; }
.cmp-card-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-st { font-size: 11.5px; }
.cmp-card-head .ic { width: 12px; height: 12px; }
.cmp-mini { display: flex; justify-content: center; min-height: 20px; }
.cmp-kv { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 6px; }

.opp-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.opp { display: flex; gap: 10px; align-items: center; text-align: left; border: 1px solid var(--border); background: var(--panel-2); border-radius: 11px; padding: 9px 10px; cursor: pointer; }
.opp:hover { border-color: var(--border-strong); }
.opp.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: var(--accent-soft); }
.opp-av { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none; }
.opp-av .ic { width: 18px; height: 18px; }
.av-rookie { background: linear-gradient(135deg, #3bb273, #1f8a4c); }
.av-challenger { background: linear-gradient(135deg, #ff9f1c, #ef6b2f); }
.av-grandmaster { background: var(--grad-agent); }
.opp-txt { display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.opp-txt .muted { font-size: 11.5px; }

/* win modal */
.win-card { text-align: center; }
.win-badge { width: 54px; height: 54px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; background: var(--good); color: #fff; box-shadow: 0 6px 20px color-mix(in srgb, var(--good) 45%, transparent); }
.win-badge .ic { width: 28px; height: 28px; }
.win-badge.gold { background: linear-gradient(135deg, #ffcf3f, #ff9f1c); box-shadow: 0 6px 20px rgba(255, 159, 28, .45); }
.win-card .kicker { margin-top: 4px; }
.win-card h2 { margin: 2px 0 2px; }
.big { font-size: 52px; font-weight: 850; letter-spacing: -2px; line-height: 1.1; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pb { display: inline-flex; gap: 6px; align-items: center; font-weight: 700; color: #c77700; background: #fff4d6; border-radius: 999px; padding: 3px 12px; font-size: 13px; margin: 4px 0; }
:root[data-theme="dark"] .pb { background: #3a2e12; color: #ffc453; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pb { background: #3a2e12; color: #ffc453; } }
.win-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; margin: 14px 0 10px; }
.win-stats div { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 7px 4px; }
.win-stats .k { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.win-stats .v { display: block; font-size: 16px; font-weight: 750; }
.share-text { text-align: left; font: 12.5px/1.5 var(--font-mono); background: var(--panel-2); border: 1px dashed var(--border-strong); border-radius: 10px; padding: 9px 12px; margin: 0; white-space: pre-wrap; color: var(--ink-2); user-select: all; }

/* how to play */
.help-card { max-width: 560px; }
.howto { display: grid; grid-template-columns: 150px 1fr; gap: 18px; align-items: center; margin: 6px 0 10px; }
@media (max-width: 520px) { .howto { grid-template-columns: 1fr; justify-items: center; } }
.howto-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 7px; font-size: 13.5px; color: var(--ink-2); }
.demo { width: 150px; height: 150px; }
.demo .demo-cells rect { fill: var(--cell); stroke: var(--cell-edge); }
.demo .demo-path { fill: none; stroke: url(#none); stroke: #d63a8f; stroke-width: 15; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 1; animation: demo 3.6s ease-in-out infinite; }
.demo .demo-cps circle { fill: var(--cp); stroke: var(--cp-ring); stroke-width: 1.5; }
.demo .demo-cps text { fill: var(--cp-ink); font-weight: 800; font-size: 16px; }
@keyframes demo { 0% { stroke-dashoffset: 1; } 70%, 88% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: 1; } }
table.keys { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.keys td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.keys td:first-child { white-space: nowrap; width: 48%; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
