/* ==========================================================================
   Nelson — taipei49314.github.io
   Two surfaces, like gallery lighting: NIGHT (hero, works, boundary-unpack,
   Starry Night, research) and GESSO (checkwash, Editorial Doll, music,
   contact, footer), plus a SAND variant of night for The Returning Passage. Two meaning colours: gold = something
   lines up, signal red = something got weaker. System fonts only, no
   dependencies.

   Never put overflow (other than `clip` on <html>) on an ancestor of
   .scene-sticky: it silently breaks position: sticky.
   ========================================================================== */

:root {
  --night: #05070d;
  --night-2: #0b1020;
  --night-ink: #f2efe8;
  --night-ink-2: #a3a9b6;
  --night-line: rgba(242, 239, 232, 0.14);

  --gesso: #f3efe6;
  --gesso-panel: #e8e2d4;
  --gesso-line: #d8d1c1;
  --ink: #15171c;
  --ink-2: #545864;
  --ink-3: #8a8d96;

  --gold: #e9b949;
  --gold-ink: #7d5400;
  --signal: #9f2814;
  --signal-night: #ff6a55;
  --pass-green: #1f5e3a;

  /* The Returning Passage's own palette (its docs/DESIGN.md). */
  --sand-bg: #14110d;
  --sand-ink: #ede2cf;
  --sand-ink-2: #aa9b85;
  --sand-gold: #d3b27c;
  --sand-line: rgba(237, 226, 207, 0.14);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial,
    "PingFang TC", "Noto Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Cascadia Code", Consolas,
    "Liberation Mono", Menlo, monospace;

  --gutter: clamp(20px, 5vw, 64px);
  --bar-h: 56px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
}

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

html {
  overflow-x: clip;
  scroll-padding-top: calc(var(--bar-h) + 8px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--night);
  color: var(--night-ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

:lang(zh-Hant) body,
body:lang(zh-Hant) {
  line-height: 1.8;
}

h1,
h2,
h3,
h4,
p,
ol,
ul,
dl,
dd,
figure {
  margin: 0;
}

img,
canvas,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

sup {
  font-size: 0.6em;
  line-height: 0;
  margin-left: 0.1em;
}

sup a {
  text-decoration: none;
  color: var(--gold-ink);
  font-weight: 700;
  padding: 0 0.12em;
}

.surface-night sup a,
.hero sup a {
  color: var(--gold);
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: 4px;
}

.surface-gesso :focus-visible {
  outline-color: var(--ink);
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--night-ink);
  color: var(--night);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.mono {
  font-family: var(--mono);
}

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

/* Controls that only work with app.js. "no-js" is set before first paint
   (no JavaScript) or by the script tag's onerror / start()'s catch. */
.no-js .seg,
.no-js .cmd-copy,
.no-js #copy-email,
.no-js .lang-toggle,
.no-js .replay {
  display: none;
}
/* The <audio> players are the browser's own and work without app.js. */

/* ---------- Surfaces ---------- */

.surface-gesso {
  background: var(--gesso);
  color: var(--ink);
  color-scheme: light;
}

.surface-night {
  background: var(--night);
  color: var(--night-ink);
  color-scheme: dark;
}

.surface-sand {
  background: var(--sand-bg);
  color: var(--sand-ink);
  color-scheme: dark;
}

/* ---------- Header ---------- */

.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 var(--gutter);
  color: var(--night-ink);
  background: rgba(5, 7, 13, 0.82);
  border-bottom: 1px solid rgba(242, 239, 232, 0.08);
  transition: background-color 0.35s var(--ease), color 0.35s var(--ease), border-color 0.35s var(--ease);
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .bar {
    background: rgba(5, 7, 13, 0.66);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    backdrop-filter: saturate(160%) blur(14px);
  }
}

.bar.is-top {
  background: transparent;
  border-bottom-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.bar[data-surface="gesso"]:not(.is-top) {
  color: var(--ink);
  background: rgba(243, 239, 230, 0.86);
  border-bottom-color: rgba(21, 23, 28, 0.08);
}

.bar[data-surface="gesso"] :focus-visible {
  outline-color: var(--ink);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  text-decoration: none;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.wordmark-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  flex: none;
}

.bar-nav {
  display: flex;
  align-items: center;
  gap: clamp(12px, 3vw, 28px);
}

.bar-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  opacity: 0.86;
}

.bar-nav a:hover {
  opacity: 1;
}

.lang-toggle {
  min-width: 44px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.86;
}

.lang-toggle:hover {
  opacity: 1;
}

@media (max-width: 400px) {
  .wordmark-text {
    display: none;
  }
}

/* ---------- Shared type ---------- */

.wrap {
  width: min(100% - 2 * var(--gutter), 1080px);
  margin-inline: auto;
}

.wrap-narrow {
  width: min(100% - 2 * var(--gutter), 780px);
}

.chapter {
  padding-block: clamp(88px, 14vh, 176px);
}

.kicker {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-bottom: 18px;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-2);
}

.surface-night .kicker {
  color: var(--night-ink-2);
}

.kicker-name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

/* A work's title rather than a repository name. */
.kicker-name.kicker-title {
  font-family: var(--sans);
  font-size: 17px;
}

.kicker-ver {
  align-self: center;
  padding: 1px 10px;
  border: 1px solid var(--gesso-line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-2);
}

.surface-night .kicker-name {
  color: var(--gold);
}

.display {
  font-size: clamp(38px, 6.6vw, 88px);
  line-height: 1.06;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 28px;
  text-wrap: balance;
}

:lang(zh-Hant) .display {
  letter-spacing: 0.01em;
  line-height: 1.16;
}

.lead {
  max-width: 760px;
  font-size: clamp(19px, 1.9vw, 24px);
  line-height: 1.55;
  font-weight: 500;
  color: var(--ink-2);
  text-wrap: pretty;
}

:lang(zh-Hant) .lead {
  line-height: 1.75;
}

.surface-night .lead {
  color: var(--night-ink-2);
}

.fine {
  font-size: 14px;
  color: var(--ink-2);
}

.surface-night .fine {
  color: var(--night-ink-2);
}

.fine-center {
  text-align: center;
  margin-inline: auto;
  max-width: 640px;
}

/* ---------- Links & buttons ---------- */

.text-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  text-decoration-color: rgba(127, 127, 127, 0.55);
}

.text-link:hover {
  text-decoration-color: currentColor;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.2s var(--ease), background-color 0.2s var(--ease);
}

.pill:hover {
  transform: translateY(-1px);
}

.pill-light {
  background: var(--night-ink);
  color: var(--night);
}

.pill-ink {
  background: var(--ink);
  color: var(--gesso);
}

.pill-gold {
  background: var(--gold);
  color: #1a1200;
}

.pill-outline {
  background: transparent;
  border-color: currentColor;
}

.links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  margin-top: 28px;
}

.links-center {
  justify-content: center;
}

.links-small {
  margin-top: 14px;
  gap: 0 20px;
  font-size: 15px;
}

/* ==========================================================================
   HERO
   ========================================================================== */

.hero {
  position: relative;
  background:
    radial-gradient(60% 50% at 50% 42%, rgba(29, 78, 216, 0.22), transparent 70%),
    var(--night);
  color: var(--night-ink);
}

.scene-sticky {
  position: relative;
}

.hero-visual {
  position: relative;
}

.hero-fallback {
  width: 100%;
  height: auto;
}

.hero-canvas {
  display: none;
}

.eyebrow {
  font-size: clamp(15px, 1.5vw, 18px);
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 18px;
}

.hero-title {
  font-size: clamp(42px, 8.6vw, 124px);
  font-size: clamp(36px, min(8.6vw, 14svh), 124px);
  line-height: 1.04;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 22px;
}

:lang(zh-Hant) .hero-title {
  letter-spacing: 0.02em;
  line-height: 1.14;
}

@media (orientation: portrait) {
  :lang(zh-Hant) .hero-title {
    font-size: clamp(42px, 13vw, 124px);
    font-size: clamp(36px, min(13vw, 14svh), 124px);
  }
}

.hero-sub {
  max-width: 640px;
  margin-inline: auto;
  font-size: clamp(18px, 1.9vw, 23px);
  line-height: 1.6;
  font-weight: 500;
  color: #c9cdd6;
}

/* Small text over the moving painting gets its own dark backing. */
.is-scrub .backed {
  display: inline-block;
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(5, 7, 13, 0.8);
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 24px;
  margin-top: 28px;
}

.scroll-cue {
  display: none;
}

.caption-lead {
  font-size: clamp(17px, 1.7vw, 21px);
  line-height: 1.6;
  font-weight: 500;
}

.bridge-title {
  font-size: clamp(38px, 6.6vw, 88px);
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 18px;
}

:lang(zh-Hant) .bridge-title {
  letter-spacing: 0.01em;
  line-height: 1.18;
}

.bridge-title,
.bridge-sub,
.hero-sub,
.caption-lead {
  text-wrap: balance;
}

/* Short zh lines that name things: break only at spaces and punctuation, so
   balance can't split a word like 任務 across lines. */
:lang(zh-Hant) .bridge-sub,
:lang(zh-Hant) .hero-sub {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.bridge-sub {
  max-width: 620px;
  margin-inline: auto;
  font-size: clamp(18px, 1.8vw, 22px);
  line-height: 1.6;
  font-weight: 500;
  color: var(--night-ink-2);
}

.bridge-map {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 28px;
  margin-top: 26px;
}

.bridge-map a {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  min-height: 44px;
  padding-top: 10px;
  text-decoration: none;
  color: var(--night-ink);
  font-weight: 500;
}

.bridge-map a:hover span {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.bridge-map b {
  font-weight: 700;
  color: var(--gold);
}

.bridge-map b.mono {
  font-size: 0.92em;
}

/* Static hero: no JS, no sticky support, or reduced motion. The page reads
   top to bottom: words, the finished painting, its caption, the bridge line. */
html:not(.is-scrub) .hero .scene-sticky {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  padding: calc(var(--bar-h) + 64px) var(--gutter) clamp(72px, 12vh, 140px);
  text-align: center;
}

html:not(.is-scrub) .hero-steps {
  display: contents;
}

html:not(.is-scrub) .step-intro {
  order: 0;
}

html:not(.is-scrub) .hero-visual {
  order: 1;
  width: min(100%, 1000px);
  aspect-ratio: 880 / 716;
  overflow: hidden;
  border-radius: 6px;
  background: #000;
}

html:not(.is-scrub) .hero-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

html:not(.is-scrub) .step[data-step="1"] {
  display: none;
}

html:not(.is-scrub) .step[data-step="2"] {
  order: 2;
  max-width: 680px;
  margin-top: -12px;
  color: var(--night-ink-2);
}

html:not(.is-scrub) .step[data-step="3"] {
  order: 3;
  margin-top: 48px;
}

/* Scroll-scrubbed hero */
.is-scrub .hero {
  height: 250vh;
  height: 250svh;
}

.is-scrub .hero .scene-sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}

.is-scrub .hero-visual {
  position: absolute;
  inset: 0;
}

.is-scrub .hero-canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease);
}

.is-scrub .hero.is-ready .hero-canvas {
  opacity: 1;
}

.is-scrub .hero[data-step="3"] .hero-canvas {
  opacity: 0.2;
  transform: scale(0.96);
}

.is-scrub .hero-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: calc(var(--bar-h) + 4vh) 6vw 8vh;
  opacity: 0;
  transition: opacity 0.6s var(--ease);
}

.is-scrub .hero.is-fallback .hero-fallback {
  opacity: 1;
}

.is-scrub .hero-steps {
  position: absolute;
  inset: 0;
  display: grid;
  /* One row the size of the stage: a tall intro can't push the others. */
  grid-template-rows: minmax(0, 1fr);
  padding: calc(var(--bar-h) + 20px) var(--gutter) max(28px, 5vh);
  pointer-events: none;
}

/* Steps not on screen are only transparent (not visibility: hidden), so
   screen readers still read all four in order, as in the static page.
   Focusing a link in a hidden step scrolls to it (app.js). */
.is-scrub .hero .step {
  grid-area: 1 / 1;
  justify-self: center;
  text-align: center;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.45s var(--ease), transform 0.6s var(--ease);
}

.is-scrub .hero .step.is-on {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.is-scrub .step-intro {
  position: relative;
  isolation: isolate;
  align-self: center;
  align-self: safe center;
  max-width: 940px;
}

.is-scrub .step-intro::before {
  content: "";
  position: absolute;
  inset: -16% -14%;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(5, 7, 13, 0.86), rgba(5, 7, 13, 0.72) 62%, rgba(5, 7, 13, 0.4) 84%, rgba(5, 7, 13, 0));
  pointer-events: none;
}

.is-scrub .scroll-cue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: clamp(28px, 6vh, 64px);
  font-size: 14px;
  color: var(--night-ink-2);
}

/* Short screens (landscape phones, small laptop windows). Must come after
   the .scroll-cue rule above, which has the same specificity. */
@media (max-height: 560px) {
  .is-scrub .scroll-cue {
    display: none;
  }

  .is-scrub .hero-steps {
    padding-top: calc(var(--bar-h) + 8px);
    padding-bottom: 12px;
  }
}

@media (max-width: 599px) {
  .is-scrub .hero-sub {
    padding: 4px 12px;
    border-radius: 14px;
    background: rgba(5, 7, 13, 0.72);
  }
}

.scroll-cue-line {
  width: 1px;
  height: 40px;
  background: linear-gradient(var(--night-ink-2), transparent);
}

.is-scrub .step-caption {
  align-self: end;
  max-width: 660px;
  padding: 14px 22px;
  border-radius: 18px;
  background: rgba(5, 7, 13, 0.78);
}

.is-scrub .step-bridge {
  align-self: center;
  max-width: 900px;
}

/* ==========================================================================
   TOOLS (gesso)
   ========================================================================== */

.tool-body {
  max-width: 760px;
  margin-top: 8px;
  display: grid;
  gap: 14px;
  color: var(--ink-2);
}

.limits {
  padding-left: 16px;
  border-left: 3px solid var(--gold);
  color: var(--ink);
  font-weight: 500;
}

/* Segmented control */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--gesso-panel);
}

.seg-btn {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}

.seg-btn:hover {
  color: var(--ink);
}

.seg-btn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--gesso);
}

/* Demo frame */
.demo {
  margin-block: clamp(36px, 6vh, 64px) 28px;
}

/* All captions of a demo share one grid cell, so the box always has the
   height of the longest one and nothing below jumps while it plays. Only the
   current one is visible (and exposed to screen readers). */
.demo-caption {
  display: grid;
  max-width: 760px;
  margin-top: 18px;
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
}

.demo-caption .cap {
  grid-area: 1 / 1;
  display: block;
  visibility: hidden;
}

/* Flags */
.flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.flag-mark {
  font-size: 10px;
}

.flag-block {
  background: rgba(192, 49, 27, 0.1);
  color: var(--signal);
  border: 1px solid rgba(192, 49, 27, 0.4);
}

/* checkwash: code panel */
.code-panel {
  margin-top: 20px;
  padding: clamp(16px, 3.4vw, 36px);
  border-radius: 20px;
  background: var(--gesso-panel);
  border: 1px solid var(--gesso-line);
}

.code-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
}

.chip-green {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(31, 94, 58, 0.1);
  border: 1px solid rgba(31, 94, 58, 0.35);
  color: var(--pass-green);
  font-weight: 700;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.code {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(14px, 4.1vw, 28px);
  line-height: 1.6;
  color: var(--ink);
  white-space: pre;
  overflow-x: auto;
  tab-size: 4;
}

.code code {
  font: inherit;
}

.ln-ctx {
  color: var(--ink-2);
}

.ln-del {
  display: none;
  color: var(--ink-2);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.ln-add {
  visibility: hidden;
}

.ln-add-text {
  background-image: linear-gradient(transparent 56%, rgba(233, 185, 73, 0.6) 56%, rgba(233, 185, 73, 0.6) 92%, transparent 92%);
  background-repeat: no-repeat;
  background-size: 0% 100%;
  transition: background-size 0.7s var(--ease) 0.2s;
}

.code-flag {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 14px;
  font-size: 15px;
  color: var(--ink-2);
  visibility: hidden;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease), visibility 0s linear 0.4s;
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .ln-orig {
  display: none;
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .ln-del {
  display: inline;
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .ln-add {
  visibility: visible;
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .ln-add-text {
  background-size: 100% 100%;
}

.demo-cw[data-state="flagged"] .code-flag {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease), visibility 0s;
}

.demo-cw[data-state="flagged"] .ln-add-text {
  color: var(--signal);
}

.demo-cw[data-state="before"] .cap-before,
.demo-cw[data-state="after"] .cap-after,
.demo-cw[data-state="flagged"] .cap-flagged {
  visibility: visible;
}

/* checkwash: number line (all DOM, positions in %) */
.numline {
  position: relative;
  height: 96px;
  margin: 28px 12px 0;
}

.numline-axis {
  position: absolute;
  left: 0;
  right: 0;
  top: 48px;
  height: 2px;
  background: var(--ink-3);
}

.numline-band {
  position: absolute;
  top: 36px;
  height: 26px;
  left: calc(52.65% - 4px);
  width: 8px;
  border-radius: 6px;
  border: 2px solid var(--ink);
  background: transparent;
  transition: left 0.9s var(--ease-io), width 0.9s var(--ease-io), border-color 0.3s, background-color 0.3s;
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .numline-band {
  left: 0;
  width: 100%;
  border-color: rgba(192, 49, 27, 0.55);
  background: rgba(192, 49, 27, 0.1);
}

.numline-tick {
  position: absolute;
  left: var(--x);
  top: 64px;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
}

.nl-dot {
  position: absolute;
  left: var(--x);
  top: 49px;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid var(--ink-3);
  background: var(--gesso);
  transition: background-color 0.35s var(--ease) var(--d, 0s), border-color 0.35s var(--ease) var(--d, 0s);
}

.nl-dot.is-right {
  background: var(--ink);
  border-color: var(--ink);
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .nl-dot.is-wrong {
  background: var(--signal);
  border-color: var(--signal);
}

.nl-val {
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink-2);
}

.nl-up .nl-val {
  top: -30px;
}

.is-far .nl-val {
  left: auto;
  right: -7px;
  transform: none;
}

.nl-dot.is-right .nl-val {
  color: var(--ink);
}

.nl-dot.is-right .nl-val::after {
  content: " ✓";
}

.nl-dot.is-wrong .nl-val::after {
  content: " ✕";
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .nl-dot.is-wrong .nl-val {
  color: var(--signal);
}

.demo-cw:is([data-state="after"], [data-state="flagged"]) .nl-dot.is-wrong .nl-val::after {
  content: " ✓";
}

/* Replay button (a demo may have one; none does at the moment) */
.replay {
  display: none;
  margin-top: 10px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--ink-3);
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.js .replay {
  display: inline-flex;
  align-items: center;
}

/* Facts, try-it, builders */
/* Version, license and requirements fold away under a disclosure. */
.spec {
  max-width: 900px;
  margin-top: 22px;
}

.spec > summary {
  display: list-item;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}

.spec > summary:hover {
  color: var(--ink);
}

.spec[open] > summary {
  color: var(--ink);
}

.spec-note {
  margin-top: 12px;
}

.spec-inner {
  margin-top: 16px;
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  max-width: 900px;
  margin-top: 8px;
  border: 1px solid var(--gesso-line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--gesso-line);
}

@media (min-width: 760px) {
  .facts {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.facts > div {
  padding: 14px 18px;
  background: var(--gesso);
}

.builders .facts > div {
  background: var(--gesso-panel);
}

.facts dt {
  font-size: 13px;
  color: var(--ink-2);
}

.facts dd {
  margin-top: 2px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.try {
  max-width: 760px;
  margin-top: 28px;
}

.try-label {
  font-size: 16px;
  color: var(--ink-2);
  margin-bottom: 4px;
}

.cmd {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 8px 8px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #f2efe8;
}

.cmd code {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: pre;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 2;
  scrollbar-width: thin;
}

.cmd-copy {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: rgba(242, 239, 232, 0.14);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.cmd-copy:hover {
  background: rgba(242, 239, 232, 0.24);
}

/* Covers the copy button and the scrollable <code> (focusable when it
   overflows); an ink ring would vanish on the ink box. */
.cmd :focus-visible {
  outline-color: var(--gold);
}

.builders {
  max-width: 900px;
  margin-top: clamp(48px, 8vh, 80px);
  padding: clamp(22px, 4vw, 40px);
  border-radius: 20px;
  border: 1px solid var(--gesso-line);
  background: var(--gesso-panel);
}

.builders h3 {
  font-size: clamp(22px, 2.6vw, 30px);
  line-height: 1.25;
  margin-bottom: 12px;
}

.builders > p {
  color: var(--ink-2);
  max-width: 720px;
}

.exit-table {
  margin-top: 20px;
  border-collapse: collapse;
  font-size: 15px;
}

.exit-table caption {
  text-align: left;
  font-size: 13px;
  color: var(--ink-2);
  padding-bottom: 6px;
}

.exit-table th,
.exit-table td {
  padding: 8px 14px 8px 0;
  border-top: 1px solid var(--gesso-line);
  text-align: left;
  vertical-align: top;
}

.exit-table th {
  font-family: var(--mono);
  font-size: 16px;
  width: 2.5em;
}

.builders .fine {
  margin-top: 6px;
}

/* checkwash-prove: the same panel as .builders, placed just before it. */
.prove {
  max-width: 900px;
  margin-top: clamp(48px, 8vh, 80px);
  padding: clamp(22px, 4vw, 40px);
  border-radius: 20px;
  border: 1px solid var(--gesso-line);
  background: var(--gesso-panel);
}

.prove h3 {
  font-size: clamp(22px, 2.6vw, 30px);
  line-height: 1.25;
}

.prove-meta {
  margin: 6px 0 14px;
}

.prove-body {
  color: var(--ink-2);
  max-width: 720px;
}

.prove .limits {
  margin-top: 16px;
  max-width: 720px;
}

.prove .try-label {
  margin-top: 20px;
}

/* ==========================================================================
   STARRY NIGHT (night)
   ========================================================================== */

.shot {
  margin: 0;
}

.frame {
  aspect-ratio: var(--ar, 16 / 9);
  overflow: hidden;
  border-radius: 12px;
  background: #000;
}

.frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.shot figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin-top: 10px;
  font-size: 15px;
  color: var(--night-ink-2);
}

.shot figcaption strong {
  color: var(--night-ink);
  font-weight: 700;
}

.shot .count {
  font-family: var(--mono);
  font-size: 13px;
}

.shot .count::after {
  content: " 筆";
}

:lang(en) .shot .count::after {
  content: " strokes";
}

.gallery-title {
  margin-top: clamp(56px, 9vh, 96px);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.25;
}

/* Justified rows: each item's basis and grow are proportional to its aspect
   ratio, so every picture in a row has the same height. --row sets how tall
   a row wants to be before it wraps. */
.gallery {
  --row: 190px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 22px;
}

@media (max-width: 599px) {
  .gallery {
    --row: 140px;
  }
}

@media (min-width: 1040px) {
  .gallery {
    --row: 216px;
  }
}

.gallery .shot {
  flex: calc(var(--ar) * 100) 1 calc(var(--ar) * var(--row));
  min-width: 0;
}

.gallery .frame {
  aspect-ratio: var(--ar);
}

.gallery-note {
  margin-top: 16px;
}

.surface-night .kicker-ver {
  border-color: var(--night-line);
  color: var(--night-ink-2);
}

.surface-night .tool-body {
  color: var(--night-ink-2);
}

/* Column widths follow the frames' aspect ratios (1.25, 16/9, 16/9), so all
   three come out the same height; on phones they stack. */
.triptych {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.778fr) minmax(0, 1.778fr);
  margin-top: clamp(36px, 6vh, 64px);
}

@media (max-width: 599px) {
  .triptych {
    grid-template-columns: minmax(0, 1fr);
  }
}

.shots-note {
  margin-top: 12px;
}

.starry .tool-body {
  margin-top: clamp(28px, 5vh, 44px);
}

.sn-facts {
  max-width: 760px;
  margin-top: 12px;
}

.gallery-lead {
  max-width: 760px;
  margin-top: 10px;
  color: var(--night-ink-2);
}

/* Links inside running text stay inline. */
.gallery-lead .text-link {
  display: inline;
  min-height: 0;
  color: var(--night-ink);
  font-family: var(--mono);
  font-weight: 700;
}

/* ==========================================================================
   WORKS (night)
   ========================================================================== */

.work-grid {
  list-style: none;
  margin: clamp(36px, 6vh, 64px) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

@media (min-width: 700px) {
  .work-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.work-card {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid var(--night-line);
  background: var(--night-2);
  transition: border-color 0.25s var(--ease), transform 0.25s var(--ease);
}

.work-card:hover,
.work-card:focus-within {
  border-color: rgba(233, 185, 73, 0.6);
}

.work-card:hover {
  transform: translateY(-2px);
}

.work-art {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
}

.work-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Music: a 3 x 3 wall of the nine covers, each cropped to fill its cell. */
.work-art-mu {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 2px;
  background: var(--night-2);
}

.work-art-mu img {
  min-height: 0;
}

/* Research text panels: the same panel as the tools', in night colours
   (two classes, so this wins over .work-art-cw further down). */
.work-art-cw.work-art-rs {
  background: #101626;
  color: var(--night-ink);
}

.work-art-rs .wa-cmd {
  color: var(--night-ink-2);
}

.work-art-rs .wa-add {
  color: var(--night-ink);
  background-image: linear-gradient(transparent 56%, rgba(211, 178, 124, 0.38) 56%, rgba(211, 178, 124, 0.38) 92%, transparent 92%);
}

.work-art-ed {
  background: var(--gesso-panel);
}

.work-art-ed img {
  object-position: 50% 12%;
}

.work-art-ps {
  background: var(--sand-bg);
}

.work-art-cw {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 6px;
  padding: clamp(16px, 4vw, 32px);
  background: var(--gesso-panel);
  color: var(--ink);
  font-family: var(--mono);
  font-size: clamp(13px, 1.7vw, 18px);
}

.wa-line {
  white-space: pre;
}

.wa-del {
  color: var(--ink-2);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.wa-add {
  color: var(--signal);
  background-image: linear-gradient(transparent 56%, rgba(233, 185, 73, 0.6) 56%, rgba(233, 185, 73, 0.6) 92%, transparent 92%);
}

.work-art-cw .flag {
  margin-top: 10px;
}

.work-body {
  display: grid;
  gap: 6px;
  padding: 18px 20px 22px;
}

.work-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  font-size: 13px;
  color: var(--night-ink-2);
}

.work-status-wip {
  color: var(--sand-gold);
}

.work-name {
  font-size: clamp(20px, 2.2vw, 26px);
  line-height: 1.3;
}

.work-link {
  text-decoration: none;
  color: var(--night-ink);
}

/* The whole card follows the link in its heading. */
.work-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.work-line {
  font-size: 16px;
  color: var(--night-ink-2);
}

/* Four groups (developer tools, interactive works, music, research), each
   with its own grid. */
.work-group {
  margin-top: clamp(40px, 7vh, 72px);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--night-ink-2);
}

.work-group + .work-grid {
  margin-top: 16px;
}

@media (min-width: 1000px) {
  .work-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* boundary-unpack's card: the same text panel as checkwash's, no strike-through.
   Its highlighted line is a successful run, so it keeps the gold band but not
   the signal red, which means "got weaker". */
.wa-cmd {
  color: var(--ink-2);
}

.work-art-bu .wa-add {
  color: var(--ink);
}

/* ==========================================================================
   BOUNDARY-UNPACK (night)
   ========================================================================== */

.unpack .tool-body {
  margin-top: clamp(28px, 5vh, 44px);
}

.unpack .limits {
  color: var(--night-ink);
}

.unpack .try-label {
  color: var(--night-ink-2);
}

/* The ink command box would vanish on night: lift it to the card colour. */
.unpack .cmd {
  background: var(--night-2);
  border: 1px solid var(--night-line);
}

.bu-facts {
  max-width: 760px;
  margin-top: 12px;
}

/* ==========================================================================
   EDITORIAL DOLL (gesso)
   ========================================================================== */

.looks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 22px);
  max-width: 980px;
  margin-top: clamp(36px, 6vh, 64px);
}

.look {
  margin: 0;
}

.look .frame {
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  border: 1px solid var(--gesso-line);
  background: var(--gesso-panel);
}

.look figcaption {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 10px;
  font-size: 16px;
}

.look-no {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
}

.looks-note {
  margin-top: 14px;
}

.atelier .tool-body {
  margin-top: clamp(28px, 5vh, 44px);
}

/* ==========================================================================
   THE RETURNING PASSAGE (sand)
   ========================================================================== */

.surface-sand .kicker {
  color: var(--sand-ink-2);
}

.surface-sand .kicker-name {
  color: var(--sand-gold);
}

.surface-sand .kicker-ver {
  border-color: rgba(211, 178, 124, 0.45);
  color: var(--sand-gold);
}

.surface-sand .lead,
.surface-sand .tool-body,
.surface-sand .fine {
  color: var(--sand-ink-2);
}

.surface-sand .limits {
  border-left-color: var(--sand-gold);
  color: var(--sand-ink);
}

/* The work's own title face: system serifs, as in its docs/DESIGN.md. */
.passage .display {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Noto Serif TC", "Noto Serif CJK TC", PMingLiU, serif;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Three 16:9 screenshots: equal columns; on phones they stack. */
.triptych-even {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 599px) {
  .triptych-even {
    grid-template-columns: minmax(0, 1fr);
  }
}

.surface-sand .frame {
  border: 1px solid var(--sand-line);
}

.surface-sand .shot figcaption {
  color: var(--sand-ink-2);
}

.surface-sand .shot figcaption strong {
  color: var(--sand-ink);
}

.sample {
  margin-top: clamp(32px, 5vh, 48px);
}

.sample-label {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--sand-gold);
}

.sample-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.sample-steps li {
  counter-increment: step;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 14px;
  border: 1px solid var(--sand-line);
  border-radius: 999px;
  font-size: 15px;
  color: var(--sand-ink);
}

.sample-steps li::before {
  content: counter(step);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--sand-gold);
}

.passage .tool-body {
  margin-top: clamp(28px, 5vh, 44px);
}

.ps-facts {
  margin-top: 14px;
}

/* ==========================================================================
   MUSIC (gesso)
   ========================================================================== */

/* Phones: one row per song, small cover on the left. From 700px: cards with
   the cover on top, two then three across. */
.tracks {
  list-style: none;
  margin: clamp(36px, 6vh, 64px) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.track {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 10px;
  border: 1px solid var(--gesso-line);
  border-radius: 16px;
  background: var(--gesso-panel);
}

.track-cover {
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 10px;
  background: var(--ink);
}

.track-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.track-body {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.track-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  font-size: 16px;
  line-height: 1.3;
}

.track-title strong {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.track-no,
.track-len {
  font-size: 12px;
  color: var(--ink-3);
}

.track-len {
  margin-left: auto;
}

.track-audio {
  display: block;
  width: 100%;
  height: 40px;
}

@media (min-width: 700px) {
  .tracks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
  }

  .track {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    padding: 12px 12px 14px;
    border-radius: 20px;
  }

  .track-cover {
    border-radius: 12px;
  }
}

@media (min-width: 1000px) {
  .tracks {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.tracks-note {
  margin-top: 16px;
}

/* ==========================================================================
   RESEARCH (night)
   ========================================================================== */

.study {
  display: grid;
  gap: 14px 48px;
  margin-top: clamp(40px, 7vh, 72px);
  padding-top: clamp(28px, 4vh, 40px);
  border-top: 1px solid var(--night-line);
}

@media (min-width: 860px) {
  .study {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }
}

.study-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--night-ink-2);
}

.study-name {
  font-size: clamp(24px, 2.6vw, 32px);
  line-height: 1.25;
}

.study-body {
  display: grid;
  gap: 14px;
  max-width: 720px;
  color: var(--night-ink-2);
}

.study-body > p:first-child {
  color: var(--night-ink);
  font-size: clamp(17px, 1.6vw, 19px);
}

.study-fig {
  margin-top: 8px;
}

.study-fig figcaption {
  margin-top: 10px;
}

.research-note {
  margin-top: clamp(40px, 7vh, 64px);
}

/* ==========================================================================
   CONTACT & FOOTER (gesso)
   ========================================================================== */

.contact {
  text-align: left;
}

.email-xl {
  margin-top: clamp(28px, 5vh, 48px);
  font-size: clamp(22px, 5.6vw, 60px);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.email-xl a {
  text-decoration: none;
}

.email-xl a:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 8px;
}

.contact-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-top: 26px;
}

.copy-status {
  min-height: 1.6em;
  margin-top: 10px;
  font-size: 15px;
  color: var(--ink-2);
}

.issues {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 18px;
  margin-top: 18px;
  font-size: 15px;
  color: var(--ink-2);
}

.issues .text-link {
  color: var(--ink);
}

.issues.channels {
  margin-top: 4px;
}

.whoami {
  margin-top: 36px;
  font-size: 15px;
  color: var(--ink-2);
}

.footer {
  padding-block: 64px 40px;
  border-top: 1px solid var(--gesso-line);
  background: #ebe5d8;
}

.footer-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.footnotes {
  max-width: 860px;
  padding-left: 1.4em;
  display: grid;
  gap: 8px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
}

.footnotes li:target {
  color: var(--ink);
}

.fn-back {
  text-decoration: none;
  color: var(--gold-ink);
  padding: 0 4px;
}

.footer-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 24px;
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--gesso-line);
  font-size: 14px;
  color: var(--ink-2);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 599px) {
  body {
    font-size: 16px;
  }

  .is-scrub .hero {
    height: 210vh;
    height: 210svh;
  }

  .look figcaption {
    font-size: 14px;
  }

  .look-no {
    display: none;
  }

  .seg {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
  }

  /* Equal-width buttons whose labels wrap inside, instead of one button
     dropping to a second row on its own. */
  .seg-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 8px;
    line-height: 1.25;
  }

  .contact-actions .pill {
    flex: 1 1 100%;
  }
}

@media (max-width: 359px) {
  .display,
  .bridge-title {
    font-size: 33px;
  }
}

/* Windows High Contrast and other forced-colour modes. */
@media (forced-colors: active) {
  .seg-btn {
    border: 1px solid ButtonText;
  }

  .seg .seg-btn[aria-pressed="true"] {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
}

/* Reduced motion: the JS also switches to the static page. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    animation: none !important;
  }

  .pill:hover,
  .work-card:hover {
    transform: none;
  }

  /* Demos already rest on their final state; nothing to replay. */
  .js .replay {
    display: none;
  }
}
