/* Game-HUD styling: condensed italic display type, hard drop shadows,
   no solid panels — text sits directly on the scene like a PS2-era menu. */
:root {
  /* palette: Sanzo Wada, A Dictionary of Color Combinations, No. 268, without its
     orange — Nile Blue (type, and the knob on a lit switch), Light Brown Drab
     (highlights and fills), Deep Slate Olive (plates). (Raw Sienna #bb7125 was the
     accent; No. 263 before that: ink 181,222,204 / accent 238,180,128 / fill #ae5224.) */
  --ink-rgb: 188, 228, 229;   /* Nile Blue #bce4e5 */
  --accent-rgb: 181, 147, 146; /* Light Brown Drab #b59392 */
  --slate-rgb: 37, 49, 34;    /* Deep Slate Olive #253122 */
  --text: rgb(var(--ink-rgb));
  --dim: rgba(var(--ink-rgb), .58);
  --accent: rgb(var(--accent-rgb));
  --sienna: var(--accent);    /* switch fill */
  --drab: var(--text);        /* switch knob */
  --cool: rgb(var(--slate-rgb));
  --shade: rgba(8, 8, 8, .78);
  --gut: clamp(16px, 2.6vw, 36px);
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --mono: "Share Tech Mono", ui-monospace, Menlo, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --drop: 0 2px 0 rgba(0, 0, 0, .75), 0 0 10px rgba(0, 0, 0, .45);
  --zt: clamp(34px, 4.2vw, 56px);   /* zone title size (the download button is placed from it) */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: #232526; color: var(--text);
  font: 500 16px/1.25 var(--display);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
  text-shadow: var(--drop);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; text-shadow: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* keycap prompt glyph */
kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  font: 400 12px/1 var(--mono); color: var(--text); text-shadow: none;
  border: 1.5px solid rgba(var(--ink-rgb), .85); border-radius: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, .02));
  box-shadow: 0 2px 0 rgba(0, 0, 0, .6);
}

#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
.vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(120% 95% at 50% 45%, transparent 60%, rgba(6, 6, 6, .22) 100%); }
.letterbox {
  position: fixed; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, .3) 0, transparent 14%, transparent 80%, rgba(0, 0, 0, .36) 100%);
}

/* top bar: a soft dark scrim behind it so the menu reads over any part of the scene */
.top {
  position: fixed; top: 0; left: 0; right: 0;
  padding: calc(var(--gut) * .6) var(--gut) 0;
  display: flex; align-items: center; gap: clamp(16px, 2.4vw, 32px);
  pointer-events: none;
}
.top::before {
  content: ""; position: absolute; z-index: -1; inset: 0 0 auto; height: calc(var(--gut) * .6 + 84px); pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 8, 8, .55), rgba(8, 8, 8, .22) 55%, transparent);
}
.top > * { pointer-events: auto; }
.mark { display: block; margin-right: auto; color: var(--text); line-height: 0; }
/* the logo: four strokes and six nodes over faint construction lines, in the bar's
   cream with a dark halo so it holds up over the bright wall like the page links */
.mark svg { height: 44px; width: auto; overflow: visible; filter: drop-shadow(0 0 2px rgba(8, 8, 8, .7)) drop-shadow(0 1px 5px rgba(8, 8, 8, .45)); }
.mark-grid { stroke: currentColor; stroke-width: 1; opacity: .4; fill: none; }
.mark-line { stroke: currentColor; stroke-width: 3.4; stroke-linecap: round; fill: none; }
.mark-dot { fill: currentColor; }
/* Hovering the corner mark replays its drawing in miniature, using the reveal's own
   timings (on the logo in index.html) sped up by --k: grid, dots, then lines. Moving
   off shows it whole again. Only where there's a real hover (not touch screens). */
@media (hover: hover) {
  .mark { --k: .7; }
  .mark:hover path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: mark-draw calc(var(--t, .42s) * var(--k)) calc(var(--d) * var(--k)) cubic-bezier(.6, .05, .35, 1) forwards; }
  .mark:hover .mark-grid path { --t: .28s; }
  .mark:hover circle { transform-box: fill-box; transform-origin: center; transform: scale(0); opacity: 0; animation: mark-plot .2s calc(var(--d) * var(--k)) ease-out forwards; }
}
/* The logo reveal after "press start": a copy of the mark, large in the middle of the
   screen, set out the way it would be on paper. First the faint construction grid,
   each line a quick flick of the pencil; then the six nodes plotted one by one, each
   pressed in (small, a touch too big as the lead spreads, then settled); then the
   lines drawn between them, each starting slowly as the pencil finds its dot and easing
   off as it reaches the next (optionally with a small nudge of the dot). A light
   graphite grain roughens the edges. Then it holds for a beat and flies into the
   corner, where the real (clean) mark takes over.
   Every stroke's length is normalised (pathLength="1"), so one dash animation draws any
   of them. Per-part timing lives on the logo in index.html: --d (start), --t (stroke
   duration), --h (when the pencil touches a dot again).
   Tweak it in tools/logo-reveal.html (open it through the local server). The knobs
   here: --fly-at (when it leaves for the corner), the transition (the flight's length
   and easing), the easings and durations below, and the size (height). */
.reveal { --fly-at: 2.85s; position: fixed; inset: 0; z-index: 6; display: grid; place-items: center; pointer-events: none; color: var(--text); }
.reveal svg {
  width: auto; height: min(34vh, 260px); overflow: visible;
  filter: drop-shadow(0 0 3px rgba(8, 8, 8, .7)) drop-shadow(0 2px 12px rgba(8, 8, 8, .45));
  transition: transform .75s cubic-bezier(.65, 0, .25, 1);
}
.reveal :is(.mark-grid, .mark-line, .mark-dot) { filter: url(#pencil); }
.reveal path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: mark-draw var(--t, .42s) var(--d) cubic-bezier(.6, .05, .35, 1) forwards; }
.reveal .mark-grid path { --t: .28s; animation-timing-function: cubic-bezier(.2, .6, .3, 1); }
.reveal circle {
  transform-box: fill-box; transform-origin: center; transform: scale(0); opacity: 0;
  animation: mark-plot .2s var(--d) ease-out forwards;
}
/* optional: each dot gives a small nudge when the pencil touches it again. Off unless
   the reveal has the "jiggle" class (on #reveal in index.html; there's a switch for it
   in the playground) */
.reveal.jiggle circle { animation: mark-plot .2s var(--d) ease-out forwards, mark-hit .24s var(--h, 99s) ease-out; }
@keyframes mark-draw { to { stroke-dashoffset: 0; } }
@keyframes mark-plot { 0% { transform: scale(.25); opacity: 0; } 35% { transform: scale(1.14); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes mark-hit { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.2); } }
body.revealing .mark svg { opacity: 0; }
.top nav { display: flex; gap: clamp(16px, 2.4vw, 32px); align-items: center; }
.top nav a, .atog {
  font: italic 700 17px/1 var(--display); letter-spacing: .06em; text-transform: uppercase; color: rgba(var(--ink-rgb), .92);
  transition: color .2s, transform .2s var(--ease), background-color .2s;
}
/* the page links carry the most contrast in the bar: full-strength cream, a bit
   larger, and a dense dark halo so they hold up over the bright wall and corkboard */
.top nav a {
  position: relative; font-size: 18px; color: var(--text); padding: 6px 0;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .9), 0 0 3px rgba(0, 0, 0, .7), 0 0 14px rgba(0, 0, 0, .75);
}
.top nav a::after { /* a short accent rule slides in under the link you're on */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--accent);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .7); transform: scaleX(0); transform-origin: left; transition: transform .25s var(--ease);
}
.top nav a:hover, .top nav a:focus-visible { color: var(--accent); transform: translateY(-1px); }
.top nav a:hover::after, .top nav a:focus-visible::after { transform: none; }

/* audio: a slab of tinted glass holding two switches, Music and Effects, each with
   an icon that is slashed when off and a small switch that reads on (lit) or off.
   No drawn outline: the edge is made by the glass itself, in three layers
     ::before  the body: a slate tint over a light blur of the scene behind
     ::after   the thick rim: the scene blurred and brightened more, masked to the
               edges so the distortion grows toward them like a convex lens, with
               light catching the top edge and fading as it curves round the sides
   Chromium also bends the scene at the rim (.lens: an SVG displacement map, see
   index.html); elsewhere the blur and light alone carry it.
   (backdrop-filter sits on the pseudo-elements, not .audio: a backdrop-filter on the
   parent would stop its children seeing the scene behind.) */
.audio {
  position: relative; isolation: isolate;
  display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .16);
}
.audio::before, .audio::after { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none; }
.audio::before {
  background: linear-gradient(180deg, rgba(var(--ink-rgb), .07), rgba(var(--slate-rgb), .26) 55%, rgba(var(--slate-rgb), .34));
  -webkit-backdrop-filter: blur(2.5px) saturate(1.2); backdrop-filter: blur(2.5px) saturate(1.2);
}
.audio.lens::before { backdrop-filter: url(#lens) blur(2px) saturate(1.2); }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; } /* filter definitions only: out of the flex row */
.audio::after {
  background:
    radial-gradient(60% 140% at 22% 0%, rgba(255, 255, 255, .13), transparent 70%),   /* soft specular, top left */
    linear-gradient(180deg, rgba(255, 255, 255, .09), transparent 45%, transparent 75%, rgba(var(--ink-rgb), .05));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .22),      /* light along the top edge */
    inset 0 -1px 0 rgba(0, 0, 0, .18),            /* shade along the bottom */
    inset 0 0 10px rgba(var(--ink-rgb), .08);     /* glow inside the rim */
  -webkit-backdrop-filter: blur(6px) saturate(1.5) brightness(1.1); backdrop-filter: blur(6px) saturate(1.5) brightness(1.1);
  -webkit-mask: radial-gradient(closest-side, transparent 62%, #000 100%); mask: radial-gradient(closest-side, transparent 62%, #000 100%);
}
.atog { display: inline-flex; align-items: center; gap: 8px; padding: 7px 10px 7px 9px; border-radius: 5px; }
.atog:hover { background: rgba(var(--ink-rgb), .1); color: #fff; }
.atog .ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1.5px 0 rgba(0, 0, 0, .7)); }
.atog .slash { display: none; }
.atog[aria-pressed="false"] { color: rgba(var(--ink-rgb), .55); }
.atog[aria-pressed="false"] .slash { display: inline; }
.atog[aria-pressed="false"] .wave { display: none; }
.atog .sw {
  position: relative; width: 24px; height: 13px; flex: none; border-radius: 7px;
  border: 1.5px solid currentColor; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .6); transition: background-color .2s, border-color .2s;
}
.atog .sw::after {
  content: ""; position: absolute; top: 1.5px; left: 2px; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; transition: transform .22s var(--ease), background-color .2s;
}
.atog[aria-pressed="true"] .sw { background: var(--sienna); border-color: var(--sienna); }
.atog[aria-pressed="true"] .sw::after { transform: translateX(10px); background: var(--drab); }
.audio .caliper-wrap + .atog { margin-left: 2px; }

/* volume: a digital vernier caliper slides open to the left of the switches.
   The jaw gap is the volume (closed = 0, fully open = 100); the LCD reads it out. */
/* opens on hover (or keyboard focus); slides back out and fades when you move away.
   Mouse focus doesn't hold it open: only :focus-visible (keyboard) does. */
.caliper-wrap {
  width: 0; opacity: 0; overflow: hidden; pointer-events: none; transform: translateX(24px);
  transition: width .45s var(--ease) .05s, opacity .3s ease .05s, transform .45s var(--ease) .05s;
}
.audio:has(:focus-visible) .caliper-wrap, .audio:hover .caliper-wrap {
  width: 206px; opacity: 1; pointer-events: auto; transform: none;
  transition: width .4s var(--ease), opacity .2s ease, transform .4s var(--ease);
}
/* the caliper itself is flat-shaded SVG (js/caliper.js): hard facets, no gradients */
.caliper {
  position: relative; width: 200px; height: 46px; margin: 2px 3px 0;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .6)) drop-shadow(0 0 6px rgba(0, 0, 0, .3));
}
.caliper-svg { display: block; overflow: visible; shape-rendering: geometricPrecision; }
.caliper-head { transition: transform .12s var(--ease); }
/* the real slider sits on top, invisible, so dragging, keys and screen readers all work */
.caliper input[type=range] {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize;
  -webkit-appearance: none; appearance: none;
}

/* drawer select list */
.index {
  position: fixed; left: var(--gut); top: 50%; transform: translateY(-50%);
  width: 250px;
  transition: opacity .45s var(--ease), transform .45s var(--ease);
  /* stronger read over a busy background: heavier shadow + a soft haze that fades out (no box) */
  text-shadow: 0 2px 0 rgba(0, 0, 0, .85), 0 0 14px rgba(0, 0, 0, .7);
}
.index::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  inset: -40px -90px -40px calc(-1 * var(--gut));
  background: radial-gradient(70% 60% at 30% 50%, rgba(8, 8, 8, .5), rgba(8, 8, 8, .22) 55%, transparent 80%);
}
.index .label {
  font: 400 11px/1 var(--mono); letter-spacing: .2em; text-transform: uppercase; color: rgba(var(--ink-rgb), .78);
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.index ol { list-style: none; }
.index button {
  position: relative; width: 100%; display: grid; grid-template-columns: 16px 46px 1fr; align-items: center;
  padding: 6px 8px 6px 4px; text-align: left; color: rgba(var(--ink-rgb), .84);
  transition: color .2s, padding .3s var(--ease);
}
.index button::before { /* highlight bar */
  content: ""; position: absolute; inset: 2px 0; z-index: -1; opacity: 0;
  background: linear-gradient(90deg, rgba(var(--accent-rgb), .38), rgba(var(--accent-rgb), .08) 70%, transparent);
  transition: opacity .2s;
}
.index .sw { width: 0; height: 0; border-left: 8px solid var(--accent); border-top: 5px solid transparent; border-bottom: 5px solid transparent; opacity: 0; transform: translateX(-4px); transition: opacity .2s, transform .3s var(--ease); filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .7)); }
.index .c { font: 400 12px/1 var(--mono); letter-spacing: .04em; }
.index .t { font: italic 700 21px/1 var(--display); text-transform: uppercase; letter-spacing: .02em; }
.index button.on, .index button:hover { color: var(--text); padding-left: 10px; }
.index button.on::before { opacity: 1; }
.index button.on .sw { opacity: 1; transform: none; }
.index button.on .c { color: var(--accent); }

/* inspect panel (drawer preview) */
.card {
  position: fixed; left: 0; top: 50%;
  width: min(440px, 100vw); padding: 22px 70px 20px var(--gut);
  background: linear-gradient(90deg, var(--shade) 0%, rgba(8, 8, 8, .62) 62%, transparent 100%);
  opacity: 0; pointer-events: none; transform: translate(-18px, -50%);
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tab, var(--accent)); box-shadow: 0 0 14px var(--tab, var(--accent)); }
.card .code { font: 400 12px/1 var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--accent); }
.card h2 { font: italic 800 44px/.95 var(--display); text-transform: uppercase; letter-spacing: -0.005em; margin: 8px 0 14px; }
.card dl { display: grid; gap: 5px; max-width: 300px; }
.card dl div { display: flex; align-items: baseline; gap: 8px; font-size: 17px; }
.card dl div::after { content: ""; order: 1; flex: 1; border-bottom: 1px dotted rgba(var(--ink-rgb), .35); transform: translateY(-4px); }
.card dt { font: 400 12px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.card dd { order: 2; font-weight: 600; }
.card .summary { margin: 14px 0 18px; max-width: 32ch; font-size: 17px; line-height: 1.3; color: rgba(var(--ink-rgb), .82); }
.card .actions { display: flex; gap: 22px; }
.card .actions button { display: inline-flex; align-items: center; gap: 9px; font: italic 700 18px/1 var(--display); text-transform: uppercase; letter-spacing: .04em; transition: color .2s, transform .2s var(--ease); }
.card .actions button:hover { color: var(--accent); transform: translateX(2px); }
.card .actions .primary kbd { border-color: var(--accent); color: var(--accent); }

/* area readout (bottom right), like a game zone name */
.zone { position: fixed; right: var(--gut); bottom: calc(var(--gut) * .8); text-align: right; pointer-events: none; }
.zone .kicker { font: 400 12px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--dim); display: flex; gap: 6px; justify-content: flex-end; align-items: baseline; }
.zone .kicker b { font-weight: 400; color: var(--text); }
.zone .kicker i { font-style: normal; opacity: .5; margin: 0 4px; }
.zone-title {
  font: italic 800 var(--zt)/.95 var(--display); text-transform: uppercase; letter-spacing: -0.005em;
  margin-top: 6px; -webkit-text-stroke: 1px rgba(0, 0, 0, .35);
  text-shadow: 0 3px 0 rgba(0, 0, 0, .8), 0 0 18px rgba(0, 0, 0, .5);
}

/* control prompts (bottom left) */
.hint {
  position: fixed; left: var(--gut); bottom: calc(var(--gut) * .8);
  display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; max-width: 60vw;
  font: italic 600 17px/1 var(--display); text-transform: uppercase; letter-spacing: .03em;
  transition: opacity .4s var(--ease);
}
.hint span { display: inline-flex; align-items: center; gap: 8px; }
.hint:empty { display: none; }

/* back to drawer (folio only) */
.back {
  position: fixed; left: 50%; top: calc(var(--gut) * .6 + 13px); transform: translate(-50%, -8px);
  display: inline-flex; gap: 9px; align-items: center;
  font: italic 700 18px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  opacity: 0; pointer-events: none;
  transition: opacity .4s var(--ease), transform .4s var(--ease), color .2s;
}
.back:hover { color: var(--accent); }

/* download folio: sits above the area title, ringed by a red markup revision cloud.
   Its offset is the zone's own height (kicker 12 + gap 6 + title) plus the cloud's
   16px overhang and a 10px gap, so the cloud clears the kicker at every width. */
.download-wrap {
  position: fixed; right: calc(var(--gut) + 14px); bottom: calc(var(--gut) * .8 + 44px + var(--zt) * .95);
  --markup-rgb: 212, 109, 122; /* Old Rose #d46d7a (Wada): a red-pen mark that is red, not orange */
  --markup: rgb(var(--markup-rgb));
}
.download {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 9px;
  font: italic 700 18px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 6px; transition: color .2s, transform .2s var(--ease);
}
.download small { font: 400 11px/1 var(--mono); letter-spacing: .12em; color: var(--dim); }
.download kbd { border-color: var(--markup); color: var(--text); background: linear-gradient(180deg, rgba(var(--markup-rgb), .55), rgba(var(--markup-rgb), .25)); }
.download:hover { color: var(--accent); transform: translateY(-1px); }
.revcloud { position: absolute; overflow: visible; pointer-events: none; animation: revcloud 3.2s ease-in-out infinite; transform-origin: center; }
.revcloud path { fill: rgba(var(--markup-rgb), .07); stroke: var(--markup); stroke-width: 1.8; stroke-linejoin: round; filter: drop-shadow(0 1.5px 0 rgba(0, 0, 0, .55)); }
.revcloud .tag polygon { fill: var(--markup); stroke: rgba(0, 0, 0, .35); stroke-width: 1; }
.revcloud .tag text { font: 700 11px/1 var(--display); fill: #fff; text-anchor: middle; }
/* subtle "look here": the cloud breathes, never flashes */
@keyframes revcloud { 0%, 100% { opacity: .62; transform: scale(1); } 50% { opacity: 1; transform: scale(1.025); } }
.download-wrap:hover .revcloud { animation-play-state: paused; opacity: 1; }
.toast {
  position: absolute; right: 0; bottom: calc(100% + 18px); white-space: nowrap;
  font: italic 700 15px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  background: rgba(8, 8, 8, .78); padding: 8px 12px; border-left: 3px solid var(--markup);
  opacity: 0; transform: translateY(6px); pointer-events: none; transition: opacity .3s, transform .3s var(--ease);
}
.toast.show { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .revcloud { animation: none; opacity: .9; } }

/* idle prompt: ghost cursor that glides to the top drawer and "clicks" */
/* gentle: a small hairline ring that drifts in slowly, then sends out one soft ripple */
.ghost {
  position: fixed; left: 0; top: 0; z-index: 4; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
  border: 1px solid rgba(var(--ink-rgb), .65); background: rgba(var(--ink-rgb), .05);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .45), 0 0 10px rgba(0, 0, 0, .25);
  opacity: 0; pointer-events: none;
  transition: transform 1.6s cubic-bezier(.45, .05, .25, 1), opacity .7s ease;
}
.ghost::after { content: ""; position: absolute; left: 50%; top: 50%; width: 3px; height: 3px; margin: -1.5px; border-radius: 50%; background: rgba(var(--ink-rgb), .75); }
.ghost.show { opacity: 1; }
/* small white caption beside the ring */
.ghost-label {
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  font: 11px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; white-space: nowrap; color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .75), 0 0 8px rgba(0, 0, 0, .55);
}
.ghost.press::before {
  content: ""; position: absolute; inset: -1px; border-radius: 50%; border: 1px solid rgba(var(--ink-rgb), .7);
  animation: ghost-ring 1.8s cubic-bezier(.2, .6, .3, 1) 1 forwards;
}
@keyframes ghost-ring { from { transform: scale(1); opacity: .7; } to { transform: scale(2.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ghost { transition: opacity .6s ease; } .ghost.press::before { animation: none; } }

/* title screen ("press start") */
.start {
  position: fixed; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 10px;
  background: radial-gradient(80% 70% at 50% 50%, rgba(10, 10, 10, .35), rgba(10, 10, 10, .72));
  color: var(--text); cursor: pointer; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .7s var(--ease);
}
.start-kicker { font: 400 12px/1 var(--mono); letter-spacing: .24em; text-transform: uppercase; color: var(--dim); }
.start-title {
  font: italic 800 clamp(56px, 10vw, 128px)/.9 var(--display); text-transform: uppercase; letter-spacing: -0.01em;
  -webkit-text-stroke: 1px rgba(0, 0, 0, .35); text-shadow: 0 4px 0 rgba(0, 0, 0, .8), 0 0 30px rgba(0, 0, 0, .5);
}
.start-prompt { margin-top: 18px; display: inline-flex; gap: 10px; align-items: center; font: italic 700 20px/1 var(--display); text-transform: uppercase; letter-spacing: .05em; animation: start-blink 1.6s ease-in-out infinite; }
/* "better with sound": headphones icon with a slow, soft glow — noticed, not shouted */
.start-note {
  margin-top: 6px; display: inline-flex; align-items: center; gap: 9px;
  font: 400 12px/1 var(--mono); letter-spacing: .18em; text-transform: uppercase; color: rgba(var(--ink-rgb), .8);
  animation: start-note 3.4s ease-in-out infinite;
}
/* thin cream line icon, same colour and weight as the mono text beside it */
.headphones { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1.5px 0 rgba(0, 0, 0, .7)); }
@keyframes start-note {
  0%, 100% { opacity: .7; text-shadow: var(--drop); }
  50% { opacity: 1; text-shadow: var(--drop), 0 0 12px rgba(var(--accent-rgb), .45); }
}
@keyframes start-blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
body[data-state="start"] .start { opacity: 1; pointer-events: auto; }
body[data-state="start"] :is(.top, .zone, .download-wrap) { opacity: 0; pointer-events: none; }
.top, .zone, .download-wrap { transition: opacity .6s var(--ease); }
@media (prefers-reduced-motion: reduce) { .start-prompt, .start-note { animation: none; } }

/* state-driven visibility */
body:is([data-state="folio"], [data-state="board"]) .back { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
body[data-state="preview"] .card { opacity: 1; pointer-events: auto; transform: translate(0, -50%); }
body:not([data-state="chest"]):not([data-state="intro"]) .index { opacity: 0; transform: translate(-14px, -50%); pointer-events: none; }
body:is([data-state="pulling"], [data-state="putting"], [data-state="opening"], [data-state="closing"], [data-state="intro"], [data-state="preview"]) .hint { opacity: 0; }

/* loading screen: the scale bar from a drawing sheet, over a faint drafting grid and
   a floor plan that draws itself in as --p goes 0 → 1. Type matches the HUD:
   italic condensed caps for words, mono for numbers. */
.loader {
  --line: rgba(var(--ink-rgb), .42); --ink: rgba(var(--ink-rgb), .9);
  position: fixed; inset: 0; z-index: 8; display: grid; place-content: center; overflow: hidden;
  background:
    repeating-linear-gradient(0deg, rgba(var(--ink-rgb), .045) 0 1px, transparent 1px 120px),
    repeating-linear-gradient(90deg, rgba(var(--ink-rgb), .045) 0 1px, transparent 1px 120px),
    repeating-linear-gradient(0deg, rgba(var(--ink-rgb), .02) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, rgba(var(--ink-rgb), .02) 0 1px, transparent 1px 24px),
    radial-gradient(75% 70% at 50% 45%, #26302f, #141a1a);
  background-position: center;
  transition: opacity .9s var(--ease), visibility 0s linear .9s;
}
.loader.done { opacity: 0; visibility: hidden; }
/* the construction grid: chain lines slide in one after another, then their
   bubbles appear. Pure CSS transforms/opacity, so they stay smooth even while
   the page is busy building the scene. */
.loader-grid { position: absolute; inset: 0; pointer-events: none; --chain: rgba(var(--ink-rgb), .12); }
.gl { position: absolute; overflow: hidden; }
.gl.v { top: 16%; bottom: 7%; width: 1px; }
.gl.h { left: 20%; right: 8%; height: 1px; }
.gl i { position: absolute; inset: 0; animation: gl-draw 1.7s cubic-bezier(.45, 0, .2, 1) calc(.15s + var(--i) * .1s) both; }
.gl.v i { background: repeating-linear-gradient(180deg, var(--chain) 0 22px, transparent 22px 28px, var(--chain) 28px 31px, transparent 31px 37px); --from: translateY(-100%); }
.gl.h i { background: repeating-linear-gradient(90deg, var(--chain) 0 22px, transparent 22px 28px, var(--chain) 28px 31px, transparent 31px 37px); --from: translateX(-100%); }
@keyframes gl-draw { from { transform: var(--from); } to { transform: none; } }
.gb {
  position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border: 1px solid rgba(var(--ink-rgb), .16); border-radius: 50%;
  display: grid; place-items: center; font: 400 13px/1 var(--mono); color: rgba(var(--ink-rgb), .26); text-shadow: none;
  animation: gb-in 1.2s ease-out calc(.55s + var(--i) * .1s) both; transition: color .5s ease;
}
.gb.col { top: calc(16% - 22px); }
.gb.row { left: calc(20% - 22px); }
@keyframes gb-in { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .gl i, .gb { animation: none; } }
/* a soft pool of dark behind the bar so it stays readable over the linework */
.loader-inner { position: relative; width: clamp(240px, 32vw, 400px); }
.loader-inner::before { content: ""; position: absolute; inset: -60px -90px; z-index: -1; background: radial-gradient(closest-side, rgba(18, 23, 23, .85), transparent); }
.scalebar { position: relative; height: 12px; }
.sb-cells { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 1fr 5fr; grid-template-rows: 1fr 1fr; border: 1px solid var(--line); }
.sb-cells span:not(:nth-child(6n+1)) { border-left: 1px solid var(--line); }
.sb-cells span:nth-child(-n+6) { border-bottom: 1px solid var(--line); }
/* the inked layer: full-strength lines and solid alternate cells, revealed left to right */
.sb-fill { --line: var(--ink); }
.sb-fill .on { background: var(--ink); }
/* The reveal: a window that slides right while the inked bar inside slides the
   opposite way, so the ink stays put and is uncovered left to right. Both are
   transforms run by js/loader.js as Web Animations, so the browser keeps them
   moving smoothly even while the page is busy building the 3D scene. */
.sb-reveal { position: absolute; left: 0; right: 0; top: -4px; bottom: -4px; overflow: hidden; transform: translateX(-100%); will-change: transform; }
.sb-reveal .sb-fill { inset: 4px 0; transform: translateX(100%); will-change: transform; }
/* the pen: a short stroke riding the leading edge */
.sb-edge { position: absolute; right: 0; top: 0; bottom: 0; width: 1px; background: var(--text); opacity: .85; transition: opacity .4s ease; }
.loader.full .sb-edge { opacity: 0; }
.sb-labels { position: relative; height: 20px; font: 400 11px/1 var(--mono); color: var(--dim); }
.sb-labels span { position: absolute; top: 8px; transform: translateX(-50%); }
.sb-labels span::before { content: ""; position: absolute; left: 50%; top: -8px; width: 1px; height: 4px; background: var(--line); }
.sb-labels b { position: absolute; left: 100%; margin-left: 3px; font-weight: 400; }
.loader-foot { margin-top: 16px; display: flex; justify-content: space-between; align-items: baseline; }
#load-msg { font: italic 700 20px/1 var(--display); text-transform: uppercase; letter-spacing: .03em; }
.loader-scale { font: 400 11px/1 var(--mono); letter-spacing: .1em; color: var(--dim); }
/* words wait for their fonts (see js/loader.js), then fade up */
.loader :is(.loader-foot, .sb-labels) { transition: opacity .5s ease; }
.loader:not(.type-ready) :is(.loader-foot, .sb-labels) { opacity: 0; }
.loader:not(.type-ready) .gb { color: transparent; }

.nojs { position: fixed; inset: 0; z-index: 9; display: grid; place-items: center; padding: 24px; text-align: center; font-size: 18px; background: #1b2121; }
.nogl-msg, .noload-msg { display: none; }
body[data-state="nogl"] .nogl-msg, body[data-state="noload"] .noload-msg { display: grid; }
body:is([data-state="nogl"], [data-state="noload"]) .loader { display: none; }

/* the tape measure easter egg fades out to the loading screen's colour, which is
   where the easter-egg page starts (its crash sequence begins on a frozen loader) */
body::after { content: ""; position: fixed; inset: 0; z-index: 30; background: #1d2423; opacity: 0; pointer-events: none; transition: opacity .5s ease; }
body.whiteout::after { opacity: 1; }

/* notched phones: keep the HUD inside the safe area (viewport-fit=cover) */
@supports (padding: max(0px)) {
  .top { padding-left: max(var(--gut), env(safe-area-inset-left)); padding-right: max(var(--gut), env(safe-area-inset-right)); padding-top: max(calc(var(--gut) * .6), env(safe-area-inset-top)); }
  .index, .hint { left: max(var(--gut), env(safe-area-inset-left)); }
  .hint { bottom: max(calc(var(--gut) * .8), env(safe-area-inset-bottom)); }
  .zone { right: max(var(--gut), env(safe-area-inset-right)); bottom: max(calc(var(--gut) * .8), env(safe-area-inset-bottom)); }
  .download-wrap { right: calc(max(var(--gut), env(safe-area-inset-right)) + 14px); }
}

/* touch screens: words that match the hand (Tap, not Click; no keyboard keys), and
   no hover-only volume caliper (phones have volume buttons) */
.touch-only { display: none; }
.vol-btn { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: contents; }
  .mouse-only { display: none !important; }
  .back .touch-only { font-size: 1.3em; }
  /* the info card is a drag surface too (it covers the drawer's front edge): a grab
     handle says so, in place of the coloured rule along its top */
  .card { touch-action: none; -webkit-user-select: none; user-select: none; }
  .card::before { display: none; }
  .card.dragging { transition: none; }
  .card::after { content: ""; position: absolute; top: 8px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: rgba(var(--ink-rgb), .45); box-shadow: 0 1px 0 rgba(0, 0, 0, .5); }
  /* volume: the caliper drops down under the audio chip when its button is tapped
     (a sticky :hover after tapping a switch must not open it) */
  .vol-btn { display: inline-flex; padding: 5px 4px; touch-action: none; }
  /* the readout: the caliper's own LCD in miniature, its level shaded in behind the
     number, with nudge marks either side to say it slides */
  .vol-btn .lcd { display: block; line-height: 0; border-radius: 2px; overflow: hidden; box-shadow: 0 1.5px 0 rgba(0, 0, 0, .55); }
  .vol-btn .readout-svg { display: block; }
  .vol-btn.sliding .lcd { box-shadow: 0 0 0 1.5px var(--accent); }
  body[data-state="preview"] .hint { opacity: 1; } /* the swipe-to-push-back prompt */
  .audio .caliper-wrap, .audio:hover .caliper-wrap, .audio:has(:focus-visible) .caliper-wrap {
    position: absolute; top: calc(100% + 8px); right: 0; width: 0; opacity: 0; pointer-events: none; transform: translateY(-6px);
  }
  .audio.vol-open .caliper-wrap {
    width: 222px; opacity: 1; pointer-events: auto; transform: none; padding: 6px 8px 4px; border-radius: 10px;
    background: rgba(var(--slate-rgb), .5); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 6px 16px rgba(0, 0, 0, .2);
  }
  .audio.vol-open .vol-btn { background: rgba(var(--ink-rgb), .14); }
  .top:has(.audio.vol-open) ~ .hint { opacity: 0; }
}

/* the folio is a wide spread: on a phone held upright, suggest turning it */
.rotate-tip {
  position: fixed; left: 50%; bottom: calc(var(--gut) * .8 + var(--zt) + 34px); transform: translate(-50%, 8px);
  display: none; align-items: center; gap: 9px; white-space: nowrap; padding: 8px 14px; border-radius: 8px;
  font: italic 700 15px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  background: rgba(var(--slate-rgb), .45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .5s var(--ease) .8s, transform .5s var(--ease) .8s; pointer-events: none;
}
.rotate-tip svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: none) and (orientation: portrait) {
  .rotate-tip { display: inline-flex; }
  body[data-state="folio"] .rotate-tip { opacity: 1; transform: translate(-50%, 0); }
}

/* compact layouts: phones, and tablets held upright. The scene fills the width
   there, so the drawer list (which would sit on top of the chest) goes, the
   preview card becomes a sheet along the bottom, and Back tucks under the mark. */
@media (max-width: 760px), (max-width: 1100px) and (orientation: portrait) {
  .index { display: none; }
  .card { top: auto; bottom: 0; transform: translate(0, 12px); width: 100vw; padding: 18px 20px 18px; background: linear-gradient(0deg, var(--shade) 0%, rgba(8, 8, 8, .6) 75%, transparent 100%); }
  .card::before { width: auto; height: 3px; right: 0; bottom: auto; }
  body[data-state="preview"] .card { transform: none; }
  body[data-state="preview"] .zone { display: none; }
  body[data-state="preview"] .download-wrap { opacity: 0; pointer-events: none; }
  .back { left: var(--gut); top: calc(var(--gut) * .6 + 52px); transform: translate(0, -8px); }
  body:is([data-state="folio"], [data-state="board"]) .back { transform: none; }
  body:is([data-state="opening"], [data-state="folio"], [data-state="closing"]) .download-wrap { opacity: 0; pointer-events: none; }
}
@media (max-width: 760px) {
  :root { --zt: 30px; }
  /* the menu stays (it is the only way to About / Contact); it steps aside while the caliper is open */
  .top nav { gap: 8px; }
  .top nav a, .atog { font-size: 13.5px; letter-spacing: .03em; }
  .mark svg { height: 38px; }
  .atog .lbl { display: none; } /* icon + switch only on phones: the bar is full */
  .atog { padding: 7px 5px; gap: 4px; }
  .top { gap: 8px; }
  .atog .sw { width: 20px; height: 12px; }
  .atog[aria-pressed="true"] .sw::after { transform: translateX(7px); }
  .audio { gap: 0; padding: 2px; }
  .top:has(.audio :focus-visible) nav { display: none; }
  @media (hover: hover) { .top:has(.audio:hover) nav { display: none; } }
  .hint { bottom: auto; top: calc(var(--gut) * .6 + 46px); max-width: 80vw; font-size: 15px; }
  .back { top: calc(var(--gut) * .6 + 78px); }
  .card h2 { font-size: 34px; }
  .card .summary { display: none; }
  .card .actions { margin-top: 16px; }   /* the gap the hidden summary used to give */
}

/* phones on their side: little height, so everything gets tighter. Back tucks under
   the mark instead of sitting on the menu, and the download steps aside while the
   folio is open (it would cover the right-hand page). */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --zt: 26px; --gut: 16px; }
  .mark svg { height: 34px; }
  .top nav a, .atog { font-size: 15px; }
  .atog { padding: 6px 8px; }
  .hint { font-size: 14px; }
  .back { left: max(var(--gut), env(safe-area-inset-left)); top: calc(var(--gut) * .6 + 40px); transform: translate(0, -8px); font-size: 15px; }
  body:is([data-state="folio"], [data-state="board"]) .back { transform: none; }
  body:is([data-state="opening"], [data-state="folio"], [data-state="closing"]) .download-wrap { opacity: 0; pointer-events: none; }
  .index .label { margin-bottom: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}
