html, body { margin: 0; height: 100%; background: #000; overflow: hidden; overscroll-behavior: none; }
body { font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif; color: #fff; }
body.nocursor { cursor: none; }
#host { position: fixed; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; }
#host canvas { display: block; width: 100vw; height: 100vh; height: 100dvh; }
#stats {
  position: fixed; top: max(6px, env(safe-area-inset-top)); left: max(6px, env(safe-area-inset-left));
  display: none; padding: 4px 8px; border-radius: 6px; font: 12px/1.3 ui-monospace, monospace;
  background: rgba(0, 0, 0, 0.6); pointer-events: none;
}
button, select {
  font: inherit; color: #fff; background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 8px; padding: 0.45em 0.9em; cursor: pointer;
}
button:hover, select:hover { background: rgba(255, 255, 255, 0.2); }
button:focus-visible, select:focus-visible, li:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
select option { color: #000; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 6vh; transform: translateX(-50%);
  padding: 0.5em 1em; border-radius: 999px; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.4s; pointer-events: none;
}
#toast.on { opacity: 1; }

/* ---- settings panel: the Apple TV HUD (see src/overlay.ts) ----
   Sizes are the TV's (1920-wide layout) times --k, which the panel sets from
   the window width. */
#overlay {
  --k: 1;
  --cut: calc(16px * var(--k));
  --line: rgba(255, 255, 255, 0.3);
  --plate: linear-gradient(90deg, rgba(0, 0, 0, 0.85), rgba(8, 20, 31, 0.85));
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --chamfer: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
  position: fixed; inset: 0; overflow: hidden;
  font-family: var(--mono); text-transform: uppercase;
  opacity: 0; visibility: hidden; transition: opacity 0.35s, visibility 0s linear 0.35s;
}
#overlay.on { opacity: 1; visibility: visible; transition: opacity 0.25s; }

/* Panel: slides down over a dark gradient; the rest of the screen stays clear. */
#overlay .hud-panel {
  position: absolute; left: 0; right: 0; top: 0; box-sizing: border-box;
  max-height: 100%; overflow-y: auto; overflow-x: hidden; scrollbar-width: none;
  padding: max(calc(18px * var(--k)), env(safe-area-inset-top)) 0 calc(60px * var(--k));
  display: flex; flex-direction: column; align-items: center; gap: calc(22px * var(--k));
  background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.4) 70%, transparent);
  transform: translateY(-24px); transition: transform 0.25s ease-out;
}
#overlay .hud-panel::-webkit-scrollbar { display: none; }
#overlay.on .hud-panel { transform: none; }

/* HUD frame: chamfered outline (.face is the line colour, .fill the plate
   1px inside it), corner brackets, glow and lift on focus. */
#overlay .hud {
  position: relative; cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent;
  transition: transform 0.18s ease-out, filter 0.18s ease-out;
}
#overlay .hud > .face { position: relative; height: 100%; padding: 1px; box-sizing: border-box; clip-path: var(--chamfer); background: var(--line); }
#overlay .hud > .face > .fill { position: relative; height: 100%; overflow: hidden; clip-path: var(--chamfer); background: var(--plate); }
#overlay .hud::after {
  content: ''; position: absolute; inset: calc(-4px * var(--k)); pointer-events: none;
  --b: calc(18px * var(--k)); --w: 2px;
  background:
    linear-gradient(var(--line), var(--line)) top right / var(--b) var(--w) no-repeat,
    linear-gradient(var(--line), var(--line)) top right / var(--w) var(--b) no-repeat,
    linear-gradient(var(--line), var(--line)) bottom left / var(--b) var(--w) no-repeat,
    linear-gradient(var(--line), var(--line)) bottom left / var(--w) var(--b) no-repeat;
  transition: inset 0.18s ease-out;
}
#overlay .hud.active, #overlay .spinner { --line: rgba(255, 255, 255, 0.7); }
#overlay .hud:focus, #overlay .hud:hover, #overlay .hud.spinning {
  --line: #fff; z-index: 2;
  transform: scale(1.06);
  filter: drop-shadow(0 0 calc(14px * var(--k)) rgba(255, 255, 255, 0.5)) drop-shadow(0 8px 12px rgba(0, 0, 0, 0.5));
}
#overlay .card:focus, #overlay .card:hover { transform: scale(1.1); }
#overlay .hud:focus > .face, #overlay .hud.spinning > .face { padding: 2px; }
#overlay .hud:focus::after, #overlay .hud.spinning::after { inset: calc(-9px * var(--k)); --w: 3px; }
/* White bar along the bottom that grows in on focus. */
#overlay .hud > .face > .fill::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: #fff;
  transition: width 0.25s ease-out;
}
#overlay .hud:focus > .face > .fill::after { width: 100%; }
#overlay .scan {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(transparent 0 2px, rgba(0, 0, 0, 0.18) 2px 3px);
}

/* Top row: logo, Mix it up, four spinners. Each has a title plate above. */
#overlay .top-row {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start;
  gap: calc(14px * var(--k)) calc(32px * var(--k)); padding: 0 calc(40px * var(--k));
  position: relative; z-index: 3;
}
#overlay .col { position: relative; display: flex; flex-direction: column; gap: calc(10px * var(--k)); }
#overlay .title {
  display: flex; align-items: center; gap: calc(8px * var(--k)); padding-left: 4px;
  font-size: calc(15px * var(--k)); font-weight: 700; letter-spacing: 0.17em; color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}
#overlay .num { color: rgba(255, 255, 255, 0.45); letter-spacing: 0.05em; }
#overlay .bar { display: inline-block; width: 1px; height: calc(14px * var(--k)); background: rgba(255, 255, 255, 0.35); }
#overlay .col:focus-within .title, #overlay .col:hover .title, #overlay .col:focus-within .num { color: #fff; }
#overlay .tile, #overlay .spinner { height: calc(120px * var(--k)); }
#overlay .logo { width: calc(230px * var(--k)); }
#overlay .mix { width: calc(270px * var(--k)); }
#overlay .sp-palette { width: calc(320px * var(--k)); }
#overlay .sp-complexity, #overlay .sp-show { width: calc(200px * var(--k)); }
#overlay .sp-speed { width: calc(240px * var(--k)); }

/* Logo: plate and keyed wordmark with the letter faces cut out, so the live
   artwork shows through them. */
#overlay .logo > .face > .fill { background: transparent; }
#overlay .logo .cut {
  position: absolute; inset: 0; box-sizing: border-box; padding: 0 calc(18px * var(--k));
  background: url(img/logo-keyed.png) center / contain no-repeat content-box, var(--plate);
  -webkit-mask: url(img/logo-letters.png) center / contain no-repeat content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: url(img/logo-letters.png) center / contain no-repeat content-box exclude, linear-gradient(#000 0 0);
}

#overlay .mix .fill { display: flex; align-items: center; gap: calc(14px * var(--k)); padding: 0 calc(16px * var(--k)); box-sizing: border-box; }
#overlay .mix .icon { font-size: calc(40px * var(--k)); line-height: 1; }
#overlay .mix .big { font-size: calc(22px * var(--k)); font-weight: 700; letter-spacing: 0.09em; white-space: nowrap; }
#overlay .mix .small { margin-top: calc(6px * var(--k)); font-size: calc(13px * var(--k)); letter-spacing: 0.12em; opacity: 0.6; white-space: nowrap; }

/* Spinner, closed: previous / current / next, the current between hairlines. */
#overlay .spinner .rows { display: flex; flex-direction: column; height: 100%; }
#overlay .spinner .rows > div {
  flex: 1; display: flex; align-items: center; min-width: 0; padding: 0 calc(14px * var(--k));
  white-space: nowrap; overflow: hidden;
}
#overlay .spinner .rows .v { overflow: hidden; text-overflow: ellipsis; }
#overlay .spinner .nb { padding-left: calc(34px * var(--k)) !important; font-size: calc(16px * var(--k)); letter-spacing: 0.09em; color: rgba(255, 255, 255, 0.4); }
#overlay .spinner .cur {
  gap: calc(10px * var(--k)); font-size: calc(22px * var(--k)); font-weight: 600; letter-spacing: 0.09em;
  border-top: 1px solid rgba(255, 255, 255, 0.2); border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
#overlay .spinner .caret { color: rgba(255, 255, 255, 0.4); }
#overlay .spinner:focus .cur, #overlay .spinner:hover .cur { font-weight: 700; border-color: rgba(255, 255, 255, 0.6); }
#overlay .spinner:focus .caret, #overlay .spinner:hover .caret { color: #fff; }
#overlay .spinner.spinning { visibility: hidden; }

/* Spinner, open: a taller drum centred on where the value sat. */
#overlay .drum {
  position: absolute; left: 0; right: 0; z-index: 5; outline: none;
  height: calc(40px * var(--k) * 9); box-sizing: border-box;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.95), rgba(8, 20, 31, 0.95));
  clip-path: var(--chamfer); box-shadow: inset 0 0 0 2px #fff;
  filter: drop-shadow(0 0 calc(14px * var(--k)) rgba(255, 255, 255, 0.4));
}
#overlay .drum .list {
  height: 100%; overflow-y: auto; scrollbar-width: none; box-sizing: border-box;
  padding: calc(40px * var(--k) * 4) 0;
  -webkit-mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent);
  mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent);
}
#overlay .drum .list::-webkit-scrollbar { display: none; }
#overlay .drum .row {
  display: flex; align-items: center; gap: calc(10px * var(--k)); height: calc(40px * var(--k));
  margin: 0 calc(10px * var(--k)); padding: 0 calc(14px * var(--k));
  font-size: calc(17px * var(--k)); letter-spacing: 0.09em; color: rgba(255, 255, 255, 0.55); white-space: nowrap;
}
#overlay .drum .row .v { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#overlay .drum .row .caret, #overlay .drum .row .dot { visibility: hidden; }
#overlay .drum .row .dot { font-size: calc(10px * var(--k)); color: rgba(255, 255, 255, 0.6); }
#overlay .drum .row.chosen:not(.focus) .dot { visibility: visible; }
#overlay .drum .row:hover { color: #fff; background: rgba(255, 255, 255, 0.05); }
#overlay .drum .row.focus {
  color: #fff; font-size: calc(22px * var(--k)); font-weight: 700; letter-spacing: 0.12em;
  background: rgba(255, 255, 255, 0.08); box-shadow: inset 0 0 0 2px #fff;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
#overlay .drum .row.focus .caret { visibility: visible; }
#overlay.spinning .cards-row, #overlay.spinning .readout { opacity: 0.5; }

/* Style cards: picture over a numbered plate; ACTIVE tag on the current one. */
#overlay .cards-row {
  display: flex; gap: calc(30px * var(--k)); width: 100%; box-sizing: border-box;
  overflow-x: auto; scrollbar-width: none; scroll-behavior: smooth;
  padding: calc(24px * var(--k)) calc(60px * var(--k));
  transition: opacity 0.15s;
}
#overlay .cards-row::-webkit-scrollbar { display: none; }
#overlay .card { flex: none; width: calc(230px * var(--k)); }
#overlay .card .pic { position: relative; height: calc(230px * var(--k) * 9 / 16); background: #000; }
#overlay .card canvas { display: block; width: 100%; height: 100%; filter: saturate(0.75) brightness(0.88); transition: filter 0.18s; }
#overlay .card:focus canvas, #overlay .card:hover canvas { filter: none; }
#overlay .card .pic .icon { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(48px * var(--k)); color: rgba(255, 255, 255, 0.8); }
#overlay .card .divider { height: 1px; background: var(--line); opacity: 0.8; }
#overlay .card .plate {
  position: relative; display: flex; align-items: center; gap: calc(10px * var(--k));
  height: calc(40px * var(--k)); padding: 0 var(--cut) 0 calc(12px * var(--k));
  font-size: calc(17px * var(--k)); white-space: nowrap;
}
#overlay .card .plate .bar { height: calc(18px * var(--k)); }
#overlay .card .plate .name { overflow: hidden; text-overflow: ellipsis; letter-spacing: 0.14em; color: rgba(255, 255, 255, 0.85); }
#overlay .card:focus .plate, #overlay .card:hover .plate { font-weight: 700; }
#overlay .card:focus .num, #overlay .card:hover .num { color: #fff; }
#overlay .card:focus .bar, #overlay .card:hover .bar { background: #fff; }
#overlay .card .tag {
  display: none; position: absolute; left: calc(var(--cut) + 6px); top: 8px; z-index: 1;
  padding: 2px 6px; font-size: calc(12px * var(--k)); font-weight: 800; letter-spacing: 0.15em;
  color: #000; background: rgba(255, 255, 255, 0.85);
}
#overlay .card.active .tag { display: block; }
#overlay .card:focus .tag { background: #fff; }

/* Readout: what's on screen now, then help and the web's buttons. */
#overlay .readout {
  width: min(calc(1690px * var(--k)), calc(100% - 32px)); box-sizing: border-box;
  padding: calc(18px * var(--k)) calc(34px * var(--k));
  background:
    repeating-linear-gradient(transparent 0 2px, rgba(0, 0, 0, 0.15) 2px 3px),
    var(--plate);
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
  transition: opacity 0.15s;
}
#overlay .now {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: calc(8px * var(--k)) calc(14px * var(--k));
}
#overlay .now .head { font-size: calc(15px * var(--k)); font-weight: 700; letter-spacing: 0.17em; color: rgba(255, 255, 255, 0.55); }
#overlay .now .field { display: inline-flex; align-items: center; gap: calc(8px * var(--k)); white-space: nowrap; }
#overlay .now .bar { height: calc(18px * var(--k)); background: rgba(255, 255, 255, 0.3); }
#overlay .now .label { font-size: calc(13px * var(--k)); letter-spacing: 0.15em; color: rgba(255, 255, 255, 0.5); }
#overlay .now .value { font-size: calc(17px * var(--k)); font-weight: 700; letter-spacing: 0.09em; }
#overlay .now .diamond { font-size: calc(11px * var(--k)); color: rgba(255, 255, 255, 0.7); }
#overlay .rule { height: 1px; margin: calc(14px * var(--k)) 0; background: rgba(255, 255, 255, 0.18); }
#overlay .foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; }
#overlay .help { font-size: calc(14px * var(--k)); letter-spacing: 0.14em; color: rgba(255, 255, 255, 0.6); }
#overlay .buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
#overlay .hud-btn {
  font: inherit; font-size: max(11px, calc(13px * var(--k))); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: #fff; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 0;
  padding: 0.5em 0.9em; clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
}
#overlay .hud-btn:hover, #overlay .hud-btn:focus-visible { background: rgba(255, 255, 255, 0.18); border-color: #fff; outline: none; }
#overlay .lang { position: relative; display: inline-block; }
#overlay .lang-btn { text-transform: none; }
#overlay .lang-btn .glyph { margin-right: 0.6em; opacity: 0.7; }
#overlay .drum.above { right: auto; width: max(230px, calc(320px * var(--k))); text-transform: none; }
#overlay .links { display: flex; gap: 14px; margin-left: 6px; font-size: max(11px, calc(13px * var(--k))); letter-spacing: 0.12em; }
#overlay .links a { color: rgba(255, 255, 255, 0.65); text-decoration: none; }
#overlay .links a:hover, #overlay .links a:focus-visible { color: #fff; text-decoration: underline; outline: none; }

/* About page: over the artwork, on the wordmark's own background colour. */
#overlay .about {
  position: absolute; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center;
  padding: 16px; box-sizing: border-box; background: rgba(0, 0, 0, 0.65); overflow-y: auto;
}
#overlay .about.on { display: flex; }
#overlay .about-card {
  display: flex; flex-direction: column; align-items: center; gap: calc(30px * var(--k));
  width: min(1100px, 100%); box-sizing: border-box; margin: auto;
  padding: calc(60px * var(--k)) calc(70px * var(--k)); text-transform: none; text-align: center;
  background: #260c22; clip-path: var(--chamfer); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}
#overlay .about .wordmark { width: min(760px, 100%); height: auto; }
#overlay .about .copy p { margin: 0 0 0.5em; font-size: max(15px, calc(24px * var(--k))); line-height: 1.5; color: rgba(255, 255, 255, 0.9); }
#overlay .about .dedication { margin: 0; font-style: italic; font-size: max(13px, calc(18px * var(--k))); color: rgba(255, 255, 255, 0.7); }
#overlay .about-foot p { margin: 0.4em 0; font-size: max(11px, calc(15px * var(--k))); letter-spacing: 0.13em; text-transform: uppercase; color: rgba(255, 255, 255, 0.75); }
#overlay .about-foot .dim { color: rgba(255, 255, 255, 0.5); }
#overlay .about-foot a { color: inherit; }
#overlay .about-foot .copied { color: #fff; }
#overlay .about-foot a:focus { color: #fff; outline: 2px solid #fff; outline-offset: 4px; }
#overlay .about .done { min-width: calc(220px * var(--k)); height: calc(64px * var(--k)); }
#overlay .about .done .fill { display: flex; align-items: center; justify-content: center; padding: 0 32px; font-size: max(14px, calc(22px * var(--k))); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }

@media (max-width: 700px) {
  #overlay .top-row { gap: 12px 18px; }
  #overlay .readout { padding: 12px 14px; }
}

/* ---- photosensitivity notice ---- */
#notice {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.6); z-index: 10;
}
#notice.on { display: flex; }
#notice .card {
  width: min(90vw, 440px); padding: 22px 24px; border-radius: 16px;
  background: rgba(20, 20, 20, 0.95); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
#notice h2 { margin: 0 0 8px; font-size: 18px; }
#notice p { margin: 0 0 10px; opacity: 0.85; }
#notice button { margin-top: 6px; }

/* ---- loading / error ---- */
#status {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #ccc; padding: 2em; text-align: center;
}
#notice .links { margin: 1em 0 0; font-size: 0.85em; opacity: 0.7; }
#notice .links a { color: inherit; }

/* ---- get the app header (src/getapp.ts) ---- */
#getapp {
  position: fixed; top: 0; left: 0; right: 0; z-index: 6; box-sizing: border-box;
  display: flex; align-items: center; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.78), rgba(8, 20, 31, 0.78));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  transform: translateY(-100%); opacity: 0; transition: transform 0.35s ease, opacity 0.35s ease;
  cursor: auto;
}
#getapp.on { transform: none; opacity: 1; }
#getapp .icon { width: 40px; height: 40px; border-radius: 9px; flex: none; }
#getapp .text { flex: 1; min-width: 0; }
#getapp .title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#getapp .sub { font-size: 12px; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#getapp .get {
  flex: none; color: #000; background: #fff; text-decoration: none; font-weight: 600; font-size: 13px;
  padding: 0.5em 1em; border-radius: 999px; white-space: nowrap;
}
#getapp .get:hover { background: #e6e6e6; }
#getapp .get:focus-visible, #getapp .close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#getapp .close {
  flex: none; background: none; border: 0; padding: 0 4px; font-size: 22px; line-height: 1; color: rgba(255, 255, 255, 0.7);
}
#getapp .close:hover { color: #fff; background: none; }
@media (max-width: 420px) {
  #getapp { gap: 10px; }
  #getapp .icon { width: 34px; height: 34px; }
  #getapp .sub { display: none; }
  #getapp .title { white-space: normal; font-size: 14px; line-height: 1.25; }
}
@media (prefers-reduced-motion: reduce) { #getapp { transition: opacity 0.2s; } }
