/* Stage: the TLDR (DESIGN.md variant C). The screen is dark in both themes; only its edge changes. */
:root {
  --stage-screen: #111a15;
  --stage-screen-raise: #1a261f;
  --stage-screen-line: #2f4237;
  --stage-screen-ink: #ebe7dc;
  --stage-screen-muted: #9aa69d;
  --stage-screen-edge: transparent;
  --stage-signal: #7ec99a;
  --stage-bad: #e0897e;
  --stage-caution: #d4b04f;
  --stage-cap: clamp(1.3rem, 0.95rem + 1.45vw, 2rem);
  --stage-cap-side: 1.4rem;
  --stage-title: clamp(1rem, 0.9rem + 0.4vw, 1.2rem);
  --stage-target: 2.75rem;
  --stage-ease: cubic-bezier(.2, .7, .2, 1);
  --stage-ease-travel: cubic-bezier(.5, 0, .3, 1);
  --stage-reveal: 480ms;
  --stage-draw: 800ms;
  --stage-travel: 1100ms;
  --stage-pulse: 2400ms;
  --stage-swap: 220ms;
}
@media (prefers-color-scheme: dark) { :root:not(.light-mode) { --stage-screen-edge: #26362c; } }
:root.dark-mode { --stage-screen-edge: #26362c; }

.stage {
  --s-bg: var(--stage-screen); --s-panel: var(--stage-screen-raise); --s-ink: var(--stage-screen-ink); --s-muted: var(--stage-screen-muted);
  --s-line: var(--stage-screen-line); --s-slab: var(--stage-screen-raise);
  --s-signal: var(--stage-signal); --s-bad: var(--stage-bad); --s-caution: var(--stage-caution);
  --s-rule: var(--color-border); --s-done: var(--color-text-muted);
  position: relative; min-width: 0;
  font-family: var(--font-sans); color: var(--color-text);
}
/* out of the column to 960px (cqw: the post) */
.stage { width: min(100cqw - 32px, 960px); margin-left: calc(50% - min(50cqw - 16px, 480px)); }
@media (min-width: 68.75em) {
  .shell > .post:has(.stage) { container-type: inline-size; }
  .stage { width: min(100cqw + var(--space-lg), 960px); margin-left: calc(50% - min(50cqw + var(--space-lg) / 2, 480px)); }
}
.post-content > .stage { margin-top: var(--space-xs); margin-bottom: var(--space-lg); }
/* a still (one step): the picture and its caption, no rail, count, dots, Back, Next or Play */
.stage--still :is(.stage__rail, .stage__count, .stage__ctl, .stage__play) { display: none !important; }
.stage :focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: .3em; }
.stage__fold > summary { list-style: none; }
.stage__fold > summary::-webkit-details-marker { display: none; }
.stage__head { display: flex; align-items: center; gap: .75rem; min-width: 0; min-height: var(--stage-target); padding-right: 8.5rem; cursor: pointer; }
.stage__kind { font-family: var(--font-serif); font-weight: 600; font-size: var(--text-lg); }
/* no visible text in the stage is ever cut */
.stage__meta { color: var(--color-text-muted); font-size: var(--text-ui); line-height: 1.3; min-width: 0; }
.stage__head::after { content: ""; flex: none; width: .45rem; height: .45rem; border: solid var(--color-text-muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-2px); }
.stage__fold:not([open]) > .stage__head::after { transform: rotate(-45deg); }
.stage__play { position: absolute; top: 0; right: 0; display: inline-flex; align-items: center; gap: .45rem; min-height: var(--stage-target); padding: 0 .9rem 0 .7rem; font: inherit; font-size: var(--text-ui); font-weight: 500; color: var(--color-text); background: none; border: 1px solid var(--s-rule); border-radius: 999px; cursor: pointer; white-space: nowrap; }
.stage__play[hidden] { display: none; }
.stage__play svg { width: 1.15rem; height: 1.15rem; flex: none; }
.stage__play .ring-bg { fill: none; stroke: var(--s-rule); stroke-width: 2.5; }
.stage__play .ring { fill: none; stroke: var(--color-accent); stroke-width: 2.5; stroke-dasharray: 1 1; stroke-dashoffset: 1; transform: rotate(-90deg); transform-origin: center; }
.stage__play .glyph { fill: currentColor; }
.stage__play:hover { border-color: var(--color-accent); }
.stage__body { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: .8rem; padding-top: .4rem; }

.stage__rail { display: flex; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.stage__rail::-webkit-scrollbar { display: none; }
.stage__chip { flex: var(--chip, 1) 1 0px; min-width: min-content; min-height: var(--stage-target); display: flex; flex-direction: column; justify-content: flex-end; gap: .35rem; padding: 0 0 .25rem; font: inherit; font-size: var(--text-ui); color: var(--color-text-muted); text-align: left; background: none; border: 0; cursor: pointer; }
/* a chip is its step's whole name, or its number (chips.cjs) */
.stage__chip span { line-height: 1.25; text-wrap: balance; }
.stage__chip--n { flex: none; width: var(--stage-target); text-align: center; font-variant-numeric: tabular-nums; }
.stage__chip i { display: block; height: 3px; background: var(--s-rule); border-radius: 2px; overflow: hidden; order: 2; }
.stage__chip i b { display: block; height: 100%; width: 100%; background: var(--color-accent); transform-origin: left; transform: scaleX(0); }
.stage__chip.is-done i b { transform: scaleX(1); background: var(--s-done); }
.stage__chip[aria-current="step"] { color: var(--color-text); font-weight: 600; }
.stage__chip[aria-current="step"] i b { transform: scaleX(1); }
.stage.is-playing .stage__chip[aria-current="step"] i b { animation: stageFill var(--dwell, 7000ms) linear both; }
.stage.is-playing .stage__play .ring { animation: stageRing var(--dwell, 7000ms) linear both; }
@keyframes stageFill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes stageRing { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }

.stage__screen { position: relative; min-width: 0; background: var(--stage-screen); border: 1px solid var(--stage-screen-edge); border-radius: 14px; padding: clamp(.75rem, .3rem + 2vw, 2rem) clamp(.75rem, .2rem + 2.4vw, 2.5rem); }
.stage__screen :focus-visible { outline-color: var(--stage-screen-ink); }
.stage__scene { display: none; width: 100%; height: auto; max-height: var(--stage-scene-max, none); overflow: visible; }
.stage__view, .stage__words { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: .8rem; min-width: 0; }
.stage:not(.is-compact) .is-on[data-layout=wide], .stage.is-compact .is-on[data-layout=narrow] { display: block; }
.stage__text { display: flex; gap: .15rem .8rem; align-items: baseline; flex-wrap: wrap; margin-top: .25rem; min-width: 0; }
.stage__count { margin: 0; font-size: var(--text-ui); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.stage__title { flex-basis: 100%; margin: .15rem 0 0; font-family: var(--font-sans); font-weight: 600; font-size: var(--stage-title); line-height: 1.3; color: var(--color-accent); }
.stage__title code { font-family: var(--font-mono); font-size: .9em; font-weight: 500; }
.stage__capbox { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; min-height: calc(var(--stage-cap) * 1.24 * 3); }
.stage__sub { margin: 0 0 .4rem; font-family: var(--font-serif); font-size: var(--text-base); line-height: 1.4; max-width: 52ch; color: var(--color-text-muted); }
.stage__sub:empty { display: none; }
.stage__cap { margin: 0; font-family: var(--font-serif); font-weight: 450; font-size: var(--stage-cap); line-height: 1.24; letter-spacing: -0.005em; text-wrap: pretty; max-width: 36ch; color: var(--color-text); }
.stage__ctl { display: flex; align-items: center; gap: .75rem; min-width: 0; border-top: 1px solid var(--color-border); padding-top: .6rem; }
.stage__btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: var(--stage-target); min-width: var(--stage-target); padding: 0 1.1rem; font: inherit; font-size: var(--text-ui); font-weight: 600; color: var(--color-text); background: transparent; border: 1px solid var(--s-rule); border-radius: .55em; cursor: pointer; white-space: nowrap; }
.stage__btn svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stage__btn:hover:not(:disabled) { border-color: var(--color-accent); }
.stage__btn:disabled { opacity: .38; cursor: default; }
.stage__btn--next { margin-left: auto; background: var(--color-accent); border-color: var(--color-accent); color: var(--color-bg); min-width: 8.5rem; }
.stage__btn--next:hover:not(:disabled) { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
.stage__btn--next.is-again { background: transparent; color: var(--color-text); border-color: var(--s-rule); }
/* Start over stays an outline on hover, as Back does: the Next hover fill under its dark text read about 2.7:1. */
.stage__btn--next.is-again:hover:not(:disabled) { background: transparent; color: var(--color-text); border-color: var(--color-accent); }
.stage__dots { display: flex; }
.stage__dots button { width: 1.6rem; height: var(--stage-target); padding: 0; display: grid; place-items: center; background: none; border: 0; cursor: pointer; }
.stage__dots button i { width: .5rem; height: .5rem; border-radius: 1rem; background: var(--s-rule); }
.stage__dots button.is-done i { background: var(--s-done); }
.stage__dots button[aria-current="step"] i { width: 1.25rem; background: var(--color-accent); }
.stage__alt { font-size: var(--text-ui); color: var(--color-text-muted); }
.stage__alt summary { cursor: pointer; min-height: var(--stage-target); display: inline-flex; align-items: center; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }
.stage__alt ol { font-family: var(--font-serif); font-size: var(--text-sm); color: var(--color-text); line-height: 1.5; padding-left: 1.4em; margin: 0; }
.stage__alt li { margin-bottom: .5em; }
/* no script: the text alternative */
.stage:not(.is-live) :is(.stage__rail, .stage__screen, .stage__text, .stage__capbox, .stage__ctl) { display: none; }

/* a phone: tight gaps, a smaller caption, so the first view holds the stage (FIGURES 4.5) */
.stage.is-narrow :is(.stage__body, .stage__view, .stage__words) { row-gap: .2rem; }
.stage.is-narrow :is(.stage__body, .stage__text) { padding-top: 0; margin-top: 0; }
.stage--tldr.is-narrow .stage__count, .is-row .stage__meta { display: none; }
.is-row .stage__rail { position: absolute; top: 0; left: var(--rail-left); right: 0; height: var(--stage-target); }
.is-row .stage__head { padding-right: 0; }
.is-row .stage__ctl .stage__play { position: static; }
.stage.is-narrow .stage__capbox { min-height: 4rem; }
.stage.is-narrow .stage__cap { font-size: 1.05rem; line-height: 1.22; }
.stage.is-narrow .stage__sub { font-size: var(--text-ui); line-height: 1.35; margin-bottom: .2rem; }
.stage.is-narrow .stage__ctl { padding-top: .1rem; }
/* a phone: every chip its number, in one row */
.stage__n { display: none; }
.stage.is-narrow .stage__chip { flex: 1 0 var(--stage-target); min-height: 1.6rem; text-align: center; }
.stage.is-narrow .stage__chip > span:first-child:not(:only-of-type) { display: none; }
.stage.is-narrow .stage__n { display: inline; font-variant-numeric: tabular-nums; }
.stage.is-narrow .stage__btn--next { flex: 1; min-width: 0; }
.stage.is-narrow .stage__btn--back span { display: none; }
.stage.is-narrow .stage__btn--back { padding: 0; width: var(--stage-target); }
.stage.is-narrow .stage__dots { display: none; }
.stage.is-narrow .stage__screen { border-radius: 10px; padding: .15rem .4rem; }
@media (max-width: 380px) { .stage__meta { display: none; } }
/* beside: the words right of the square drawing */
.stage.is-side .stage__view { grid-template-columns: minmax(0, 11fr) minmax(0, 9fr); column-gap: 1.25rem; align-items: start; }
.stage.is-side .stage__capbox { min-height: 0; }
.stage.is-side .stage__cap { font-size: var(--stage-cap-side); }

/* scene paint */
/* Labels: --fig-face, 400 or 600 (a muted word is no name), never italic (STYLE.md "Figure type and labels"). opsz pinned: WebKit took it from scaled size, 9% wider than kit.cjs measures. */
.stage__scene text { font-family: var(--fig-face); font-size: 16px; font-weight: 400; font-optical-sizing: none; font-variation-settings: "opsz" 16; }
[data-layout=narrow] .t-label { font-size: 17px; }
.stage__scene :is(.t-serif, .t-serif-lg) { font-size: 20px; font-weight: 600; }
.stage__scene .t-serif.sc-muted { font-weight: 400; }
.stage__scene .t-serif-lg { font-size: 24px; }
.stage__scene .t-quote { font-size: 19px; }
.stage__scene :is(.t-big, .t-huge) { font-size: 56px; font-variant-numeric: lining-nums; }
.stage__scene :is(.t-quote, .t-big, .t-huge, .t-count) { font-optical-sizing: auto; font-variation-settings: normal; }
.stage__scene .t-huge { font-size: 96px; } .stage__scene .z22 { font-size: 22px; } .stage__scene .z26 { font-size: 26px; } .stage__scene .z30 { font-size: 30px; }
.sc-ink { fill: var(--s-ink); } .sc-muted { fill: var(--s-muted); } .sc-signal { fill: var(--s-signal); }
.sc-bad-t { fill: var(--s-bad); } .sc-caution-t { fill: var(--s-caution); }
.sc-slab { fill: var(--s-slab); stroke: color-mix(in srgb, var(--s-muted) 55%, var(--s-bg)); stroke-width: 1.2; }
.sc-slab-good { fill: color-mix(in srgb, var(--s-signal) 26%, var(--s-bg)); stroke: var(--s-signal); stroke-width: 1.4; }
.sc-slab-bad { fill: color-mix(in srgb, var(--s-bad) 22%, var(--s-bg)); stroke: var(--s-bad); stroke-width: 1.4; }
.sc-slab-hot, .sc-token { fill: var(--s-signal); stroke: none; }
.sc-bar { fill: color-mix(in srgb, var(--s-ink) 70%, var(--s-bg)); stroke: none; } .sc-on-bar { fill: var(--s-bg); }
.sc-lit { fill: none; stroke: var(--s-ink); stroke-width: 2; }
.sc-hole { fill: none; stroke: var(--s-muted); stroke-width: 1.4; stroke-dasharray: 5 4; }
.sc-box { fill: var(--s-panel); stroke: var(--s-ink); stroke-width: 1.6; }
.sc-region { fill: var(--s-panel); stroke: var(--s-line); stroke-width: 1.2; }
.sc-region-out { fill: none; stroke: var(--s-line); stroke-width: 1.2; stroke-dasharray: 6 5; }
.sc-wire { fill: none; stroke: var(--s-ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sc-wire-muted { fill: none; stroke: var(--s-muted); stroke-width: 1.4; stroke-linecap: round; }
.sc-wire-signal, .sc-pulse { fill: none; stroke: var(--s-signal); stroke-width: 2; stroke-linecap: round; }
.sc-wire-bad { fill: none; stroke: var(--s-bad); stroke-width: 2.2; stroke-linecap: round; }
.sc-ring { fill: none; stroke: var(--s-caution); stroke-width: 2.4; }
.sc-scan { fill: none; stroke: var(--s-ink); stroke-width: 2; stroke-dasharray: 2 5; }
.stage__scene * { transform-box: fill-box; } .stage__scene .sc-frame { transform-box: view-box; }
.stage__scene .pu { transform-origin: center; }
.stage__scene .gx { transform-origin: 0 50%; }

/* motion */
@keyframes sReveal { from { opacity: 0; transform: translateY(10px); } }
@keyframes sFade { from { opacity: 0; } }
@keyframes sDraw { from { stroke-dashoffset: 1; } }
@keyframes sTravel { from { opacity: var(--o, 1); transform: translate(var(--x, 0px), var(--y, 0px)); } }
@keyframes sGrow { from { transform: scaleX(0); } }
@keyframes sPulse { 0% { opacity: 0; transform: scale(.96); } 25% { opacity: 1; transform: scale(1.04); } 55% { transform: scale(1); } 100% { opacity: 1; transform: scale(1); } }
@keyframes sScan { from { transform: translateY(0); } to { transform: translateY(var(--y, 0px)); } }
@keyframes sSwap { from { opacity: 0; } }
.stage__scene .scan { transform: translateY(var(--y, 0px)); }
/* the live line (core.js): visually hidden, read by assistive tech */
.stage__live { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) {
  .stage:is(.is-run, .is-pre) .rv { animation: sReveal var(--t, var(--stage-reveal)) var(--stage-ease) both; animation-delay: var(--d, 0s); }
  .stage:is(.is-run, .is-pre) .fd { animation: sFade var(--t, var(--stage-reveal)) ease both; animation-delay: var(--d, 0s); }
  .stage:is(.is-run, .is-pre) .dr { stroke-dasharray: 1 1; animation: sDraw var(--t, var(--stage-draw)) ease-in-out both; animation-delay: var(--d, 0s); }
  .stage:is(.is-run, .is-pre) .tr { animation: sTravel var(--t, var(--stage-travel)) var(--stage-ease-travel) both; animation-delay: var(--d, 0s); }
  .stage:is(.is-run, .is-pre) .gx { animation: sGrow var(--t, 700ms) var(--stage-ease) both; animation-delay: var(--d, 0s); }
  .stage:is(.is-run, .is-pre) .pu { animation: sPulse var(--t, var(--stage-pulse)) var(--stage-ease) both; animation-delay: var(--d, 0s); }
  .stage:is(.is-run, .is-pre) .scan { animation: sScan var(--t, 2400ms) linear both; animation-delay: var(--d, 0s); }
  /* is-pre (autoplay.js): step 1 waits in its first frame until autoplay starts its entrance */
  .stage.is-pre .stage__scene * { animation-play-state: paused; }
  .stage.is-run :is(.stage__text.swap, .stage__cap.swap) { animation: sSwap var(--stage-swap) ease both; }
  .stage__chip i b { transition: transform var(--stage-swap) var(--stage-ease); }
  .stage__dots button i { transition: width var(--stage-swap) var(--stage-ease), background var(--stage-swap); }
}

/* print: the screen as paper */
@media print {
  .stage { --s-bg: var(--color-bg); --s-panel: var(--color-bg); --s-ink: var(--color-text); --s-muted: var(--color-text-muted); --s-line: var(--color-border); --s-slab: var(--color-bg); --s-signal: var(--color-accent); --s-bad: var(--color-text); --s-caution: var(--color-text); }
  .stage__screen { background: none; border-color: var(--color-border); }
  .stage__play, .stage__ctl, .stage__rail { display: none; }
}
