/* 100 Turns to Treasure — design system.
   Tokens, reset, shared components, and the title / campaign / free-play / help screens.
   game.css and postgame.css build on the tokens and classes defined here. */

/* ---------- tokens ---------- */
:root {
  color-scheme: dark;

  /* surfaces: abyss -> page -> panel -> raised -> hover */
  --bg-0: #040a13;
  --bg-1: #07111f;
  --surface-1: #0c1929;
  --surface-2: #12233a;
  --surface-3: #1a304b;
  --line: rgba(126, 190, 230, 0.14);
  --line-strong: rgba(126, 190, 230, 0.3);
  --line-control: rgba(126, 190, 230, 0.55); /* the edge of an input, select or slider track: 3:1 on the panels */
  --scrim: rgba(2, 6, 12, 0.74);

  /* text (all AA on every surface above) */
  --text: #e8f1f8;
  --text-2: #b5c7d6;
  --text-3: #8aa0b4;

  /* accents: cyan = instruments, amber = boat and treasure, coral = misses and rivals */
  --cyan: #6adff2;
  --cyan-strong: #9aecf9;
  --cyan-dim: #2f8ea3;
  --teal: #2cc0ae;
  --amber: #ffb545;
  --coral: #ff7a6b;
  --success: #62d6a0;
  --on-accent: #04202a; /* text on a filled accent */
  --focus: #b9f3ff;

  /* accent washes for fills behind accent-coloured text */
  --cyan-wash: rgba(106, 223, 242, 0.12);
  --amber-wash: rgba(255, 181, 69, 0.12);
  --coral-wash: rgba(255, 122, 107, 0.12);
  --success-wash: rgba(98, 214, 160, 0.12);

  /* spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* radii */
  --r-1: 4px;
  --r-2: 8px;
  --r-3: 12px;
  --r-pill: 999px;

  /* type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, "Roboto Mono", Menlo, "Liberation Mono", monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.9375rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 2rem;

  /* depth */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.5), 0 18px 48px rgba(0, 0, 0, 0.5);
  --glow-cyan: 0 0 0 1px rgba(106, 223, 242, 0.25), 0 0 18px rgba(106, 223, 242, 0.18);
  --glow-amber: 0 0 0 1px rgba(255, 181, 69, 0.25), 0 0 18px rgba(255, 181, 69, 0.16);

  /* motion */
  --t-fast: 120ms;
  --t-med: 220ms;
  --t-slow: 480ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --control-h: 40px;
}

@media (pointer: coarse) {
  :root { --control-h: 44px; }
}

/* ---------- reset ---------- */
.game-intro {
  max-width: 42rem;
  margin: 1.5rem auto;
  padding: 0 1rem;
  color: var(--text-2);
  font-size: 1rem;
  line-height: 1.6;
}

.game-intro h2 { font-size: 1.125rem; color: var(--text); }

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg-1);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 700px at 50% -10%, rgba(30, 62, 96, 0.55), transparent 65%),
    var(--bg-1);
  background-attachment: fixed;
  color: var(--text);
  font: 400 var(--fs-md) / 1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1, h2, h3, h4 { font-weight: 650; line-height: 1.2; text-wrap: balance; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg, canvas { display: block; max-width: 100%; }
a { color: var(--cyan); }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
/* headings receive focus when a screen changes; they are not controls, so no ring */
h1[tabindex="-1"]:focus { outline: none; }

::selection { background: rgba(106, 223, 242, 0.3); }

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.boot {
  margin: auto;
  padding: var(--s-6) var(--s-4);
  color: var(--text-2);
  text-align: center;
}

/* ---------- utilities ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* numerals: monospace, tabular */
.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 0;
}

.muted { color: var(--text-2); }
.dim { color: var(--text-3); }

.icon { display: inline-flex; flex: none; width: 18px; height: 18px; }
.icon svg { width: 100%; height: 100%; }

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-1);
  background: var(--surface-2);
  color: var(--text);
  font: 600 var(--fs-xs) / 1 var(--mono);
  white-space: nowrap;
}

/* small uppercase label used above panels, stats and fields */
.eyebrow {
  color: var(--text-3);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--control-h);
  padding: 0 var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  background: var(--surface-2);
  color: var(--text);
  font: 600 var(--fs-md) / 1.1 var(--font);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--surface-3); border-color: var(--cyan-dim); }
.btn:active { transform: translateY(1px); }
.btn[aria-pressed="true"],
.btn.is-active {
  background: var(--cyan-wash);
  border-color: var(--cyan);
  color: var(--cyan-strong);
  box-shadow: var(--glow-cyan);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn:disabled:hover,
.btn[aria-disabled="true"]:hover { background: var(--surface-2); border-color: var(--line-strong); }

.btn--primary {
  background: var(--cyan);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: 0 0 20px rgba(106, 223, 242, 0.22);
}
.btn--primary:hover { background: var(--cyan-strong); border-color: transparent; }
.btn--primary:disabled:hover,
.btn--primary[aria-disabled="true"]:hover { background: var(--cyan); border-color: transparent; }

.btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover { background: rgba(126, 190, 230, 0.1); border-color: transparent; color: var(--text); }
.btn--ghost:disabled:hover { background: transparent; color: var(--text-2); }

.btn--danger { background: transparent; border-color: rgba(255, 122, 107, 0.55); color: var(--coral); }
.btn--danger:hover { background: var(--coral-wash); border-color: var(--coral); }
.btn--danger:disabled:hover { background: transparent; border-color: rgba(255, 122, 107, 0.55); }

.btn--icon { width: var(--control-h); padding: 0; }
.btn--sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn--sm.btn--icon { width: 32px; padding: 0; }
.btn--lg { min-height: 48px; padding: 0 var(--s-5); font-size: 1rem; }
.btn--block { display: flex; width: 100%; }

/* ---------- panel ---------- */
.panel {
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 72px), var(--surface-1);
  box-shadow: var(--shadow-1);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.panel-title {
  color: var(--text-3);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.panel > .panel-title { margin-bottom: var(--s-3); }

/* top bar shared by every screen: back / title on the left, actions on the right */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 56px;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: var(--s-1); margin-left: auto; }

/* ---------- chip / badge ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 22px;
  padding: 0 var(--s-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: rgba(126, 190, 230, 0.08);
  color: var(--text-2);
  font-size: 0.6875rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip--cyan { border-color: rgba(106, 223, 242, 0.45); background: var(--cyan-wash); color: var(--cyan); }
.chip--amber { border-color: rgba(255, 181, 69, 0.45); background: var(--amber-wash); color: var(--amber); }
.chip--coral { border-color: rgba(255, 122, 107, 0.45); background: var(--coral-wash); color: var(--coral); }
.chip--success { border-color: rgba(98, 214, 160, 0.45); background: var(--success-wash); color: var(--success); }
.chip--plain { border-color: transparent; background: none; padding: 0; color: var(--text-3); }

/* ---------- grade badge: .grade.grade--S | A | B | C | D ---------- */
.grade {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid currentColor;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text-2);
  font: 700 0.875rem / 1 var(--mono);
}
.grade--S { color: var(--amber); background: var(--amber-wash); box-shadow: var(--glow-amber); }
.grade--A { color: var(--success); background: var(--success-wash); }
.grade--B { color: var(--cyan); background: var(--cyan-wash); }
.grade--C { color: var(--text-2); }
.grade--D { color: var(--coral); background: var(--coral-wash); }
.grade--lg { width: 64px; height: 64px; border-width: 2px; border-radius: 14px; font-size: 2.125rem; }

/* ---------- stat tile ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: var(--s-2); }
.stat {
  display: grid;
  gap: 2px;
  padding: 10px var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background: rgba(4, 10, 19, 0.5);
  min-width: 0;
}
.stat-label { color: var(--text-3); font-size: 0.6875rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }
.stat-value { color: var(--text); font: 600 var(--fs-md) / 1.3 var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- form fields ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; }
.field-hint { color: var(--text-3); font-size: var(--fs-sm); line-height: 1.45; }
.field-row { display: flex; gap: var(--s-2); }
.field-row > .input, .field-row > .select { flex: 1; min-width: 0; }

.input,
.select {
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--s-3);
  border: 1px solid var(--line-control);
  border-radius: var(--r-2);
  background-color: var(--bg-0);
  color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder { color: var(--text-3); opacity: 1; }
.input:hover, .select:hover { border-color: var(--cyan-dim); }
.input:focus-visible, .select:focus-visible { outline-offset: 0; border-color: var(--cyan); }
.input:disabled, .select:disabled { opacity: 0.45; cursor: not-allowed; }

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%238aa0b4' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  cursor: pointer;
  text-overflow: ellipsis;
}
.select option { background: var(--surface-1); color: var(--text); }

/* ---------- toggle: <label class="toggle"><input type="checkbox"><span class="toggle-track"></span>Label</label> ---------- */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.toggle input {
  position: absolute;
  width: 36px;
  height: 20px;
  margin: 0;
  opacity: 0;
  cursor: inherit;
}
.toggle-track {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--bg-0);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast), box-shadow var(--t-fast);
}
.toggle input:checked + .toggle-track { border-color: var(--cyan); background: rgba(106, 223, 242, 0.22); }
.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(106, 223, 242, 0.6);
}
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.toggle:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }

/* ---------- range slider: set --fill (e.g. "40%") from JS to tint the travelled part ---------- */
.range {
  --fill: 0%;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--cyan) var(--fill), var(--line-control) var(--fill));
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 2px solid var(--cyan);
  border-radius: 50%;
  background: var(--bg-0);
  box-shadow: 0 0 10px rgba(106, 223, 242, 0.45);
  transition: transform var(--t-fast);
}
.range:active::-webkit-slider-thumb { transform: scale(1.12); }
.range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line-control); }
.range::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--cyan); }
.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--cyan);
  border-radius: 50%;
  background: var(--bg-0);
  box-shadow: 0 0 10px rgba(106, 223, 242, 0.45);
}
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--focus); outline-offset: 2px; }
.range:focus-visible::-moz-range-thumb { outline: 2px solid var(--focus); outline-offset: 2px; }
.range:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- segmented control ----------
   radios:  <div class="segmented" role="radiogroup"><label><input type="radio" name=..><span>A</span></label>...</div>
   buttons: <div class="segmented"><button aria-pressed="true">A</button>...</div> (also role=tab + aria-selected) */
.segmented {
  display: inline-flex;
  max-width: 100%;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  background: var(--bg-0);
}
.segmented--block { display: flex; }
.segmented > label { position: relative; display: flex; flex: 1; min-width: 0; }
.segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segmented > label > span,
.segmented > button {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: calc(var(--control-h) - 8px);
  padding: 0 var(--s-3);
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.segmented > label:hover > span,
.segmented > button:hover { color: var(--text); background: rgba(126, 190, 230, 0.08); }
.segmented input:checked + span,
.segmented > button[aria-pressed="true"],
.segmented > button[aria-selected="true"] {
  background: var(--surface-3);
  color: var(--cyan-strong);
  box-shadow: inset 0 0 0 1px rgba(106, 223, 242, 0.4);
}
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.segmented input:disabled + span,
.segmented > button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- table ---------- */
/* a table wider than its wrap shows a shade on the right edge until it is scrolled to the end (the first layer travels with the table and covers it) */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background:
    linear-gradient(to left, var(--surface-1) 50%, transparent) right / 56px 100% no-repeat local,
    linear-gradient(to left, rgba(106, 223, 242, 0.32), transparent) right / 24px 100% no-repeat scroll;
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th,
.table td { padding: var(--s-2) var(--s-3); text-align: left; vertical-align: top; }
.table thead th {
  border-bottom: 1px solid var(--line-strong);
  background: rgba(4, 10, 19, 0.5);
  color: var(--text-3);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.table tbody th { color: var(--text); font-weight: 600; white-space: nowrap; }
.table tbody td { color: var(--text-2); }
.table tbody tr + tr > * { border-top: 1px solid var(--line); }
.table .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.is-current > * { background: var(--cyan-wash); color: var(--text); }
/* .table--wide: cells never wrap; the row header stays put while the wrap scrolls sideways */
.table--wide th, .table--wide td { white-space: nowrap; }
.table--wide tbody th { position: sticky; left: 0; background: var(--surface-1); box-shadow: 1px 0 0 var(--line); }
.table--wide tr.is-current > th { background: #12303f; }

/* ---------- dialog ---------- */
.dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-3);
  background: var(--surface-1);
  color: var(--text);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.dialog[open] { display: flex; flex-direction: column; animation: rise var(--t-med) var(--ease); }
.dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
.dialog--wide { width: min(860px, calc(100vw - 32px)); }
.dialog > form { display: contents; }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-5);
  border-bottom: 1px solid var(--line);
}
.dialog-title { font-size: var(--fs-lg); }
.dialog-body { padding: var(--s-5); overflow-y: auto; overscroll-behavior: contain; }
.dialog-body > p + p { margin-top: var(--s-3); }
.dialog-body > .dialog-title + p { margin-top: var(--s-2); color: var(--text-2); }
.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5) var(--s-4);
}
.dialog-head + .dialog-body + .dialog-foot { border-top: 1px solid var(--line); padding-top: var(--s-3); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

/* ---------- tooltip ----------
   .tooltip: a box you position yourself (map hover readout).
   [data-tip]: text tooltip on hover / keyboard focus, above the element; data-tip-pos="below" flips it,
   data-tip-align="start" | "end" keeps it on screen near a side edge. */
.tooltip,
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  z-index: 60;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-1);
  background: rgba(3, 9, 17, 0.96);
  color: var(--text);
  font: 500 var(--fs-xs) / 1.4 var(--font);
  letter-spacing: 0;
  text-transform: none;
  box-shadow: var(--shadow-1);
  pointer-events: none;
}
.tooltip { position: absolute; max-width: 260px; }
[data-tip] { position: relative; }
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  white-space: normal;
  text-align: left;
}
[data-tip][data-tip-pos="below"]:hover::after,
[data-tip][data-tip-pos="below"]:focus-visible::after { top: calc(100% + 8px); bottom: auto; }
[data-tip][data-tip-align="start"]:hover::after,
[data-tip][data-tip-align="start"]:focus-visible::after { left: 0; transform: none; }
[data-tip][data-tip-align="end"]:hover::after,
[data-tip][data-tip-align="end"]:focus-visible::after { left: auto; right: 0; transform: none; }

/* ---------- toast ---------- */
.toast-stack {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(var(--s-4), env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  width: min(460px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  max-width: 100%;
  padding: 10px var(--s-4);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--cyan);
  border-radius: var(--r-2);
  background: var(--surface-3);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: rise var(--t-med) var(--ease);
}
.toast--error { border-left-color: var(--coral); }
.toast--success { border-left-color: var(--success); }

/* ---------- screen frame (campaign, free play) ---------- */
.screen {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--s-4) var(--s-4) var(--s-7);
}
.screen-head { margin-bottom: var(--s-5); }
.screen-head h1 { font-size: var(--fs-xl); }
.screen-sub { margin-top: 2px; color: var(--text-2); font-size: var(--fs-sm); }

/* ---------- title screen ---------- */
.title {
  position: relative;
  isolation: isolate;
  flex: 1;
  display: grid;
  place-items: center;
  padding: var(--s-6) var(--s-4);
  overflow: hidden;
}
.title-backdrop { position: absolute; inset: 0; z-index: -1; overflow: hidden; }
.title-backdrop svg {
  position: absolute;
  inset: -4%;
  width: 108%;
  height: 108%;
  max-width: none;
  animation: drift 48s ease-in-out infinite alternate;
}
.title-backdrop path {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: 0.1;
}
.title-backdrop path.is-index { stroke-width: 1.5; opacity: 0.22; }
/* quiet the centre so the wordmark reads, darken the edges */
.title-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 55% at 50% 45%, rgba(7, 17, 31, 0.86), rgba(7, 17, 31, 0.35) 60%, transparent 100%),
    radial-gradient(ellipse at center, transparent 55%, rgba(4, 10, 19, 0.9) 100%);
}
@keyframes drift {
  from { transform: translate(-1.5%, -1%); }
  to { transform: translate(1.5%, 1%); }
}

.title-inner {
  display: grid;
  justify-items: center;
  width: min(420px, 100%);
  text-align: center;
}

.mark { position: relative; width: 96px; height: 96px; margin-bottom: var(--s-5); }
.mark svg { position: relative; width: 100%; height: 100%; }
.mark::before,
.mark::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--cyan);
  border-radius: 50%;
  opacity: 0;
  animation: sonar 6s ease-out infinite;
}
.mark::after { animation-delay: 3s; }
@keyframes sonar {
  0% { transform: scale(0.86); opacity: 0.4; }
  70%, 100% { transform: scale(3.6); opacity: 0; }
}

.wordmark { display: grid; justify-items: center; }
.wordmark-num {
  background: linear-gradient(180deg, #f4fcff 25%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font: 700 clamp(84px, 26vw, 128px) / 0.86 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  filter: drop-shadow(0 0 28px rgba(106, 223, 242, 0.28));
}
.wordmark-rest {
  margin-top: var(--s-4);
  padding-left: 0.4em; /* balances the trailing letter-spacing */
  color: var(--text);
  font-size: clamp(14px, 4.2vw, 19px);
  font-weight: 600;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  white-space: nowrap;
}
.wordmark-rest b { color: var(--amber); font-weight: 700; }

.pitch { margin-top: var(--s-4); color: var(--text-2); font-size: 1rem; text-wrap: balance; }

.menu { display: grid; gap: var(--s-2); width: 100%; margin-top: var(--s-6); }
.menu-btn {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 18px;
  align-items: center;
  gap: var(--s-3);
  min-height: 64px;
  padding: 10px var(--s-4) 10px var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-3);
  background: rgba(12, 25, 41, 0.82);
  color: var(--text);
  text-align: left;
  backdrop-filter: blur(6px);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.menu-btn:hover { background: var(--surface-2); border-color: var(--cyan); box-shadow: var(--glow-cyan); }
.menu-btn:active { transform: translateY(1px); }
.menu-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--cyan-wash);
  color: var(--cyan);
}
.menu-icon .icon { width: 20px; height: 20px; }
.menu-text { display: grid; min-width: 0; }
.menu-label { font-size: 1rem; font-weight: 650; line-height: 1.3; }
.menu-sub { color: var(--text-3); font-size: var(--fs-sm); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn > .icon { color: var(--text-3); transition: transform var(--t-fast), color var(--t-fast); }
.menu-btn:hover > .icon { color: var(--cyan); transform: translateX(2px); }
.menu-btn--primary { border-color: rgba(255, 181, 69, 0.6); background: linear-gradient(90deg, rgba(255, 181, 69, 0.14), rgba(12, 25, 41, 0.82) 70%); }
.menu-btn--primary .menu-icon { background: var(--amber-wash); color: var(--amber); }
.menu-btn--primary:hover { border-color: var(--amber); box-shadow: var(--glow-amber); }
.menu-btn--primary:hover > .icon { color: var(--amber); }

.title-foot { margin-top: var(--s-5); color: var(--text-3); font-size: var(--fs-xs); letter-spacing: 0.04em; }

/* ---------- campaign ---------- */
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(310px, 100%), 1fr)); gap: var(--s-4); }
.level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  height: 100%;
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 72px), var(--surface-1);
  box-shadow: var(--shadow-1);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.level-card:hover { border-color: var(--cyan-dim); background-color: var(--surface-2); transform: translateY(-2px); }
.level-card.is-next { border-color: rgba(255, 181, 69, 0.6); box-shadow: var(--shadow-1), var(--glow-amber); }
.level-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.level-num { color: var(--text-3); font: 600 var(--fs-sm) / 1 var(--mono); letter-spacing: 0.08em; }
.level-name { font-size: var(--fs-lg); }
.level-link { all: unset; cursor: pointer; }
.level-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--r-3); }
.level-link:focus-visible::after { outline: 2px solid var(--focus); outline-offset: 2px; }
.level-blurb { flex: 1; color: var(--text-2); font-size: 0.875rem; }
.level-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: var(--s-1); }
.level-tags .chip { height: auto; min-height: 22px; padding-block: 3px; line-height: 1.25; white-space: normal; } /* a long race chip wraps instead of being cut */
.level-foot {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  margin-top: var(--s-1);
  padding-top: var(--s-3);
  border-top: 1px solid var(--line);
  color: var(--text-3);
  font-size: var(--fs-sm);
}
.level-score { color: var(--text); font: 600 var(--fs-md) / 1 var(--mono); font-variant-numeric: tabular-nums; }
.level-foot .chip { margin-left: auto; }

/* ---------- free play ---------- */
.freeplay { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); align-items: start; }
.freeplay .panel { display: grid; gap: var(--s-4); align-content: start; height: 100%; }
.freeplay .panel > .panel-title { margin-bottom: 0; }
.hidden-rule {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--control-h);
  padding: 0 var(--s-3);
  border: 1px dashed rgba(255, 181, 69, 0.5);
  border-radius: var(--r-2);
  background: var(--amber-wash);
  color: var(--amber);
  font-weight: 600;
}
.freeplay .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.freeplay .freeplay-start {
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-4) var(--s-7);
  align-items: center;
  border-color: var(--line-strong);
}
.freeplay-go { display: grid; gap: var(--s-3); justify-items: end; text-align: right; }
.freeplay-summary { min-width: 0; color: var(--text-2); font-size: var(--fs-sm); }
.freeplay-summary strong { display: block; color: var(--text); font-size: var(--fs-md); }

/* ---------- how to play ---------- */
.manual { display: grid; gap: var(--s-5); }
.manual section { display: grid; gap: var(--s-3); }
.manual h3 {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--cyan);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.manual h3::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.manual p { color: var(--text-2); max-width: 84ch; }
.manual strong { color: var(--text); font-weight: 600; }
.manual-lead { color: var(--text) !important; font-size: 1rem; }
.manual-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.manual-action {
  display: grid;
  gap: var(--s-1);
  align-content: start;
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background: rgba(4, 10, 19, 0.45);
}
.manual-action-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.manual-action-head strong { font-size: var(--fs-md); }
.manual-action p { font-size: var(--fs-sm); }
.manual-list { display: grid; gap: var(--s-2); }
.manual-list li { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: var(--s-3); color: var(--text-2); font-size: 0.875rem; }
.manual-list li > :first-child { color: var(--text); font-weight: 600; }
.swatches { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); font-size: var(--fs-sm); color: var(--text-2); }
.swatch { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.swatch::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 2px var(--bg-0), 0 0 0 3px rgba(255, 255, 255, 0.18);
}
.keys { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5); color: var(--text-2); font-size: 0.875rem; }
.keys span { display: inline-flex; align-items: center; gap: var(--s-2); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .freeplay { grid-template-columns: minmax(0, 1fr); }
  .freeplay .freeplay-start { grid-template-columns: minmax(0, 1fr); }
  .freeplay-go { justify-items: stretch; text-align: left; }
  .manual-actions { grid-template-columns: minmax(0, 1fr); }
  .dialog-body { padding: var(--s-4); }
  .dialog-head { padding-left: var(--s-4); }
  .dialog-foot { padding: var(--s-3) var(--s-4) var(--s-4); }
}
@media (max-width: 520px) {
  /* .hide-narrow: text that collapses to its icon on phones (still read by screen readers) */
  .hide-narrow { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .btn:has(> .hide-narrow) { width: var(--control-h); padding: 0; }
  .manual-list li { grid-template-columns: minmax(0, 1fr); gap: 0; }

  .screen { padding-bottom: var(--s-6); }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .title-backdrop svg, .mark::before, .mark::after { animation: none !important; }
}
