/* ------------------------------------------------------------------ tokens */
:root {
  --font: 'Outfit', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;

  --bg: #070913;
  --glow-a: #1b2058;
  --glow-b: #33124d;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-2: rgba(255, 255, 255, 0.085);
  --border: rgba(165, 175, 255, 0.17);
  --border-2: rgba(165, 175, 255, 0.32);
  --ink: #eef0ff;
  --muted: #8f95bd;
  --faint: #596096;

  --cur: #6cf1ff;   --cur-rgb: 108, 241, 255;
  --opt: #a99bff;   --opt-rgb: 169, 155, 255;
  --tgt: #7dffb5;   --tgt-rgb: 125, 255, 181;
  --start: #ff5fa2; --start-rgb: 255, 95, 162;
  --good: #46e39a;
  --warn: #ffd166;   --warn-rgb: 255, 209, 102;
  --bad: #ff6b81;    --bad-rgb: 255, 107, 129;

  --node-bg: #151938;
  --node-bg-hover: #1e2350;
  --sheet-bg: #0e1128;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --ease: cubic-bezier(0.2, 0.9, 0.25, 1);
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f3ec;
  --glow-a: #e2dcff;
  --glow-b: #ffe0ee;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-2: rgba(255, 255, 255, 0.95);
  --border: rgba(40, 40, 100, 0.13);
  --border-2: rgba(40, 40, 100, 0.26);
  --ink: #14162b;
  --muted: #62678d;
  --faint: #9a9ec0;

  --cur: #0794b8;   --cur-rgb: 7, 148, 184;
  --opt: #5a49d6;   --opt-rgb: 90, 73, 214;
  --tgt: #0f9a58;   --tgt-rgb: 15, 154, 88;
  --start: #e3226f; --start-rgb: 227, 34, 111;
  --good: #16a765;
  --warn: #c98a00;   --warn-rgb: 201, 138, 0;
  --bad: #d92d4b;    --bad-rgb: 217, 45, 75;

  --node-bg: #ffffff;
  --node-bg-hover: #f1eeff;
  --sheet-bg: #fbfaf6;
  --shadow: 0 18px 50px rgba(40, 40, 90, 0.18);
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 640px at 50% -12%, var(--glow-a) 0%, transparent 62%),
    radial-gradient(900px 620px at 105% 105%, var(--glow-b) 0%, transparent 58%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#ambient { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 12px);
}
main { flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }

:focus-visible { outline: 2px solid var(--cur); outline-offset: 3px; border-radius: 10px; }
.dlg-close .icon-btn:focus-visible { outline: none; background: var(--panel); }

/* ------------------------------------------------------------------ header */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 58px;
}
.side { display: flex; gap: 2px; align-items: center; }
.side.right { justify-content: flex-end; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  transition: color 0.15s, background 0.15s, transform 0.15s;
}
.icon-btn:hover { color: var(--ink); background: var(--panel); }
.icon-btn:active { transform: scale(0.92); }

.wordmark {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.035em;
  display: flex;
  align-items: center;
}
.wordmark .glyph {
  width: 0.56em;
  height: 0.56em;
  margin: 0 0.02em 0 0.03em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff 0 12%, var(--cur) 40%, var(--opt) 100%);
  box-shadow: 0 0 14px rgba(var(--cur-rgb), 0.75), 0 0 34px rgba(var(--opt-rgb), 0.5);
  position: relative;
  animation: breathe 3.6s ease-in-out infinite;
}
.wordmark .glyph::before,
.wordmark .glyph::after {
  content: '';
  position: absolute;
  height: 1.5px;
  background: linear-gradient(90deg, rgba(var(--cur-rgb), 0.9), transparent);
  transform-origin: 0 50%;
  width: 11px;
}
.wordmark .glyph::before { left: 82%; top: 20%; transform: rotate(-38deg); }
.wordmark .glyph::after { left: 90%; top: 62%; transform: rotate(28deg); width: 8px; }
@keyframes breathe { 50% { transform: scale(1.14); filter: brightness(1.2); } }

/* ------------------------------------------------------------------ mission */
.puzzle-meta {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.puzzle-meta i { width: 3px; height: 3px; border-radius: 50%; background: var(--faint); }

.mission {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.endpoint { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.endpoint.to { align-items: flex-end; text-align: right; }
.endpoint .tag {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.endpoint .word {
  font-size: clamp(19px, 5.6vw, 28px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.endpoint.from .word { color: var(--start); }
.endpoint.to .word {
  color: var(--tgt);
  text-shadow: 0 0 22px rgba(var(--tgt-rgb), 0.55);
}
.endpoint .sub { font-size: 12px; color: var(--muted); min-height: 15px; }

.link { display: grid; justify-items: center; gap: 2px; position: relative; padding: 0 6px; }
.link::before,
.link::after {
  content: '';
  position: absolute;
  top: 19px;
  width: 22px;
  border-top: 2px dashed var(--border-2);
}
.link::before { right: 100%; }
.link::after { left: 100%; }
.hops {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--node-bg);
  border: 1.5px solid rgba(var(--cur-rgb), 0.55);
  box-shadow: 0 0 22px rgba(var(--cur-rgb), 0.28), inset 0 0 14px rgba(var(--cur-rgb), 0.12);
  line-height: 1;
  align-content: center;
}
.hops span { font-size: 22px; font-weight: 800; color: var(--cur); font-variant-numeric: tabular-nums; }
.hops small { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-top: 1px; }
.hops.bump { animation: bump 0.35s var(--ease); }
@keyframes bump { 40% { transform: scale(1.18); } }
.min { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.min b { color: var(--ink); font-weight: 700; }

/* the "+N carried" flourish that plays over the moves badge when a new endless round inherits leftover moves */
.carry-pop {
  position: absolute;
  top: -4px;
  left: 50%;
  z-index: 5;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(var(--cur-rgb), 0.16);
  border: 1px solid rgba(var(--cur-rgb), 0.5);
  color: var(--cur);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.carry-pop.show { animation: carryPop 1.7s var(--ease) forwards; }
@keyframes carryPop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.85); }
  18% { opacity: 1; transform: translate(-50%, -14px) scale(1.08); }
  32% { opacity: 1; transform: translate(-50%, -14px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(0.92); }
}

.gateways {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  padding: 9px 12px;
  border-radius: 14px;
  border: 1px dashed rgba(var(--tgt-rgb), 0.5);
  background: rgba(var(--tgt-rgb), 0.07);
  font-size: 13px;
}
.gateways .label { color: var(--muted); font-size: 11.5px; letter-spacing: 0.04em; width: 100%; }
.gateways .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.gateways .chip { padding: 3px 10px; border-radius: 999px; background: rgba(var(--tgt-rgb), 0.14); color: var(--tgt); font-weight: 600; }

/* ------------------------------------------------------------------ trail */
.trail {
  display: flex;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 6px 20px;
  margin: 0 -16px;
  min-height: 42px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%);
}
.trail::-webkit-scrollbar { display: none; }
.trail .chip {
  flex: none;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.trail button.chip:hover { color: var(--ink); border-color: var(--border-2); background: var(--panel-2); }
.trail .chip.first { color: var(--start); border-color: rgba(var(--start-rgb), 0.4); }
.trail .chip.now {
  color: #06121a;
  background: var(--cur);
  border-color: transparent;
  box-shadow: 0 0 18px rgba(var(--cur-rgb), 0.5);
}
.trail .chip.goal { color: var(--tgt); border: 1px dashed rgba(var(--tgt-rgb), 0.6); background: rgba(var(--tgt-rgb), 0.06); }
.trail .chip.won { color: #fff; background: var(--tgt); border-color: transparent; box-shadow: 0 0 18px rgba(var(--tgt-rgb), 0.6); }
.trail .sep {
  flex: none;
  width: 14px;
  height: 2px;
  background: linear-gradient(90deg, var(--border-2), rgba(var(--opt-rgb), 0.55));
}
.trail .sep.dim { background: repeating-linear-gradient(90deg, var(--border-2) 0 3px, transparent 3px 6px); }

/* ------------------------------------------------------------------ stage */
.stage-wrap { position: relative; flex: 1; min-height: 340px; display: flex; }
.stage { position: relative; flex: 1; touch-action: manipulation; }
.synapses, .burst { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.burst { z-index: 6; }
.nodes { position: absolute; inset: 0; z-index: 3; }

.syn { fill: none; stroke-linecap: round; }
.syn.base { stroke: url(#synGrad); opacity: 0.9; }
.syn.flow { stroke: var(--cur); stroke-dasharray: 7 400; filter: drop-shadow(0 0 5px rgba(var(--cur-rgb), 0.9)); }
.syn.hot { stroke: var(--tgt); }
.syn.draw { animation: draw 0.5s var(--ease) both; }
@keyframes draw { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }
.syn.flow { animation: flow 2.8s linear infinite; }
@keyframes flow { from { stroke-dashoffset: 407; } to { stroke-dashoffset: 0; } }

.node {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  padding: 10px 17px;
  border-radius: 999px;
  border: 1.5px solid rgba(var(--opt-rgb), 0.6);
  background: var(--node-bg);
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  box-shadow: 0 0 0 0 rgba(var(--opt-rgb), 0), 0 8px 24px rgba(0, 0, 0, 0.28), 0 0 26px rgba(var(--opt-rgb), 0.2);
  transition: transform 0.55s var(--ease), opacity 0.4s ease, background 0.2s, border-color 0.2s, box-shadow 0.25s, color 0.2s;
  will-change: transform;
  user-select: none;
}
.node.long { font-size: 15px; padding: 9px 14px; }
.node.option:hover,
.node.option:focus-visible {
  background: var(--node-bg-hover);
  border-color: var(--opt);
  box-shadow: 0 0 0 4px rgba(var(--opt-rgb), 0.14), 0 8px 28px rgba(0, 0, 0, 0.3), 0 0 36px rgba(var(--opt-rgb), 0.45);
}
.node.option:active { filter: brightness(1.2); }
.node .k {
  position: absolute;
  top: -8px;
  left: 10px;
  min-width: 17px;
  padding: 0 4px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  display: none;
}
@media (hover: hover) and (pointer: fine) { .node.option .k { display: block; } }

.node.current {
  pointer-events: none;
  border-color: var(--cur);
  color: #04141c;
  background: linear-gradient(135deg, var(--cur), color-mix(in srgb, var(--cur) 55%, var(--opt)));
  box-shadow: 0 0 34px rgba(var(--cur-rgb), 0.6), 0 0 90px rgba(var(--cur-rgb), 0.28);
  font-weight: 700;
  z-index: 4;
}
.node.current::after {
  content: '';
  position: absolute;
  inset: -9px;
  border-radius: inherit;
  border: 1.5px solid rgba(var(--cur-rgb), 0.45);
  animation: ring 2.6s ease-out infinite;
}
@keyframes ring { from { transform: scale(0.94); opacity: 0.9; } to { transform: scale(1.22); opacity: 0; } }

/* A brief colored flash on the word you just hopped to, echoing the hop sound's own closer/sideways/farther
   cue (the same trend value that drives the extra low undertone and the share screen's 🟩🟨🟥). Recolors the
   whole node, not just its glow, so it reads clearly rather than blending into the node's usual cyan glow.
   Green matches the target's own color (closer = heading toward it), red matches the start's (farther = drifting
   back toward where you began). One-shot and imperative (Stage.pulseTrend), separate from the persistent ring
   tint below so a later re-render (e.g. a resize) can't accidentally replay it. */
.node.current.flash-up { animation: trendFlash 1.4s var(--ease); --trend: var(--tgt); --trend-rgb: var(--tgt-rgb); }
.node.current.flash-flat { animation: trendFlash 1.4s var(--ease); --trend: var(--warn); --trend-rgb: var(--warn-rgb); }
.node.current.flash-down { animation: trendFlash 1.4s var(--ease); --trend: var(--start); --trend-rgb: var(--start-rgb); }
@keyframes trendFlash {
  0%, 50% {
    background: linear-gradient(135deg, var(--trend), color-mix(in srgb, var(--trend) 55%, var(--opt)));
    border-color: var(--trend);
    box-shadow: 0 0 0 7px rgba(var(--trend-rgb), 0.45), 0 0 50px rgba(var(--trend-rgb), 0.95), 0 0 120px rgba(var(--trend-rgb), 0.55);
  }
  100% {
    background: linear-gradient(135deg, var(--cur), color-mix(in srgb, var(--cur) 55%, var(--opt)));
    border-color: var(--cur);
    box-shadow: 0 0 34px rgba(var(--cur-rgb), 0.6), 0 0 90px rgba(var(--cur-rgb), 0.28);
  }
}

/* The continual ring keeps echoing the most recent hop's trend until the next hop changes it (derived from
   the game's own hop history in view(), so it survives re-renders rather than being wiped like the flash). */
.node.current.trend-up::after { border-color: rgba(var(--tgt-rgb), 0.55); }
.node.current.trend-flat::after { border-color: rgba(var(--warn-rgb), 0.55); }
.node.current.trend-down::after { border-color: rgba(var(--start-rgb), 0.55); }

.node.visited { opacity: 0.55; border-style: dashed; }
.node.visited:hover { opacity: 0.9; }

.node.is-target {
  border-color: var(--tgt);
  background: color-mix(in srgb, var(--node-bg) 78%, var(--tgt));
  color: var(--ink);
  box-shadow: 0 0 34px rgba(var(--tgt-rgb), 0.65), 0 0 0 4px rgba(var(--tgt-rgb), 0.18);
  animation: goal 1.6s ease-in-out infinite;
  opacity: 1;
}
@keyframes goal { 50% { box-shadow: 0 0 52px rgba(var(--tgt-rgb), 0.95), 0 0 0 9px rgba(var(--tgt-rgb), 0.08); } }
.node.current.is-target { background: var(--tgt); border-color: var(--tgt); color: #fff; animation: none; }
.node.current.is-target::after { border-color: rgba(var(--tgt-rgb), 0.6); }

.node.hint {
  border-color: var(--warn);
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.2), 0 0 34px rgba(255, 209, 102, 0.5);
  animation: hintPulse 1.3s ease-in-out infinite;
}
@keyframes hintPulse { 50% { box-shadow: 0 0 0 9px rgba(255, 209, 102, 0.06), 0 0 46px rgba(255, 209, 102, 0.7); } }

.node.leaving { opacity: 0; pointer-events: none; }
.node.locked { pointer-events: none; }
.node.shake { animation: shake 0.3s; }
@keyframes shake { 25% { margin-left: -5px; } 75% { margin-left: 5px; } }

/* ------------------------------------------------------------------ controls */
.controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ctl {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 46px;
  padding: 0 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.12s, opacity 0.2s;
}
.ctl span { white-space: nowrap; }
.ctl:hover:not(:disabled) { color: var(--ink); background: var(--panel-2); border-color: var(--border-2); }
.ctl:active:not(:disabled) { transform: scale(0.96); }
.ctl:disabled { opacity: 0.35; cursor: default; }
.controls.over { grid-template-columns: 1fr; }
.controls.endless-done { grid-template-columns: 1fr 1fr; }
.controls.endless-done #btn-results { grid-column: 1 / -1; }
.btn.wide { width: 100%; min-height: 50px; }
.ctl.on { color: var(--warn); border-color: rgba(255, 209, 102, 0.5); }

/* ------------------------------------------------------------------ dialogs */
dialog {
  width: min(92vw, 460px);
  max-height: min(88dvh, 820px);
  padding: 26px 24px 24px;
  border: 1px solid var(--border-2);
  border-radius: 26px;
  background: var(--sheet-bg);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: auto;
}
dialog[open] { animation: pop 0.32s var(--ease); }
dialog::backdrop { background: rgba(4, 5, 14, 0.62); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
:root[data-theme='light'] dialog::backdrop { background: rgba(30, 30, 60, 0.35); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(0.97); } }
.dlg-close { position: absolute; top: 12px; right: 12px; margin: 0; }
dialog h2 { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; padding-right: 30px; }
dialog h3 {
  margin: 20px 0 10px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.lede { margin-top: 4px; color: var(--muted); font-size: 15.5px; line-height: 1.45; }
.fine { margin-top: 12px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.fine a { color: var(--cur); }
dialog .row { display: flex; gap: 10px; margin-top: 16px; }
dialog .row > * { flex: 1; }

.sheet {
  margin: auto auto 0;
  width: min(100vw, 520px);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 26px; } }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  border: 1px solid var(--border-2);
  background: var(--panel);
  font-weight: 700;
  font-size: 15.5px;
  transition: transform 0.12s, filter 0.15s, background 0.15s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  border-color: transparent;
  color: #061019;
  background: linear-gradient(135deg, var(--cur), var(--opt));
  box-shadow: 0 8px 26px rgba(var(--cur-rgb), 0.32);
}
.btn.primary:hover { filter: brightness(1.08); }
:root[data-theme='light'] .btn.primary { color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 14px; }
#help-go { width: 100%; margin-top: 18px; }

/* help */
.help-demo {
  position: relative;
  height: 172px;
  margin: 16px 0 6px;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 50%, rgba(var(--cur-rgb), 0.12), transparent 65%), var(--panel);
  border: 1px solid var(--border);
  overflow: hidden;
}
.hd-center, .hd {
  position: absolute;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--node-bg);
  border: 1.5px solid rgba(var(--opt-rgb), 0.6);
  transform: translate(-50%, -50%);
}
.hd-center { left: 50%; top: 50%; background: var(--cur); color: #04141c; border-color: transparent; box-shadow: 0 0 24px rgba(var(--cur-rgb), 0.6); font-size: 15px; z-index: 2; }
.hd1 { left: 50%; top: 14%; } .hd2 { left: 82%; top: 38%; } .hd3 { left: 71%; top: 84%; }
.hd4 { left: 29%; top: 84%; } .hd5 { left: 18%; top: 38%; }
.help-demo::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    conic-gradient(from 0deg at 50% 50%, transparent 0 4deg, rgba(var(--opt-rgb), 0.35) 4deg 4.6deg, transparent 4.6deg 72deg, rgba(var(--opt-rgb), 0.35) 76deg 76.6deg, transparent 76.6deg 144deg, rgba(var(--opt-rgb), 0.35) 148deg 148.6deg, transparent 148.6deg 216deg, rgba(var(--opt-rgb), 0.35) 220deg 220.6deg, transparent 220.6deg 288deg, rgba(var(--opt-rgb), 0.35) 292deg 292.6deg, transparent 292.6deg);
  mask-image: radial-gradient(circle, transparent 22%, #000 24%);
  -webkit-mask-image: radial-gradient(circle, transparent 22%, #000 24%);
  animation: spin 40s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hd { animation: hdpulse 5s ease-in-out infinite; }
.hd2 { animation-delay: 1s; } .hd3 { animation-delay: 2s; } .hd4 { animation-delay: 3s; } .hd5 { animation-delay: 4s; }
@keyframes hdpulse { 10%, 18% { border-color: var(--cur); box-shadow: 0 0 18px rgba(var(--cur-rgb), 0.6); } }
.steps { margin: 14px 0 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; position: relative; padding-left: 36px; font-size: 15px; line-height: 1.45; color: var(--muted); }
.steps li b { color: var(--ink); font-weight: 600; }
.steps li::before {
  content: counter(s);
  position: absolute;
  left: 0;
  top: 0;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--cur);
  border: 1.5px solid rgba(var(--cur-rgb), 0.5);
}

/* stats + result shared */
.stat-row, .res-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.res-stats { grid-template-columns: repeat(3, 1fr); }
.stat {
  position: relative;
  display: grid;
  gap: 2px;
  place-items: center;
  padding: 12px 4px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  text-align: center;
}
.stat b { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat small { font-size: 10.5px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.stat em { font-style: normal; font-size: 12px; color: var(--warn); font-weight: 700; }

/* the "just set a new record" corner ribbon on a stat box - personal (Your Best) or global (Community Best/Most Hops) */
.stat .corner-tag {
  position: absolute;
  top: -8px;
  right: -6px;
  background: var(--warn);
  color: #1a1200;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

/* the arcade-style 3-character initials prompt shown when a run's link count makes the global top 10 */
.qualify {
  display: grid;
  gap: 8px;
  justify-items: center;
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(var(--warn-rgb), 0.08);
  border: 1px dashed rgba(var(--warn-rgb), 0.5);
  text-align: center;
}
.qualify .lede { margin: 0; font-size: 13px; }
.qualify .row { justify-content: center; }
.qualify input {
  width: 84px;
  padding: 10px 0;
  border-radius: 12px;
  border: 1.5px solid var(--border-2);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
}
.qualify input:focus-visible { outline: 2px solid var(--cur); outline-offset: 2px; }
.qualify .err { color: var(--bad); font-size: 12.5px; min-height: 15px; }
.qualify .done { font-size: 15px; font-weight: 700; color: var(--warn); }

.lb-list { display: grid; gap: 6px; margin-top: 14px; max-height: 50vh; overflow-y: auto; }
.lb-row {
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.lb-row .rank { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-row:first-child .rank { color: var(--warn); }
.lb-row .initials { font-weight: 800; letter-spacing: 0.12em; font-size: 16px; }
.lb-row .links { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-row .lb-hops {
  justify-self: end;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1.5px solid rgba(var(--cur-rgb), 0.55);
  font-size: 12px;
  white-space: nowrap;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.lb-empty { text-align: center; color: var(--muted); padding: 20px; }

.dist { display: grid; gap: 6px; }
.dist .bar { display: grid; grid-template-columns: 112px 1fr; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.dist .fill {
  min-width: 26px;
  height: 22px;
  border-radius: 7px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-weight: 700;
  font-size: 12.5px;
  background: var(--panel-2);
  color: var(--ink);
}
.dist .bar.hl .fill { background: linear-gradient(90deg, rgba(var(--cur-rgb), 0.55), var(--cur)); color: #04141c; }

.next { margin-top: 18px; text-align: center; color: var(--muted); font-size: 13px; letter-spacing: 0.04em; }
.next b { display: block; margin-top: 2px; font-size: 26px; font-weight: 800; color: var(--ink); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }

/* result */
.res-head { text-align: center; padding-top: 6px; }
.res-emoji { font-size: 54px; line-height: 1; filter: drop-shadow(0 0 22px rgba(var(--cur-rgb), 0.5)); animation: floaty 3.2s ease-in-out infinite; }
@keyframes floaty { 50% { transform: translateY(-5px); } }
.res-head h2 { margin-top: 8px; padding: 0; }
.constellation {
  display: block;
  width: 100%;
  aspect-ratio: 1.25;
  margin-top: 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 50%, rgba(var(--opt-rgb), 0.1), transparent 70%), var(--panel);
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.dot.start { background: var(--start); } .dot.path { background: var(--cur); } .dot.dead { background: var(--opt); }
.dot.seen { background: var(--faint); } .dot.goal { background: var(--tgt); }
.route { margin-top: 12px; font-size: 14px; color: var(--muted); }
.route summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.route .path-words { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; padding: 6px 0 2px; color: var(--ink); font-weight: 600; }
.route .path-words i { font-style: normal; color: var(--faint); }
.share-preview {
  margin: 14px 0 0;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  font: 600 14.5px/1.5 var(--font);
  white-space: pre-wrap;
  color: var(--ink);
}
.res-mini { display: flex; justify-content: space-around; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.res-mini div { text-align: center; }
.res-mini b { display: block; font-size: 22px; font-weight: 800; }
.res-mini small { font-size: 10.5px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

/* archive */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; }
.cal-head b { font-size: 16px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--faint); letter-spacing: 0.08em; padding: 4px 0; }
.cal .day {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-weight: 700;
  font-size: 14px;
}
.cal button.day:hover { border-color: var(--cur); }
.cal .day.off { opacity: 0.28; cursor: default; }
.cal .day.blank { border: 0; background: none; }
.cal .day.today { border-color: var(--cur); box-shadow: 0 0 14px rgba(var(--cur-rgb), 0.3); }
.cal .day.won { background: rgba(var(--cur-rgb), 0.16); }
.cal .day.lost { background: rgba(var(--bad-rgb), 0.14); }
.cal .day small { position: absolute; bottom: 3px; font-size: 9px; font-weight: 600; color: var(--muted); }

/* settings */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting:last-of-type { border-bottom: 0; }
.setting b { display: block; font-size: 15.5px; }
.setting small { color: var(--muted); font-size: 12.5px; }
.seg { display: flex; padding: 3px; border-radius: 12px; background: var(--panel); border: 1px solid var(--border); }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button[aria-checked='true'] { background: var(--panel-2); color: var(--ink); box-shadow: 0 0 0 1px var(--border-2); }
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform 0.2s var(--ease), background 0.2s; }
.switch:checked { background: rgba(var(--cur-rgb), 0.3); border-color: var(--cur); }
.switch:checked::after { transform: translateX(20px); background: var(--cur); }
.credits { margin-top: 8px; }

/* hint sheet */
.hint-opt {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  margin-top: 12px;
  padding: 14px 16px;
  text-align: left;
  border-radius: 16px;
  border: 1px solid var(--border-2);
  background: var(--panel);
  transition: background 0.15s, transform 0.12s;
}
.hint-opt:hover { background: var(--panel-2); }
.hint-opt:active { transform: scale(0.98); }
.hint-opt:disabled { opacity: 0.4; }
.hint-opt .hi { color: var(--warn); display: grid; }
.hint-opt b { display: block; font-size: 16px; }
.hint-opt small { color: var(--muted); font-size: 13px; line-height: 1.35; display: block; margin-top: 2px; }
.hint-opt em { font-style: normal; font-weight: 800; color: var(--warn); font-size: 15px; }

/* toasts */
.toasts { position: fixed; bottom: calc(env(safe-area-inset-bottom) + 96px); left: 0; right: 0; z-index: 50; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toast 2.2s var(--ease) both;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(8px) scale(0.96); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* reduced motion */
:root[data-motion='off'] *, :root[data-motion='off'] *::before, :root[data-motion='off'] *::after {
  animation-duration: 0.001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001s !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
}

@media (min-width: 720px) {
  .app { max-width: 680px; }
  .stage-wrap { min-height: 460px; }
  .node { font-size: 18px; padding: 11px 19px; }
  .node.long { font-size: 16px; }
}
@media (max-height: 700px) {
  .mission { padding: 10px 14px; }
  .hops { width: 46px; height: 46px; }
  .hops span { font-size: 19px; }
  .link::before, .link::after { top: 15px; }
  .stage-wrap { min-height: 300px; }
}

/* ------------------------------------------------------------------ modes + endless */
.modes {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-self: center;
  width: min(260px, 100%);
  padding: 3px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.modes button {
  position: relative;
  z-index: 1;
  height: 32px;
  border: 0;
  background: none;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  transition: color 0.2s;
}
.modes button[aria-selected='true'] { color: #051019; }
:root[data-theme='light'] .modes button[aria-selected='true'] { color: #fff; }
.modes .thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--cur), var(--opt));
  box-shadow: 0 4px 16px rgba(var(--cur-rgb), 0.35);
  transition: transform 0.35s var(--ease);
}
.modes[data-mode='endless'] .thumb { transform: translateX(100%); }
.modes .dot { display: none; }
.modes.nudge #mode-endless::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tgt);
  box-shadow: 0 0 10px var(--tgt);
  animation: breathe 1.6s ease-in-out infinite;
}

.hops.low { border-color: var(--bad); box-shadow: 0 0 22px rgba(var(--bad-rgb), 0.5), inset 0 0 14px rgba(var(--bad-rgb), 0.15); animation: lowPulse 1s ease-in-out infinite; }
.hops.low span { color: var(--bad); }
@keyframes lowPulse { 50% { transform: scale(1.07); } }
.hops.low.bump { animation: bump 0.35s var(--ease), lowPulse 1s 0.35s ease-in-out infinite; }
.min .sep { color: var(--faint); padding: 0 2px; }
.carry-note { display: block; color: var(--cur); font-weight: 700; font-size: 10px; }

.inf { color: var(--cur); }
.endless-cta { width: 100%; margin-top: 14px; border-color: rgba(var(--cur-rgb), 0.45); }
.endless-cta b { color: var(--cur); font-size: 20px; line-height: 0; vertical-align: -2px; }

.chain { display: flex; flex-wrap: wrap; gap: 6px 4px; align-items: center; justify-content: center; margin-top: 16px; padding: 14px; border-radius: 16px; background: var(--panel); border: 1px solid var(--border); max-height: 190px; overflow: auto; }
.chain .chip { padding: 4px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); font-size: 13.5px; font-weight: 600; }
.chain .chip.first { color: var(--start); border-color: rgba(var(--start-rgb), 0.4); }
.chain .chip.miss { color: var(--tgt); border: 1px dashed rgba(var(--tgt-rgb), 0.6); background: rgba(var(--tgt-rgb), 0.06); }
.chain .arr { color: var(--faint); font-size: 12px; }
.route-label { margin-top: 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.route-label:first-child { margin-top: 4px; }

/* ------------------------------------------------------------------ plasticity's extra links */
.stage.dense .node { font-size: 15px; padding: 8px 13px; }
.stage.dense .node.long { font-size: 13.5px; padding: 7px 11px; }
.stage.dense .node.current { font-size: 15px; }
.node.extra {
  border-color: rgba(var(--start-rgb), 0.75);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28), 0 0 26px rgba(var(--start-rgb), 0.28);
}
.node.extra:hover, .node.extra:focus-visible {
  border-color: var(--start);
  box-shadow: 0 0 0 4px rgba(var(--start-rgb), 0.16), 0 8px 28px rgba(0, 0, 0, 0.3), 0 0 36px rgba(var(--start-rgb), 0.5);
}
.syn.base.extra { stroke: var(--start); stroke-dasharray: 5 6; }
.hint-opt#hint-plasticity .hi { color: var(--start); }
.hint-opt#hint-plasticity em { color: var(--start); }
.hint-opt#hint-gateways .hi { color: var(--tgt); }
.hint-opt#hint-gateways em { color: var(--tgt); }

/* ------------------------------------------------------------------ community stats */
.community { margin-top: 4px; }
.community h3 { margin: 20px 0 10px; }
.community .res-stats { margin-top: 0; }
.community .route { margin-top: 10px; }

/* ------------------------------------------------------------------ wide-screen results layout */
/* Narrow/short screens (the default): .res-cols and .res-col are plain blocks, so their children stack in exactly
   the same order and look as if the wrapper divs weren't there at all - this is what keeps mobile untouched. */
@media (min-width: 760px) and (min-height: 760px) {
  .res-dialog { width: min(90vw, 740px); max-height: min(92dvh, 920px); }
  .res-cols {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    gap: 4px 28px;
  }
  .res-cols + .res-cols { margin-top: 16px; }
}

/* ------------------------------------------------------------------ endless reroll */
.mode-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.reroll-btn { display: none; }
body[data-mode='endless'] .reroll-btn { display: inline-grid; }
.reroll-btn:active { transform: scale(0.92); }

/* ------------------------------------------------------------------ community first/last word */
.community-words { display: flex; flex-wrap: wrap; gap: 14px 28px; margin-top: 14px; }
.community-words .cword { display: flex; flex-direction: column; gap: 6px; }
.community-words .route-label { margin-top: 0; }
.community-words .cword-val { display: flex; align-items: center; gap: 8px; }
.community-words .chip { padding: 4px 12px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border-2); color: var(--ink); font-weight: 700; font-size: 14px; }
.community-words em { font-style: normal; font-size: 11.5px; color: var(--muted); }
