/* Signal: start with a narrow, touch-first viewport; expand only when it fits. */
:root {
  color-scheme: dark;
  --bg: #101311;
  --panel: #191d19;
  --raised: #222722;
  --text: #f0f2e9;
  --secondary: #a5aea0;
  --muted: #8c9788;
  --line: #30372f;
  --accent: #d5f879;
  --accent-ink: #18210c;
  --danger: #ffb4aa;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden], audio { display: none !important; }
html { background: var(--bg); scroll-padding-block: 20px 120px; }
body { margin: 0; color: var(--text); background: var(--bg); -webkit-tap-highlight-color: transparent; }
body.sound-open { overflow: hidden; }
button, input { font: inherit; }
button {
  min-height: 48px;
  border: 1px solid transparent;
  color: inherit;
  background: var(--raised);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button, summary, input { outline-offset: 4px; }
:focus-visible { outline: 2px solid var(--accent); }
button:disabled { opacity: .55; cursor: wait; }
button:active:not(:disabled) { transform: scale(.98); }
svg { display: block; width: 22px; height: 22px; flex: none; }
h1, h2, h3, p { margin: 0; }

.app {
  width: min(1120px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--safe-t) max(20px, var(--safe-r)) 0 max(20px, var(--safe-l));
  display: flex;
  flex-direction: column;
}
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 0; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 23px; font-weight: 700; letter-spacing: -.8px; }
.brand-mark { display: flex; align-items: center; justify-content: center; gap: 3px; width: 40px; height: 40px; border-radius: 13px; background: var(--accent); }
.brand-mark i { width: 3px; background: var(--accent-ink); border-radius: 2px; }
.brand-mark i:nth-child(1) { height: 10px; }
.brand-mark i:nth-child(2) { height: 22px; }
.brand-mark i:nth-child(3) { height: 16px; }
.brand-mark i:nth-child(4) { height: 8px; }
.brand-caption { display: block; margin-top: 3px; color: var(--secondary); font-size: 10px; font-weight: 500; letter-spacing: 1.8px; text-transform: uppercase; }
.sound-button { display: flex; align-items: center; justify-content: center; gap: 8px; border-color: var(--line); border-radius: 999px; padding: 0 17px; background: transparent; font-size: 14px; font-weight: 600; }
.sound-button svg { width: 20px; height: 20px; }

.content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 26px; align-content: start; flex: 1; padding: 10px 0 28px; }
.now-playing { min-width: 0; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 24px; }
.eyebrow { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-bottom: 25px; }
.section-label, .programme-label, .transport-caption { font-size: 11px; font-weight: 600; line-height: 1.4; letter-spacing: 1.5px; text-transform: uppercase; color: var(--secondary); }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; color: var(--secondary); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="playing"] { color: var(--accent); }
.status[data-state="playing"] .dot { background: var(--accent); box-shadow: 0 0 0 4px #d5f87912; }
.status[data-state="connecting"], .status[data-state="reconnecting"] { color: #e6cb89; }
.status[data-state="connecting"] .dot, .status[data-state="reconnecting"] .dot { background: #e6cb89; }
.status[data-state="error"] { color: var(--danger); }
.status[data-state="error"] .dot { background: var(--danger); }
.station-identity { display: flex; align-items: center; gap: 16px; }
.station-art { width: 64px; height: 64px; flex: none; display: grid; place-items: center; border: 1px solid #394035; border-radius: 15px; background: #0e120e; overflow: hidden; }
.station-art img { width: 80%; max-height: 62%; object-fit: contain; }
.station-art span { font-size: 20px; font-weight: 700; color: var(--accent); }
.station-heading { min-width: 0; }
.station-title { font-size: clamp(25px, 5.8vw, 36px); line-height: 1.12; letter-spacing: -1px; font-weight: 650; overflow-wrap: anywhere; }
.station-description { margin-top: 9px; font-size: 13px; line-height: 1.5; color: var(--secondary); }
.programme { display: none; border-top: 1px solid var(--line); padding-top: 19px; margin-top: 24px; overflow-wrap: anywhere; }
.programme.visible { display: block; }
.programme-label { margin-bottom: 9px; font-size: 10px; }
.programme-title { font-size: 19px; line-height: 1.35; font-weight: 550; letter-spacing: -.3px; }
.programme-sub { margin-top: 7px; font-size: 14px; line-height: 1.5; color: var(--secondary); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.programme-meta { margin-top: 10px; font-size: 12px; line-height: 1.5; color: var(--secondary); }
.programme[data-state="loading"] .programme-title, .programme[data-state="empty"] .programme-title { font-size: 16px; font-weight: 400; color: var(--secondary); }
.tuning-scale { display: none; }

.station-section { min-width: 0; }
.station-section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.station-section h2 { font-size: 20px; font-weight: 550; letter-spacing: -.4px; }
.station-count { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--secondary); border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px; }
#stationButtons { display: grid; gap: 8px; }
.station-btn { display: flex; align-items: center; gap: 13px; width: 100%; min-width: 0; min-height: 76px; padding: 13px 14px; text-align: left; border: 1px solid var(--line); border-radius: 15px; background: transparent; scroll-margin-block: 16px 125px; }
.station-logo { width: 56px; height: 42px; display: grid; place-items: center; flex: none; padding: 7px; background: #1d221d; border-radius: 8px; }
.station-logo img { width: 100%; max-height: 100%; object-fit: contain; }
.station-copy { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.station-name { font-size: 15px; font-weight: 550; line-height: 1.3; overflow-wrap: anywhere; }
.station-detail { font-size: 12px; line-height: 1.4; color: var(--secondary); }
.station-indicator { display: grid; place-items: center; width: 23px; height: 23px; flex: none; border: 1px solid #4a5345; border-radius: 50%; color: var(--accent-ink); }
.station-indicator .check { width: 14px; height: 14px; opacity: 0; }
.station-btn[aria-checked="true"] { background: #d5f8790a; border-color: #899e53; }
.station-btn[aria-checked="true"] .station-indicator { border-color: var(--accent); background: var(--accent); }
.station-btn[aria-checked="true"] .check { opacity: 1; }

/* A single transport remains reachable as the document scrolls. */
.transport { position: sticky; bottom: 0; z-index: 2; padding: 16px 0 max(18px, var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); box-shadow: 0 -12px 20px var(--bg); }
.transport-main { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.transport-info { flex: 1; min-width: 0; }
.transport-caption { display: flex; align-items: center; gap: 8px; font-size: 9px; letter-spacing: 1.3px; }
.transport-station { display: block; margin-top: 7px; font-size: 13px; font-weight: 550; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mini-signal { display: flex; align-items: center; gap: 2px; height: 13px; }
.mini-signal i { width: 2px; height: 4px; border-radius: 2px; background: var(--secondary); }
.mini-signal i:nth-child(2) { height: 10px; }
.mini-signal i:nth-child(3) { height: 7px; }
.app[data-playing="true"] .mini-signal i { background: var(--accent); }
.play-row { display: flex; gap: 8px; flex: none; }
#playBtn { display: flex; align-items: center; justify-content: center; gap: 9px; min-width: 138px; min-height: 58px; padding: 0 20px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); font-size: 15px; font-weight: 650; }
#playBtn svg { width: 22px; height: 22px; }
#retryBtn { display: none; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; border: 1px solid var(--line); border-radius: 16px; font-size: 14px; font-weight: 600; }
#retryBtn.visible { display: flex; }
#retryBtn svg { width: 20px; height: 20px; }
.error-box { display: none; padding: 12px 14px; margin-bottom: 14px; border-radius: 12px; border: 1px solid #69403b; background: #2b1d1b; color: var(--danger); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: min(140px, 25dvh); overflow-y: auto; }
.error-box.visible { display: block; }

/* Native dialog supplies focus containment, Escape, and inert background content. */
#soundDialog { position: fixed; inset: auto 0 0; width: min(100%, 480px); max-width: none; max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px - var(--safe-t)); margin: 0 auto; padding: 26px max(24px, var(--safe-r)) max(24px, var(--safe-b)) max(24px, var(--safe-l)); border: 1px solid #3c4437; border-bottom: 0; border-radius: 26px 26px 0 0; background: #1a1f19; color: var(--text); box-shadow: 0 -20px 80px #0008; overscroll-behavior: contain; }
#soundDialog::backdrop { background: #050805b8; }
.sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 30px; }
.sheet-heading .section-label { font-size: 10px; letter-spacing: 1px; margin-bottom: 7px; }
.sheet-heading h2 { font-size: 28px; font-weight: 600; letter-spacing: -.7px; }
.icon-button { display: grid; place-items: center; width: 48px; flex: none; border: 1px solid var(--line); border-radius: 50%; background: transparent; }
.setting-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.setting-heading label, .clarity-setting h3 { font-size: 16px; font-weight: 550; }
.setting-heading output { color: var(--accent); font-size: 14px; font-variant-numeric: tabular-nums; }
.setting-description, .clarity-setting p { margin-top: 7px; color: var(--secondary); font-size: 13px; line-height: 1.5; }
.slider-setting input { --level: 0%; width: 100%; height: 48px; margin: 8px 0 0; background: transparent; cursor: pointer; -webkit-appearance: none; appearance: none; }
.slider-setting input::-webkit-slider-runnable-track { height: 5px; border-radius: 99px; background: linear-gradient(to right, var(--accent) var(--level), #434d3e var(--level)); }
.slider-setting input::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -10.5px; border: 3px solid #1a1f19; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1px var(--accent); -webkit-appearance: none; appearance: none; }
.slider-setting input::-moz-range-track { height: 5px; border-radius: 99px; background: #434d3e; }
.slider-setting input::-moz-range-progress { height: 5px; border-radius: 99px; background: var(--accent); }
.slider-setting input::-moz-range-thumb { width: 22px; height: 22px; border: 3px solid #1a1f19; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.clarity-setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 0; margin: 12px 0 26px; border-block: 1px solid var(--line); }
#clarityBtn { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 0; min-width: 86px; background: transparent; border-radius: 8px; font-size: 13px; color: var(--secondary); }
.switch-track { position: relative; width: 42px; height: 26px; border-radius: 20px; background: #4b5547; }
.switch-track::after { content: ""; position: absolute; top: 4px; left: 4px; width: 18px; height: 18px; border-radius: 50%; background: var(--text); }
#clarityBtn[aria-pressed="true"] { color: var(--accent); }
#clarityBtn[aria-pressed="true"] .switch-track { background: var(--accent); }
#clarityBtn[aria-pressed="true"] .switch-track::after { transform: translateX(16px); background: var(--accent-ink); }
.playback-details { margin-top: 18px; border-top: 1px solid var(--line); color: var(--secondary); }
.playback-details summary { display: list-item; min-height: 48px; padding: 17px 0 10px; font-size: 12px; cursor: pointer; }
#engineHint { font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; padding-bottom: 4px; }

@media (hover: hover) {
  .sound-button:hover, .icon-button:hover, #retryBtn:hover { background: #30372c; }
  .station-btn:hover { background: #252d20; border-color: #717e61; }
  #playBtn:hover { background: #e0ff93; }
}

@media (min-width: 760px) {
  .app { padding-inline: max(32px, var(--safe-l)) max(32px, var(--safe-r)); }
  .app-header { padding-block: 26px; }
  .content { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 32px; align-content: center; align-items: center; padding-block: 24px 44px; }
  .now-playing { display: flex; flex-direction: column; min-height: 392px; padding: 28px; }
  .station-identity { flex-wrap: wrap; gap: 20px; }
  .station-art { width: 76px; height: 76px; }
  .station-heading { width: 100%; }
  .station-title { font-size: clamp(32px, 3.7vw, 46px); letter-spacing: -1.5px; }
  .station-description { font-size: 14px; }
  .tuning-scale { display: block; position: relative; height: 21px; min-height: 21px; margin-top: 28px; background: repeating-linear-gradient(to right, #65715355 0 1px, transparent 1px 9px) bottom / 100% 9px no-repeat; }
  .tuning-scale::before { content: ""; position: absolute; height: 16px; inset: auto 0 0; background: repeating-linear-gradient(to right, #65715377 0 1px, transparent 1px 45px); }
  .tuning-scale span { position: absolute; left: 38%; bottom: 0; width: 2px; height: 21px; background: var(--accent); box-shadow: 0 0 12px #d5f87940; }
  .station-section-heading { margin-bottom: 19px; }
  .station-btn { min-height: 78px; }
  .transport { padding-block: 22px max(24px, var(--safe-b)); }
  .transport-caption { font-size: 10px; }
  .transport-station { font-size: 17px; }
  #playBtn { min-width: 192px; min-height: 62px; font-size: 16px; }
  #soundDialog { inset: 0; width: 440px; margin: auto; border: 1px solid #3c4437; border-radius: 26px; }
}

@media (max-width: 359px) {
  .app { padding-inline: max(14px, var(--safe-l)) max(14px, var(--safe-r)); }
  .now-playing { padding: 18px; }
  .station-art { width: 50px; height: 50px; border-radius: 12px; }
  .station-identity { gap: 12px; }
  .station-title { font-size: 24px; }
  .station-btn { gap: 10px; padding-inline: 11px; }
  .station-logo { width: 44px; }
  #playBtn { min-width: 124px; padding-inline: 14px; }
}

@media (max-width: 600px) {
  .transport:has(.error-box.visible) .transport-main { flex-wrap: wrap; }
  .transport:has(.error-box.visible) .transport-info { flex-basis: 100%; }
  .transport:has(.error-box.visible) .play-row { width: 100%; }
  .transport:has(.error-box.visible) #playBtn { flex: 1; }
}

@media (max-height: 700px) and (min-width: 760px) {
  .app-header { padding-block: 12px; }
  .content { padding-block: 10px 24px; gap: 24px; }
  .now-playing { min-height: 0; padding: 22px; }
  .eyebrow { margin-bottom: 18px; }
  .station-identity { flex-wrap: nowrap; gap: 14px; }
  .station-art { width: 50px; height: 50px; }
  .station-title { font-size: 28px; }
  .station-description { font-size: 12px; }
  .programme { margin-top: 18px; padding-top: 16px; }
  .programme-sub { -webkit-line-clamp: 2; }
  .tuning-scale { display: none; }
  .station-btn { min-height: 64px; padding-block: 8px; }
  .station-section-heading { margin-bottom: 10px; }
  .transport { padding-block: 12px max(14px, var(--safe-b)); }
}

@media (max-height: 600px) and (max-width: 759px) {
  .app-header { padding-block: 12px; }
  .now-playing { padding: 18px; }
  .eyebrow { margin-bottom: 16px; }
  .programme { margin-top: 18px; padding-top: 16px; }
  .programme-sub { -webkit-line-clamp: 2; }
}

@media (prefers-reduced-motion: no-preference) {
  button { transition: background 150ms, border-color 150ms, transform 150ms; }
  .switch-track::after { transition: transform 150ms; }
  .status[data-state="connecting"] .dot, .status[data-state="reconnecting"] .dot { animation: pulse 1s ease-in-out infinite; }
  .app[data-playing="true"] .mini-signal i { animation: signal 900ms ease-in-out infinite alternate; }
  .app[data-playing="true"] .mini-signal i:nth-child(2) { animation-delay: -300ms; }
  .app[data-playing="true"] .mini-signal i:nth-child(3) { animation-delay: -600ms; }
}
@keyframes pulse { 50% { opacity: .35; } }
@keyframes signal { to { transform: scaleY(.4); } }
