/* Teletext 2026 styles. Plain CSS, no build step.

   AA contrast for every colour pair used (WCAG 2.x ratio, recomputed by test/style.test.mjs).
   "text" pairs need 4.5:1, "ui" pairs (borders, focus ring) need 3:1.
   Grid cells use the Teletext palette; generated frames are checked by Property 12.
   text #FFFFFF on #000000 21.00  page text, grid white
   text #FFFFFF on #181818 17.76  panel text
   text #FFFFFF on #272727 14.94  buttons
   text #FFFFFF on #313131 13.01  buttons, hover
   text #BDBDBD on #000000 11.18  muted text on page
   text #BDBDBD on #181818 9.45   muted text on panel
   text #FFFF00 on #000000 19.56  messages, entry display
   text #FFFF00 on #181818 16.54  entry display on panel
   text #8C8C8C on #000000 6.25   input placeholder
   text #000000 on #FF0000 5.25   red Fastext key
   text #000000 on #00FF00 15.30  green Fastext key
   text #000000 on #FFFF00 19.56  yellow Fastext key, pressed toggle
   text #FFFFFF on #0000FF 8.59   blue Fastext key
   ui   #8C8C8C on #000000 6.25   input border
   ui   #8C8C8C on #181818 5.28   input border on panel
   ui   #FFFF00 on #000000 19.56  focus ring on page
   ui   #FFFF00 on #181818 16.54  focus ring on panel

   Scanlines (off by default) darken one pixel row in four by 35%, 8.75% on average,
   which keeps red on black at 4.59:1 on average (see test/style.test.mjs). */

:root {
  --t0: #000000; --t1: #FF0000; --t2: #00FF00; --t3: #FFFF00;
  --t4: #0000FF; --t5: #FF00FF; --t6: #00FFFF; --t7: #FFFFFF;
  --page: #000000;
  --surface: #181818;
  --raised: #272727;
  --raised-hover: #313131;
  --text: #FFFFFF;
  --muted: #BDBDBD;
  --line: #8C8C8C;
  --focus: #FFFF00;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --sans: "Geist", "Manrope", "Poppins", system-ui, sans-serif;
  /* Cell width: 40 cells across the viewport minus 32px of padding, at most 18px.
     At 375px wide a cell is 8.575px. Cells are 4:5, like a 4:3 TV split into 40 x 24. */
  --cw: min(calc((100vw - 32px) / 40), 18px);
  --rh: calc(var(--cw) * 1.25);
  color-scheme: dark;
}

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

html { background: var(--page); color: var(--text); font-family: var(--sans); }
body { margin: 0; padding: 8px; min-height: 100vh; }

/* Named text styles (type scale steps only). */
.title-2 { font-size: 1.125rem; line-height: 1.75rem; font-weight: 500; }
.title-3 { font-size: 1rem; line-height: 1.5rem; font-weight: 500; }
.title-4 { font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; }
.body-3 { font-size: 1rem; line-height: 1.5rem; font-weight: 400; }
.body-5 { font-size: 0.875rem; line-height: 1.25rem; font-weight: 500; }
.body-6 { font-size: 0.875rem; line-height: 1.25rem; font-weight: 400; }
.caption-2 { font-size: 0.875rem; line-height: 1.25rem; font-weight: 400; }
.button-lg { font-size: 1.125rem; line-height: 1.75rem; font-weight: 600; }
.button-md { font-size: 1rem; line-height: 1.5rem; font-weight: 600; }
.button-sm { font-size: 0.875rem; line-height: 1.25rem; font-weight: 600; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
h1, h2, p, ul { margin: 0; }
p, li { text-wrap: pretty; }

.vh {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.skip {
  position: absolute; left: 8px; top: -64px; z-index: 2;
  padding: 8px 12px; border-radius: 8px; background: var(--raised); color: var(--text);
}
.skip:focus { top: 8px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 4px 8px 12px; }

.layout { display: grid; gap: 16px; justify-content: center; }

/* The TV screen. */
.tv { display: grid; gap: 8px; justify-items: start; min-width: 0; }
.tv:focus { outline: none; }
.tv:focus-visible .screen { outline: 2px solid var(--focus); outline-offset: 2px; }
.screen { position: relative; padding: 8px; border-radius: 12px; background: var(--page); border: 1px solid var(--raised-hover); }
.grid {
  width: calc(var(--cw) * 40);
  height: calc(var(--rh) * 24);
  overflow: hidden;
  border-radius: 4px;
  background: var(--t0);
  color: var(--t7);
  font-family: var(--mono);
  font-weight: 600;
  /* Glyph height fills most of a row; app.mjs measures the font and sets --sx so 40 cells span the grid. */
  font-size: calc(var(--rh) * 0.86);
  line-height: var(--rh);
  font-kerning: none;
  font-variant-ligatures: none;
}
.row { height: var(--rh); white-space: pre; overflow: visible; }
.row > .in { display: block; width: max-content; transform-origin: 0 0; transform: scaleX(var(--sx, 1)); }
.row.dbl { height: calc(var(--rh) * 2); }
.row.dbl > .in { transform: scale(var(--sx, 1), 2); }
.in > span { display: inline-block; height: var(--rh); vertical-align: top; }

/* Teletext palette: f = foreground, b = background. */
.f0 { color: var(--t0); } .f1 { color: var(--t1); } .f2 { color: var(--t2); } .f3 { color: var(--t3); }
.f4 { color: var(--t4); } .f5 { color: var(--t5); } .f6 { color: var(--t6); } .f7 { color: var(--t7); }
.b0 { background-color: var(--t0); } .b1 { background-color: var(--t1); } .b2 { background-color: var(--t2); } .b3 { background-color: var(--t3); }
.b4 { background-color: var(--t4); } .b5 { background-color: var(--t5); } .b6 { background-color: var(--t6); } .b7 { background-color: var(--t7); }

/* Mosaic cell: 2 x 3 sextants drawn as blocks, one character wide. */
.in .m {
  display: inline-grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr;
  width: 1ch; height: var(--rh); vertical-align: top;
}
.m > i { display: block; }
.m > i.on { background-color: currentColor; }
.m.sep > i.on { border: max(1px, 0.06em) solid transparent; background-clip: padding-box; }

@media (prefers-reduced-motion: no-preference) {
  .fl { animation: flash 1s steps(1) infinite; }
}
@keyframes flash { 50% { color: transparent; } }

/* Scanlines: off by default. One pixel row in four darkened by 35%. */
.screen[data-scanlines="on"] .grid { position: relative; }
.screen[data-scanlines="on"] .grid::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect y='3' width='4' height='1' fill-opacity='0.35'/%3E%3C/svg%3E");
  background-size: 4px 4px;
}

.status { color: var(--text); }
.msg { min-height: 1.25rem; color: var(--t3); }

/* Remote control panel. */
.controls {
  display: grid; gap: 16px; align-content: start;
  padding: 16px; border-radius: 16px; background: var(--surface);
  width: calc(var(--cw) * 40 + 18px);
}

button {
  font: inherit; color: var(--text); background: var(--raised);
  border: 0; border-radius: 8px; padding: 8px 12px; cursor: pointer;
  transition: background-color 300ms var(--ease), transform 300ms var(--ease);
  touch-action: manipulation;
}
button:hover { background: var(--raised-hover); }
button:active { transform: scale(0.98); }
button.button-lg { font-size: 1.125rem; line-height: 1.75rem; }
button.button-md { font-size: 1rem; line-height: 1.5rem; }
button.button-sm { font-size: 0.875rem; line-height: 1.25rem; }

/* Labels never wrap. Measured in Chrome with the system-ui fallback: the longest label,
   "Sources", is 55px wide at 14px; keys are 69px wide at 320px and 1280px viewports,
   76px at 375px and 171px at 768px, leaving room inside the 2px side padding. */
.fastext { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.fx {
  min-height: 48px; padding: 8px 2px; color: var(--t0);
  white-space: nowrap; overflow-wrap: normal; word-break: keep-all;
}
button.fx.button-md { font-size: 0.875rem; line-height: 1.25rem; }
.fx-red, .fx-red:hover { background: var(--t1); }
.fx-green, .fx-green:hover { background: var(--t2); }
.fx-yellow, .fx-yellow:hover { background: var(--t3); }
.fx-blue, .fx-blue:hover { background: var(--t4); color: var(--t7); }
.fx:hover { transform: translateY(-2px); }
.fx:active { transform: translateY(1px); }

.pad-wrap { display: grid; gap: 8px; }
.entry { color: var(--t3); letter-spacing: 0.05em; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { min-height: 48px; font-family: var(--mono); }

.tune { display: grid; gap: 8px; }
.tune-row { display: flex; gap: 8px; }
.tune input {
  flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; border-radius: 8px;
  color: var(--text); background: var(--page); border: 1px solid var(--line);
}
.tune input::placeholder { color: var(--line); opacity: 1; }
.tune button { min-height: 44px; }
.tune button[aria-busy="true"] { cursor: progress; }

.options { display: flex; gap: 8px; }
.toggle { min-height: 44px; }
.toggle[aria-pressed="true"] { background: var(--t3); color: var(--t0); }

.help { display: grid; gap: 4px; }
.help ul { padding-left: 16px; display: grid; gap: 4px; }

.foot { display: grid; gap: 4px; max-width: 680px; margin: 24px auto 8px; padding: 0 8px; }

/* Wide screens: remote control beside the TV, cells sized to fit the viewport height too. */
@media (min-width: 1120px) {
  :root { --cw: min(18px, calc((100vh - 136px) / 30)); }
  .layout { grid-template-columns: auto 320px; align-items: start; gap: 32px; }
  .controls { width: 320px; }
}

@media (prefers-reduced-motion: reduce) {
  button, .fx { transition: background-color 300ms var(--ease), opacity 300ms var(--ease); }
  button:active, .fx:hover, .fx:active { transform: none; }
}
