/* 24/7UNO — Phase 1 styles. "Midnight Broadcast".
   Near-black base, warm off-white type, #e30000 signal, per-song accent hue. */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #0A0A0B;
  --text: #EDE8E0;
  --text-muted: #8A857D;
  --text-dim: #7A756C;   /* was #5f5b54 (2.68:1, failed AA on #0A0A0B) → now ~4.1:1 */

  --signal: #e30000;                 /* the constant "tally light" */
  --signal-glow: rgba(227, 0, 0, .55);

  /* Per-song accent — JS overrides these each track. Default = signal red. */
  --accent: #e30000;
  --accent-soft: rgba(227, 0, 0, .16);
  --accent-glow: rgba(227, 0, 0, .5);

  --surface: rgba(18, 18, 20, .5);
  --border: rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .16);

  --radius: 16px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Segoe UI Mono', Menlo, Consolas, monospace;

  /* Time-of-day (overridden per band below) */
  --env-bright: .6;
  --env-sat: 1.35;
  --scrim: .66;
  --tint: rgba(80, 30, 10, .16);
}

html[data-timeofday="night"] { --env-bright: .48; --scrim: .76; --tint: rgba(70, 26, 8, .26); }
html[data-timeofday="dawn"]  { --env-bright: .60; --scrim: .64; --tint: rgba(86, 66, 96, .16); }
html[data-timeofday="day"]   { --env-bright: .74; --scrim: .54; --tint: rgba(44, 64, 92, .10); }
html[data-timeofday="dusk"]  { --env-bright: .60; --scrim: .66; --tint: rgba(92, 40, 12, .20); }

/* ── Base ───────────────────────────────────────────────────────────────── */
* , *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* beats the display on chips/glyph/toast */
html { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100svh;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.mono { font-family: var(--font-mono); }
/* Visually hidden but exposed to assistive tech (for the now-playing live region). */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ── Signature environment ──────────────────────────────────────────────── */
.environment { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: var(--bg); }
.env-layer {
  position: absolute; inset: -8%;          /* overscan so blur edges never show */
  background-size: cover; background-position: center;
  filter: blur(64px) saturate(var(--env-sat)) brightness(var(--env-bright));
  transform: scale(1.18);
  opacity: 0; transition: opacity 1.2s ease;
  will-change: opacity;
  animation: drift 42s ease-in-out infinite alternate;
}
.env-layer.is-active { opacity: 1; }
@keyframes drift {
  from { transform: scale(1.18) translate3d(0, 0, 0); }
  to   { transform: scale(1.28) translate3d(-2%, -2%, 0); }
}
.env-scrim {
  position: absolute; inset: 0; opacity: var(--scrim);
  background:
    radial-gradient(120% 90% at 50% 0%, transparent 38%, rgba(0, 0, 0, .5) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, .38) 0%, rgba(0, 0, 0, .10) 30%, rgba(0, 0, 0, .55) 74%, rgba(6, 6, 7, .92) 100%);
}
.env-tint { position: absolute; inset: 0; background: var(--tint); mix-blend-mode: soft-light; pointer-events: none; }
/* Living Signal canvas — hidden until a source is chosen, then screen-blended over the art. */
.viz { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; will-change: opacity; }
html.living-signal .viz { opacity: .55; mix-blend-mode: screen; transition: opacity .8s ease; }
@media (prefers-reduced-motion: reduce) { html.living-signal .viz { opacity: .32; } }

/* Signal Readout — radial audio-reactive spectrum (audit item B). Its OWN layer:
   NO mix-blend-mode, so it doesn't stack onto the blur+blend GPU budget like .viz.
   When on we rebalance: trim the env blur (64→46px) + PAUSE drift (the biggest GPU
   reclaim), and dim the constellation — so total cost stays flat. See the handoff. */
.spectrum { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; will-change: opacity; }
html.has-spectrum .spectrum { opacity: 1; transition: opacity .8s ease; }
html.has-spectrum .env-layer { filter: blur(46px) saturate(var(--env-sat)) brightness(var(--env-bright)); animation: none; }
html.has-spectrum .viz { opacity: .3; }
@media (prefers-reduced-motion: reduce) { html.has-spectrum .spectrum { opacity: .85; } }

/* ── Tune-in intro ("signal acquire") ──────────────────────────────────────── */
.tune-in { position: fixed; inset: 0; z-index: 50; pointer-events: none; background: #08080a; overflow: hidden; }
.tune-in__static {
  position: absolute; inset: -20%; opacity: .5; mix-blend-mode: screen;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .09) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .05) 0 1px, transparent 1px 2px);
  background-size: 100% 4px, 3px 100%;
}
.tune-in__scan {
  position: absolute; left: 0; right: 0; top: 0; height: 2px; opacity: 0;
  background: hsl(var(--accent-h, 0) 90% 60%);
  box-shadow: 0 0 26px 6px hsl(var(--accent-h, 0) 90% 60% / .7);
}
.tune-in__label {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; opacity: 0;
  letter-spacing: .32em; text-transform: uppercase; color: var(--text); font-size: .72rem;
}
.tune-in__label small { display: block; margin-top: 9px; color: var(--signal); letter-spacing: .26em; font-size: .6rem; }

.tune-in--play { animation: tuneOut .5s ease 1.05s forwards; }
.tune-in--play .tune-in__static { animation: staticShift .5s steps(6) infinite, staticFade 1.5s ease forwards; }
.tune-in--play .tune-in__scan { animation: scanDown 1s cubic-bezier(.5, 0, .2, 1) forwards; }
.tune-in--play .tune-in__label { animation: labelFlicker 1.15s steps(9) forwards; }
.tune-in--instant { animation: tuneOut .25s ease forwards; }

@keyframes tuneOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes staticShift { to { background-position: 0 -8px, 6px 0; } }
@keyframes staticFade { 0% { opacity: .5; } 70% { opacity: .32; } 100% { opacity: 0; } }
@keyframes scanDown { 0% { top: -2%; opacity: 0; } 8% { opacity: 1; } 92% { opacity: 1; } 100% { top: 102%; opacity: 0; } }
@keyframes labelFlicker { 0%, 9% { opacity: 0; } 13% { opacity: 1; } 18% { opacity: .35; } 24% { opacity: 1; } 62% { opacity: 1; } 100% { opacity: 0; } }

/* ── Stage ──────────────────────────────────────────────────────────────── */
.stage {
  position: relative; z-index: 1;
  max-width: 1080px; margin: 0 auto;
  min-height: 100svh;
  display: flex; flex-direction: column;
  gap: clamp(20px, 4vh, 40px);
  padding: clamp(20px, 4vw, 44px) clamp(18px, 4vw, 44px) clamp(24px, 4vh, 40px);
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.logo-slot { display: inline-flex; align-items: center; gap: 10px; }
.logo-img { height: 34px; width: auto; display: block; }
.logo-slot.is-placeholder {
  padding: 7px 13px 7px 11px; border-radius: 999px;
  border: 1px dashed rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .03);
}
.logo-mark { width: 11px; height: 11px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 12px var(--signal-glow); }
.logo-word { font-weight: 650; letter-spacing: .14em; text-transform: uppercase; font-size: .82rem; }

.onair {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.onair-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 10px var(--signal-glow); animation: pulse 2s ease-in-out infinite; }
.onair-text { font-size: .68rem; letter-spacing: .2em; text-transform: uppercase; }
.onair[data-mode="off"] { opacity: .65; }
.onair[data-mode="off"] .onair-dot { background: var(--text-dim); box-shadow: none; animation: none; }
.onair[data-mode="off"] .onair-text { color: var(--text-muted); }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.82); } }

/* ── Now playing ────────────────────────────────────────────────────────── */
.now-playing { display: flex; flex-direction: column; gap: clamp(18px, 3vw, 28px); align-items: flex-start; margin-top: auto; }
.cover {
  position: relative; width: clamp(150px, 42vw, 200px); aspect-ratio: 1; flex: none;
  border-radius: var(--radius); overflow: hidden;
  background: #111214; border: 1px solid var(--border);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), inset 0 2px 0 rgba(255, 255, 255, .04);
}
.cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-mark { display: none; }
.cover.is-artless {
  background: radial-gradient(120% 120% at 30% 20%, hsl(var(--mark-hue, 0) 55% 30%), hsl(var(--mark-hue, 0) 50% 12%) 70%, #0a0a0b);
}
.cover.is-artless .cover-img { display: none; }
.cover.is-artless .cover-mark { display: grid; place-items: center; position: absolute; inset: 0; }
.cover-mark svg { width: 36%; height: 36%; fill: rgba(255, 255, 255, .5); }

.np-info { min-width: 0; }
.np-eyebrow { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin: 0 0 12px; }
.np-label { margin: 0; display: inline-flex; align-items: center; gap: 9px; font-size: .66rem; letter-spacing: .24em; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }
.np-label::before { content: ""; width: 16px; height: 2px; background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }

/* Signal glyph — 3 rising "connection" bars, always full; recolors with the per-song accent. */
.energy-glyph { display: inline-flex; align-items: flex-end; gap: 3px; height: 13px; }
.energy-glyph i { width: 3px; border-radius: 2px; background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); transition: background .4s ease, box-shadow .4s ease; }
.energy-glyph i:nth-child(1) { height: 5px; }
.energy-glyph i:nth-child(2) { height: 9px; }
.energy-glyph i:nth-child(3) { height: 13px; }
.np-title { margin: 0; font-weight: 600; letter-spacing: -.02em; line-height: 1.02; font-size: clamp(2.1rem, 7.5vw, 4.6rem); text-wrap: balance; text-shadow: 0 2px 30px rgba(0, 0, 0, .5); }
.np-artist { margin: 12px 0 0; font-size: clamp(1rem, 2.6vw, 1.35rem); color: var(--text); }
.np-album { margin: 5px 0 0; font-size: .9rem; color: var(--text-muted); }

/* ── Transport ──────────────────────────────────────────────────────────── */
.transport { display: flex; align-items: center; gap: clamp(14px, 3vw, 22px); }
.play-btn {
  position: relative; flex: none; width: 64px; height: 64px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: rgba(255, 255, 255, .06);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  color: var(--text); cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  transition: transform .18s ease, box-shadow .3s ease, background .3s ease, border-color .3s ease;
}
.play-btn:hover { transform: translateY(-1px); background: rgba(255, 255, 255, .09); box-shadow: 0 0 30px 2px var(--accent-glow), 0 10px 30px rgba(0, 0, 0, .4); }
.play-btn:active { transform: scale(.96); }
.play-btn .icon { grid-area: 1 / 1; width: 26px; height: 26px; fill: var(--text); }
.icon-play { transform: translateX(2px); }
.play-btn .icon-pause { display: none; }
.play-btn[data-state="playing"] .icon-play,
.play-btn[data-state="loading"] .icon-play { display: none; }
.play-btn[data-state="playing"] .icon-pause,
.play-btn[data-state="loading"] .icon-pause { display: block; }
.play-btn[data-state="playing"] { border-color: var(--accent); box-shadow: 0 0 26px 1px var(--accent-glow), 0 10px 30px rgba(0, 0, 0, .4); }
.play-ring { position: absolute; inset: -1px; border-radius: 50%; border: 2px solid transparent; pointer-events: none; }
.play-btn[data-state="loading"] .play-ring { border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.progress-track { height: 4px; border-radius: 99px; background: rgba(255, 255, 255, .14); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; border-radius: 99px; background: var(--accent); box-shadow: 0 0 12px var(--accent-glow); transition: width .35s linear; }
.progress-time { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-muted); letter-spacing: .04em; }

.volume { display: inline-flex; align-items: center; gap: 9px; color: var(--text-muted); flex: none; }
.vol-icon { width: 22px; height: 22px; fill: currentColor; }
input[type="range"]#volume { -webkit-appearance: none; appearance: none; width: 84px; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, .16); outline: none; cursor: pointer; }
input[type="range"]#volume::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; background: var(--text); box-shadow: 0 0 8px rgba(0, 0, 0, .5); }
input[type="range"]#volume::-moz-range-thumb { width: 13px; height: 13px; border: none; border-radius: 50%; background: var(--text); }

/* ── Readouts ───────────────────────────────────────────────────────────── */
.readouts { display: flex; gap: clamp(20px, 5vw, 48px); flex-wrap: wrap; align-items: flex-end; }
.readout { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.readout-label { font-family: var(--font-mono); font-size: .62rem; letter-spacing: .22em; text-transform: uppercase; color: var(--text-muted); }
.listener-count { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 500; line-height: 1; display: inline-flex; align-items: center; gap: 10px; }
/* Low-listener state: the value is session uptime (text, not a head-count) → smaller. */
.listeners[data-low="1"] .listener-count { font-size: clamp(1.15rem, 3.2vw, 1.5rem); letter-spacing: .02em; }
.listeners .listener-count::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 8px var(--signal-glow); animation: pulse 2s ease-in-out infinite; }
.upnext { max-width: min(62vw, 360px); }
.next-track { font-size: .95rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ── History ────────────────────────────────────────────────────────────── */
.history { display: flex; flex-direction: column; gap: 12px; }
.history-heading { margin: 0; }
.history-list { list-style: none; margin: 0; padding: 0 0 4px; display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.history-list::-webkit-scrollbar { height: 0; }
.history-item {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px; scroll-snap-align: start;
  padding: 8px 15px 8px 8px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.history-swatch { width: 38px; height: 38px; border-radius: 8px; background-size: cover; background-position: center; background-color: #15161a; flex: none; }
.history-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.history-title { font-size: .86rem; white-space: nowrap; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.history-time { font-size: .64rem; color: var(--text-muted); letter-spacing: .04em; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
.footer { display: flex; justify-content: space-between; gap: 12px; font-size: .62rem; letter-spacing: .16em; color: var(--text-dim); text-transform: uppercase; padding-top: 4px; }
.footer .adlib { text-transform: none; letter-spacing: .08em; }

/* ── Welcome-back line ──────────────────────────────────────────────────────── */
.welcome {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px); z-index: 40;
  max-width: min(92vw, 460px); text-align: center;
  padding: 10px 18px; border-radius: 999px;
  background: rgba(16, 16, 18, .74); border: 1px solid var(--border);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  color: var(--text); font-size: .72rem; letter-spacing: .05em;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .46);
  opacity: 0; transition: opacity .5s ease, transform .5s ease; pointer-events: none;
}
.welcome.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* ── Focus ──────────────────────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (min-width: 720px) {
  .now-playing { flex-direction: row; align-items: flex-end; gap: clamp(24px, 4vw, 40px); }
  .cover { width: clamp(190px, 22vw, 240px); }
  .np-info { padding-bottom: 6px; }
  .history-title { max-width: 220px; }
}
@media (max-width: 420px) {
  .volume { display: none; }
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .env-layer { animation: none; transition-duration: .35s; }
  .onair-dot, .listeners .listener-count::before { animation: none; }
  .play-btn[data-state="loading"] .play-ring { animation-duration: 2s; }
  .welcome { transition: opacity .3s ease; transform: translate(-50%, 0); }
}
