/* demo.css — the page chrome every example shares (headings, panels, buttons, banner, focus ring).
 *
 * Driven by the same attributes as the docs site:
 *   <html data-style="graph|riso|collage|crayon|saturday" data-theme="light|dark">
 * The docs embed sets both. Opened on its own, a page uses Saturday morning (every example's <html> says
 * data-style="saturday", like the docs site) and follows prefers-color-scheme (demo-theme.js sets data-theme);
 * ?style=graph etc. still switches it. With no JS at all it shows Saturday morning · light.
 * Canvas code reads these same tokens through DemoTheme (demo-theme.js).
 *
 * Contrast (checked in scripts/check-demo-contrast.mjs): text ≥ 4.5:1 on its background;
 * objects, guides, ground lines and UI controls ≥ 3:1 against --demo-surface (stage tokens: against --demo-stage).
 *
 * The tokens live in demo-tokens.css (imported below); this file is the page chrome every example shares.
 */
@import url('demo-tokens.css');

/* Saturday morning's fonts, shipped with the examples so they work offline and from disk (SIL OFL, see fonts/).
 * Same family names as the docs site's Fontsource packages, so the tokens resolve in both places. */
@font-face { font-family: 'Figtree Variable'; font-style: normal; font-weight: 300 900; font-display: swap;
  src: url('fonts/figtree-latin-wght-normal.woff2') format('woff2-variations'); }
@font-face { font-family: 'Figtree Variable'; font-style: italic; font-weight: 300 900; font-display: swap;
  src: url('fonts/figtree-latin-wght-italic.woff2') format('woff2-variations'); }
@font-face { font-family: 'Caprasimo'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('fonts/caprasimo-latin-400-normal.woff2') format('woff2'); }

/* ── Page chrome shared by every example ────────────────────────────────── */
:root { color-scheme: light; --toon-color: var(--demo-primary); }
:root[data-theme='dark'] { color-scheme: dark; }
body { font-family: var(--demo-font); color: var(--demo-text); background: var(--demo-bg);
  transition: background-color .3s, color .3s; }
/* Embedded in the docs: the <toon-demo> host stands in for <html> and <body> (each rule alone, so a page
 * that doesn't understand :host still applies the rest). */
:host { display: block; --toon-color: var(--demo-primary); font-family: var(--demo-font); color: var(--demo-text);
  background: var(--demo-bg); font-size: 15px; line-height: 1.5; padding: 16px; border-radius: 12px;
  transition: background-color .3s, color .3s; }
/* The same 16px on every side: the last element (often the hint) adds no margin of its own at the bottom. */
:host > :last-child { margin-bottom: 0; }
h1, h2, h3 { font-family: var(--demo-display); color: var(--demo-ink); }
a { color: var(--demo-primary); }
small, .note { color: var(--demo-muted); }
input { accent-color: var(--demo-primary); }
/* Sliders get a 24px-tall hit area (WCAG 2.5.8); the track stays centred in it. */
input[type=range] { min-height: 24px; margin-block: 0; }
code { font-size: .92em; }
/* Panels: every canvas and demo container uses the site's card treatment. */
canvas, .demo-panel {
  background: var(--demo-surface); border-radius: var(--demo-radius);
  border: var(--demo-panel-border); box-shadow: var(--demo-panel-shadow);
}
.demo-btn { font: var(--font-weight-strong) 15px var(--demo-font); padding: .7em 1.4em; border: 0; border-radius: var(--demo-control-radius);
  background: var(--demo-btn); color: var(--demo-on-btn); cursor: pointer; }
.demo-btn-quiet { font: var(--font-weight-strong) 14px var(--demo-font); padding: .45em 1.1em; border-radius: var(--demo-control-radius);
  border: 1.5px solid var(--demo-faint); background: var(--demo-surface); color: var(--demo-ink); cursor: pointer; }
.demo-tint-1 { background: color-mix(in srgb, var(--demo-primary) 14%, var(--demo-surface)); }
.demo-tint-2 { background: color-mix(in srgb, var(--demo-secondary) 14%, var(--demo-surface)); }
.demo-tint-3 { background: color-mix(in srgb, var(--demo-tertiary) 16%, var(--demo-surface)); }
.demo-tint-4 { background: color-mix(in srgb, var(--demo-soft) 16%, var(--demo-surface)); }
:is(.demo-tint-1, .demo-tint-2, .demo-tint-3, .demo-tint-4) { color: var(--demo-text); }
.obj-primary   { --toon-color: var(--demo-primary); }
.obj-secondary { --toon-color: var(--demo-secondary); }
.obj-tertiary  { --toon-color: var(--demo-tertiary); }
.obj-neutral   { --toon-color: var(--demo-neutral); }

/* Reduced motion: paused banner with an opt-in play control (added by demo-theme.js). */
.demo-motion-note { display: flex; gap: var(--space-sm); align-items: center; margin: 0 0 var(--space-md); padding: .6rem .9rem;
  border-radius: var(--demo-control-radius); background: var(--demo-surface-2); color: var(--demo-text); font-size: 14px; }
/* The text takes the free space, so Play/Pause stays put at the right edge when the message changes length. */
.demo-motion-note > span { flex: 1; }
.demo-motion-note.is-nudged { outline: 2px solid var(--demo-primary); outline-offset: 2px; }
/* With motion allowed: a single Pause button above any demo that moves on its own. Pausing freezes the demo's
 * CSS animations too (the class goes on <html>, or on the <toon-demo> host in the docs). */
.demo-motion-bar { display: flex; justify-content: flex-end; margin: 0 0 var(--space-sm); }
.demo-paused * { animation-play-state: paused !important; }
:host(.demo-paused) * { animation-play-state: paused !important; }

/* The hint under an interactive demo (what to press or move). Kept out of the intro paragraph so it stays visible when the docs embed the demo. */
.demo-try { margin: var(--space-xs) 0 var(--space-md); font-size: 13px; color: var(--demo-muted); }

/* Action buttons that sit beside interactive canvases, so every canvas action also works from the keyboard. */
.demo-act { font: var(--font-weight-strong) 13px var(--demo-font, system-ui); padding: .45em 1.1em; margin-right: .6em; border-radius: var(--radius-pill);
  border: 1.5px solid var(--demo-text); background: var(--demo-surface); color: var(--demo-text); cursor: pointer; vertical-align: middle; }
.demo-act-range { color: var(--demo-text); margin-right: .6em; }
/* A slider wrapped in its <label> (implicit association): lay the text, slider and <output> out as flex items so they
 * share one vertical centre. The default vertical-align: baseline puts a range input ~2px above the text in Chrome. */
label:has(> input[type=range]) { display: inline-flex; align-items: center; gap: .4em; max-width: 100%; }
/* …and on a narrow phone the slider gives up width first, so the row never pushes the page sideways. */
label:has(> input[type=range]) > input[type=range] { flex: 0 1 auto; min-width: 4rem; }
/* Hover and disabled states (Figma: Button State=Hover / Disabled). Hover is a print shadow, like the docs cards. */
.demo-btn:not(:disabled, [aria-disabled='true']):hover { box-shadow: 3px 3px 0 var(--demo-btn-shadow); translate: -1px -1px; }
:is(.demo-btn-quiet, .demo-act):not(:disabled, [aria-disabled='true']):hover { background: var(--demo-surface-2); border-color: var(--demo-ink); }
:is(.demo-btn, .demo-btn-quiet, .demo-act):is(:disabled, [aria-disabled='true']) { opacity: var(--demo-disabled-opacity); cursor: not-allowed; }

/* One visible focus ring for every control in every style (browser defaults vary and can vanish on tinted panels). */
:is(button, input, select, textarea, a, [tabindex]):focus-visible { outline: 3px solid var(--demo-primary); outline-offset: 2px; }
/* A hint with its own control (a button or slider): the control sits on its own line above the text, so the hint
 * wraps as plain prose instead of flowing around the button (which left ragged gaps on narrow screens). */
.demo-try > :is(.demo-act, label.demo-act-range) { display: flex; width: fit-content; margin: 0 0 var(--space-xs); }

/* ── Saturday morning page chrome (a demo opened on its own page) ──
 * Scoped to body, so none of this reaches a demo embedded in the docs (its shadow root has no body; the docs page
 * draws the TV around it there). The page is cream (deep navy in dark mode) and the demo panel is the TV: black
 * bezel, orange cabinet (outline) and a black rim with an offset drop (box-shadow). Outline and shadows don't take
 * up layout space, so the panel never widens the page on a phone. */
:root[data-style='saturday'] body { background: #fff7ec; color: var(--demo-text); padding-inline: 28px; }
:root[data-style='saturday'][data-theme='dark'] body { background: #141838; }
:root[data-style='saturday'] body :is(h1, h2, h3) { font-weight: 400; letter-spacing: 0; }
:root[data-style='saturday'] body h1 { font-size: clamp(2rem, 6vw, 2.75rem); line-height: 1.1; }
:root[data-style='saturday'] body :is(canvas, .row, .panel):not(.panel canvas) {
  border: 4px solid #1a1a1a; border-radius: 26px; outline: 12px solid #ff8a3d; outline-offset: 0;
  box-shadow: 0 0 0 16px #1a1a1a, 8px 8px 0 16px #1a1a1a; margin-block: 30px 34px; }
:root[data-style='saturday'] body :is(.demo-btn, .demo-btn-quiet, .demo-act, .panel button, .row button.demo-btn) {
  border: 2.5px solid #1a1a1a; border-radius: 999px; box-shadow: 0 3px 0 #1a1a1a; font-weight: 800; }
:root[data-style='saturday'] body :is(.demo-btn-quiet, .demo-act) { background: #ff9acb; color: #1a1a1a; }
:root[data-style='saturday'] body :is(.demo-btn, .demo-btn-quiet, .demo-act, .panel button):not(:disabled):hover {
  translate: 0 -1px; box-shadow: 0 4px 0 #1a1a1a; }
:root[data-style='saturday'] body :is(.demo-btn-quiet, .demo-act):not(:disabled):hover { background: #ff9acb; border-color: #1a1a1a; }
