/*
  Static: Channel 404, a 404 page as a television that has lost the signal.
  1. Tokens and the room.  2. The set: cabinet, bezel, tube, glass, power sequence.
  3. What is on screen: test card, teletext pages, on-screen display.
  3b. Components: select menu, confirmation, notice, buttons, fields (all drawn by the set, from the tokens).
  4. The control panel: dial, channel keys, switches.  5. Stacked layout and motion preferences.
*/

/* ---------- 1. Tokens ---------- */

@property --u {
  syntax: "<length>";
  inherits: true;
  initial-value: 8px;
}

:root {
  /* tube and room */
  --room: oklch(0.105 0.008 255);
  --room-lift: oklch(0.285 0.022 232);     /* the wall where the screen light lands */
  --room-mid: oklch(0.175 0.014 245);
  --tube-black: oklch(0.155 0.014 165);
  --raster-black: oklch(0.085 0.006 200);

  /* cabinet plastic, light to dark */
  --cab-1: oklch(0.455 0.008 250);
  --cab-2: oklch(0.335 0.008 252);
  --cab-3: oklch(0.235 0.007 255);
  --cab-4: oklch(0.155 0.006 255);
  --trim: oklch(0.62 0.01 240);           /* the bright moulded line round the tube */
  --seam: oklch(0.06 0.004 255);

  /* phosphor white and the printed legends */
  --phosphor: oklch(0.955 0.028 150);
  --phosphor-dim: oklch(0.76 0.03 150);
  --legend: oklch(0.87 0.012 140);
  --legend-dim: oklch(0.69 0.012 140);
  --tick: oklch(0.47 0.008 255);

  /* muted test-card bars */
  --bar-white: oklch(0.86 0.012 110);
  --bar-yellow: oklch(0.845 0.115 98);
  --bar-cyan: oklch(0.80 0.075 205);
  --bar-green: oklch(0.775 0.115 150);
  --bar-magenta: oklch(0.66 0.12 340);
  --bar-red: oklch(0.60 0.135 28);
  --bar-blue: oklch(0.46 0.10 262);
  --card-grey: oklch(0.47 0.008 160);
  --ink-red: oklch(0.74 0.13 30);        /* the red bar, lifted so it reads as text on black */

  /* the one warm light */
  --power-red: oklch(0.69 0.215 33);

  /* geometry: the whole set is drawn in --u, one hundredth of its height */
  --u: min(max(5.2px, (100svh - 128px) / 101.5), (100vw - 96px) / 161);
  --tune: 100;                            /* 0 static, 100 clear. Script overrides. */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");

  color-scheme: dark;
}

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

html {
  background: var(--room);
  scrollbar-color: var(--cab-1) var(--room);
  scrollbar-width: thin;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100svh;
  font-family: "Rubik", ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--legend);
  accent-color: var(--phosphor);
  caret-color: var(--phosphor);
  background:
    var(--grain),
    radial-gradient(96% 88% at 50% 40%, var(--room-lift) 30%, var(--room-mid) 68%, var(--room) 100%);
  background-blend-mode: soft-light, normal;
  overflow-x: hidden;
}

::selection { background: var(--phosphor); color: var(--raster-black); text-shadow: none; }

p, h2, dl, dd, ol { margin: 0; }
ol { padding: 0; list-style: none; }
a { color: inherit; text-underline-offset: 0.18em; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

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

.defs { position: absolute; }

.ico {
  width: 1.25em; height: 1.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------- 2. The room and the set ---------- */

.room {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 24px 88px;
  overflow: clip;
}

.set {
  position: relative;
  isolation: isolate;
  --lum: 1;
}

/* light the tube throws on the wall behind the set */
.set::before {
  content: "";
  position: absolute;
  inset: calc(var(--u) * -14) calc(var(--u) * -16);
  background: radial-gradient(50% 50% at 42% 48%, oklch(0.78 0.05 185 / 0.2), transparent 100%);
  opacity: var(--lum);
  transition: opacity 0.7s var(--ease-out);
  pointer-events: none;
}

.cabinet {
  position: relative;
  display: grid;
  grid-template-columns: auto calc(var(--u) * 33);
  gap: calc(var(--u) * 2);
  height: calc(var(--u) * 100);
  padding: calc(var(--u) * 2.4);
  border-radius: calc(var(--u) * 3.6);
  background:
    var(--grain),
    linear-gradient(177deg, var(--cab-1) 0%, var(--cab-2) 12%, var(--cab-2) 58%, var(--cab-3) 100%);
  background-blend-mode: soft-light, normal;
  box-shadow:
    inset 0 1.5px 0 oklch(1 0 0 / 0.34),
    inset 0 0 0 1px oklch(1 0 0 / 0.07),
    inset 0 calc(var(--u) * -0.6) calc(var(--u) * 0.9) oklch(0 0 0 / 0.5),
    0 0 0 1px oklch(0 0 0 / 0.55),
    0 calc(var(--u) * 1.2) calc(var(--u) * 2.4) oklch(0 0 0 / 0.5),
    0 calc(var(--u) * 5) calc(var(--u) * 9) oklch(0 0 0 / 0.55);
}

/* the shelf the set stands on, catching a little of the screen light */
.set::after {
  content: "";
  position: absolute;
  top: calc(100% - var(--shelf-top) * 0.72);       /* the feet stand a little back from the front edge */
  left: 50%;
  width: 100vw;
  height: 50svh;
  translate: -50% 0;
  --shelf-top: calc(var(--u) * 2.6);
  background:
    /* screen light pooling on the top, then spilling down the front */
    radial-gradient(30% 100% at 43% 0%, oklch(0.8 0.05 185 / calc(0.22 * var(--lum))), transparent 100%) 0 0 / 100% var(--shelf-top) no-repeat,
    radial-gradient(32% 26% at 43% 0%, oklch(0.8 0.05 185 / calc(0.07 * var(--lum))), transparent 100%),
    linear-gradient(oklch(1 0 0 / 0.16), oklch(1 0 0 / 0)) 0 var(--shelf-top) / 100% 1px no-repeat,
    linear-gradient(oklch(0.25 0.012 245), oklch(0.335 0.014 242)) 0 0 / 100% var(--shelf-top) no-repeat,
    linear-gradient(oklch(0.205 0.01 250), oklch(0.13 0.008 255) 34%, oklch(0.09 0.008 255));
  pointer-events: none;
  z-index: -1;
}

.feet {
  position: relative;
  display: flex;
  justify-content: space-between;
  padding: 0 calc(var(--u) * 9);
}
.feet i {
  width: calc(var(--u) * 11);
  height: calc(var(--u) * 1.5);
  background: linear-gradient(var(--seam), var(--cab-4));
  clip-path: polygon(0 0, 100% 0, 92% 100%, 8% 100%);
}
/* the set's own shadow on the shelf */
.feet::before {
  content: "";
  position: absolute;
  inset: 20% calc(var(--u) * 2) auto;
  height: calc(var(--u) * 2.2);
  border-radius: 50%;
  background: oklch(0 0 0 / 0.62);
  filter: blur(calc(var(--u) * 0.9));
  z-index: -1;
}

/* the moulded frame round the tube */
.bezel {
  display: flex;
  flex-direction: column;
  padding: calc(var(--u) * 2.2) calc(var(--u) * 2.2) 0;
  border-radius: calc(var(--u) * 2.6);
  background: linear-gradient(174deg, var(--cab-3), var(--cab-4) 30%, oklch(0.125 0.005 255));
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.14),
    inset 0 -1px 0 oklch(0 0 0 / 0.7),
    0 0 0 1px var(--seam),
    0 1px 0 1px oklch(1 0 0 / 0.14);
}

.mask {
  position: relative;
  padding: calc(var(--u) * 1.2);
  border-radius: calc(var(--u) * 5.4) / calc(var(--u) * 5.8);
  background: oklch(0.045 0.004 255);
  box-shadow:
    inset 0 calc(var(--u) * 0.7) calc(var(--u) * 1.6) oklch(0 0 0 / 0.95),
    inset 0 0 0 1px oklch(1 0 0 / 0.04),
    0 0 0 max(1.5px, calc(var(--u) * 0.24)) var(--trim),
    0 0 0 max(2.5px, calc(var(--u) * 0.36)) var(--seam),
    0 calc(var(--u) * 0.5) calc(var(--u) * 0.2) oklch(1 0 0 / 0.06);
}

/* spill of screen light onto the inside of the mask */
.mask::before {
  content: "";
  position: absolute;
  inset: calc(var(--u) * 1.4);
  border-radius: calc(var(--u) * 5);
  background: oklch(0.86 0.04 180 / 0.34);
  filter: blur(calc(var(--u) * 1.6));
  opacity: var(--lum);
  transition: opacity 0.6s var(--ease-out);
}

.tube {
  position: relative;
  height: calc(var(--u) * 85.6);
  aspect-ratio: 4 / 3;
  container-type: size;
  border-radius: 7% / 9%;             /* fallback outline; the inline clip-path draws the true tube face */
  overflow: hidden;
  background:
    radial-gradient(90% 90% at 50% 45%, oklch(0.215 0.016 165), var(--tube-black) 70%, oklch(0.09 0.01 165));
  isolation: isolate;

  /* picture state, driven by script.js from the dial */
  --pic-o: 1;
  --noise-o: 0;
  --blur: 0px;
  --sat: 1;
  --con: 1;
  --roll-o: 0;
}

.raster {
  position: absolute;
  inset: 0;
  background: var(--raster-black);
  transform-origin: 50% 50%;
}

.picture {
  position: absolute;
  inset: 0;
  opacity: var(--pic-o);
  filter: blur(var(--blur)) saturate(var(--sat)) contrast(var(--con));
  font-family: "VT323", ui-monospace, "Courier New", monospace;
  font-size: clamp(19px, 3.3cqw, 34px);
  line-height: 1.14;
  color: var(--phosphor);
  text-shadow: 0 0 0.35em oklch(0.955 0.028 150 / 0.38);
  will-change: transform, opacity;
}
.tube.is-locked .picture { filter: none; }
.tube.is-weak .picture { pointer-events: none; }

.noise {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;                          /* script.js sizes it to whole grains; the tube clips the spare pixel */
  height: 100%;
  opacity: var(--noise-o);
  mix-blend-mode: screen;               /* snow adds light, so the picture underneath keeps its darks and colour */
  image-rendering: pixelated;
  pointer-events: none;
}

.rollbar {
  position: absolute;
  inset: 0 0 auto;
  height: 22%;
  background: linear-gradient(transparent, oklch(0 0 0 / 0.6) 38%, oklch(1 0 0 / 0.07) 58%, transparent);
  opacity: var(--roll-o);
  pointer-events: none;
  animation: roll 6.5s linear infinite;
}
@keyframes roll {
  from { transform: translateY(-110%); }
  to { transform: translateY(470%); }
}

/* glass: reflections, vignette, scanlines, the dark at the curved edge */
.glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(58% 38% at 20% 6%, oklch(1 0 0 / 0.13), transparent 70%),
    radial-gradient(13% 9% at 81% 12%, oklch(1 0 0 / 0.07), transparent 72%),
    linear-gradient(104deg, oklch(1 0 0 / 0.05) 0 16%, transparent 31%),
    radial-gradient(76% 76% at 50% 50%, transparent 58%, oklch(0 0 0 / 0.46) 100%);
}
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom, oklch(0 0 0 / 0.3) 0 1px, transparent 1px 3px);
  opacity: var(--lum);
}
.glass::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 5cqw 1.2cqw oklch(0 0 0 / 0.72);
}

/* the beam: what is left of the picture when the set is switched */
.beam {
  position: absolute;
  inset: 50% 0 auto;
  height: 3px;
  margin-top: -1.5px;
  background: oklch(1 0 0);
  box-shadow: 0 0 12px 3px oklch(0.97 0.03 170 / 0.85), 0 0 46px 10px oklch(0.9 0.04 190 / 0.4);
  opacity: 0;
  pointer-events: none;
}

/* power: the picture folds to a line, the line to a dot, the dot fades */
.set[data-power="off"] { --lum: 0; }
/* with the set off, the lamps on the panel go dark too */
.set[data-power="off"] .dial__lit { opacity: 0; }
.set[data-power="off"] .key[aria-current="true"] .key__lamp {
  background: oklch(0.1 0.004 255);
  box-shadow: inset 0 1px 1px oklch(0 0 0 / 0.9), 0 1px 0 oklch(1 0 0 / 0.1);
}
.set[data-power="off"] .dial__grip::after { background: var(--legend-dim); box-shadow: none; }
.set[data-power="off"] .raster { visibility: hidden; }

.set.is-switching-off .raster {
  visibility: visible;
  animation: raster-off 0.46s var(--ease-in) forwards;
}
.set.is-switching-off .beam { animation: beam-off 1.05s linear forwards; }
.set.is-switching-on .raster { animation: raster-on 0.7s var(--ease-out) both; }
.set.is-switching-on .beam { animation: beam-on 0.55s linear both; }

@keyframes raster-off {
  0% { transform: scale(1, 1); filter: brightness(1); }
  55% { transform: scale(1, 0.006); filter: brightness(7); }
  100% { transform: scale(0, 0.004); filter: brightness(12); }
}
@keyframes beam-off {
  0% { opacity: 0; inset-inline: 0; }
  18% { opacity: 1; inset-inline: 0; }
  42% { opacity: 1; inset-inline: calc(50% - 2px); }
  70% { opacity: 0.85; inset-inline: calc(50% - 2px); }
  100% { opacity: 0; inset-inline: calc(50% - 1px); }
}
@keyframes raster-on {
  0% { transform: scale(0.004, 0.004); filter: brightness(10); }
  22% { transform: scale(1, 0.006); filter: brightness(7); }
  100% { transform: scale(1, 1); filter: brightness(1); }
}
@keyframes beam-on {
  0% { opacity: 1; inset-inline: calc(50% - 2px); }
  40% { opacity: 1; inset-inline: 0; }
  100% { opacity: 0; inset-inline: 0; }
}

/* chin: the maker's plate */
.chin {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: calc(var(--u) * 5);
  padding: 0 calc(var(--u) * 1.4);
  font-size: max(12px, calc(var(--u) * 1.3));
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7em;
  min-height: 100%;
  font-weight: 600;
  font-size: max(12px, calc(var(--u) * 1.5));
  color: var(--legend);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.2s var(--ease-out);
}
.brand svg {
  width: 2em; height: 1.43em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.brand { position: relative; }
.brand::after { content: ""; position: absolute; inset: -8px -10px; }   /* a full-size target round the small plate */
.brand:hover { color: var(--phosphor); }
.chin__model { color: var(--legend-dim); font-weight: 400; }

/* focus on anything printed on the cabinet */
.brand:focus-visible,
.key:focus-visible,
.pill:focus-visible,
.round:focus-visible .round__cap,
.dial:focus-visible {
  outline: 2px solid var(--phosphor);
  outline-offset: 3px;
}
.round:focus-visible { outline: none; }

/* ---------- 3. On screen ---------- */

.page {
  position: absolute;
  inset: 0;
  display: none;
  outline: none;
}
.page.is-active,
html:not(.js) .page:target,
html:not(.js) .picture:not(:has(.page:target)) > #ch-1 { display: flex; }
html:not(.js) .picture:has(.page:target) > .page:not(:target) { display: none; }

.picture a { color: inherit; }
.picture :focus-visible {
  outline: 2px solid var(--bar-yellow);
  outline-offset: 2px;
}

/* CH 01: test card */
/* The card fills the tube from top to bottom; the captions sit over its foot, as closed captions do. */
.page--card {
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 5cqw 4.4cqh;
  --card: min(93cqh, 88cqw);
  --side: calc((100cqw - var(--card)) / 2 - 3.2cqw);     /* width of the colour stacks either side of the circle */
  background:
    /* colour stacks at the edges of the raster */
    linear-gradient(to bottom, var(--bar-yellow) 0 25%, var(--bar-cyan) 0 50%, var(--bar-green) 0 75%, var(--bar-white) 0) 0 0 / var(--side) 100% no-repeat,
    linear-gradient(to bottom, var(--bar-magenta) 0 25%, var(--bar-red) 0 50%, var(--bar-blue) 0 75%, oklch(0.2 0.006 160) 0) 100% 0 / var(--side) 100% no-repeat,
    linear-gradient(to right, oklch(0.9 0.012 150 / 0.5) 2px, transparent 2px) 50% 50% / calc(100cqw / 14) calc(100cqw / 14),
    linear-gradient(to bottom, oklch(0.9 0.012 150 / 0.5) 2px, transparent 2px) 50% 50% / calc(100cqw / 14) calc(100cqw / 14),
    var(--card-grey);
}

.card {
  position: absolute;
  top: calc((100cqh - var(--card)) / 2);
  left: calc((100cqw - var(--card)) / 2);
  width: var(--card);
  height: var(--card);
  font-family: "VT323", ui-monospace, monospace;
  text-shadow: none;
}
.c-black { fill: var(--raster-black); }
.c-white { fill: var(--bar-white); }
.c-yellow { fill: var(--bar-yellow); }
.c-cyan { fill: var(--bar-cyan); }
.c-green { fill: var(--bar-green); }
.c-magenta { fill: var(--bar-magenta); }
.c-red { fill: var(--bar-red); }
.c-blue { fill: var(--bar-blue); }
.c-g1 { fill: oklch(0.2 0.006 160); }
.c-g2 { fill: oklch(0.34 0.006 160); }
.c-g3 { fill: oklch(0.48 0.006 160); }
.c-g4 { fill: oklch(0.62 0.008 160); }
.c-g5 { fill: oklch(0.75 0.01 160); }
.card-plate { font-size: 14.5px; fill: var(--raster-black); letter-spacing: 0.04em; }
.card-404 { font-size: 94px; fill: var(--phosphor); letter-spacing: 0.01em; }
.card-sub { font-size: 17px; fill: var(--raster-black); letter-spacing: 0.06em; }
.card-line { fill: none; stroke: var(--bar-white); stroke-width: 1; }
.card-ring { fill: none; stroke: var(--bar-white); stroke-width: 1.4; }

/* closed captions: each line sits on its own black box */
.captions {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0;                               /* lines butt together into one black plate over the card */
  text-align: center;
  text-wrap: balance;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.cc {
  display: inline-block;
  padding: 0.1em 0.5em 0.12em;
  background: var(--raster-black);
}
.captions__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5em;
  margin-top: 0.4em;
  transition: opacity 0.3s var(--ease-out);
}
/* a weak picture cannot be clicked, so its links give their place to the tuning hint */
.tube.is-weak .captions__links { opacity: 0; }
.picture .cc--link {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-height: 44px;
  padding-inline: 0.7em;
  text-decoration: none;
  color: var(--raster-black);
  background: var(--phosphor);
  text-shadow: none;
  transition: background-color 0.15s var(--ease-out);
}
.picture .cc--link + .cc--link {
  color: var(--phosphor);
  background: var(--raster-black);
  box-shadow: inset 0 0 0 2px var(--phosphor);
}
.picture .cc--link:hover { background: var(--bar-yellow); color: var(--raster-black); }
.cc--link .ico { width: 0.8em; height: 0.8em; stroke-width: 2.4; }

/* CH 02 to 04: teletext pages */
.page--text {
  flex-direction: column;
  gap: 0.34em;
  padding: clamp(34px, 9.5cqh, 70px) clamp(18px, 5.4cqw, 56px) clamp(12px, 4.6cqh, 36px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--phosphor-dim) transparent;
}
.page--text::-webkit-scrollbar,
.menu__list::-webkit-scrollbar { width: 8px; }
.page--text::-webkit-scrollbar-track,
.menu__list::-webkit-scrollbar-track { background: transparent; }
.page--text::-webkit-scrollbar-thumb,
.menu__list::-webkit-scrollbar-thumb { background: var(--phosphor-dim); }

.tt-head {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  color: var(--phosphor-dim);
  font-variant-numeric: tabular-nums;
}

.tt-title {
  align-self: stretch;
  margin-bottom: 0.14em;
  padding: 0.02em 0.34em 0.06em;
  font-size: 1.9em;
  font-weight: 400;
  line-height: 1;
  color: var(--raster-black);
  text-shadow: none;
  text-wrap: balance;
}
.tt-title--yellow { background: var(--bar-yellow); }
.tt-title--green { background: var(--bar-green); }
.tt-title--cyan { background: var(--bar-cyan); }

.tt-note { max-width: 62ch; text-wrap: pretty; }
.tt-note--dim { color: var(--phosphor-dim); }
.tt-note a { color: var(--bar-cyan); }
.tt-note a:hover { color: var(--phosphor); }

.tt-btn {
  flex: none;
  min-height: 44px;
  padding: 0 0.9em;
  border: 0;
  border-radius: 0;
  background: var(--phosphor);
  color: var(--raster-black);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-shadow: none;
  transition: background-color 0.15s var(--ease-out);
}
.tt-btn:hover { background: var(--bar-yellow); }
.tt-btn:active { background: var(--bar-white); }
.tt-btn[disabled] { background: var(--phosphor-dim); cursor: progress; }
.tt-btn--wide { align-self: flex-start; }

.picture input,
.picture textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.14em 0.5em;
  border: 2px solid var(--phosphor-dim);
  border-radius: 0;
  background: oklch(0 0 0 / 0.35);
  color: var(--phosphor);
  text-shadow: inherit;
  caret-color: var(--bar-yellow);
  appearance: none;
  transition: border-color 0.15s var(--ease-out);
}
.picture textarea { display: block; resize: none; line-height: 1.14; }
.picture input::placeholder,
.picture textarea::placeholder { color: oklch(0.68 0.026 150); opacity: 1; }
.picture input:hover,
.picture textarea:hover { border-color: var(--phosphor); }
.picture input:focus-visible,
.picture textarea:focus-visible { border-color: var(--bar-yellow); outline-offset: 0; }
.picture input[aria-invalid="true"],
.picture textarea[aria-invalid="true"] { border-color: var(--ink-red); }
.picture input[type="search"]::-webkit-search-cancel-button { display: none; }
/* browser autofill would paint the field pale yellow or blue; keep it on the tube */
.picture input:-webkit-autofill,
.picture input:autofill {
  -webkit-text-fill-color: var(--phosphor);
  box-shadow: inset 0 0 0 100px var(--raster-black);
  caret-color: var(--bar-yellow);
}
.picture label,
.report__label { color: var(--bar-cyan); }

/* search */
.search { display: grid; gap: 0.2em; }
.search__row { display: flex; gap: 0.4em; }
.search__row input { flex: 1; min-width: 0; }

.results { display: grid; }
.results a {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  min-height: 44px;
  padding: 0 0.3em;
  margin-inline: -0.3em;
  line-height: 44px;
  text-decoration: none;
}
.results__pg { color: var(--bar-yellow); font-variant-numeric: tabular-nums; }
.results__nm { flex: none; }
.results a::after {                     /* dotted leader between name and path */
  content: "";
  order: 1;
  flex: 1;
  min-width: 1em;
  align-self: center;
  border-bottom: 2px dotted oklch(0.76 0.03 150 / 0.55);
}
.results__path { order: 2; color: var(--phosphor-dim); }
@media (hover: hover) and (pointer: fine) {
  .results a { min-height: 41px; line-height: 41px; }      /* six rows and the fastext keys fit the tube without scrolling */
}
.results a:hover,
.results a:focus-visible {
  background: var(--phosphor);
  color: var(--raster-black);
  text-shadow: none;
  outline: none;
}
.results a:hover *, .results a:focus-visible * { color: inherit; }
.results a:hover::after, .results a:focus-visible::after { border-color: currentColor; }

/* status */
.status { display: grid; gap: 0.04em; margin-block: 0.1em 0.3em; }
.status > div { display: flex; align-items: baseline; gap: 0.6em; }
.status dt { flex: none; }
.status > div::after {
  content: "";
  order: 1;
  flex: 1;
  min-width: 1em;
  align-self: center;
  border-bottom: 2px dotted oklch(0.76 0.03 150 / 0.55);
}
.status dd { order: 2; text-transform: uppercase; }
.status .is-up { color: var(--bar-green); }
.status .is-down { color: var(--raster-black); background: var(--ink-red); padding: 0 0.34em; text-shadow: none; }

/* contact */
.report { display: grid; gap: 0.3em; }
.report__addr { display: flex; align-items: center; gap: 0.5em; min-width: 0; color: var(--phosphor-dim); white-space: nowrap; }
.report__addr-k { flex: none; }
.report__addr-v { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--phosphor); }
.report__pair { display: grid; gap: 0.3em 0.8em; }
@container (min-width: 620px) {
  .report__pair { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}
.report__actions { display: flex; flex-wrap: wrap; gap: 0.4em; margin-top: 0.14em; }
.report__field { display: grid; gap: 0.06em; }
.report__err { color: var(--ink-red); }
.report__err--form { padding: 0.1em 0.4em; color: var(--raster-black); background: var(--ink-red); text-shadow: none; }
.report.is-sending [data-report-label]::after {
  content: "...";
  display: inline-block;
  width: 3ch;
  text-align: left;
  animation: dots 0.9s steps(4, jump-none) infinite;
  clip-path: inset(0 0 0 0);
}
@keyframes dots {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}
.report-done { display: grid; gap: 0.4em; justify-items: start; max-width: 54ch; outline: none; }
.report-done[hidden], .report[hidden], .report__err[hidden] { display: none; }
.report-done__big { font-size: 1.5em; line-height: 1; color: var(--bar-green); text-transform: uppercase; }

/* fastext: the four coloured keys along the bottom of a teletext page */
.fastext {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex: none;
  margin-top: auto;
  text-transform: uppercase;
}
.fx {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 0.3em;
  text-decoration: none;
  text-shadow: none;
  background: var(--fx);
  box-shadow: inset 0 0 0 2px var(--fx);
  transition: background-color 0.15s var(--ease-out), color 0.15s var(--ease-out);
}
.picture a.fx { color: var(--raster-black); }
.fx--red { --fx: var(--ink-red); }
.fx--green { --fx: var(--bar-green); }
.fx--yellow { --fx: var(--bar-yellow); }
.fx--cyan { --fx: var(--bar-cyan); }
/* the page you are on is the key that is pressed in: black, lettered in its own colour */
.picture a.fx[aria-current="page"] { background: var(--raster-black); color: var(--fx); }
.picture a.fx:hover { background: var(--phosphor); color: var(--raster-black); }

/* on-screen display */
.osd {
  position: absolute;
  inset: 0;
  font-family: "VT323", ui-monospace, monospace;
  font-size: clamp(19px, 3.3cqw, 34px);
  line-height: 1.1;
  color: var(--bar-green);
  text-shadow: 0 0 0.4em oklch(0.775 0.115 150 / 0.55);
  pointer-events: none;
}
html:not(.js) .osd { display: none; }
.osd p { position: absolute; display: flex; align-items: center; transition: opacity 0.5s var(--ease-out); }
.osd p > span { padding: 0 0.34em; background: oklch(0 0 0 / 0.78); white-space: nowrap; }
.osd__ch { top: clamp(10px, 4cqh, 30px); left: clamp(16px, 5cqw, 52px); gap: 0; }
.osd__ch span + span { padding-left: 0.1em; }
.osd__sig { top: clamp(10px, 4cqh, 30px); right: clamp(16px, 5cqw, 52px); }
.osd p > .osd__meter {
  position: relative;
  width: 4.4em;
  height: 1.1em;
  padding: 0;
}
.osd__meter::before,
.osd__meter::after {
  content: "";
  position: absolute;
  left: 0.3em;
  top: 50%;
  width: 3.8em;
  height: 0.56em;
  translate: 0 -50%;
}
.osd__meter::before {
  background: linear-gradient(90deg, var(--bar-green) calc(var(--tune) * 1%), oklch(0.775 0.115 150 / 0.24) 0);
}
.osd__meter::after {                      /* notches that cut the bar into ten steps */
  background: repeating-linear-gradient(90deg, transparent 0 0.3em, oklch(0 0 0) 0.3em 0.38em);
}
.osd__hint { left: 0; right: 0; bottom: clamp(14px, 7cqh, 54px); justify-content: center; opacity: 0; }
.tube.is-weak .osd__hint { opacity: 1; animation: blink 1.6s steps(1, end) infinite; }
@keyframes blink { 62% { visibility: hidden; } }
.tube.is-osd-off .osd__ch,
.tube.is-osd-off .osd__sig { opacity: 0; }


/* ==========================================================================
   3b. Components
   Everything a browser would normally draw for you, drawn by the set instead.
   All of it runs on the tokens above, so a re-coloured set re-colours the kit.
     .tt-btn (+ --ghost, --red, .tt-chip)   buttons
     .pick + .menu                           select: a field that opens the on-screen menu
     .confirm                                confirmation dialog
     .notice                                 notice (toast) in the on-screen display
   ========================================================================== */

/* shared type for anything the set draws over the picture */
.menu, .confirm, .notice {
  font-family: "VT323", ui-monospace, "Courier New", monospace;
  font-size: clamp(19px, 3.3cqw, 34px);
  line-height: 1.14;
  color: var(--phosphor);
}
.menu :focus-visible,
.confirm :focus-visible {
  outline: 2px solid var(--bar-yellow);
  outline-offset: 2px;
}

/* buttons */
.tt-btn--ghost {
  background: var(--raster-black);
  color: var(--phosphor);
  box-shadow: inset 0 0 0 2px var(--phosphor);
}
.tt-btn--ghost:hover { background: var(--phosphor); color: var(--raster-black); }
.tt-btn--red { background: var(--ink-red); }
.tt-btn--red:hover { background: var(--bar-yellow); }
.tt-chip {
  position: relative;
  flex: none;
  min-height: 28px;
  padding: 0 0.4em;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--bar-cyan);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow: inset 0 0 0 2px currentColor;
  transition: background-color 0.15s var(--ease-out), color 0.15s var(--ease-out);
}
.tt-chip::after { content: ""; position: absolute; inset: -9px -6px; }     /* a finger-sized target round a small key */
.tt-chip:hover { background: var(--bar-cyan); color: var(--raster-black); text-shadow: none; box-shadow: none; }

/* select, closed: a field with the current value and a stepped arrow */
.pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  width: 100%;
  min-height: 44px;
  padding: 0.14em 0.5em;
  border: 2px solid var(--phosphor-dim);
  border-radius: 0;
  background: oklch(0 0 0 / 0.35);
  color: var(--phosphor);
  text-align: left;
  text-shadow: inherit;
  transition: border-color 0.15s var(--ease-out), background-color 0.15s var(--ease-out), color 0.15s var(--ease-out);
}
.pick__value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick__arrow { flex: none; width: 0.6em; height: 0.4em; fill: var(--bar-cyan); shape-rendering: crispEdges; }
.pick:hover { border-color: var(--phosphor); }
.picture .pick:focus-visible { border-color: var(--bar-yellow); outline-offset: 0; }
.pick[aria-expanded="true"] { background: var(--bar-cyan); border-color: var(--bar-cyan); color: var(--raster-black); text-shadow: none; }
.pick[aria-expanded="true"] .pick__arrow { fill: currentColor; }

/* select, open: the set's menu, centred on the tube so it can never be clipped */
.menu, .confirm {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(30px, 8cqh, 60px) clamp(16px, 6cqw, 64px) clamp(14px, 6cqh, 48px);
  /* themed backdrop: the picture drops to a dark, coarse interlace */
  background:
    repeating-linear-gradient(to bottom, oklch(0 0 0 / 0.5) 0 2px, transparent 2px 4px),
    oklch(0.085 0.006 200 / 0.74);
}
.menu[hidden], .confirm[hidden], .notice[hidden] { display: none; }

.menu__box, .confirm__box {
  display: flex;
  flex-direction: column;
  width: min(100%, 21em);
  max-height: 100%;
  background: var(--raster-black);
  box-shadow: 0 0 0 2px var(--raster-black), 0 0 0 4px var(--phosphor), 0 0 2.4em oklch(0.955 0.028 150 / 0.16);
  outline: none;
  animation: unfold 0.22s steps(5, jump-none) both;
}
.is-closing .menu__box, .is-closing .confirm__box { animation: fold 0.12s steps(3, jump-none) both; }
.menu.is-closing, .confirm.is-closing { background: none; }
/* the box paints from the middle line outward, in steps, the way a tube draws */
@keyframes unfold {
  from { clip-path: inset(50% -1em); }
  to { clip-path: inset(-1em -1em); }
}
@keyframes fold {
  from { clip-path: inset(-1em -1em); }
  to { clip-path: inset(50% -1em); }
}

.menu__title {
  flex: none;
  padding: 0.06em 0.5em 0.1em;
  background: var(--bar-cyan);
  color: var(--raster-black);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.menu__list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--phosphor-dim) transparent;
}
.menu__list [role="option"] {
  display: flex;
  align-items: center;
  gap: 0.6em;
  min-height: 44px;
  padding: 0 0.5em;
  cursor: pointer;
}
.menu__n { flex: none; color: var(--bar-yellow); font-variant-numeric: tabular-nums; }
.menu__t { flex: 1; min-width: 0; }
/* the chosen row carries a solid block, the mark a teletext page uses */
.menu__tick { flex: none; width: 0.5em; height: 0.62em; }
[role="option"][aria-selected="true"] .menu__tick { background: var(--bar-green); }
/* the row under the cursor is in reverse video */
.menu__list [role="option"].is-active { background: var(--phosphor); color: var(--raster-black); }
.menu__list [role="option"].is-active .menu__n { color: inherit; }
.menu__list [role="option"].is-active .menu__tick { background: var(--raster-black); opacity: 0; }
.menu__list [role="option"].is-active[aria-selected="true"] .menu__tick { opacity: 1; }
.menu__foot {
  flex: none;
  padding: 0.1em 0.5em 0.14em;
  border-top: 2px solid var(--phosphor-dim);
  color: var(--phosphor-dim);
  font-size: 0.8em;
}
@media (hover: none), (pointer: coarse) { .menu__foot { display: none; } }
@container (max-height: 420px) {
  .menu__foot { display: none; }
  .menu__list [role="option"] { min-height: 40px; }
}

/* confirmation: a boxed teletext flash with the question on a red plate */
.confirm__box { width: min(100%, 19em); gap: 0.5em; padding-bottom: 0.6em; overflow-y: auto; scrollbar-width: none; }
.confirm__title {
  margin: 0;
  padding: 0.04em 0.4em 0.08em;
  background: var(--ink-red);
  color: var(--raster-black);
  font-size: 1.5em;
  font-weight: 400;
  line-height: 1;
  text-wrap: balance;
}
.confirm__text { padding: 0 0.6em; text-wrap: pretty; }
.confirm__actions { display: flex; flex-wrap: wrap; gap: 0.4em; padding: 0.1em 0.6em 0; }
.confirm__actions .tt-btn { flex: 1 1 auto; }

/* notice: a reverse-video status line, on the bottom row of the screen where teletext puts its messages */
.notice {
  position: absolute;
  left: 0; right: 0;
  bottom: clamp(12px, 4.6cqh, 36px);
  display: flex;
  padding: 0 clamp(18px, 5.4cqw, 56px);
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.notice > span {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.1em 0.7em;
  background: var(--bar-green);
  color: var(--raster-black);
  box-shadow: 0 0 0 2px var(--raster-black), 0 0 1.6em oklch(0.775 0.115 150 / 0.35);
  text-align: center;
  text-wrap: balance;
  animation: wipe-in 0.26s steps(6, jump-none) both;
}
.notice[data-tone="warn"] > span { background: var(--ink-red); box-shadow: 0 0 0 2px var(--raster-black), 0 0 1.6em oklch(0.74 0.13 30 / 0.35); }
.notice.is-closing > span { animation: wipe-out 0.18s steps(4, jump-none) both; }
@keyframes wipe-in {
  from { clip-path: inset(-4px 100% -4px -4px); }
  to { clip-path: inset(-4px -4px -4px -4px); }
}
@keyframes wipe-out {
  from { clip-path: inset(-4px -4px -4px -4px); }
  to { clip-path: inset(-4px -4px -4px 100%); }
}
/* while the set is showing a menu or a question, the tuning hint keeps out of the way */
.tube.is-overlaid .osd__hint { opacity: 0; animation: none; }

/* ---------- 4. The control panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--u) * 2.2);
  min-width: 0;
  padding: calc(var(--u) * 2.4) calc(var(--u) * 2.4) calc(var(--u) * 1.8);
  border-radius: calc(var(--u) * 2.2);
  background:
    repeating-linear-gradient(to bottom, oklch(1 0 0 / 0.024) 0 1px, transparent 1px 3px),
    linear-gradient(178deg, var(--cab-3), var(--cab-4) 40%, oklch(0.125 0.005 255));
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.1),
    inset 0 0 0 1px oklch(0 0 0 / 0.6),
    inset 0 calc(var(--u) * 0.6) calc(var(--u) * 1.4) oklch(0 0 0 / 0.45),
    0 1px 0 1px oklch(1 0 0 / 0.14);
  font-size: max(12px, calc(var(--u) * 1.42));
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.grille {
  flex: 1;
  width: 100%;
  min-height: calc(var(--u) * 6);
  border-radius: calc(var(--u) * 1);
  background:
    radial-gradient(circle at 50% 44%, oklch(0.03 0 0) 0 32%, oklch(1 0 0 / 0.07) 39%, transparent 46%)
    50% 50% / calc(var(--u) * 1.5) calc(var(--u) * 1.5);
}

/* tuning dial */
.tuner {
  position: relative;
  flex: none;
  width: calc(var(--u) * 27);
  height: calc(var(--u) * 26.4);
}
.dial {
  position: absolute;
  inset: 0 calc(var(--u) * 0.5) auto;
  height: calc(var(--u) * 26);
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.dial.is-dragging { cursor: grabbing; }

.dial__scale,
.dial__lit,
.dial__scale::before,
.dial__lit::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
}
/* 31 fine ticks over 270 degrees, cut into a ring */
.dial__scale,
.dial__lit {
  background: repeating-conic-gradient(from -135.5deg, var(--tick) 0 1deg, transparent 1deg 9deg);
  -webkit-mask:
    radial-gradient(closest-side, transparent 89%, #000 89.6% 98.4%, transparent 99%),
    conic-gradient(from -136deg, #000 0 272deg, transparent 272deg);
  -webkit-mask-composite: source-in;
  mask:
    radial-gradient(closest-side, transparent 89%, #000 89.6% 98.4%, transparent 99%),
    conic-gradient(from -136deg, #000 0 272deg, transparent 272deg);
  mask-composite: intersect;
}
/* seven long ticks */
.dial__scale::before,
.dial__lit::before {
  background: repeating-conic-gradient(from -135.8deg, var(--tick) 0 1.6deg, transparent 1.6deg 45deg);
  -webkit-mask:
    radial-gradient(closest-side, transparent 83%, #000 83.6% 98.4%, transparent 99%),
    conic-gradient(from -136deg, #000 0 272deg, transparent 272deg);
  -webkit-mask-composite: source-in;
  mask:
    radial-gradient(closest-side, transparent 83%, #000 83.6% 98.4%, transparent 99%),
    conic-gradient(from -136deg, #000 0 272deg, transparent 272deg);
  mask-composite: intersect;
}
/* the lit copy is revealed up to the pointer */
.dial__lit {
  --tick: var(--phosphor);
  -webkit-mask:
    radial-gradient(closest-side, transparent 83%, #000 83.6% 98.4%, transparent 99%),
    conic-gradient(from -136deg, #000 0 calc(var(--tune) * 2.7deg + 1.8deg), transparent 0);
  -webkit-mask-composite: source-in;
  mask:
    radial-gradient(closest-side, transparent 83%, #000 83.6% 98.4%, transparent 99%),
    conic-gradient(from -136deg, #000 0 calc(var(--tune) * 2.7deg + 1.8deg), transparent 0);
  mask-composite: intersect;
  background:
    repeating-conic-gradient(from -135.8deg, var(--tick) 0 1.6deg, transparent 1.6deg 45deg),
    repeating-conic-gradient(from -135.5deg, var(--tick) 0 1deg, transparent 1deg 9deg);
  filter: drop-shadow(0 0 calc(var(--u) * 0.4) oklch(0.955 0.028 150 / 0.5));
  transition: opacity 0.4s var(--ease-out);
}
.dial__lit::before { content: none; }
.dial__knob {
  position: absolute;
  inset: 17.5%;
  border-radius: 50%;
  background: linear-gradient(168deg, var(--cab-1), var(--cab-3) 55%, var(--cab-4));
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.22),
    0 calc(var(--u) * 0.3) calc(var(--u) * 0.5) oklch(0 0 0 / 0.8),
    0 calc(var(--u) * 1.5) calc(var(--u) * 2.4) oklch(0 0 0 / 0.62);
}
/* spun face of the cap */
.dial__knob::before {
  content: "";
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background:
    conic-gradient(from 28deg,
      oklch(1 0 0 / 0.1), oklch(0 0 0 / 0.22) 22%, oklch(1 0 0 / 0.07) 46%,
      oklch(0 0 0 / 0.26) 70%, oklch(1 0 0 / 0.1)),
    var(--cab-3);
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.14), inset 0 -1px 2px oklch(0 0 0 / 0.5), 0 0 0 1px oklch(0 0 0 / 0.55);
}
.dial__grip {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transform: rotate(calc(-135deg + var(--tune) * 2.7deg));
}
/* knurled rim */
.dial__grip::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(oklch(1 0 0 / 0.12) 0 2deg, oklch(0 0 0 / 0.42) 2deg 5deg);
  -webkit-mask: radial-gradient(closest-side, transparent 84%, #000 85.5%);
  mask: radial-gradient(closest-side, transparent 84%, #000 85.5%);
}
/* pointer */
.dial__grip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 4%;
  width: max(3px, calc(var(--u) * 0.46));
  height: 25%;
  border-radius: 99px;
  background: var(--phosphor);
  box-shadow: 0 0 calc(var(--u) * 0.7) oklch(0.955 0.028 150 / 0.55);
  translate: -50% 0;
}

.tuner__end,
.tuner__name {
  position: absolute;
  bottom: 0;
  line-height: 1;
  color: var(--legend-dim);
}
.tuner__end--lo { left: 0; }
.tuner__end--hi { right: 0; }
.tuner__name { left: 50%; translate: -50% 0; color: var(--legend); bottom: calc(var(--u) * 1.6); }

/* auto tune */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  flex: none;
  min-height: max(36px, calc(var(--u) * 4.8));
  padding: 0 1.3em 0 1em;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(176deg, var(--cab-1), var(--cab-3));
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.2),
    0 0 0 1px var(--seam),
    0 calc(var(--u) * 0.5) calc(var(--u) * 0.9) oklch(0 0 0 / 0.55);
  font-weight: 500;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--legend);
  transition: color 0.2s var(--ease-out), transform 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out);
}
.pill:hover { color: var(--phosphor); }
.pill:active,
.pill.is-busy {
  transform: translateY(1px);
  box-shadow: inset 0 1px 3px oklch(0 0 0 / 0.7), 0 0 0 1px var(--seam);
}
.pill.is-busy .ico { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* channel keys, set into a well */
.keys {
  display: grid;
  gap: calc(var(--u) * 0.5);
  width: 100%;
  padding: calc(var(--u) * 0.6);
  border-radius: calc(var(--u) * 1.3);
  background: oklch(0.05 0.004 255);
  box-shadow: inset 0 2px 5px oklch(0 0 0 / 0.9), 0 1px 0 oklch(1 0 0 / 0.08);
}
.key {
  display: grid;
  grid-template-columns: 1.6em 1fr auto;
  align-items: center;
  gap: 0.5em;
  min-height: max(40px, calc(var(--u) * 5.5));
  padding: 0 calc(var(--u) * 1.5);
  border-radius: calc(var(--u) * 0.8);
  background: linear-gradient(178deg, var(--cab-1), var(--cab-2) 60%, var(--cab-3));
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.2),
    inset 0 -2px 3px oklch(0 0 0 / 0.38),
    0 2px 4px oklch(0 0 0 / 0.6);
  color: var(--legend);
  text-decoration: none;
  transition: transform 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out), background-color 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.key__n { font-size: 1.55em; font-weight: 600; letter-spacing: 0; line-height: 1; font-variant-numeric: tabular-nums; }
.key__lamp {
  width: calc(var(--u) * 0.9);
  height: calc(var(--u) * 0.9);
  min-width: 6px; min-height: 6px;
  border-radius: 50%;
  background: oklch(0.1 0.004 255);
  box-shadow: inset 0 1px 1px oklch(0 0 0 / 0.9), 0 1px 0 oklch(1 0 0 / 0.1);
  transition: background-color 0.2s, box-shadow 0.2s;
}
.key:hover { color: var(--phosphor); }
.key:active,
.key[aria-current="true"] {
  transform: translateY(1.5px);
  background: linear-gradient(178deg, var(--cab-3), var(--cab-3) 60%, var(--cab-2));
  box-shadow: inset 0 2px 4px oklch(0 0 0 / 0.75), inset 0 -1px 0 oklch(1 0 0 / 0.06);
}
.key[aria-current="true"] { color: var(--phosphor); }
.key[aria-current="true"] .key__lamp {
  background: var(--phosphor);
  box-shadow: 0 0 calc(var(--u) * 0.9) oklch(0.955 0.028 150 / 0.7);
}

/* sound and power */
.switches {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  padding: 0 calc(var(--u) * 1.6);
}
.round {
  display: grid;
  justify-items: center;
  gap: calc(var(--u) * 0.9);
  padding: 0;
  border: 0;
  background: none;
  font-weight: 500;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--legend);
  -webkit-tap-highlight-color: transparent;
}
.round__cap {
  display: grid;
  place-items: center;
  width: max(44px, calc(var(--u) * 6.2));
  height: max(44px, calc(var(--u) * 6.2));
  border-radius: 50%;
  background: linear-gradient(170deg, var(--cab-1), var(--cab-3) 70%);
  box-shadow:
    inset 0 1px 0 oklch(1 0 0 / 0.22),
    0 0 0 1px var(--seam),
    0 0 0 calc(var(--u) * 0.45) oklch(0.07 0.004 255),
    0 calc(var(--u) * 0.5) 0 calc(var(--u) * 0.45) oklch(1 0 0 / 0.05),
    0 calc(var(--u) * 0.8) calc(var(--u) * 1.2) oklch(0 0 0 / 0.5);
  font-size: max(15px, calc(var(--u) * 2));
  color: var(--legend-dim);
  transition: transform 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out), color 0.2s;
}
.round:hover .round__cap { color: var(--phosphor); }
.round:active .round__cap,
.round[aria-pressed="true"] .round__cap {
  transform: translateY(1px);
  background: linear-gradient(170deg, var(--cab-2), var(--cab-3) 70%);
  box-shadow:
    inset 0 2px 4px oklch(0 0 0 / 0.7),
    0 0 0 1px var(--seam),
    0 0 0 calc(var(--u) * 0.45) oklch(0.07 0.004 255),
    0 calc(var(--u) * 0.5) 0 calc(var(--u) * 0.45) oklch(1 0 0 / 0.05);
}
.round[aria-pressed="true"] .round__cap { color: var(--phosphor); }
.round__label { display: inline-flex; align-items: center; gap: 0.55em; line-height: 1; white-space: nowrap; }
.round__label b { font-weight: 500; color: var(--legend-dim); }
.round[aria-pressed="true"] .round__label b { color: var(--phosphor); }
.round[aria-pressed="false"] .snd-on,
.round[aria-pressed="true"] .snd-off { display: none; }

.led {
  width: calc(var(--u) * 0.95);
  height: calc(var(--u) * 0.95);
  min-width: 7px; min-height: 7px;
  border-radius: 50%;
  background: oklch(0.2 0.03 30);
  box-shadow: inset 0 1px 1px oklch(0 0 0 / 0.8), 0 1px 0 oklch(1 0 0 / 0.1);
  transition: background-color 0.25s, box-shadow 0.25s;
}
.round[aria-pressed="true"] .led {
  background: radial-gradient(circle at 40% 35%, oklch(0.86 0.13 45), var(--power-red) 55%);
  box-shadow: 0 0 calc(var(--u) * 0.5) 1px oklch(0.69 0.215 33 / 0.75), 0 0 calc(var(--u) * 2) oklch(0.69 0.215 33 / 0.45);
}

.legend span { display: block; }
.legend {
  font-size: max(12px, calc(var(--u) * 1.4));
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  text-align: center;
  text-wrap: balance;
  color: var(--legend-dim);
}

html:not(.js) [data-needs-js] { display: none; }
@media (pointer: coarse) {
  .pill, .key { min-height: 44px; }
}
@media (hover: none), (pointer: coarse) {
  .legend { display: none; }
}

/* short or narrow desktop windows: the panel sheds its grille and small print */
@media (max-height: 800px), (max-width: 1180px) {
  .panel { justify-content: space-between; }
  .grille, .legend { display: none; }
}
@media (max-height: 700px), (max-width: 1080px) {
  .tuner__name { display: none; }
  .switches { padding-inline: 0; }
}

/* ---------- 5. Stacked layout: tablets upright, phones ---------- */

@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  :root { --u: clamp(7.2px, 1.95vw, 10px); }

  .room { padding: 8px 8px 60px; }
  .set { width: min(100%, 860px); }
  .set::before { inset: -60px -8px 30%; }
  .set::after { --shelf-top: 20px; }

  .cabinet {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    height: auto;
    padding: 10px;
    border-radius: 26px;
  }
  .bezel { padding: 10px 10px 0; border-radius: 19px; }
  .mask { padding: 7px; border-radius: 34px / 36px; }
  .mask::before { inset: 9px; }
  /* 4:3 where there is room; on a shorter window the tube gives up height so the set stays in view */
  .tube { width: 100%; height: auto; aspect-ratio: 4 / 3; max-height: max(300px, calc(100svh - 384px)); }
  .chin { height: 38px; padding: 0 8px; }
  .feet { padding: 0 44px; }
  .feet i { width: 70px; height: 9px; }

  .panel {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "tuner keys side";
    align-items: center;
    gap: 22px;
    padding: 18px 22px;
    border-radius: 17px;
    font-size: 12px;
  }
  .tuner__name { display: revert; }
  .tuner { grid-area: tuner; width: 176px; height: 172px; }
  .dial { inset: 0 3px auto; height: 170px; }
  .tuner__name { bottom: 10px; }
  .keys { grid-area: keys; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 5px; padding: 5px; border-radius: 12px; }
  .key { min-height: 56px; padding: 0 14px; border-radius: 8px; }
  .panel > .pill, .switches { grid-area: side; }
  .panel > .pill { align-self: start; min-height: 44px; }
  .switches { align-self: end; gap: 22px; padding: 0 4px 2px; }
  .round { gap: 9px; }
  .round__cap { width: 50px; height: 50px; font-size: 17px; }
}

@media (max-width: 600px) {
  .room { padding: 6px 8px 52px; }
  .feet i { height: 6px; }
  /* the tube is upright on a tall phone and gives up height on a short one, so the whole set stays in view */
  .tube { aspect-ratio: 5 / 7; max-height: max(232px, calc(100svh - var(--set-chrome))); }
  .set { --set-chrome: 398px; --dial: 148px; }
  .page--card { padding: 0 3cqw 18px; --card: min(94cqw, 100cqh - 96px); --side: 0px; }
  .card { top: max(30px, (100cqh - 132px - var(--card)) / 2 + 30px); }
  /* the keys under the screen change channel, so the report page spends that row on the form */
  #ch-4 .fastext { display: none; }
  .tt-roomy { display: none; }
  .captions { letter-spacing: 0; }
  .cc { padding-inline: 0.36em; }
  .captions__links { gap: 8px; margin-top: 6px; }
  .picture .cc--link { padding-inline: 0.55em; }
  .tt-title { font-size: 1.6em; }
  .search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .page--text { gap: 0.3em; padding-top: 36px; }
  .chin__model { display: none; }
  .chin { justify-content: center; height: 30px; }

  .panel {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "keys keys"
      "tuner side";
    gap: 12px 12px;
    padding: 10px 10px 12px;
    font-size: 12px;
  }
  .keys { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .key {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 5px;
    min-height: 54px;
    padding: 8px 2px 7px;
    font-size: 12px;
    letter-spacing: 0.04em;
  }
  .key__n { font-size: 18px; }
  .key__lamp { position: absolute; }
  .key { position: relative; }
  .key__lamp { top: 7px; right: 7px; width: 6px; height: 6px; }
  .tuner { width: calc(var(--dial) + 4px); height: calc(var(--dial) + 2px); }
  .tuner__name { display: none; }        /* no room between Static and Clear at this size; the dial keeps its accessible name */
  .dial { inset: 0 2px auto; height: var(--dial); }
  .panel > .pill { justify-self: stretch; margin-top: 4px; }
  .switches { justify-content: space-around; gap: 8px; padding: 0 0 4px; }
}

/* short phones: a smaller dial and shallower keys buy the tube some height */
@media (max-width: 600px) and (max-height: 760px) {
  .set { --set-chrome: 358px; --dial: 116px; }
  .key { min-height: 48px; padding-block: 6px 5px; gap: 3px; }
  .panel { gap: 10px 12px; }
  .panel > .pill { margin-top: 0; }
  .round { gap: 7px; }
  .round__cap { width: 46px; height: 46px; }
}
/* a squat tube: each page keeps only what it needs, and the keys under the screen stand in for the fastext row */
@container (max-height: 400px) {
  .page--card .captions p:nth-child(2) { display: none; }
  .page--card { --card: min(94cqw, 100cqh - 60px); }
  .page--text { gap: 0.16em; padding-top: 36px; padding-bottom: 10px; }
  .status { gap: 0; margin-block: 0 0.1em; }
  .tt-head, .fastext, .report__addr, .tt-note--dim { display: none; }
  .tt-title { font-size: 1.3em; }
  .picture textarea { height: 44px; white-space: nowrap; overflow: hidden; }
  /* the two short fields speak for themselves here; their labels stay for screen readers */
  .report { gap: 0.2em; }
  .report__pair .report__label,
  .report__pair label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: no-preference) {
  .set[data-power="on"] .raster::after {    /* a faint mains flicker over the whole raster */
    content: "";
    position: absolute;
    inset: 0;
    background: oklch(0 0 0);
    opacity: 0;
    pointer-events: none;
    animation: flicker 0.26s steps(2, jump-none) infinite;
  }
  @keyframes flicker { to { opacity: 0.035; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
  .rollbar { display: none; }
  .tube.is-weak .osd__hint { visibility: visible; }
}
