/*
  Fieldcast - stylesheet

  Rules that are easy to break later:

  1. Colours are the Fieldcast brand (deploy/branding): Iris #6269F5 accent,
     Ink #17191F, Paper #F3F2ED, Mist #E7E8F0. Iris is a mid-tone, so no text
     colour reaches 4.5:1 on it; following the brand, buttons use Ink on Iris
     (4.06:1, fine for large text and graphics). Where Iris itself would be
     small TEXT, --accent-text is used instead: a darker Iris in light mode and a
     lighter one in dark mode, same hue, both above 5.9:1.
  2. Status colours (good, critical, warning) mean a state and nothing else.
     The edible / poisonous verdict always carries an icon and a word as well,
     because red and green are not reliably distinguishable for everyone.
  3. One corner rule: panels and cards 22px, everything you can press or pick
     (buttons, chips, sliders, the switch) is a full pill.
  4. Both themes are designed, not inverted. Tokens are set for the OS setting
     under prefers-color-scheme and again under [data-theme="dark"] for the
     toggle; the :not([data-theme="light"]) guard lets the toggle win both ways.
  5. Every animation stops under prefers-reduced-motion (bottom of the file,
     and the 3D scene checks it too).
*/

/* Registered so the sky gradient behind the 3D scene can fade between colours
   instead of jumping. */
@property --sky-top    { syntax: "<color>"; inherits: true; initial-value: #dfe6ee; }
@property --sky-bottom { syntax: "<color>"; inherits: true; initial-value: #f3f6f9; }

:root {
  color-scheme: light;
  --bg:          #f3f2ed;   /* Paper */
  --surface:     #ffffff;
  --surface-2:   #e7e8f0;   /* Mist */
  --surface-3:   #d9dbe6;
  --glass:       rgba(255, 255, 255, .74);
  --ink:         #17191f;   /* Ink */
  --ink-2:       #474b57;
  --ink-3:       #656977;
  --line:        rgba(23, 25, 31, .10);
  --line-strong: rgba(23, 25, 31, .20);

  --brand:       #6269f5;   /* Iris: logo mark */
  --wordmark:    #17191f;   /* Ink on light */
  --accent:      #6269f5;   /* Iris */
  --accent-ink:  #17191f;   /* Ink on Iris, as the brand asks */
  --accent-text: #4a50d8;   /* Iris, darkened for small text: 6.1:1 on white */
  --accent-soft: rgba(98, 105, 245, .14);
  --accent-glow: rgba(98, 105, 245, .38);

  --good:        #0ca30c;
  --critical:    #d03b3b;
  --warning:     #fab219;

  --shadow-sm: 0 1px 2px rgba(22, 30, 60, .06);
  --shadow:    0 1px 2px rgba(22, 30, 60, .05), 0 14px 34px -18px rgba(22, 30, 60, .30);
  --shadow-lg: 0 2px 6px rgba(22, 30, 60, .06), 0 30px 70px -30px rgba(22, 30, 60, .45);

  --r-card: 22px;
  --bar: 64px;
  --sans: "Outfit Variable", "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono Variable", "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease:   cubic-bezier(.16, 1, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:          #101217;
    --surface:     #17191f;   /* Ink */
    --surface-2:   #20232b;
    --surface-3:   #2b2f39;
    --glass:       rgba(23, 25, 31, .76);
    --ink:         #f3f2ed;   /* Paper */
    --ink-2:       #bdbfc9;
    --ink-3:       #8d909c;
    --line:        rgba(243, 242, 237, .09);
    --line-strong: rgba(243, 242, 237, .18);
    --brand:       #6269f5;
    --wordmark:    #f3f2ed;   /* Paper on dark */
    --accent:      #6269f5;
    --accent-ink:  #17191f;
    --accent-text: #8f94fa;   /* Iris, lightened for small text: 6.0:1 on Ink */
    --accent-soft: rgba(98, 105, 245, .20);
    --accent-glow: rgba(98, 105, 245, .40);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 16px 36px -18px rgba(0, 0, 0, .75);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, .45), 0 30px 70px -30px rgba(0, 0, 0, .9);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #101217;
  --surface:     #17191f;   /* Ink */
  --surface-2:   #20232b;
  --surface-3:   #2b2f39;
  --glass:       rgba(23, 25, 31, .76);
  --ink:         #f3f2ed;   /* Paper */
  --ink-2:       #bdbfc9;
  --ink-3:       #8d909c;
  --line:        rgba(243, 242, 237, .09);
  --line-strong: rgba(243, 242, 237, .18);
  --brand:       #6269f5;
  --wordmark:    #f3f2ed;   /* Paper on dark */
  --accent:      #6269f5;
  --accent-ink:  #17191f;
  --accent-text: #8f94fa;   /* Iris, lightened for small text: 6.0:1 on Ink */
  --accent-soft: rgba(98, 105, 245, .20);
  --accent-glow: rgba(98, 105, 245, .40);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 16px 36px -18px rgba(0, 0, 0, .75);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .45), 0 30px 70px -30px rgba(0, 0, 0, .9);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
code {
  font-family: var(--mono);
  font-size: .86em;
  padding: .1em .38em;
  border-radius: 6px;
  background: var(--surface-2);
}
a { color: var(--accent-text); }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ================================================================ top bar */

.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--bar);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: color-mix(in oklab, var(--bg) 80%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}
/* The Fieldcast logo is drawn through CSS masks: the PNGs in brand/ hold only
   the shapes (cleaned from deploy/branding), and the colour comes from the
   tokens. That keeps the exact brand hex values and lets the wordmark turn from
   Ink to Paper with the theme, from one file. */
.brand-mark {
  width: 31px;
  height: 28px;
  flex: none;
  background: var(--brand);
  -webkit-mask: url("brand/fieldcast-mark.png") center / contain no-repeat;
          mask: url("brand/fieldcast-mark.png") center / contain no-repeat;
  transition: transform .5s var(--spring);
}
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.06); }
.brand-word {
  width: 100px;
  height: 21px;
  flex: none;
  background: var(--wordmark);
  -webkit-mask: url("brand/fieldcast-wordmark.png") left center / contain no-repeat;
          mask: url("brand/fieldcast-wordmark.png") left center / contain no-repeat;
}
/* Forced-colours mode ignores mask colours; fall back to a readable name. */
@media (forced-colors: active) {
  .brand-mark, .brand-word { display: none; }
  .brand::after { content: "Fieldcast"; font-weight: 700; }
}

/* The mode switch: a pill with a thumb that slides to the chosen side. */
.switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.switch-thumb {
  position: absolute;
  inset: 4px auto 4px 4px;
  width: calc(50% - 4px);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--line);
  transition: transform .45s var(--spring);
}
body[data-mode="citibike"] .switch-thumb { transform: translateX(100%); }
.switch button {
  position: relative;
  z-index: 1;
  padding: 7px 20px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-3);
  cursor: pointer;
  transition: color .25s;
  white-space: nowrap;
}
.switch button[aria-selected="true"] { color: var(--ink); }
.switch button:hover { color: var(--ink); }

.bar-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

/* The dot here is real state (online / waking / unreachable / demo). */
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}
.status:hover { border-color: var(--line-strong); color: var(--ink); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.status[data-state="online"] .status-dot  { background: var(--good); animation: breathe 2.6s ease-in-out infinite; }
.status[data-state="waking"] .status-dot  { background: var(--warning); animation: blink 1s ease-in-out infinite; }
.status[data-state="offline"] .status-dot { background: var(--critical); }
.status[data-state="demo"] .status-dot    { background: var(--warning); }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, .45); } 50% { box-shadow: 0 0 0 5px rgba(12, 163, 12, 0); } }
@keyframes blink { 50% { opacity: .35; } }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 18px;
  cursor: pointer;
  transition: transform .3s var(--spring), color .2s;
}
.icon-btn:hover { color: var(--ink); transform: rotate(-20deg); }
.icon-btn:active { transform: scale(.92); }
.icon-to-light { display: none; }
:root[data-theme="dark"] .icon-to-dark { display: none; }
:root[data-theme="dark"] .icon-to-light { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-to-dark { display: none; }
  :root:not([data-theme="light"]) .icon-to-light { display: inline; }
}

/* ================================================================ layout */

.studio {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(380px, .65fr);
  align-items: start;
}

/* The stage stays in view while the form scrolls, so every change you make in
   the panel is visible in the scene at once. */
.stage {
  position: sticky;
  top: var(--bar);
  height: calc(100dvh - var(--bar));
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  transition: --sky-top 1s var(--ease), --sky-bottom 1s var(--ease);
}
.stage-view { position: absolute; inset: 0; }
/* A band of sky behind the intro text, so the headline stays readable whatever
   scenery turns behind it. It uses the live sky colour, so it is invisible as a
   shape and only lifts the contrast. */
.stage-view::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 42%;
  pointer-events: none;
  background: linear-gradient(180deg,
    color-mix(in oklab, var(--sky-top) 92%, transparent) 0%,
    color-mix(in oklab, var(--sky-top) 60%, transparent) 45%,
    transparent 100%);
}
.stage-intro, .stage-hint { z-index: 1; }
#stage-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;
}
#stage-canvas:active { cursor: grabbing; }

.stage-intro {
  position: absolute;
  top: 26px;
  left: 28px;
  max-width: 440px;
  pointer-events: none;
}
.stage-intro h1 {
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: #10141b;
  text-wrap: balance;
}
.stage-intro p {
  margin-top: 8px;
  font-size: 15px;
  color: rgba(16, 20, 27, .72);
  max-width: 34ch;
}
/* The sky is always fairly light in daytime and dark at night, so the intro
   text follows the theme rather than the page ink. */
:root[data-theme="dark"] .stage-intro h1 { color: #f4f6fa; }
:root[data-theme="dark"] .stage-intro p  { color: rgba(244, 246, 250, .72); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stage-intro h1 { color: #f4f6fa; }
  :root:not([data-theme="light"]) .stage-intro p  { color: rgba(244, 246, 250, .72); }
}
.stage-intro.swap { animation: intro-swap .55s var(--ease); }
@keyframes intro-swap {
  0%   { opacity: 0; transform: translateY(10px); filter: blur(4px); }
  100% { opacity: 1; transform: none; filter: none; }
}

.stage-hint {
  position: absolute;
  top: 30px;
  right: 26px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  color: rgba(16, 20, 27, .7);
  background: rgba(255, 255, 255, .55);
  backdrop-filter: blur(8px);
  pointer-events: none;
  transition: opacity .6s;
}
.stage-hint.gone { opacity: 0; }
@media (pointer: coarse) { .stage-hint { display: none; } }

.stage-fallback {
  position: absolute;
  inset: 0;
  display: none;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  color: rgba(16, 20, 27, .7);
}
.stage-fallback i { font-size: 56px; }
body.no-3d .stage-fallback { display: grid; }
body.no-3d #stage-canvas, body.no-3d .stage-hint { display: none; }

/* ================================================================ result card */

.hud-dock {
  position: absolute;
  left: 24px;
  bottom: 24px;
  width: min(372px, calc(100% - 48px));
}
.hud {
  position: relative;
  padding: 20px 22px 18px;
  border-radius: var(--r-card);
  background: var(--glass);
  backdrop-filter: saturate(1.5) blur(18px);
  -webkit-backdrop-filter: saturate(1.5) blur(18px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: opacity .3s;
}
.hud[hidden] { display: none; }
.hud > div, .hud-stale { display: none; }
.hud[data-state="idle"]    .hud-idle    { display: block; }
.hud[data-state="loading"] .hud-loading { display: block; }
.hud[data-state="done"]    .hud-done    { display: block; animation: pop .5s var(--spring) both; }
.hud[data-state="error"]   .hud-error   { display: block; }
.hud[data-stale] .hud-done { opacity: .45; filter: saturate(.4); transition: opacity .3s, filter .3s; }
.hud[data-stale] .hud-stale { display: block; }

@keyframes pop {
  0%   { opacity: 0; transform: translateY(12px) scale(.96); }
  100% { opacity: 1; transform: none; }
}

.hud-lead { font-size: 16px; font-weight: 650; letter-spacing: -0.015em; }
.hud-text { margin-top: 4px; font-size: 13.5px; color: var(--ink-2); }
.hud-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.hud-error { font-size: 13.5px; color: var(--ink-2); }
.hud-error strong { color: var(--ink); }
.hud-stale {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}

/* "Scanning" shimmers while the request is in flight. */
.scan-text {
  background: linear-gradient(90deg, var(--ink) 30%, var(--accent) 50%, var(--ink) 70%);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }

/* A state, so: icon + word + colour. Never colour alone. */
.verdict {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 15px 7px 11px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 650;
  border: 1px solid currentColor;
}
.verdict-icon { font-size: 19px; }
.verdict[data-level="critical"] { color: var(--critical); background: color-mix(in oklab, var(--critical) 13%, var(--surface)); }
.verdict[data-level="good"]     { color: var(--good);     background: color-mix(in oklab, var(--good) 13%, var(--surface)); }

/* Probability against one decision point: the arc and the threshold tick share
   one path, so "how far past the line" reads at a glance. The track is a
   lighter step of the fill's own hue. */
.gauge { position: relative; width: min(260px, 100%); margin: 10px auto 0; }
.gauge svg { display: block; width: 100%; height: auto; overflow: visible; }
.gauge-track { stroke: var(--track); }
.gauge-fill { stroke: var(--fill); stroke-linecap: round; transition: stroke-dashoffset .9s var(--ease); }
.gauge-tick { stroke: var(--ink); stroke-width: 2.5; }
.gauge-tick-halo { stroke: var(--surface); stroke-width: 6; }
.gauge-centre { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; }
.gauge-caption { font-size: 12px; font-weight: 600; color: var(--ink-2); }

/* Hero figure: one per view. Proportional digits; tabular ones look loose this big. */
.hero {
  font-size: clamp(42px, 5vw, 54px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1;
}
.hero small {
  margin-left: 2px;
  font-size: .38em;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--ink-3);
}
#citibike-trips { margin-top: 4px; }

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; text-align: right; font-weight: 550; }

.notes {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: color-mix(in oklab, var(--warning) 14%, var(--surface));
}
.notes strong { color: var(--ink); }
.notes ul { margin: 4px 0 0; padding-left: 17px; }

.about { margin-top: 12px; font-size: 12.5px; color: var(--ink-3); }
.about summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
.about p { margin-top: 6px; line-height: 1.5; }

.meter { margin-top: 14px; }
.meter-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in oklab, var(--accent) 20%, var(--surface-2));
}
.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width .9s var(--ease);
}
.meter-mark {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  transform: translateX(-1px);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--ink) inset;
}
.meter-scale {
  position: relative;
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
}
.meter-mark-label {
  position: absolute;
  transform: translateX(-50%);
  font-family: var(--sans);
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; padding: 0; list-style: none; }
.tags li {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.tags li.flag { color: var(--accent-text); background: var(--accent-soft); border-color: transparent; }

/* ================================================================ panel */

.panel {
  min-height: calc(100dvh - var(--bar));
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--bg);
}
.panel-body { flex: 1; padding: 22px 22px 0; }
.panel-body[hidden] { display: none; }

.safety {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  background: color-mix(in oklab, var(--critical) 9%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--critical) 28%, transparent);
}
.safety summary {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  font-weight: 650;
  list-style: none;
}
.safety summary::-webkit-details-marker { display: none; }
.safety summary i { color: var(--critical); font-size: 18px; margin-top: 1px; flex: none; }
.safety summary::after {
  content: "Why";
  margin-left: auto;
  padding-left: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
  text-decoration: underline;
}
.safety[open] summary::after { content: "Less"; }
.safety p { margin-top: 8px; color: var(--ink-2); padding-left: 27px; }

.section {
  padding: 18px 18px 6px;
  margin-bottom: 14px;
  border-radius: var(--r-card);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  animation: rise .6s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.section h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.015em;
  margin-bottom: 12px;
}
.section h2 i { font-size: 18px; color: var(--accent); }

.group { margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
.group legend {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.group legend output { font-weight: 500; color: var(--ink-3); }
.group legend output.set { color: var(--accent-text); font-weight: 650; }

/* Chips are real radio buttons: arrow keys move between them, and a screen
   reader announces the group and the choice. The input is hidden but focusable. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: transform .25s var(--spring), background .2s, color .2s, border-color .2s;
  user-select: none;
}
.chip span i { font-size: 15px; }
.chip:hover span { border-color: var(--line-strong); color: var(--ink); }
.chip input:active + span { transform: scale(.94); }
.chip input:checked + span {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 6px 14px -8px var(--accent-glow);
}
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.unknown input:checked + span {
  color: var(--ink);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  box-shadow: none;
}

/* Colour swatches for gill and spore colours. The name is in the legend and
   in the accessible label, so the colour is never the only cue. */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch span {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14);
  transition: transform .3s var(--spring), box-shadow .2s;
}
.swatch:hover span { transform: scale(1.12); }
.swatch input:checked + span {
  transform: scale(1.12);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14), 0 0 0 3px var(--surface), 0 0 0 5px var(--accent);
}
.swatch input:checked + span::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--dot, #fff);
}
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 5px; }
.swatch.unknown span { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.swatch.unknown span::before { content: "?"; font-size: 14px; font-weight: 700; color: var(--ink-3); }
.swatch.unknown input:checked + span::after { display: none; }
.swatch.none span {
  background: repeating-linear-gradient(45deg, var(--surface-3) 0 4px, var(--surface) 4px 8px);
}

/* Sliders. An unset slider has a hollow thumb and reads "not measured". */
.slider { margin: 0 0 16px; }
.slider-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.slider-head label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.slider-value {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-text);
  white-space: nowrap;
}
.slider[data-unset] .slider-value { color: var(--ink-3); font-weight: 500; }
.slider-clear {
  margin-left: 6px;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--ink-3);
  font-size: 15px;
  vertical-align: -2px;
  cursor: pointer;
}
.slider-clear:hover { color: var(--ink); }
.slider[data-unset] .slider-clear { display: none; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --pct: 0%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--pct), var(--surface-3) var(--pct));
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--surface-3); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  transition: transform .25s var(--spring);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.2); }
.slider[data-unset] input[type="range"]::-webkit-slider-runnable-track { background: var(--surface-3); }
.slider[data-unset] input[type="range"]::-moz-range-progress { background: transparent; }
.slider[data-unset] input[type="range"]::-webkit-slider-thumb { background: var(--surface); border: 2px dashed var(--ink-3); }
.slider[data-unset] input[type="range"]::-moz-range-thumb { background: var(--surface); border: 2px dashed var(--ink-3); }
.slider-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-3);
}

.text-field { display: grid; gap: 6px; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.text-field input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  font-weight: 500;
  color: var(--ink);
}
.text-field input::placeholder { color: var(--ink-3); }

/* The actions stay reachable while the form scrolls. */
.panel-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px -22px 0;
  padding: 14px 22px calc(14px + env(safe-area-inset-bottom));
  background: color-mix(in oklab, var(--bg) 84%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 650;
  font-size: 14.5px;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .25s var(--spring), filter .2s, background .2s, border-color .2s, color .2s;
}
.btn i { font-size: 17px; }
.btn:active { transform: scale(.96); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-primary {
  flex: 1 1 auto;
  min-width: 150px;
  color: var(--accent-ink);
  background: var(--accent);
  box-shadow: 0 10px 24px -12px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:hover i { transform: translateX(3px); }
.btn-primary i { transition: transform .3s var(--spring); }
.btn-quiet { color: var(--ink-2); background: var(--surface); border-color: var(--line); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover .ph-shuffle { animation: wiggle .5s var(--ease); }
.btn-quiet:hover .ph-arrow-counter-clockwise { transform: rotate(-90deg); }
.btn-quiet i { transition: transform .4s var(--spring); }
@keyframes wiggle { 30% { transform: rotate(-14deg); } 65% { transform: rotate(10deg); } }

.colophon {
  padding: 18px 22px 26px;
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.6;
}
.colophon a { margin-left: 4px; }
.link {
  margin-left: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
}

/* ================================================================ dialog */

dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 24px;
  border-radius: var(--r-card);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog[open] { animation: pop .4s var(--spring); }
dialog::backdrop { background: rgba(8, 10, 14, .5); backdrop-filter: blur(3px); }
dialog h2 { font-size: 18px; letter-spacing: -0.02em; }
.dialog-text { margin: 8px 0 16px; font-size: 13.5px; color: var(--ink-2); }
.check { display: flex; gap: 10px; font-size: 13px; color: var(--ink-2); line-height: 1.45; }
.check input { margin-top: 3px; flex: none; accent-color: var(--accent); }
.check strong { color: var(--ink); }
.dialog-actions { display: flex; gap: 8px; margin-top: 20px; }

.demo-banner {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 40;
  width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 11px 16px;
  border-radius: 16px;
  font-size: 13px;
  text-align: center;
  color: #1a1403;
  background: var(--warning);
  box-shadow: var(--shadow-lg);
}
.demo-banner[hidden] { display: none; }
.demo-banner .link { color: #1a1403; }

/* ================================================================ small screens */

@media (max-width: 1023px) {
  .studio { grid-template-columns: minmax(0, 1fr); }
  .stage {
    position: relative;
    top: auto;
    height: auto;
    overflow: visible;
  }
  .stage-view { position: relative; height: min(56vh, 520px); overflow: hidden; }
  .hud-dock { position: relative; left: auto; bottom: auto; width: auto; padding: 0 16px; margin-top: -40px; }
  .panel { border-left: 0; min-height: 0; }
  .panel-body { padding: 18px 16px 0; }
  .panel-actions { margin: 4px -16px 0; padding-left: 16px; padding-right: 16px; }
  .colophon { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 640px) {
  .bar { grid-template-columns: auto 1fr auto; padding: 0 12px; gap: 8px; }
  .brand-word, #api-status-text { display: none; }
  .status { padding: 9px; }
  .switch { justify-self: center; }
  .switch button { padding: 7px 14px; }
  .stage-intro { top: 18px; left: 16px; right: 16px; }
  .stage-intro p { display: none; }
  .btn-primary { min-width: 100%; }
  .btn-quiet { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .hud, .bar, .panel-actions { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
