/* Radio Vala 98.3 FM — player */

:root {
  --brand: #003998;
  --font-display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --font-ui: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --live: #ff4d5e;
  --warn: #ffb547;
  --play: clamp(84px, 11vh, 104px);
  --freq-size: clamp(4.6rem, min(24vw, 24vh), 14rem);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #040a1c;
  --ink: #eef3ff;
  --muted: #8d9ac1;
  --accent: #5b93ff;
  --wave-front: #8fb8ff;
  --wave-back: #2a5fd6;
  --num-a: #ffffff;
  --num-b: #5b93ff;
  --play-bg: #ffffff;
  --play-ink: #003998;
  --play-shadow: rgba(91, 147, 255, .55);
  --surface: rgba(255, 255, 255, .06);
  --surface-hover: rgba(255, 255, 255, .11);
  --border: rgba(255, 255, 255, .12);
  --track: rgba(255, 255, 255, .18);
  --glow: rgba(32, 88, 255, .30);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fc;
  --ink: #06173f;
  --muted: #56658f;
  --accent: #003998;
  --wave-front: #003998;
  --wave-back: #6f95e0;
  --num-a: #0a4bc4;
  --num-b: #002a73;
  --play-bg: #003998;
  --play-ink: #ffffff;
  --play-shadow: rgba(0, 57, 152, .45);
  --surface: rgba(0, 57, 152, .05);
  --surface-hover: rgba(0, 57, 152, .1);
  --border: rgba(0, 57, 152, .15);
  --track: rgba(0, 57, 152, .18);
  --glow: rgba(0, 57, 152, .10);
}

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

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

svg { display: block; }

/* ---------- Page frame ---------- */

.app {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* the long ticker must not widen the page */
  grid-template-rows: auto 1fr auto;
}

.app::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 36vh;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(55% 100% at 50% 0%, var(--glow), transparent 72%);
}

/* ---------- Top bar ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) clamp(16px, 4vw, 40px) 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  color: var(--ink);
  text-decoration: none;
}

.brand svg { width: 46px; height: auto; color: var(--wave-front); }

.brand b {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: .8rem;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background .2s, transform .2s;
}

.icon-btn:hover { background: var(--surface-hover); }
.icon-btn:active { transform: scale(.94); }

.icon-btn svg,
.pill svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html[data-theme="dark"] .i-moon,
html[data-theme="light"] .i-sun { display: none; }

/* ---------- Stage ---------- */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-block: clamp(10px, 2.5vh, 28px);
  min-width: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  margin: 0 0 clamp(6px, 1.4vh, 14px);
  padding: .42rem .95rem .42rem .8rem;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: color .3s;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

[data-state="playing"] .status { color: var(--ink); }
[data-state="playing"] .status .dot { background: var(--live); animation: ping 1.8s ease-out infinite; }
[data-state="connecting"] .status .dot,
[data-state="reconnecting"] .status .dot,
.detuned .status .dot { background: var(--warn); animation: blink .9s ease-in-out infinite; }

@keyframes ping {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 70%, transparent); }
  100% { box-shadow: 0 0 0 9px transparent; }
}

@keyframes blink { 50% { opacity: .3; } }

.freq {
  position: relative;
  z-index: 1;
  margin: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: .06em;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: var(--freq-size);
  line-height: .92;
  letter-spacing: -.045em;
  white-space: nowrap;
  color: transparent;
  background: linear-gradient(180deg, var(--num-a) 18%, var(--num-b) 92%);
  -webkit-background-clip: text;
  background-clip: text;
  user-select: none;
  -webkit-user-select: none;
  transition: filter .25s, opacity .25s;
}

/* five characters (100.0 and up): shrink without moving the layout */
.freq.wide { transform: scale(.8); }

.freq .fm {
  margin-top: .55em;
  font-size: .19em;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--accent);
}

.detuned .freq { filter: saturate(.25); opacity: .8; }

/* ---------- Waves ---------- */

.sea {
  position: relative;
  z-index: 2;
  width: 100%;
  height: clamp(170px, 30vh, 300px);
  margin-top: calc(var(--freq-size) * -.3);
  pointer-events: none;
}

.sea canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---------- Play button ---------- */

.play-wrap {
  position: relative;
  z-index: 3;
  display: grid;
  place-items: center;
  margin-top: calc(var(--play) * -.62);
}

.halo {
  position: absolute;
  width: calc(var(--play) + 70px);
  height: calc(var(--play) + 70px);
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--play-shadow), transparent);
  opacity: 0;
  transform: scale(calc(.8 + var(--level, 0) * .7));
  transition: opacity .5s;
  pointer-events: none;
}

[data-state="playing"] .halo { opacity: calc(.35 + var(--level, 0) * .65); }

.play {
  position: relative;
  width: var(--play);
  height: var(--play);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--play-bg);
  color: var(--play-ink);
  box-shadow: 0 0 0 8px var(--bg), 0 14px 40px -6px var(--play-shadow);
  transition: transform .25s cubic-bezier(.3, 1.7, .5, 1);
}

.play:hover { transform: scale(1.05); }
.play:active { transform: scale(.95); }
.play:focus-visible { outline-offset: 12px; }

.play svg {
  grid-area: 1 / 1;
  width: 40%;
  height: 40%;
  fill: currentColor;
  transition: opacity .2s, transform .3s cubic-bezier(.3, 1.6, .5, 1);
}

.play .i-play { transform: translateX(4%); }
.play .i-pause { opacity: 0; transform: scale(.5); }
[data-on="true"] .play .i-play { opacity: 0; transform: scale(.5); }
[data-on="true"] .play .i-pause { opacity: 1; transform: none; }

.play .spin {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  opacity: 0;
  transition: opacity .2s;
}

[data-state="connecting"] .spin,
[data-state="reconnecting"] .spin { opacity: 1; animation: spin .9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- FM dial ---------- */

.dial {
  position: relative;
  width: min(560px, 92vw);
  height: 60px;
  margin-top: clamp(14px, 2.6vh, 26px);
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 24%, #000 76%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 24%, #000 76%, transparent);
}

.dial.dragging { cursor: grabbing; }

.dial canvas { display: block; width: 100%; height: 100%; }

/* one small wiggle when the radio first starts, to show the dial can be dragged */
.dial.nudge canvas { animation: nudge 1.3s ease-in-out .8s 1; }

@keyframes nudge {
  30% { transform: translateX(-14px); }
  65% { transform: translateX(10px); }
}

.dial .needle {
  position: absolute;
  top: 2px;
  bottom: 20px;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background: var(--live);
  box-shadow: 0 0 12px var(--live);
  pointer-events: none;
}

.dial .needle::before {
  content: "";
  position: absolute;
  top: -2px;
  left: 50%;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--live);
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: clamp(10px, 2vh, 20px);
  padding-inline: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  height: 46px;
  padding: 0 16px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .86rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: background .2s, border-color .2s, color .2s;
}

button.pill:hover { background: var(--surface-hover); }
.pill.active { border-color: var(--accent); color: var(--accent); }

.vol { padding: 0 16px 0 5px; gap: .2rem; }

.vol button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.vol button:hover { background: var(--surface-hover); }

.i-vol .spk { fill: currentColor; }
.i-vol .x { display: none; }
.muted .i-vol .w1,
.muted .i-vol .w2 { display: none; }
.muted .i-vol .x { display: inline; }
.quiet .i-vol .w2 { display: none; }

.no-volume .vol { display: none; }

input[type="range"] {
  --v: 85%;
  -webkit-appearance: none;
  appearance: none;
  width: clamp(110px, 28vw, 170px);
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--v), var(--track) var(--v));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform .15s;
}

input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.2); }

input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--ink); }

.keys {
  display: none;
  margin: clamp(10px, 2vh, 18px) 0 0;
  font-size: .74rem;
  color: var(--muted);
}

.keys i { font-style: normal; opacity: .5; margin-inline: .35em; }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: .12em .45em;
  margin-right: .25em;
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  background: var(--surface);
}

@media (hover: hover) and (pointer: fine) and (min-height: 700px) {
  .keys { display: block; }
}

.nojs { text-align: center; font-weight: 600; }

/* ---------- Ticker ---------- */

.foot {
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.ticker {
  overflow: hidden;
  white-space: nowrap;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}

.ticker-track {
  display: inline-flex;
  padding-block: 13px;
  animation: tick var(--dur, 70s) linear infinite;
  will-change: transform;
}

.ticker:hover .ticker-track,
.ticker:focus-within .ticker-track { animation-play-state: paused; }

.ticker-group { display: inline-flex; flex: none; }

.ticker span {
  display: inline-flex;
  align-items: center;
  font-size: .88rem;
  color: var(--muted);
}

/* a tiny wave between messages */
.ticker span::after {
  content: "";
  width: 22px;
  height: 9px;
  margin-inline: 1.3rem;
  background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 210 84'%3E%3Cpath d='M0 67h30c28 0 32-50 75-50s47 50 75 50h30' fill='none' stroke='%23000' stroke-width='34'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 210 84'%3E%3Cpath d='M0 67h30c28 0 32-50 75-50s47 50 75 50h30' fill='none' stroke='%23000' stroke-width='34'/%3E%3C/svg%3E") center / contain no-repeat;
}

.ticker a { color: var(--ink); font-weight: 600; text-decoration: none; margin-left: .35em; }
.ticker a:hover { text-decoration: underline; }

@keyframes tick { to { transform: translateX(-50%); } }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom));
  z-index: 10;
  max-width: calc(100vw - 32px);
  padding: .65rem 1.05rem;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: .86rem;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens / reduced motion ---------- */

@media (max-width: 420px) {
  .brand b { font-size: .7rem; letter-spacing: .12em; }
  .brand svg { width: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .ticker { overflow-x: auto; -webkit-mask-image: none; mask-image: none; }
  .ticker-track { animation: none; }
  .status .dot { animation: none !important; }
  .play, .play svg { transition: none; }
}
