/* ===========================================================================
   Mediabox Radio — tuner.css
   PALETTE COVENANT (accessibility, not taste — the operator has tritanomaly):
   purple / teal / coral / pink / blue ramps ONLY.
   BANNED: any color with hue 33-66 deg at saturation >= 15% and lightness
   10-97% (beige, tan, wheat, khaki, gold, goldenrod, mustard, amber).
   The retro-radio instinct reaches for amber dial lighting. It is banned here.
   The warm role is carried by coral (~12 deg). Audited by R2-palette-audit.py.
   =========================================================================== */

:root {
  /* --- ink (purple-black ramp, hue ~249) ------------------------------- */
  --ink-900: #0b0a16;
  --ink-850: #100d20;
  --ink-800: #171233;
  --ink-700: #1e1742;
  --ink-600: #2a2059;
  --ink-500: #3b2f75;
  --ink-400: #4a3a92;

  /* --- text (same hue family, high L) ---------------------------------- */
  --text:      #ece9fb;
  --text-soft: #b9b0e4;
  --text-dim:  #8279bb;
  --text-faint:#6a5f9c;

  /* --- teal: the "signal / locked on" role ----------------------------- */
  --teal:      #2fd9c5;
  --teal-mid:  #19a595;
  --teal-deep: #0f6b62;

  /* --- purple: the structural accent ----------------------------------- */
  --purple:      #a06bff;
  --purple-deep: #7b3ff2;

  /* --- pink: the live / now-playing role -------------------------------- */
  --pink: #ff5fa8;

  /* --- coral: the WARM role (replaces every amber/gold instinct) -------- */
  --coral:      #ff6a45;
  --coral-deep: #e0492a;

  /* --- blue: informational ---------------------------------------------- */
  --blue: #4da6ff;

  --white: #ffffff;
  --shadow: rgba(0, 0, 0, 0.55);
  --shadow-soft: rgba(0, 0, 0, 0.30);
  --sheen: rgba(255, 255, 255, 0.06);
  --sheen-2: rgba(255, 255, 255, 0.12);

  --sp: 160px;             /* detent spacing, overwritten by JS on layout */
  --radius: 16px;
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink-900);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--ink-700) 0%, var(--ink-900) 62%),
    var(--ink-900);
  padding: clamp(12px, 3vw, 28px);
  padding-bottom: max(clamp(12px, 3vw, 28px), env(safe-area-inset-bottom));
}

.shell {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.2vw, 18px);
}

/* ----------------------------- masthead ---------------------------------- */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  letter-spacing: 0.18em;
  font-weight: 700;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text-soft); }
.brand-lamp {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 10px var(--coral);
}
.conn {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 11px;
}
.conn-lamp {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  transition: background 200ms ease, box-shadow 200ms ease;
}
.conn.ok    .conn-lamp { background: var(--teal); box-shadow: 0 0 8px var(--teal); }
.conn.ok    #connText  { color: var(--teal-mid); }
.conn.bad   .conn-lamp { background: var(--coral); box-shadow: 0 0 8px var(--coral); }
.conn.bad   #connText  { color: var(--coral); }

/* ----------------------------- readout ----------------------------------- */
.readout {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(14px, 2.6vw, 20px) clamp(16px, 3vw, 24px);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--ink-800), var(--ink-850));
  border: 1px solid var(--ink-600);
  box-shadow: inset 0 1px 0 var(--sheen), 0 12px 28px -18px var(--shadow);
}
.readout-freq {
  font-family: var(--mono);
  font-size: clamp(38px, 12vw, 64px);
  line-height: 0.92;
  font-weight: 700;
  color: var(--teal);
  text-shadow: 0 0 22px var(--teal-deep);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.readout-unit {
  font-size: 0.30em;
  font-style: normal;
  margin-left: 0.35em;
  letter-spacing: 0.22em;
  color: var(--teal-mid);
  vertical-align: 0.9em;
}
.readout-station {
  margin-top: 8px;
  font-size: clamp(15px, 4.2vw, 21px);
  font-weight: 650;
  color: var(--text);
  letter-spacing: 0.01em;
}
.readout-right { text-align: right; flex: 0 0 auto; }
.sig { display: flex; align-items: flex-end; gap: 3px; height: 26px; justify-content: flex-end; }
.sig i {
  display: block;
  width: 5px;
  border-radius: 2px;
  background: var(--ink-500);
  transition: background 160ms ease, box-shadow 160ms ease;
}
.sig i.on { background: var(--teal); box-shadow: 0 0 7px var(--teal-deep); }
.sig-label {
  margin-top: 7px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ------------------------------ the dial --------------------------------- */
.tuner {
  position: relative;
  height: clamp(122px, 22vw, 150px);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(180deg, var(--ink-850) 0%, var(--ink-800) 46%, var(--ink-700) 100%);
  border: 1px solid var(--ink-600);
  box-shadow: inset 0 2px 10px var(--shadow-soft), 0 18px 40px -26px var(--shadow);
  cursor: grab;
  touch-action: none;                 /* the drag belongs to the dial */
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}
.tuner:focus-visible { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-deep); }
.tuner.dragging { cursor: grabbing; }

.band {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 0;
  will-change: transform;
}

.ticks { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.tick {
  /* The scale sits along the BOTTOM edge, the way a real dial plate reads —
     numbers and station names above it, ruler below. Anchored top it collided
     with the frequency labels. */
  position: absolute;
  bottom: 12px;
  width: 1px;
  background: var(--ink-500);
}
.tick.major { background: var(--ink-400); width: 2px; }

.detent {
  position: absolute;
  top: 0;
  bottom: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 10px;
  width: calc(var(--sp) - 8px);
  text-align: center;
  transition: opacity 120ms linear;
}
.detent-freq {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  transition: color 140ms ease;
}
.detent-stalk {
  margin-top: 6px;
  width: 2px;
  height: 30px;
  border-radius: 1px;
  background: linear-gradient(180deg, var(--purple), var(--purple-deep));
  /* Grow via transform, never height: the dial restyles all 12 stalks on every
     pointermove during a drag, and animating height relayouts the whole rail. */
  transform-origin: top center;
  transition: background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
  will-change: transform;
}
.detent-name {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  max-width: calc(var(--sp) - 12px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 140ms ease;
}
.detent.near .detent-freq { color: var(--text-soft); }
.detent.near .detent-name { color: var(--text-soft); }
.detent.live .detent-freq { color: var(--teal); }
.detent.live .detent-name { color: var(--text); }
.detent.live .detent-stalk {
  background: linear-gradient(180deg, var(--teal), var(--teal-deep));
  box-shadow: 0 0 12px var(--teal-deep);
  /* 38/30 — the same 8px growth the old `height: 38px` gave, on the compositor. */
  transform: scaleY(1.2667);
}

.glass {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(180deg, var(--sheen-2) 0%, rgba(255, 255, 255, 0) 30%),
    linear-gradient(0deg, var(--shadow-soft) 0%, rgba(0, 0, 0, 0) 40%);
}
.fade {
  position: absolute; top: 0; bottom: 0; width: 15%;
  pointer-events: none;
}
.fade-l { left: 0;  background: linear-gradient(90deg, var(--ink-850), rgba(11, 10, 22, 0)); }
.fade-r { right: 0; background: linear-gradient(270deg, var(--ink-850), rgba(11, 10, 22, 0)); }

.needle {
  position: absolute;
  left: 50%;
  top: 6px;
  bottom: 6px;
  width: 3px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: linear-gradient(180deg, var(--coral), var(--coral-deep));
  box-shadow: 0 0 14px var(--coral), 0 0 34px var(--coral-deep);
  pointer-events: none;
}
.needle-cap {
  position: absolute;
  left: 50%; top: -3px;
  width: 11px; height: 11px;
  margin-left: -5.5px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 12px var(--coral);
}

/* ------------------------------- dots ------------------------------------ */
.dots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
}
.dot {
  appearance: none;
  border: 0;
  background: none;
  /* 29 x 45 px touch target around a 7px dot. Height clears the WCAG 2.5.5
     (AAA) 44px bar; width is capped by arithmetic, not by taste -- twelve
     44px-wide targets need 528px and the dial is 366px on a 390px phone.
     29px still clears WCAG 2.5.8 (AA) at 24px, and every dot is redundant
     with the dial itself and the prev/next buttons. */
  padding: 19px 11px;
  cursor: pointer;
  line-height: 0;
}
.dot i {
  display: block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-400);
  transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
.dot[aria-current="true"] i {
  background: var(--teal);
  box-shadow: 0 0 10px var(--teal-deep);
  transform: scale(1.45);
}
.dot:focus-visible i { outline: 2px solid var(--purple); outline-offset: 3px; }

/* ----------------------------- transport --------------------------------- */
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3vw, 18px);
}
.tbtn, .pbtn, .vbtn {
  appearance: none;
  font-family: inherit;
  cursor: pointer;
  border-radius: 14px;
  border: 1px solid var(--ink-500);
  background: linear-gradient(180deg, var(--ink-700), var(--ink-800));
  color: var(--text-soft);
  box-shadow: inset 0 1px 0 var(--sheen), 0 8px 18px -12px var(--shadow);
  transition: border-color 140ms ease, color 140ms ease, transform 90ms ease;
}
.tbtn:active, .pbtn:active, .vbtn:active { transform: translateY(1px); }
.tbtn:focus-visible, .pbtn:focus-visible, .vbtn:focus-visible {
  outline: 2px solid var(--purple); outline-offset: 2px;
}
.tbtn {
  width: 62px; height: 54px;
  display: grid; place-items: center;
}
.tbtn svg { width: 22px; height: 22px; fill: currentColor; }
.tbtn:hover { color: var(--text); border-color: var(--purple-deep); }

.pbtn {
  min-width: 190px; height: 58px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.16em;
  color: var(--ink-900);
  border-color: var(--teal-mid);
  background: linear-gradient(180deg, var(--teal), var(--teal-mid));
  box-shadow: 0 0 0 1px var(--teal-deep), 0 14px 30px -16px var(--teal-deep);
}
.pbtn svg { width: 20px; height: 20px; fill: currentColor; }
.pbtn .ic-stop { display: none; }
.pbtn.on { background: linear-gradient(180deg, var(--pink), #d8397f); border-color: var(--pink); }
.pbtn.on .ic-play { display: none; }
.pbtn.on .ic-stop { display: block; }

/* ------------------------------ volume ----------------------------------- */
.vol {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-radius: 14px;
  background: var(--ink-850);
  border: 1px solid var(--ink-700);
}
.vbtn {
  width: 48px; height: 44px;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.vbtn svg { width: 20px; height: 20px; fill: currentColor; }
.vbtn svg .wave { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.vbtn.off { color: var(--coral); border-color: var(--coral-deep); }
.vbtn.off svg .wave { opacity: 0.25; }
.vbtn-wide {
  width: auto; padding: 0 14px;
  font-size: 10px; font-weight: 800; letter-spacing: 0.16em;
}
.vbtn-wide[aria-pressed="false"] { color: var(--text-faint); }
.vbtn-wide[aria-pressed="true"]  { color: var(--teal); border-color: var(--teal-deep); }

.vslider {
  appearance: none;
  flex: 1 1 auto;
  height: 32px;
  background: none;
  cursor: pointer;
}
.vslider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--purple), var(--teal));
}
.vslider::-moz-range-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--purple), var(--teal));
}
.vslider::-webkit-slider-thumb {
  appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--ink-900);
  box-shadow: 0 2px 8px var(--shadow);
}
.vslider::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--ink-900);
}

/* --------------------------- now playing --------------------------------- */
.now {
  padding: clamp(14px, 2.6vw, 20px) clamp(16px, 3vw, 22px);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--ink-800), var(--ink-850));
  border: 1px solid var(--ink-600);
  min-height: 118px;
}
.now-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 10px; font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--pink);
}
.now-mount {
  font-family: var(--mono);
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 600;
}
.now-artist {
  margin-top: 10px;
  font-size: clamp(17px, 4.6vw, 22px);
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}
.now-title {
  margin-top: 3px;
  font-size: clamp(14px, 3.8vw, 17px);
  color: var(--text-soft);
  overflow-wrap: anywhere;
}
.now.changed .now-artist, .now.changed .now-title { animation: lift 600ms ease; }
@keyframes lift { from { opacity: 0.15; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.now-meta {
  margin-top: 12px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-faint);
}
.pill {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--blue);
  background: var(--ink-700);
  border: 1px solid var(--ink-500);
}

/* ------------------------------- hint ------------------------------------ */
.hint {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  justify-content: center;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}
.hint b { color: var(--text-dim); font-weight: 700; }

/* --------------------------- narrow screens ------------------------------ */
@media (max-width: 460px) {
  .readout { flex-direction: row; align-items: center; }
  .readout-station { font-size: 15px; }
  .pbtn { min-width: 0; flex: 1 1 auto; }
  .tbtn { width: 56px; }
  .hint span:nth-child(2) { display: none; }   /* no scroll wheel on a phone */
  .now { min-height: 106px; }
}

@media (hover: none) {
  .tbtn:hover { color: var(--text-soft); border-color: var(--ink-500); }
}

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