/* ============================================================
   Connect the Stars: tokens
   Midnight (dark) is the default; Daylight (light) is opt-in or
   follows the OS when the theme is "System".
   ============================================================ */
:root {
  --bg: oklch(0.17 0.03 272);
  --bg-glow: oklch(0.24 0.045 272);
  --surface: oklch(0.215 0.03 272);
  --surface-2: oklch(0.265 0.032 272);
  --surface-3: oklch(0.32 0.034 272);
  --ink: oklch(0.955 0.008 85);
  --ink-2: oklch(0.82 0.015 272);
  --muted: oklch(0.72 0.02 272);
  --border: oklch(0.95 0.01 272 / 0.12);
  --border-strong: oklch(0.95 0.01 272 / 0.24);
  --accent: oklch(0.79 0.115 84);          /* star gold */
  --accent-strong: oklch(0.84 0.12 86);
  --accent-ink: oklch(0.2 0.03 272);       /* text on gold */
  --accent-text: oklch(0.82 0.11 84);      /* gold used as text */
  --accent-soft: oklch(0.79 0.115 84 / 0.16);
  --hint: oklch(0.7 0.15 292);
  --hint-ink: oklch(0.98 0.01 292);
  --hint-soft: oklch(0.7 0.15 292 / 0.18);
  --danger: oklch(0.68 0.17 25);
  --danger-ink: oklch(0.98 0.01 25);
  --start: oklch(0.78 0.13 175);
  --line: oklch(0.95 0.01 85 / 0.55);
  --node-actor: oklch(0.93 0.01 85);
  --node-bg: oklch(0.24 0.03 272);
  --scrim: oklch(0.1 0.02 272 / 0.62);
  --shadow: 0 10px 30px oklch(0.05 0.02 272 / 0.55);
  --shadow-sm: 0 4px 14px oklch(0.05 0.02 272 / 0.45);
  --sky-star: 0.79 0.115 84;               /* OKLCH triplet for the canvas */
  --sky-line: 0.95 0.01 85;
  --sky-alpha: 1;
  color-scheme: dark;
}
:root[data-theme="daylight"] {
  --bg: oklch(0.975 0.004 272);
  --bg-glow: oklch(0.93 0.02 272);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.955 0.006 272);
  --surface-3: oklch(0.915 0.01 272);
  --ink: oklch(0.21 0.03 272);
  --ink-2: oklch(0.33 0.03 272);
  --muted: oklch(0.46 0.025 272);
  --border: oklch(0.25 0.03 272 / 0.12);
  --border-strong: oklch(0.25 0.03 272 / 0.24);
  --accent: oklch(0.72 0.13 80);
  --accent-strong: oklch(0.66 0.13 78);
  --accent-ink: oklch(0.18 0.03 272);
  --accent-text: oklch(0.5 0.11 72);
  --accent-soft: oklch(0.72 0.13 80 / 0.2);
  --hint: oklch(0.5 0.19 292);
  --hint-ink: oklch(0.99 0.005 292);
  --hint-soft: oklch(0.5 0.19 292 / 0.12);
  --danger: oklch(0.53 0.19 25);
  --danger-ink: oklch(0.99 0.005 25);
  --start: oklch(0.5 0.11 175);
  --line: oklch(0.3 0.03 272 / 0.5);
  --node-actor: oklch(0.28 0.03 272);
  --node-bg: oklch(0.96 0.005 272);
  --scrim: oklch(0.2 0.03 272 / 0.35);
  --shadow: 0 10px 30px oklch(0.3 0.04 272 / 0.18);
  --shadow-sm: 0 3px 10px oklch(0.3 0.04 272 / 0.14);
  --sky-star: 0.6 0.12 78;
  --sky-line: 0.3 0.03 272;
  --sky-alpha: 0.55;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: oklch(0.975 0.004 272);
    --bg-glow: oklch(0.93 0.02 272);
    --surface: oklch(1 0 0);
    --surface-2: oklch(0.955 0.006 272);
    --surface-3: oklch(0.915 0.01 272);
    --ink: oklch(0.21 0.03 272);
    --ink-2: oklch(0.33 0.03 272);
    --muted: oklch(0.46 0.025 272);
    --border: oklch(0.25 0.03 272 / 0.12);
    --border-strong: oklch(0.25 0.03 272 / 0.24);
    --accent: oklch(0.72 0.13 80);
    --accent-strong: oklch(0.66 0.13 78);
    --accent-ink: oklch(0.18 0.03 272);
    --accent-text: oklch(0.5 0.11 72);
    --accent-soft: oklch(0.72 0.13 80 / 0.2);
    --hint: oklch(0.5 0.19 292);
    --hint-ink: oklch(0.99 0.005 292);
    --hint-soft: oklch(0.5 0.19 292 / 0.12);
    --danger: oklch(0.53 0.19 25);
    --danger-ink: oklch(0.99 0.005 25);
    --start: oklch(0.5 0.11 175);
    --line: oklch(0.3 0.03 272 / 0.5);
    --node-actor: oklch(0.28 0.03 272);
    --node-bg: oklch(0.96 0.005 272);
    --scrim: oklch(0.2 0.03 272 / 0.35);
    --shadow: 0 10px 30px oklch(0.3 0.04 272 / 0.18);
    --shadow-sm: 0 3px 10px oklch(0.3 0.04 272 / 0.14);
    --sky-star: 0.6 0.12 78;
    --sky-line: 0.3 0.03 272;
    --sky-alpha: 0.55;
    color-scheme: light;
  }
}

:root {
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-pill: 999px;
  --tap: 44px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);   /* ease-out-quint */
  --fast: 160ms;
  --med: 240ms;
  /* z-index scale */
  --z-board: 0;
  --z-chrome: 10;
  --z-panel: 20;
  --z-suggest: 30;
  --z-toast: 40;
  --z-modal: 50;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% -10%, var(--bg-glow), var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 400 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  transition: background-color var(--med) var(--ease), color var(--med) var(--ease);
}
a { color: var(--accent-text); text-underline-offset: 3px; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.ic.sm { width: 14px; height: 14px; }

#sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.screen { position: relative; z-index: 1; height: var(--app-h, 100dvh); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  font: 500 14px var(--sans); white-space: nowrap;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease),
    color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.icon { width: var(--tap); padding: 0; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: transparent; }
.btn.lg { min-height: 52px; padding: 0 28px; font-size: 16px; }
.btn.busy { pointer-events: none; }
.btn.busy .ic { animation: spin 0.9s linear infinite; }
.row-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.row-buttons.end { justify-content: flex-end; }
.row-buttons.center { justify-content: center; }

/* ============================================================
   Setup screen
   ============================================================ */
#setup {
  display: flex; flex-direction: column; align-items: center;
  gap: clamp(18px, 3.2vh, 32px);
  padding: calc(clamp(24px, 6vh, 64px) + var(--safe-t)) 16px calc(24px + var(--safe-b));
  overflow-y: auto;
}
.setup-corner { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; }
.theme-btn .ic { transition: transform var(--med) var(--ease); }
.theme-btn:active .ic { transform: rotate(-30deg); }
.hero { text-align: center; margin-top: auto; }
.hero h1 { font: 600 clamp(32px, 6vw, 52px)/1.05 var(--serif); margin: 0; letter-spacing: -0.01em; }
.logo { color: var(--accent); font-size: 0.8em; vertical-align: 0.08em; }
.lede { margin: 10px 0 0; color: var(--muted); font-size: 16px; }

.pair { display: flex; align-items: center; gap: clamp(10px, 3vw, 28px); }
.pair-join { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--accent); }
.pair-join span { width: 1px; height: 48px; background: linear-gradient(var(--accent-soft), var(--accent), var(--accent-soft)); }
.pair-join .ic { width: 18px; height: 18px; fill: var(--accent); stroke: none; }

.card {
  --w: clamp(140px, 40vw, 236px);
  width: var(--w); aspect-ratio: 236 / 340; position: relative;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.card .num {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  min-width: 26px; height: 26px; display: grid; place-items: center; padding: 0 6px;
  border-radius: var(--r-pill); background: oklch(0.15 0.02 272 / 0.65); color: oklch(0.97 0.005 85);
  font: 600 13px var(--sans); backdrop-filter: blur(6px);
}
.card .shuffle {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  min-height: 36px; padding: 0 12px; font-size: 13px;
  background: oklch(0.15 0.02 272 / 0.65); color: oklch(0.97 0.005 85); border-color: oklch(1 0 0 / 0.16);
  backdrop-filter: blur(6px);
}
.card .shuffle:hover:not(:disabled) { background: var(--accent); color: var(--accent-ink); }
.card .shuffle .ic { width: 16px; height: 16px; }
.card .photo { flex: 1; background: var(--surface-2) center top / cover no-repeat; position: relative; }
.card .photo::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 45%, oklch(0.12 0.02 272 / 0.92));
}
.card .label {
  position: absolute; bottom: 52px; left: 0; right: 0; z-index: 1; padding: 0 12px;
  text-align: center; color: oklch(0.97 0.005 85);
  font: 600 clamp(17px, 3.6vw, 23px)/1.15 var(--serif);
}
.card .sub {
  display: block; margin-top: 4px; font: 400 12px/1.3 var(--sans); color: oklch(0.85 0.01 272);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .clear {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 2; min-height: 36px;
  background: oklch(0.97 0.005 85 / 0.14); color: oklch(0.97 0.005 85); border-color: oklch(1 0 0 / 0.2);
  backdrop-filter: blur(6px); font-size: 13px;
}
.card .clear:hover:not(:disabled) { background: oklch(0.97 0.005 85 / 0.26); }
.card .search { padding: 52px 12px 12px; display: flex; flex-direction: column; gap: 8px; height: 100%; }
.card .search-field {
  display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: var(--tap);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
}
.card .search-field:focus-within { border-color: var(--accent); }
.card .search-field .ic { width: 16px; height: 16px; color: var(--muted); }
.card input {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: none;
  color: var(--ink); font: 400 16px var(--sans);
}
.card input::placeholder { color: var(--muted); }
.card .results { overflow-y: auto; flex: 1; margin: 0 -4px; }
.card .result {
  padding: 9px 8px; border-radius: var(--r-sm); cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background-color var(--fast) var(--ease);
}
.card .result:hover { background: var(--surface-2); }
.card .result small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.card .empty-hint { color: var(--muted); font-size: 13px; text-align: center; margin: auto 0; padding: 0 6px; }

.mode-block { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 100%; }
.mode-pick { flex-wrap: wrap; justify-content: center; }
.mode-desc { margin: 0; max-width: 46ch; min-height: 2.9em; text-align: center; color: var(--muted); font-size: 14px; }
.setup-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.credits { color: var(--muted); font-size: 12.5px; text-align: center; max-width: 52ch; margin: auto 0 0; }

/* ============================================================
   Game screen
   ============================================================ */
#game { display: grid; grid-template-rows: auto 1fr auto; }

.topbar {
  position: relative; z-index: var(--z-chrome);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: linear-gradient(var(--bg), color-mix(in oklch, var(--bg) 0%, transparent));
}
.topbar > :first-child { justify-self: start; }
.title-block { text-align: center; min-width: 0; }
.brand-mini { font: 600 19px var(--serif); white-space: nowrap; }
.goal {
  margin: 3px 0 0; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; color: var(--muted); min-width: 0;
}
.goal .who { color: var(--start); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goal .ic { fill: var(--accent); stroke: none; }
.top-right { justify-self: end; display: flex; gap: 6px; }

.stage { position: relative; overflow: hidden; min-height: 0; }
#viewport { position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none; z-index: var(--z-board); }
#viewport.panning { cursor: grabbing; }
#board { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; }
#edges line { stroke: var(--line); stroke-width: 2; stroke-linecap: round; }
#edges line.hint { stroke: var(--hint); stroke-width: 2.5; stroke-dasharray: 7 6; }
#edges line.path { stroke: var(--accent); stroke-width: 4; stroke-dasharray: none; }

.node {
  position: absolute; width: 100px; transform: translate(-50%, -50%);
  border: 2px solid var(--node-actor); border-radius: 10px; overflow: hidden;
  background: var(--node-bg);
  cursor: pointer; user-select: none; touch-action: none; -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--med) var(--ease), border-color var(--med) var(--ease);
}
.node:hover { box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-sm); }
.node.film { border-color: var(--accent); }
.node.hinted { border-color: var(--hint); }
/* The two starting cards: a coloured outline, separate from film borders and the gold path glow. */
.node.target { outline: 3px solid var(--start); outline-offset: 3px; }
.node.target .cap { color: var(--start); font-weight: 600; }
.node.onpath { box-shadow: 0 0 0 5px var(--accent), var(--shadow); }
.node.selected { box-shadow: 0 0 0 4px var(--ink), var(--shadow); }
.node.fresh { animation: pop 420ms var(--ease); }
.node .img { width: 100%; aspect-ratio: 2 / 3; background: var(--surface-2) center top / cover no-repeat; }
.node .img.placeholder {
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px;
  font: 600 15px/1.2 var(--serif); color: var(--ink);
  background: linear-gradient(160deg, var(--surface-3), var(--surface));
}
.node .cap {
  font: 500 11px/1.25 var(--sans); text-align: center; padding: 5px 6px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.node.mystery { border-style: dashed; border-color: var(--hint); cursor: help; }
.node.mystery .img.placeholder { font: 700 44px var(--serif); color: var(--hint); background: var(--hint-soft); }
.node.mystery .cap { color: var(--hint); font-weight: 600; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; } }

.board-tools {
  position: absolute; left: 14px; bottom: 14px; z-index: var(--z-chrome);
  display: flex; flex-direction: column; gap: 6px;
}
.board-tools .btn { background: var(--surface); box-shadow: var(--shadow-sm); }
.hints {
  position: absolute; right: 16px; bottom: 14px; z-index: var(--z-chrome); margin: 0; padding: 0; list-style: none;
  text-align: right; color: var(--muted); font-size: 12.5px; line-height: 1.8; pointer-events: none;
}
.hints.gone { opacity: 0; transition: opacity 600ms var(--ease); }

/* Dock: guess field + stats */
.dock {
  position: relative; z-index: var(--z-chrome);
  padding: 12px 16px calc(10px + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--border);
}
.guess-wrap { position: relative; max-width: 760px; margin: 0 auto; }
.guess-field {
  display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.guess-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.guess-field > .ic { color: var(--muted); }
#guess {
  flex: 1; min-width: 0; min-height: 44px; background: transparent; border: 0; outline: none;
  color: var(--ink); font: 500 18px var(--sans);
}
#guess::placeholder { color: var(--muted); font-weight: 400; }
#guess.shake { animation: shake 300ms var(--ease); }
.guess-field:has(#guess.shake) { border-color: var(--danger); box-shadow: 0 0 0 4px color-mix(in oklch, var(--danger) 22%, transparent); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stats {
  max-width: 760px; margin: 10px auto 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px;
  font-size: 13px; color: var(--muted);
}
.stat b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.best b { color: var(--accent-text); margin-left: 4px; }

.suggest {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 10px); z-index: var(--z-suggest);
  margin: 0; padding: 6px; list-style: none; max-height: 50vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow); animation: rise var(--med) var(--ease);
}
.suggest li {
  display: flex; align-items: baseline; gap: 10px; padding: 10px 12px; min-height: var(--tap);
  border-radius: var(--r-sm); cursor: pointer;
}
.suggest li.head { cursor: default; color: var(--danger); font-size: 13px; font-weight: 500; min-height: 0; padding: 6px 12px 8px; }
.suggest li[data-id]:hover, .suggest li.active { background: var(--accent-soft); }
.suggest .kind { color: var(--accent-text); width: 18px; flex: none; }
.suggest .nm { font: 600 16px var(--serif); }
.suggest .nm small { font: 400 12px var(--sans); color: var(--muted); }
.suggest .via { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* Reverse run: timer, hint ladder */
.run-only { display: none; }
#game.reverse .run-only { display: inline; }
#game.reverse .stat.timer { display: inline-flex; }
#game.reverse .board-only { display: none; }
.stat.timer { align-items: center; gap: 5px; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat.timer b { font-size: 15px; }
.stat.timer.urgent, .stat.timer.urgent b { color: var(--danger); }
.stat.timer.urgent .ic { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.btn.hint-top { background: var(--hint-soft); color: var(--hint); border-color: transparent; }
.btn.hint-top:hover:not(:disabled) { background: var(--hint); color: var(--hint-ink); }
.info.hintbox { grid-template-columns: 1fr; }
.hint-list { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14px; max-height: 34vh; overflow-y: auto; }
.info .hint-list li { color: var(--ink); font-weight: 400; }
.info .hint-list li.none { color: var(--muted); }
.hint-list li::marker { color: var(--hint); font-weight: 600; }
.hint-list .blanks { font: 600 16px/1.6 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.02em; white-space: pre-wrap; word-break: break-word; }
.hint-img-wrap { width: 96px; aspect-ratio: 2 / 3; border-radius: var(--r-sm); overflow: hidden; margin-top: 2px; }
.hint-img { width: 100%; height: 100%; background: var(--surface-2) center top / cover no-repeat; filter: blur(14px); transform: scale(1.15); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.choices .btn { min-height: 40px; white-space: normal; text-align: center; line-height: 1.2; padding: 6px 10px; font-size: 13px; }
.choices .btn.wrong { background: color-mix(in oklch, var(--danger) 18%, transparent); color: var(--danger); }
.node.mystery .img { transition: filter 400ms var(--ease); }

/* Leaderboard */
.lb-summary { font-size: 16px; margin: 0 0 12px !important; }
.lb-summary b { font: 700 26px var(--serif); color: var(--accent-text); margin-right: 4px; }
.score-form { display: flex; gap: 8px; }
.score-form input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 0 14px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); font: 500 16px var(--sans); outline: none;
}
.score-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
#lbMsg { margin-top: 8px; min-height: 1.2em; }
#lbNote { margin: 14px 0 6px; }
.lb-list { list-style: none; margin: 0; padding: 0; max-height: 44vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
.lb-list li { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 10px; align-items: baseline; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.lb-list li:last-child { border-bottom: 0; }
.lb-list li.mine { background: var(--accent-soft); }
.lb-list li.empty { display: block; color: var(--muted); text-align: center; }
.lb-list .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-list .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .meta { color: var(--muted); font-size: 12px; }
.lb-list b { font-variant-numeric: tabular-nums; color: var(--accent-text); }
@media (max-width: 640px) {
  .lb-list li { grid-template-columns: 24px 1fr auto; }
  .lb-list .meta { display: none; }
  #hintBtn .lbl { display: none; }
  #hintBtn { width: var(--tap); padding: 0; }
  #game.reverse .top-right .theme-btn { display: none; }
}

/* Toast */
.toast {
  position: absolute; bottom: 16px; left: 50%; z-index: var(--z-toast);
  max-width: min(92%, 520px); transform: translateX(-50%);
  padding: 10px 16px; border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600; text-align: center;
  animation: drop var(--med) var(--ease);
}
.toast.bad { background: var(--danger); color: var(--danger-ink); }
.toast.hint { background: var(--hint); color: var(--hint-ink); }
@keyframes drop { from { opacity: 0; transform: translate(-50%, 8px); } }
a.btn { text-decoration: none; }

/* Info panel: image on the left, details on the right */
.info {
  position: absolute; left: 14px; top: 8px; z-index: var(--z-panel);
  width: min(360px, calc(100% - 28px));
  display: grid; grid-template-columns: 104px 1fr; gap: 14px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow); animation: rise var(--med) var(--ease);
}
.info .info-img {
  width: 104px; aspect-ratio: 2 / 3; border-radius: var(--r-sm);
  background: var(--surface-2) center top / cover no-repeat; border: 2px solid var(--node-actor);
}
.info.film .info-img { border-color: var(--accent); }
.info .info-img.placeholder {
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px;
  font: 600 14px var(--serif); background: linear-gradient(160deg, var(--surface-3), var(--surface));
}
.info .body { min-width: 0; display: flex; flex-direction: column; }
.info .kind { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.info h2 { font: 600 21px/1.15 var(--serif); margin: 2px 32px 2px 0; }
.info .year { color: var(--muted); font-size: 13px; }
.info .label { font-size: 12px; color: var(--muted); margin: 10px 0 2px; }
.info ul { list-style: none; padding: 0; margin: 0; max-height: 22vh; overflow-y: auto; }
.info li { color: var(--accent-text); font-size: 14px; font-weight: 500; padding: 2px 0; }
.info li.none { color: var(--muted); font-weight: 400; }
.info .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 12px; }
.info .actions .btn { min-height: 36px; padding: 0 12px; font-size: 13px; }
.info .actions .ic { width: 16px; height: 16px; }
.info .hint-btn { background: var(--hint-soft); color: var(--hint); border-color: transparent; }
.info .hint-btn:hover:not(:disabled) { background: var(--hint); color: var(--hint-ink); }
.info .close { position: absolute; top: 8px; right: 8px; width: 36px; min-height: 36px; background: transparent; border-color: transparent; }
.info .close:hover { background: var(--surface-2); }
.hint-pop {
  grid-column: 1 / -1; padding: 12px; border-radius: var(--r-md);
  background: var(--hint-soft); border: 1px solid color-mix(in oklch, var(--hint) 40%, transparent);
  animation: rise var(--med) var(--ease);
}
.hint-pop b { display: block; font-size: 14px; margin-bottom: 4px; }
.hint-pop p { margin: 0 0 10px; font-size: 13px; color: var(--ink-2); }
.hint-pop .row-buttons { justify-content: flex-end; }
.hint-pop .btn { min-height: 36px; font-size: 13px; }
.hint-pop .btn.primary { background: var(--hint); color: var(--hint-ink); }

/* ============================================================
   Modals
   ============================================================ */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: var(--scrim); animation: fade var(--med) var(--ease);
}
.modal-box {
  position: relative; width: 100%; max-width: 540px; max-height: calc(var(--app-h, 100dvh) - 32px); overflow-y: auto;
  padding: 28px; border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  box-shadow: var(--shadow); animation: lift var(--med) var(--ease);
}
.modal-box h2 { font: 600 28px/1.1 var(--serif); margin: 0 40px 16px 0; }
.modal-box h3 { font: 600 14px var(--sans); margin: 22px 0 8px; }
.modal-box p { margin: 0; line-height: 1.55; }
.modal-box .close { position: absolute; right: 12px; top: 12px; background: transparent; border-color: transparent; }
.modal-box .close:hover { background: var(--surface-2); }
.modal-box .row-buttons { margin-top: 22px; }
.fine { color: var(--muted); font-size: 13.5px; }
.center { text-align: center; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 12px; line-height: 1.55; }
.steps li::marker { color: var(--accent-text); font-weight: 600; }
.steps + .fine { margin-top: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes lift { from { opacity: 0; transform: translateY(12px) scale(0.98); } }

.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: var(--r-pill); border: 1px solid var(--border); }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 16px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 500; color: var(--ink-2);
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.levels { display: grid; gap: 6px; margin-top: 12px; }
.level {
  display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md); cursor: pointer;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.level:hover { background: var(--surface-2); }
.level.on { border-color: var(--accent); background: var(--accent-soft); }
.level input { position: absolute; opacity: 0; pointer-events: none; }
.level:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.level .lv-num {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); font: 600 14px var(--sans); font-variant-numeric: tabular-nums;
}
.level.on .lv-num { background: var(--accent); color: var(--accent-ink); }
.level .dot {
  width: 20px; height: 20px; margin: 0 5px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--surface);
}
.level.on .dot { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 45%, transparent 50%); }
.level b { display: block; font-size: 14px; font-weight: 600; }
.level small { display: block; font-size: 13px; color: var(--muted); line-height: 1.4; }

.path { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; margin: 6px 0 12px; }
.path .step { font: 600 15px var(--serif); padding: 6px 12px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--border); }
.path .step.film { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.path .arrow { color: var(--muted); }
#winPath { flex-direction: column; gap: 10px; }
.path-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.modes-help { margin: 0; padding-left: 20px; display: grid; gap: 8px; line-height: 1.5; }

/* ============================================================
   Responsive
   ============================================================ */
/* Tablet and small laptop */
@media (max-width: 900px) {
  .hints { display: none; }
}

/* Phone */
@media (max-width: 640px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 8px; padding-inline: 10px; }
  .brand-mini { display: none; }
  .goal { margin: 0; font-size: 14px; flex-direction: column; gap: 0; line-height: 1.25; }
  .goal .ic { display: none; }
  .goal .who { max-width: 100%; }
  .goal .who + .who::before { content: "& "; color: var(--muted); font-weight: 400; }
  .top-right { gap: 2px; }
  #giveUpBtn { width: var(--tap); padding: 0; }
  #giveUpBtn .lbl { display: none; }
  .top-right .btn { background: transparent; border-color: transparent; }

  .board-tools { left: 10px; bottom: 10px; }
  .board-tools .btn { width: 40px; min-height: 40px; }
  .board-tools #zoomInBtn, .board-tools #zoomOutBtn { display: none; }

  .dock { padding: 10px 10px calc(8px + var(--safe-b)); }
  #guess { font-size: 17px; }
  .stats { gap: 2px 12px; font-size: 12.5px; margin-top: 8px; }

  /* Info panel becomes a bottom sheet above the guess field */
  .info {
    left: 8px; right: 8px; top: auto; bottom: 8px; width: auto;
    grid-template-columns: 84px 1fr; gap: 12px; padding: 12px;
  }
  .info .info-img { width: 84px; }
  .toast { bottom: auto; top: 8px; }
  .info h2 { font-size: 19px; }
  .info ul { max-height: 16vh; }

  .modal { align-items: flex-end; padding: 0; }
  .modal-box {
    max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0; padding: 22px 18px calc(18px + var(--safe-b));
    max-height: calc(var(--app-h, 100dvh) - 40px); animation-name: sheet;
  }
  .modal-box h2 { font-size: 24px; }
  .segmented { display: flex; }
  .segmented label { flex: 1; }
  .segmented span { width: 100%; justify-content: center; padding: 0 8px; }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }

  .card .label { bottom: 50px; }
  .card .shuffle { padding: 0 10px; }
  .card .shuffle .lbl { display: none; }
  .pair-join span { height: 28px; }
  .setup-actions .row-buttons { gap: 4px; }
  .setup-actions .btn.ghost { padding: 0 12px; }
}

/* Very short screens (landscape phones) */
@media (max-height: 520px) {
  #setup { gap: 14px; padding-top: calc(16px + var(--safe-t)); }
  .hero h1 { font-size: 28px; }
  .lede { display: none; }
  .card { --w: clamp(120px, 22vh + 60px, 200px); }
  .topbar { padding-block: 6px; }
  .stats { display: none; }
  .info { top: 8px; bottom: 8px; overflow-y: auto; }
}

@media (hover: none) {
  .node:hover { box-shadow: var(--shadow-sm); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .spinner, .btn.busy .ic { animation: spin 1.6s linear infinite !important; }
}
