/* Shared look tokens for the network and the game (spec hsk-network #look). */

/* Vendored subsets cut by scripts/build_fonts.py; licenses beside them (#type-faces). */
@font-face {
  font-family: "Noto Sans CJK TC";
  src: url("fonts/noto-sans-cjk-tc.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

/* Mainland forms face (#face-forms): named only in pinyin mode, so never preloaded. */
@font-face {
  font-family: "Noto Sans CJK TC Mainland";
  src: url("fonts/noto-sans-cjk-tc-mainland.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist";
  src: url("fonts/geist.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Type (#face-stack, #type-scale): Geist first so every character and Zhuyin falls to the Chinese face. */
  --font: "Geist", "Noto Sans CJK TC", system-ui, sans-serif;
  --fs-head: 40px;
  --fs-head-phone: 36px;
  --fs-score: 56px;
  --fs-score-play: 28px;
  --fs-title: 22px;
  --fs-body: 16px;
  --lh-body: 1.5;
  --fs-label: 14px;
  --fs-caption: 12px;
  --ls-caption: .02em;
  --zhuyin-ratio: .38;
  --fs-zhuyin-min: 14px;
  --fs-zhuyin-list: 15px;
  --zhuyin-gap: .3em;
  --w-regular: 400;
  --w-medium: 500;
  --w-semibold: 600;

  /* Color (#color-table). Okabe-Ito blue and orange: distinguishable under common color blindness. */
  --paper: #f6f4ef;
  --night: #0f1424;
  --surface: #ffffff;
  --surface-night: #181e31;
  --ink: #1b1b1f;
  --ink-night: #f6f4ef;
  --muted: #5d5b57;
  --muted-night: #a9b0c2;
  --line: #e3dfd6;
  --line-night: rgba(255, 255, 255, .14);
  --hsk1: #0072b2;
  --hsk2: #e69f00;
  --hub: #8b877f;
  --hover: var(--paper);  /* row hover and selection fill on surfaces */
  /* Part strokes (#strokes-colors): the Okabe-Ito colors left after the level blue and orange. */
  --part-1: #d55e00;
  --part-2: #009e73;
  --part-3: #cc79a7;

  /* Depth (#color-depth, #color-meaning). */
  --radius-card: 14px;
  --radius-pill: 999px;
  --shadow: 0 6px 24px rgba(27, 27, 31, .08);
  --focus-ring: 2px;

  /* Motion (#motion-table): transform and opacity only. */
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --press-scale: .97;
  --rise: 8px;
  --dur-press: 140ms;
  --dur-card: 220ms;
  --dur-card-leave: 150ms;
  --dur-sheet: 260ms;
  --dur-focus: 550ms;
  --dur-load: 400ms;
  --dur-level: 200ms;
  --dur-reduced: 120ms;
}

/* Pinyin mode: the mainland forms face before the Chinese face, for every text style (#face-forms). */
:root[data-script="pinyin"] {
  --font: "Geist", "Noto Sans CJK TC Mainland", "Noto Sans CJK TC", system-ui, sans-serif;
}

/* ---------- Base (shared by both pages) ---------- */

:root {
  font-family: var(--font);
  font-size: var(--fs-body);
  font-weight: var(--w-regular);
  font-synthesis: none; /* #scale-weights: never a synthetic bold */
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent; /* #fit-touch: no gray flash on tap */
  touch-action: pan-x pan-y; /* #fit-zoom: no pinch or double-tap page zoom; pages also block iOS gestures */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* #fit-height, #fit-bounce: the body is pinned to the visible screen, so the page never scrolls or slides. */
body {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

button { font: inherit; color: inherit; }
:focus-visible { outline: var(--focus-ring) solid var(--ink); outline-offset: 2px; }

/* Collection chips (#page-levels): mark and name; an off chip shows a hollow dot, or a muted
   pill outline for a themed collection, and a muted name. */
.level {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: var(--fs-label);
  font-weight: var(--w-medium);
  white-space: nowrap;
  cursor: pointer;
}
.level[aria-disabled="true"] { cursor: default; }
.level[aria-checked="false"] { color: var(--muted); }
.swatch {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1.5px var(--swatch);
}
.swatch.l1 { --swatch: var(--hsk1); }
.swatch.l2 { --swatch: var(--hsk2); }
/* Themed collection mark (#color-levels): a small hollow pill, surface fill and ink outline. */
.swatch.pill { width: 18px; border-radius: var(--radius-pill); background: var(--surface); --swatch: var(--ink); }
.level[aria-checked="false"] .swatch { background: transparent; }
.level[aria-checked="false"] .swatch.pill { --swatch: var(--muted); }

/* Headword and readings, built by headword.js for both pages (#zhuyin-columns, #pinyin-ruby,
   #zhuyin-fallback); --head sets the headword size; characters Medium, readings Regular (#scale-weights). */
.hw {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 .12em;
  font-size: var(--head, var(--fs-head));
  font-weight: var(--w-medium);
  line-height: 1.15;
}
.hw-cell { display: inline-flex; align-items: center; }
.zy-col {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin: 0 .3em 0 .06em;
  font-weight: var(--w-regular);
  font-size: max(var(--fs-zhuyin-min), calc(var(--head, var(--fs-head)) * var(--zhuyin-ratio)));
  line-height: 1.02;
}
.zy-sym { position: relative; }
.zy-tone { position: absolute; left: 96%; top: .14em; font-size: .9em; }
.zy-dot { height: .5em; line-height: .5; }
.hw-ruby { display: block; line-height: 1; padding-top: .2em; }
.hw-ruby ruby { ruby-position: over; margin-right: .06em; }
.hw-ruby rt {
  font-size: max(var(--fs-zhuyin-min), calc(var(--head, var(--fs-head)) * var(--zhuyin-ratio)));
  line-height: 1.3;
  text-align: center;
}
.hw-line { flex-direction: column; align-items: flex-start; }
.hw-ruby rt, .hw-reading { font-weight: var(--w-regular); }
.hw-reading { font-size: 1rem; line-height: 1.4; }

/* One-line readings (#zhuyin-line): syllables 0.3em apart; lists, measure words, references. */
.zy, .py { font-size: var(--fs-zhuyin-list); font-weight: var(--w-regular); white-space: nowrap; }
.zy > span + span { margin-left: var(--zhuyin-gap); }

/* Press (#motion-press): scale on the compositor; color only with reduced motion. */
.level, .script, .voice, .play, .foot summary, .c-words button, .c-close, .c-say {
  transition: transform var(--dur-press) var(--ease-out);
}
.level:active, .script:active, .voice:active, .play:active, .foot summary:active, .c-words button:active, .c-close:active, .c-say:active {
  transform: scale(var(--press-scale));
}

/* ---------- Network page (#page) ---------- */

.stage {
  position: absolute;  /* no stacking context: the card stacks over the Sources link */
  inset: 0;
  overflow: hidden;
}

#graph {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* #fit-select: long-press on a node shows no callout */
  cursor: grab;
}
#graph:active { cursor: grabbing; }

.status {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: var(--fs-label);
  pointer-events: none;
}
.status:empty { display: none; }

/* Controls float over the graph; the gaps between them stay the graph's. */
.controls {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  z-index: 3;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.controls > * { pointer-events: auto; }
.controls input { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

.search {
  position: relative;
  flex: 0 1 340px;
  min-width: 0;
}
.search::before, .search::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.search::before {
  left: 17px;
  top: 14px;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
}
.search::after {
  left: 27px;
  top: 25px;
  width: 6px;
  height: 1.5px;
  background: var(--muted);
  transform: rotate(45deg);
  transform-origin: left center;
}
#search {
  width: 100%;
  height: 44px;
  font: inherit;
  font-size: 16px;
  padding: 0 18px 0 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  -webkit-appearance: none;
  appearance: none;
}
#search::placeholder { color: var(--muted); opacity: 1; }
#search:focus-visible { outline-offset: 0; }

.results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  max-height: min(60vh, 520px);
  max-height: min(60dvh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: rise var(--dur-card) var(--ease-out);
}
.results li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: var(--fs-label);
  cursor: pointer;
}
.results li[aria-selected="true"], .results li:hover { background: var(--hover); }
.results li.empty { color: var(--muted); cursor: default; background: none; }
.results .r-han { font-size: 20px; line-height: 1.2; flex: none; }
.results .r-def { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.results .r-lvl {
  margin-left: auto;
  flex: none;
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-caption);
  font-weight: var(--w-medium);
  color: var(--muted);
}

.panel {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}

/* Script control (#default-script-setting): reads the current script. */
.script {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: var(--fs-label);
  font-weight: var(--w-medium);
  cursor: pointer;
}
.script::before {
  content: "";
  width: 12px;
  height: 8px;
  border-top: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
}

/* Voice control (#page-voice): speaker icon and state, the icon crossed when off;
   icon only where the row is narrow. The card's speaker button reuses the icon. */
.voice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: var(--fs-label);
  font-weight: var(--w-medium);
  white-space: nowrap;
  cursor: pointer;
}
.voice[aria-checked="false"] { color: var(--muted); }
.voice svg, .c-say svg { width: 20px; height: 20px; flex: none; }
.voice svg .i-note, .c-say svg .i-note { fill: currentColor; }
.voice svg .i-wave, .voice svg .i-slash, .c-say svg .i-wave {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
.voice[aria-checked="false"] .i-wave, .voice[aria-checked="true"] .i-slash, .c-say .i-slash { display: none; }

/* Primary action: an ink pill (#color-meaning). */
.play {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: var(--surface);
  font-size: var(--fs-label);
  font-weight: var(--w-semibold);
  text-decoration: none;
  box-shadow: var(--shadow);
}

/* Graph marks */
.graph { opacity: 0; transition: opacity var(--dur-load) ease-out; }
.graph.in { opacity: 1; }
.link {
  stroke: var(--line);
  stroke-width: 1.2;
  pointer-events: none;
  transition: opacity var(--dur-focus) var(--ease-in-out), stroke-opacity var(--dur-level) ease-out;
}
.node {
  cursor: pointer;
  transition: opacity var(--dur-focus) var(--ease-in-out), visibility 0s;
}
.node > * { transition: opacity var(--dur-level) ease-out; }
.node text { pointer-events: none; text-anchor: middle; dominant-baseline: central; font-weight: var(--w-medium); }
.word rect { stroke: var(--paper); stroke-width: 1.5; }
.word.l1 rect { fill: var(--hsk1); }
.word.l2 rect { fill: var(--hsk2); }
.word text { font-size: 14px; }
.word.l1 text { fill: #ffffff; }  /* labels sit on the fixed level and hub fills, in both appearances */
.word.l2 text { fill: #1b1b1f; }
/* Themed word (#color-levels): a hollow pill, surface fill with a 2px ink outline. */
.word.pill rect { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.word.pill text { fill: var(--ink); }
.hub circle { fill: var(--hub); stroke: var(--paper); stroke-width: 1.5; }
.hub text { fill: #ffffff; font-size: 10px; }

/* Level off (#motion-level): words and links fade, then stop taking taps. */
.link.off { stroke-opacity: 0; }
.node.off > * { opacity: 0; }
.node.off {
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--dur-focus) var(--ease-in-out), visibility 0s linear var(--dur-level);
}

.dimmed .link { opacity: .25; }
.dimmed .node { opacity: .16; }
.dimmed .link.lit, .dimmed .node.lit { opacity: 1; }
.link.lit { stroke: var(--hub); }
.node.focus rect, .node.focus circle { stroke: var(--ink); stroke-width: 2; }
.node.focus.pill rect { stroke-width: 3.5; }

/* Card (#page-card-content): beside the node on desktop, a bottom sheet on phones. */
.card {
  position: absolute;
  z-index: 2;
  width: max-content;
  min-width: 220px;
  max-width: min(340px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 20px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(var(--rise));
  transition: opacity var(--dur-card-leave) ease-out, transform var(--dur-card-leave) ease-out;
}
.card.in {
  opacity: 1;
  transform: none;
  transition: opacity var(--dur-card) var(--ease-out), transform var(--dur-card) var(--ease-out);
}
.card[hidden] { display: none; }
.card.pinned { padding-right: 44px; }
.c-grip { display: none; }
.card .hw { margin: 0 0 10px; }

/* Headword with its speaker button on the right (#page-card-content); a full-size
   button (#page-touch), while tappable characters, syllables, and symbols stay text. */
.c-head { display: flex; align-items: center; gap: 4px; margin: 0 0 10px; }
.c-head .hw { margin: 0; }
.c-say {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.c-say[hidden] { display: none; }
.c-say:hover { color: var(--ink); }
.card.voice-on .say { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.c-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.card:not(.pinned) .c-close { display: none; }

.c-senses { list-style: none; margin: 0; padding: 0; line-height: var(--lh-body); }
.c-senses li + li { margin-top: 2px; }
.c-cap, .c-tag {
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-caption);
  font-weight: var(--w-medium);
  color: var(--muted);
}
.c-tag { margin-right: 6px; }
.c-mw { margin: 12px 0 0; line-height: var(--lh-body); }
.c-mw .c-cap { display: block; }
.c-level {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-caption);
  font-weight: var(--w-medium);
  color: var(--muted);
}
.c-reading + .c-reading { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

/* Hub breakdown: the drawn character beside the Radical and Parts rows, above them
   when the card is too narrow (#page-strokes). */
.c-breakdown {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px 14px;
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.b-draw { flex: none; width: 88px; height: 88px; }
.b-rows {
  flex: 1 1 160px;
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px 10px;
  margin: 0;
  align-items: start;
}
.b-rows dt { line-height: 44px; }
.b-rows dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.b-parts { display: flex; flex-wrap: wrap; gap: 2px 4px; list-style: none; margin: 0; padding: 0; }
.b-parts li { min-width: 0; max-width: 100%; }

/* Each stroke an even line with round ends; the radical's outline is a band of the card's
   ink on both sides of its line (#page-strokes-radical). */
.b-draw path, .b-sw path {
  fill: none;
  stroke-width: 11;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity var(--dur-level) ease-out;
}
.b-draw .s-out { stroke-width: 17; }
.b-sw { flex: none; width: 28px; height: 14px; align-self: center; }
.b-sw path { stroke-width: 5; }
.b-sw .s-out { stroke-width: 8; }
.s-ink, .s-out { stroke: var(--ink); }
.s-p1 { stroke: var(--part-1); }
.s-p2 { stroke: var(--part-2); }
.s-p3 { stroke: var(--part-3); }
.b-draw path.pale { opacity: .16; }

/* Radical and parts are toggle buttons; pressed shows a ring as well as a tint (#page-strokes-light). */
.b-btn {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 6px;
  max-width: 100%;
  min-height: 44px;
  margin: 0 -2px;
  padding: 2px 8px 2px 4px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-press);
}
.b-btn:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.b-btn:active { transform: scale(var(--press-scale)); }
.b-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  box-shadow: inset 0 0 0 2px var(--ink);
}
.b-char { font-size: 22px; }
.b-num { color: var(--muted); font-size: var(--fs-label); font-variant-numeric: tabular-nums; }
.b-mean, .b-none { font-size: var(--fs-label); }
.b-none { color: var(--muted); line-height: 44px; }

.c-count { margin: 16px 0 4px; padding-top: 14px; border-top: 1px solid var(--line); }
.c-words { list-style: none; margin: 0 -8px; padding: 0; }
.c-words button {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 4px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: var(--fs-label);
  text-align: left;
  cursor: pointer;
}
.c-words button:hover { background: var(--hover); }
.c-words .w-han { font-size: 20px; }
.c-words .w-reading { color: var(--muted); }
.c-words .w-han, .c-words .w-reading, .c-words .swatch { flex: none; }
.c-words .w-gloss { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Sources: a small text link bottom left (#page-sources). */
.foot {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(4px, env(safe-area-inset-bottom));
  z-index: 1;
  max-width: calc(100% - 16px);
}
.foot summary {
  -webkit-user-select: none;
  user-select: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-caption);
  font-weight: var(--w-medium);
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
  cursor: pointer;
  list-style: none;
}
.foot summary::-webkit-details-marker { display: none; }
.sources-body {
  margin-bottom: 4px;
  padding: 12px 16px;
  max-width: 460px;
  max-height: 60vh;
  max-height: 60dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  font-size: var(--fs-label);
  line-height: var(--lh-body);
  animation: rise var(--dur-card) var(--ease-out);
}
.sources-body p { margin: 0; }
.sources-body p + p { margin-top: 8px; }
.foot details[open] { display: flex; flex-direction: column-reverse; align-items: flex-start; }
.foot a { color: var(--ink); text-decoration-color: var(--muted); text-underline-offset: 2px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(var(--rise)); }
}
@keyframes fade {
  from { opacity: 0; }
}

/* Dark appearance (#color-dark, #color-table dark column): follows the device setting live;
   both pages take the night page, the dark surface, and light ink and muted; part colors stay
   (#acceptance-strokes-dark). The swap sits on body, not :root, because the game reads its
   bubble paper and ink from :root (game.js), and bubbles keep their look on the night board.
   On night the hairline alone carries a surface's edge (#color-depth). */
@media (prefers-color-scheme: dark) {
  :root { background: var(--night); color-scheme: dark; }
  body {
    --paper: var(--night);
    --surface: var(--surface-night);
    --ink: var(--ink-night);
    --muted: var(--muted-night);
    --line: var(--line-night);
    --hover: color-mix(in srgb, var(--ink-night) 8%, var(--surface-night));
    --shadow: 0 0 0 transparent;
    color: var(--ink);
  }
}

/* Phone: search on top, chips and Play beneath it, the card a bottom sheet (#acceptance-phone-fit). */
@media (max-width: 600px) {
  .controls {
    top: max(10px, calc(env(safe-area-inset-top) + 4px));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .search { flex: none; }
  .panel { gap: 6px; }
  /* Collection chips on their own row (#page-levels-phone), scrolling sideways within itself. */
  .legend {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    margin: 0 calc(-1 * max(10px, env(safe-area-inset-right))) 0 calc(-1 * max(10px, env(safe-area-inset-left)));
    padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .legend::-webkit-scrollbar { display: none; }
  .level { padding: 0 12px 0 11px; gap: 6px; }
  .script { padding: 0 12px; }
  .voice { padding: 0 11px; }
  .voice-state { display: none; }
  .play { margin-left: auto; padding: 0 16px; }
}

@media (hover: none), (max-width: 600px) {
  .card {
    position: fixed;
    left: 0 !important;
    right: 0;
    bottom: 0;
    top: auto !important;
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: 55%;
    padding: 10px max(20px, calc(env(safe-area-inset-right) + 8px)) calc(16px + env(safe-area-inset-bottom)) max(20px, calc(env(safe-area-inset-left) + 8px));
    border-bottom: 0;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    opacity: 1;
    transform: translateY(100%);
    transition: transform var(--dur-sheet) var(--ease-out);
  }
  .card.in { transform: none; transition: transform var(--dur-sheet) var(--ease-out); }
  .card.pinned { padding-right: calc(44px + env(safe-area-inset-right)); }
  .c-close { right: max(4px, env(safe-area-inset-right)); }
  .c-grip {
    display: block;
    width: 36px;
    height: 4px;
    margin: 0 auto 10px;
    border-radius: 2px;
    background: var(--line);
  }
  .card { --head: var(--fs-head-phone); }
}

/* Reduced motion (#motion-reduced): nothing slides, scales, glides, or shakes. */
@media (prefers-reduced-motion: reduce) {
  .level, .script, .voice, .play, .foot summary, .c-words button, .c-close, .c-say { transition: background-color var(--dur-reduced); }
  .level:active, .script:active, .voice:active, .play:active, .foot summary:active, .c-words button:active, .c-close:active, .c-say:active {
    transform: none;
    background-color: var(--paper);
  }
  .play:active { background-color: var(--muted); }
  .graph, .link, .node, .node > * { transition: none; }
  .b-btn { transition: background-color var(--dur-reduced); }
  .b-btn:active { transform: none; }
  .b-draw path { transition: opacity var(--dur-reduced); }
  .node.off { transition: none; }
  .card, .card.in {
    transform: none;
    transition: opacity var(--dur-reduced) ease-out;
  }
  @media (hover: none), (max-width: 600px) {
    .card { opacity: 0; }
    .card.in { opacity: 1; }
  }
  .results, .sources-body { animation: fade var(--dur-reduced) ease-out; }
}
