/* ---------------------------------------------------------------------------
   Channel 28, Day 28/30.

   This is an object in a room, not a page. A walnut console television from
   about 1974, standing in the dark, showing you. Everything on screen belongs
   to the set: there is no page chrome, no header, no card. The only element
   that is not part of the television is the day mark in the corner, which runs
   through all thirty builds.

   One accent colour: amber. It is the pilot lamp, it is the knobs, and it is
   the one button. Nothing else is allowed to be colourful, because the picture
   tube is the colourful thing and it has to win.

   Corner radii are locked to three values and never improvised:
     cabinet 16px, tube 8% of its own width, controls 6px.
   Knobs are round because knobs are round.
   --------------------------------------------------------------------------- */

:root {
  /* The room */
  --void:        #0C0A09;   /* the corners, warm near-black, never #000 */
  --floor:       #171210;   /* where the lamp reaches */

  /* The cabinet */
  --walnut-lit:  #6B4227;
  --walnut:      #4A2D1B;
  --walnut-deep: #2E1C12;
  --walnut-edge: #201206;

  /* The bevel and the plate */
  --brass:       #A98C4B;
  --brass-lit:   #DCC189;
  --brass-deep:  #4E3D1E;

  /* The one accent */
  --amber:       #E8A33D;
  --amber-deep:  #8A5B18;
  --on-amber:    #1A1005;   /* 7.8:1 on --amber */

  /* Type on the set */
  --bone:        #EDE6D8;
  --tube-off:    #090B0A;

  --display: "Archivo", ui-sans-serif, system-ui, "Helvetica Neue", Arial, sans-serif;
  --label:   "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Exponential ease-out. One curve for the whole set. */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

/* .btn sets display:inline-flex, which outranks the user agent's [hidden] rule
   and left the button on screen in every state that asks for it to be gone. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--bone);
  font-family: var(--display);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

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

/* ---------------------------------------------------------------------------
   The room. One lamp, low and behind the set, so the cabinet has something to
   stand against. Without it the walnut floats on black and reads as a graphic
   rather than as furniture.
   --------------------------------------------------------------------------- */

.room {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 78% at 50% 108%, var(--floor) 0%, transparent 62%),
    radial-gradient(70% 46% at 50% 6%, #1B1512 0%, transparent 70%),
    var(--void);
  pointer-events: none;
}

/* ---------------------------------------------------------------------------
   The set.

   Width is the driver. Everything inside is a percentage of it, so the whole
   television scales as one object and the proportions never drift. The cabinet
   works out roughly square once the fascia is added, which is what a console
   of this era actually looked like: a big face, a small picture.
   --------------------------------------------------------------------------- */

.set {
  position: relative;
  z-index: 1;
  /* Measured across five viewports: the assembled cabinet stands between 0.873
     and 0.903 of its own width tall, so the divisor is the tallest of those
     with a little over. It only binds when the viewport is short, and being
     wrong in that direction clips the fascia off the bottom of a phone.
     The second and third declarations are the same rule in dvh for browsers
     that have it, so an iOS address bar sliding away cannot clip the set. */
  width: min(96vw, 720px);
  width: min(96vw, 720px, (100vh - 3rem) / 0.91);
  width: min(96vw, 720px, (100dvh - 3rem) / 0.91);
}

/* Either note under the cabinet adds a line or two to the set, and measured in
   landscape that was enough to push the fascia four pixels off the bottom of
   the screen. The budget is a different number when a note is standing, so it
   is stated as a different number rather than padded for a case that is
   usually not there. */
body[data-note="on"] .set {
  width: min(96vw, 720px, (100vh - 3rem) / 0.98);
  width: min(96vw, 720px, (100dvh - 3rem) / 0.98);
  /* An object photographed on a surface sits above centre, with more floor
     below it than ceiling above. */
  margin-bottom: 4vh;
}

.cabinet {
  position: relative;
  padding: 3.4% 3.4% 0;
  border-radius: 16px;
  background:
    /* fine grain, running slightly off true so it reads as sliced veneer */
    repeating-linear-gradient(93deg,  rgb(0 0 0 / 0.26) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(88deg,  rgb(255 226 190 / 0.05) 0 1px, transparent 1px 7px),
    /* the wide figure of the grain */
    repeating-linear-gradient(91.5deg, rgb(0 0 0 / 0.15) 0 6px, transparent 6px 24px),
    /* the light falling across the cabinet, top left to bottom right */
    linear-gradient(163deg, var(--walnut-lit) 0%, var(--walnut) 34%, #35200F 76%, var(--walnut-edge) 100%);
  box-shadow:
    inset 0 1px 0 rgb(255 224 186 / 0.20),
    inset 0 -1px 0 rgb(0 0 0 / 0.55),
    0 2px 1px rgb(0 0 0 / 0.5),
    0 30px 60px -20px rgb(0 0 0 / 0.85);
}

/* The tube is sunk into the cabinet face. The inner shadow is the depth. */
.well {
  border-radius: 10px;
  padding: 1.1%;
  background: #1A0F06;
  box-shadow:
    inset 0 3px 7px rgb(0 0 0 / 0.85),
    inset 0 -1px 0 rgb(255 220 180 / 0.09);
}

/* Brass, catching the lamp on two edges only. A ring lit evenly all the way
   round is a stroke, not a bevel. */
.bevel {
  padding: 1.3%;
  border-radius: 9px;
  background: conic-gradient(from 218deg,
    var(--brass-deep) 0%, var(--brass-lit) 11%, var(--brass) 25%,
    #3E3117 48%, #806A33 64%, var(--brass-lit) 79%, var(--brass-deep) 100%);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.55);
}

/* ---------------------------------------------------------------------------
   The tube face.
   --------------------------------------------------------------------------- */

.glass {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 8%  / 10%;
  overflow: hidden;
  background: var(--tube-off);
  isolation: isolate;
}

#tube,
#feed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#feed {
  object-fit: cover;
  transform: scaleX(-1);   /* a self view is a mirror, or it reads as wrong */
  visibility: hidden;
}

/* The shader mirrors the front camera and leaves the back one alone. With no
   shader the video element is doing the mirroring, so it has to be told the
   same thing: a rear camera is a window, and a window is not flipped. */
body[data-cam="back"] #feed { transform: none; }

/* If WebGL never started, the video element takes the tube's place and the
   canvas steps aside. An unfiltered picture beats a black rectangle. */
body[data-gl="off"] #tube      { display: none; }
body[data-gl="off"][data-state="live"] #feed { visibility: visible; }

/* Static, for the states where there is nothing to show and no shader to draw
   it with. Fractal noise, not a gradient: a real tube's snow has no direction. */
.snow {
  position: absolute;
  inset: -20%;
  z-index: 1;
  opacity: 0;
  background-image: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'>\
<filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/>\
<feColorMatrix type='saturate' values='0'/></filter>\
<rect width='140' height='140' filter='url(%23n)' opacity='0.95'/></svg>");
  background-size: 180px 180px;
  pointer-events: none;
}

body[data-gl="off"]:not([data-state="live"]) .snow { opacity: 0.9; }

@media (prefers-reduced-motion: no-preference) {
  body[data-gl="off"]:not([data-state="live"]) .snow {
    animation: hiss 0.5s steps(6) infinite;
  }
  @keyframes hiss {
    0%   { transform: translate3d(0, 0, 0); }
    20%  { transform: translate3d(-7%, 4%, 0); }
    40%  { transform: translate3d(5%, -6%, 0); }
    60%  { transform: translate3d(-4%, -3%, 0); }
    80%  { transform: translate3d(6%, 5%, 0); }
    100% { transform: translate3d(0, 0, 0); }
  }
}

/* ---------------------------------------------------------------------------
   The tally light.

   This is the one place the set is allowed a second colour. The palette is
   amber and only amber, but a recording indicator that shares its colour with
   every other lit thing on the fascia is not an indicator, and mistaking
   "recording" for "not recording" is the one mistake here with a consequence.
   So the dot is red, and nothing else ever is: the numerals stay amber, which
   keeps the red a signal rather than a text colour.
   --------------------------------------------------------------------------- */

.tally {
  position: absolute;
  z-index: 2;
  top: 8%;
  right: 8%;
  display: none;
  align-items: center;
  gap: 0.55em;
  padding: 0.42em 0.66em;
  border-radius: 3px;
  background: rgb(5 8 6 / 0.78);
  box-shadow: inset 0 0 0 1px rgb(255 196 106 / 0.16);
  font-family: var(--label);
  font-size: 0.5625rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: #FFC46A;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

body[data-rec="on"] .tally { display: flex; }

.tally::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(0deg,
    rgb(0 0 0 / 0.34) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

.tally-dot {
  width: 0.62em;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #FF5A4A;
  box-shadow: 0 0 6px rgb(255 90 74 / 0.85);
}

/* A recording light blinks. It is a convention rather than decoration, so it
   is slow, shallow, and stops entirely under reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  body[data-rec="on"] .tally-dot { animation: tally 1.4s ease-in-out infinite; }
  @keyframes tally {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.34; }
  }
}

/* ---------------------------------------------------------------------------
   The on-screen display.

   A television answers its own controls on its own screen, so this sits on the
   phosphor rather than beside the set: amber, monospaced, scanlines running
   over it, and underneath the glass sheen so the reflection falls in front of
   it the way it falls in front of the picture.
   --------------------------------------------------------------------------- */

.osd {
  position: absolute;
  z-index: 2;
  left: 8%;
  bottom: 8%;
  display: flex;
  align-items: center;
  gap: 0.7em;
  padding: 0.42em 0.7em;
  border-radius: 3px;
  /* Measured against the worst case, which is not the tube's black but a
     blown-out white picture showing through: at 0.62 alpha the amber came out
     at 3.7:1 over that. At 0.78 the same reading is 7.0:1 and the picture is
     still visibly behind the display. */
  background: rgb(5 8 6 / 0.78);
  box-shadow: inset 0 0 0 1px rgb(255 196 106 / 0.16);
  font-family: var(--label);
  font-size: 0.5625rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #FFC46A;                      /* 9.4:1 on the tube's own black */
  text-shadow: 0 0 7px rgb(232 163 61 / 0.55);
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 200ms var(--ease), transform 260ms var(--ease);
  pointer-events: none;
}

.osd.is-up { opacity: 1; transform: none; }

/* The raster runs over the display too, because the display is painted by the
   same beam. Without this it reads as a caption laid on top of a video. */
.osd::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(0deg,
    rgb(0 0 0 / 0.34) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

.osd-bars { display: flex; gap: 2px; }

.osd-bars i {
  display: block;
  width: 0.44em;
  height: 0.95em;
  /* An unlit segment still has to be countable, so its outline is held at
     3.6:1 against the same worst-case background. */
  background: rgb(255 196 106 / 0.22);
  box-shadow: inset 0 0 0 1px rgb(255 196 106 / 0.60);
}

.osd-bars i.is-on {
  background: #FFC46A;
  box-shadow: 0 0 5px rgb(232 163 61 / 0.85);
}

/* Light on curved glass. Screen-blended, so it lifts the picture rather than
   sitting on top of it as a grey film. */
.sheen {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  mix-blend-mode: screen;
  background:
    linear-gradient(147deg, rgb(255 252 244 / 0.11) 0 15%, rgb(255 252 244 / 0.02) 33%, transparent 47%),
    radial-gradient(58% 34% at 26% 12%, rgb(255 250 240 / 0.09), transparent 70%);
}

/* The edge of the tube. The shader vignettes too, but this has to hold on its
   own when the shader is not there. */
.glass::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px rgb(0 0 0 / 0.7),
    inset 0 0 22px 4px rgb(0 0 0 / 0.55);
}

/* The shader vignettes the tube itself. Stacking the CSS one on top of it drew
   a second, harder ring that followed the corner radius instead of the glass.
   When the shader is running it only needs to hold the very edge. */
body[data-gl="on"] .glass::after {
  box-shadow:
    inset 0 0 0 1px rgb(0 0 0 / 0.7),
    inset 0 0 8px 0 rgb(0 0 0 / 0.35);
}

/* ---------------------------------------------------------------------------
   What the tube says.

   Type is sized against the tube, not the viewport, so the message fits the
   picture at every screen size instead of overflowing on a small phone.
   --------------------------------------------------------------------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 2;
  /* Flex with auto margins rather than grid centring. A centred grid item that
     outgrows its track gets clipped at the top with no way to scroll back to
     it, which on a 277px tube is the difference between a terse message and an
     unreachable one. Auto margins centre while there is room and pin to the
     start when there is not. */
  display: flex;
  padding: 1.5% 5%;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Only enough to take the edge off the snow. The message carries its own
     shade, below, so the tube can go on visibly showing static around it
     instead of dimming to a dark panel with words on it. */
  background: rgb(6 8 7 / 0.18);
}

body[data-state="live"] .screen,
body[data-state="boot"] .screen { display: none; }

/* The message sits in its own pool, feathered out to nothing at the edges, so
   the copy clears the static underneath it without a visible panel edge. Text
   over live noise has to be measured against the brightest specks, not the
   average, which is what this is for. */
.screen-inner {
  position: relative;
  margin: auto;
  text-align: center;
  max-width: 40ch;
  padding: 3% 6%;
  border-radius: 40px;
  background: rgb(4 6 5 / 0.9);
  box-shadow: 0 0 30px 20px rgb(4 6 5 / 0.9);
}

/* The pool of shade is a box-shadow rather than an oversized absolute box. An
   absolutely positioned backdrop with a negative inset overflows the scroll
   container and gives the message a scrollbar it does not need; a shadow
   feathers the same way and creates no scrollable overflow at all. */

/* The channel tag, on the two cards where it says something the headline does
   not: which channel this is, and that the set is tuning. */
.screen-tag {
  margin: 0 0 0.38em;
  font-family: var(--label);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--amber);
}

.screen-head {
  margin: 0 0 0.36em;
  font-size: 1.5rem;
  font-weight: 600;
  font-stretch: 112%;
  letter-spacing: -0.015em;
  line-height: 1.05;
  text-wrap: balance;
  color: var(--bone);
}

.screen-body {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.42;
  text-wrap: pretty;
  color: var(--bone);
}

/* The recovery path is a sequence of interface labels the visitor is about to
   go looking for, not code, so it is set in the same face as everything else
   and separated by colour rather than by a monospace costume. */
.screen-fix {
  margin: 0.5em 0 0;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.4;
  color: #F0B45E;
}

.screen-act { margin-top: 0.75em; }
.screen-act:empty { display: none; }

/* Type scales with the tube where container queries exist, which is every
   browser that can run the shader anyway. The rem sizes above are the floor. */
@supports (width: 1cqi) {
  .glass { container-type: inline-size; }
  .screen-tag  { font-size: max(0.5625rem, 2.6cqi); }
  .screen-head { font-size: max(1rem,     7.4cqi); }
  .screen-body { font-size: max(0.75rem,  3.7cqi); }
  .screen-fix  { font-size: max(0.625rem, 3.1cqi); }
  .btn         { font-size: max(0.75rem,  3.4cqi); }
  .osd         { font-size: max(0.5625rem, 2.2cqi); }
  .tally       { font-size: max(0.5625rem, 2.2cqi); }
}

/* ---------------------------------------------------------------------------
   The one button.
   --------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.5em 1.25em;
  border: 0;
  border-radius: 6px;
  font-family: var(--display);
  font-size: 0.8125rem;
  font-weight: 600;
  font-stretch: 108%;
  letter-spacing: 0.005em;
  color: var(--on-amber);              /* 7.8:1 on amber */
  background: linear-gradient(178deg, #F2B357, var(--amber) 52%, #C9832A);
  box-shadow:
    inset 0 1px 0 rgb(255 240 214 / 0.6),
    inset 0 -1px 0 rgb(0 0 0 / 0.3),
    0 2px 0 var(--amber-deep),
    0 5px 14px rgb(0 0 0 / 0.5);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease);
}

.btn:hover { background: linear-gradient(178deg, #F6BC66, #EFAC48 52%, #D08D31); }

/* The button physically goes down onto the glass. */
.btn:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgb(255 240 214 / 0.4),
    inset 0 2px 5px rgb(0 0 0 / 0.35),
    0 0 0 var(--amber-deep),
    0 2px 6px rgb(0 0 0 / 0.5);
}

.btn:focus-visible {
  outline: 2px solid var(--bone);
  outline-offset: 3px;
}

.btn[disabled] {
  cursor: default;
  opacity: 0.55;
  transform: none;
  filter: saturate(0.5);
}

/* ---------------------------------------------------------------------------
   The fascia. Brand plate, speaker cloth, controls. This is the half of the
   cabinet that makes it a television rather than a monitor, so it gets real
   depth rather than a flat strip of colour.
   --------------------------------------------------------------------------- */

.fascia {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 3.5%;
  padding: 3.6% 1% 4%;
}

/* Brass plate, letters struck into it. The light edge sits below the dark one,
   which is what makes an engraving read as cut in rather than raised. */
.plate {
  display: flex;
  align-items: baseline;
  gap: 0.32em;
  padding: 0.38em 0.72em;
  border-radius: 6px;
  font-size: clamp(0.6875rem, 2.1vw, 0.9375rem);
  /* Measured: against the old #6F5A2C foot of this gradient the engraved text
     came out at 2.6:1. The plate is now floored at #A2853F, which puts the
     worst point on it at 5.2:1. */
  background: linear-gradient(168deg, #D4B575 0%, #BC9D59 46%, #A2853F 100%);
  box-shadow:
    inset 0 1px 0 rgb(255 240 205 / 0.5),
    inset 0 -1px 0 rgb(0 0 0 / 0.45),
    0 1px 2px rgb(0 0 0 / 0.6);
}

.plate-mark,
.plate-no {
  color: #1C1406;
  text-shadow: 0 1px 0 rgb(255 243 212 / 0.38);
}

.plate-mark {
  font-family: var(--label);
  font-weight: 500;
  font-size: 0.74em;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
}

.plate-no {
  font-weight: 700;
  font-stretch: 118%;
  letter-spacing: -0.02em;
}

/* Woven cloth over the speaker. Two axes of thread, not a hatch pattern. */
.cloth {
  height: clamp(20px, 4.4vw, 34px);
  border-radius: 4px;
  background-image:
    repeating-linear-gradient(0deg,  rgb(0 0 0 / 0.62) 0 1px, rgb(255 226 186 / 0.05) 1px 2px, transparent 2px 4px),
    repeating-linear-gradient(90deg, rgb(0 0 0 / 0.55) 0 1px, rgb(255 226 186 / 0.04) 1px 2px, transparent 2px 4px),
    linear-gradient(178deg, #4A3626, #241A11);
  box-shadow:
    inset 0 2px 4px rgb(0 0 0 / 0.85),
    inset 0 -1px 0 rgb(255 222 180 / 0.08),
    0 1px 0 rgb(255 222 180 / 0.15);
}

.controls {
  display: flex;
  align-items: center;
  gap: clamp(16px, 2.2vw, 20px);
}

/* The pilot lamp. Dark when the set has no picture, amber when it does.
   It never pulses: a lamp that breathes is a notification, not a lamp. */
.lamp {
  width: clamp(7px, 1.5vw, 10px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #241505;
  box-shadow: inset 0 1px 1px rgb(0 0 0 / 0.9);
  transition: background 420ms var(--ease), box-shadow 420ms var(--ease);
}

body[data-state="requesting"] .lamp {
  background: #A9741F;
  box-shadow: inset 0 1px 1px rgb(0 0 0 / 0.5), 0 0 6px 1px rgb(232 163 61 / 0.4);
}

body[data-state="live"] .lamp {
  background: #FFC46A;
  box-shadow: inset 0 0 2px rgb(255 244 220 / 0.9), 0 0 10px 2px rgb(232 163 61 / 0.75);
}

/* Bakelite. Lit from the same direction as everything else on the cabinet, and
   sized up from the decorative original because it is now a control a thumb has
   to find rather than a shape on a fascia. */
.knob {
  width: clamp(28px, 6.2vw, 42px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(72% 72% at 34% 26%, #6E5636 0%, #3B2A17 52%, #1C1208 100%);
  box-shadow:
    inset 0 1px 0 rgb(255 224 176 / 0.34),
    inset 0 -2px 3px rgb(0 0 0 / 0.7),
    0 2px 3px rgb(0 0 0 / 0.65);
  position: relative;
}

/* The pointer notch, so the knob has a position and reads as turnable. */
.knob::after {
  content: "";
  position: absolute;
  top: 14%;
  left: 50%;
  width: 8%;
  height: 30%;
  border-radius: 2px;
  background: rgb(232 163 61 / 0.8);
  transform-origin: 50% 167%;
}

/* A faint amber collar and a lit notch say this one is live, without a printed
   label the fascia has no room for. What it is and where it is set are said by
   the on-screen display instead, which is where a television says such things. */
.knob-a {
  cursor: grab;
  touch-action: none;                  /* the drag is ours, not the browser's */
  -webkit-user-select: none;
  user-select: none;
  box-shadow:
    inset 0 1px 0 rgb(255 224 176 / 0.34),
    inset 0 -2px 3px rgb(0 0 0 / 0.7),
    0 0 0 1px rgb(232 163 61 / 0.22),
    0 2px 3px rgb(0 0 0 / 0.65);
}

.knob-a::after {
  background: var(--amber);
  box-shadow: 0 0 4px rgb(232 163 61 / 0.6);
  transform: translateX(-50%) rotate(var(--turn, 0deg));
  transition: transform 260ms var(--ease);
}

/* While a finger is on it the notch tracks the finger exactly; a transition
   here would put the knob permanently behind the hand turning it. */
.knob-a.is-turning { cursor: grabbing; }
.knob-a.is-turning::after { transition: none; }

.knob-a:focus-visible {
  outline: 2px solid var(--bone);
  outline-offset: 4px;
}

/* 44px of finger around a knob that is drawn smaller than that, without
   changing what the fascia lays out. */
.knob-a::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(44px, 126%);
  height: max(44px, 126%);
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

/* No shader, no picture to adjust. The knob keeps the fascia's balance but
   stops advertising itself as something that does anything. */
.knob-a.is-dead {
  cursor: default;
  box-shadow:
    inset 0 1px 0 rgb(255 224 176 / 0.34),
    inset 0 -2px 3px rgb(0 0 0 / 0.7),
    0 2px 3px rgb(0 0 0 / 0.65);
}

.knob-a.is-dead::before { display: none; }

.knob-a.is-dead::after {
  background: rgb(232 163 61 / 0.32);
  box-shadow: none;
}

/* ---------------------------------------------------------------------------
   The transport keys.

   A knob turns and a key presses, so they are made of different things: the
   knob is round, dark bakelite; the keys are square-shouldered ivory that goes
   down into the fascia when pressed. The 6px radius is the one this file
   reserved for controls at the top, not a new number.
   --------------------------------------------------------------------------- */

.key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(28px, 6.2vw, 42px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(176deg, #E9DFCA 0%, #D2C4A8 54%, #A8967C 100%);
  color: #2A2117;                      /* 8.9:1 on the face of the key */
  box-shadow:
    inset 0 1px 0 rgb(255 252 242 / 0.85),
    inset 0 -2px 2px rgb(0 0 0 / 0.28),
    0 2px 0 #4A3A24,
    0 4px 8px rgb(0 0 0 / 0.55);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease),
              filter 160ms var(--ease);
}

/* 44px of finger around a key drawn smaller than that, laid out over the gap
   rather than through it: the cluster is spaced so these never overlap. */
.key::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(44px, 118%);
  height: max(44px, 118%);
  transform: translate(-50%, -50%);
  border-radius: 8px;
}

.key-glyph {
  width: 60%;
  height: 60%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The key travels into the fascia and its shadow closes up underneath it. */
.key:active:not([disabled]) {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgb(255 252 242 / 0.4),
    inset 0 2px 5px rgb(0 0 0 / 0.4),
    0 0 0 #4A3A24,
    0 1px 3px rgb(0 0 0 / 0.5);
}

.key:focus-visible {
  outline: 2px solid var(--bone);
  outline-offset: 3px;
}

/* Down and dark rather than gone. A key that vanishes when there is no picture
   makes the fascia jump every time the camera starts. */
.key[disabled] {
  cursor: default;
  transform: translateY(2px);
  filter: saturate(0.2) brightness(0.55);
  box-shadow:
    inset 0 1px 0 rgb(255 252 242 / 0.25),
    inset 0 2px 5px rgb(0 0 0 / 0.45),
    0 0 0 #4A3A24;
}

/* The record key. Its dot is the only red on the fascia, for the same reason
   the tally is the only red on the tube. */
.key-dot { fill: #B33227; stroke: none; }

/* The selector's arrowheads are solid rather than drawn, because a stroked
   chevron loses its point at the size this glyph is actually rendered. */
.key-tip { fill: currentColor; stroke: none; }

/* A key that is not on the fascia at all. .key sets display:flex, which would
   otherwise beat the hidden attribute's display:none outright. */
.key[hidden] { display: none; }

/* A two-position switch stays where it was put. Down is the back camera, and
   it comes back up when the front camera is chosen again. Same latch as the
   record key, because it is the same idea. */
body[data-cam="back"] .key-flip {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgb(255 252 242 / 0.4),
    inset 0 2px 5px rgb(0 0 0 / 0.4),
    0 0 0 #4A3A24,
    0 1px 3px rgb(0 0 0 / 0.5);
}

/* A tape transport key stays latched down while it is running, and comes back
   up when it is pressed again. */
body[data-rec="on"] .key-rec {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgb(255 252 242 / 0.4),
    inset 0 2px 5px rgb(0 0 0 / 0.4),
    0 0 0 #4A3A24,
    0 1px 3px rgb(0 0 0 / 0.5);
}

body[data-rec="on"] .key-dot {
  fill: #F0402C;
  filter: drop-shadow(0 0 3px rgb(255 90 74 / 0.9));
}

/* No shader, no tube to photograph, so the capture keys go. The selector
   stays: the camera is still running and can still be pointed the other way,
   and there is nothing about that which needed a shader. */
body[data-gl="off"] .key:not(.key-flip) { display: none; }

@media (prefers-reduced-motion: reduce) {
  .key { transition: none; }
}

/* Only ever visible when WebGL did not start. */
.fallback {
  display: none;
  margin: 0.9em 0 0;
  padding: 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  text-wrap: balance;
  color: rgb(237 230 216 / 0.66);
}

body[data-gl="off"] .fallback { display: block; }

/* Same voice and same place as the fallback line, for the same reason: a
   missing control needs one sentence, not silence. */
.note {
  margin: 0.9em 0 0;
  padding: 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  text-wrap: balance;
  color: rgb(237 230 216 / 0.66);   /* 6.9:1 on the room */
}

body[data-gl="off"] .note { display: none; }

/* ---------------------------------------------------------------------------
   The day mark. Same corner, same face, same size as the other twenty-nine.
   --------------------------------------------------------------------------- */

.day {
  position: fixed;
  z-index: 12;
  right: max(0.9rem, env(safe-area-inset-right));
  bottom: max(0.5rem, calc(env(safe-area-inset-bottom) + 0.15rem));
  margin: 0;
  font-family: var(--label);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgb(237 230 216 / 0.62);   /* 6.3:1 on the room */
  pointer-events: none;
}

.probe {
  position: fixed;
  z-index: 12;
  top: max(0.6rem, env(safe-area-inset-top));
  left: max(0.9rem, env(safe-area-inset-left));
  margin: 0;
  font-family: var(--label);
  font-size: 0.625rem;
  line-height: 1.5;
  white-space: pre;
  color: rgb(237 230 216 / 0.62);
  pointer-events: none;
}

/* ---------------------------------------------------------------------------
   Landscape on a phone. The cabinet is height-bound rather than width-bound,
   and the fascia gives up its padding first because the picture matters more.
   --------------------------------------------------------------------------- */

@media (max-width: 430px) {
  .cabinet { padding: 2.7% 2.7% 0; border-radius: 13px; }
  .fascia  { padding: 3.2% 0.5% 3.6%; }
}

/* Below about 360px the tube is 208px tall and every line has to earn its
   place. The channel tag is the one that cannot: the brass plate under the
   screen already says CH 28, and the headline carries the meaning on its own.
   It goes, and the message fits. */
@media (max-width: 360px) {
  .screen-tag { display: none; }
}

@media (max-height: 460px) and (orientation: landscape) {
  .set { width: min(96vw, (100dvh - 1rem) / 0.91); margin-bottom: 0; }
  body[data-note="on"] .set { width: min(96vw, (100dvh - 1rem) / 0.98); }
  .fascia { padding: 2.4% 1% 2.8%; }
  .cloth { height: clamp(14px, 3vh, 24px); }
}

/* ---------------------------------------------------------------------------
   Arrival. The set is already switched on and already showing snow; what
   arrives is the cabinet around it, once, on load.

   The picture itself is never gated on this. Under reduced motion the whole
   arrival is skipped and the set is simply there, which is the correct
   reading: the feed is the function, the entrance is decoration.
   --------------------------------------------------------------------------- */

/* Direct manipulation still needs to show its result; what goes is the travel,
   not the feedback. The knob lands on its angle and the display appears where
   it will sit, both without moving across the screen. */
@media (prefers-reduced-motion: reduce) {
  .knob-a::after { transition: none; }
  .osd {
    transform: none;
    transition: opacity 120ms linear;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .set {
    animation: arrive 760ms var(--ease) backwards;
  }
  @keyframes arrive {
    from { opacity: 0; transform: translateY(10px) scale(0.985); }
  }
  .day { animation: arrive 640ms var(--ease) 700ms backwards; }
}
