@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #0a0908;
  --bg-panel: #141210;
  --bg-elev: #1c1916;
  --line: #2a2622;
  --line-bright: #3a342d;
  --amber: #ff9d3c;
  --amber-dim: #c47a2e;
  --copper: #d4763a;
  --copper-glow: rgba(255, 157, 60, 0.4);
  --text: #e8e0d4;
  --text-dim: #8a8175;
  --text-faint: #5a544c;
  --green: #7dd47d;
  --red: #e35b5b;
  --rec: #ff4d4d;
  --rec-dim: #c43838;
  --rec-glow: rgba(255, 77, 77, 0.5);
  --mono: 'JetBrains Mono', monospace;
  --display: 'Space Grotesk', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* Changed from 100vw/100vh to absolute pinning to bypass iOS viewport bugs */
#app { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }

#antenna-bg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; z-index: 0;
}
#antenna-bg svg {
  width: min(29vw, 230px); height: auto; max-height: 42vh;
  opacity: 0.9;
  filter: drop-shadow(0 0 28px rgba(255,157,60,0.12));
}

/* ── Top bar ─────────────────────────────── */
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  height: 64px;
  display: flex; align-items: center; gap: 24px;
  padding: 0 28px;
  background: linear-gradient(180deg, rgba(10,9,8,0.95) 0%, rgba(10,9,8,0) 100%);
  z-index: 20;
  pointer-events: none;
}
.brand { display: flex; align-items: baseline; gap: 12px; pointer-events: auto; }
.brand .mark {
  font-family: var(--mono); font-weight: 700; font-size: 22px;
  letter-spacing: 0.32em; color: var(--amber);
  text-shadow: 0 0 20px var(--copper-glow);
}
.brand .sub {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.28em;
  color: var(--text-faint); text-transform: uppercase;
}
.topbar .status {
  margin-left: auto;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em;
  color: var(--text-dim); pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.dot.live { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
.dot.loading { background: var(--amber); box-shadow: 0 0 8px var(--amber); animation: pulse 0.8s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.35} }

/* ── Search panel ────────────────────────── */
.search-panel {
  position: absolute; top: 88px; left: 28px;
  width: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  z-index: 15;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  letter-spacing: 0.22em; color: var(--text-dim); text-transform: uppercase;
}

.panel-body { padding: 18px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em;
  color: var(--text-faint); text-transform: uppercase; margin-bottom: 7px;
}
.field input, .field select {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono); font-size: 13px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus {
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 1px var(--copper-glow);
}
.field input::placeholder { color: var(--text-faint); }
.field select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%238a8175' fill='none' stroke-width='1.4'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  width: 100%;
  background: var(--amber);
  color: #1a1410;
  border: none;
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase;
  padding: 12px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: #ffad55; }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: var(--line-bright); color: var(--text-faint); cursor: wait; }

/* ── Results list ────────────────────────── */
.results {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  max-height: calc(100vh - 480px);
  min-height: 80px;
  overflow-y: auto;
}
.results::-webkit-scrollbar { width: 6px; }
.results::-webkit-scrollbar-thumb { background: var(--line-bright); }
.result-meta {
  padding: 10px 0 8px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em;
  color: var(--text-faint); text-transform: uppercase;
}
.station {
  padding: 11px 12px;
  border: 1px solid transparent;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  display: flex; align-items: center; gap: 10px;
}
.station:hover { background: var(--bg-elev); border-color: var(--line-bright); }
.station.active { background: var(--bg-elev); border-color: var(--amber-dim); }
.station .st-main { min-width: 0; flex: 1; }
.station .name {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}
.station .tags {
  font-family: var(--mono); font-size: 10px; color: var(--text-dim);
  display: flex; gap: 8px; align-items: center;
}
.station .br { color: var(--amber-dim); font-weight: 500; }
.station .codec { color: var(--text-faint); text-transform: uppercase; }
.station .star {
  flex-shrink: 0; color: var(--text-faint); font-size: 14px;
  cursor: pointer; padding: 4px; transition: color 0.15s, transform 0.1s;
}
.station .play-dot {
  flex-shrink: 0; color: var(--text-faint); font-size: 10px;
  transition: color 0.15s, transform 0.12s;
}
.station:hover .play-dot { color: var(--amber); transform: scale(1.25); }
.station.active .play-dot { color: var(--amber); }
.station .star:hover { color: var(--amber-dim); transform: scale(1.2); }
.station .star.on { color: var(--amber); }

.empty {
  padding: 28px 12px; text-align: center;
  font-family: var(--mono); font-size: 11px; color: var(--text-faint);
  line-height: 1.7;
}

/* ── Now playing bar ─────────────────────── */
.player {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 88px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line-bright);
  display: flex; align-items: center;
  padding: 0 28px; gap: 20px;
  z-index: 25;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16,1,0.3,1);
}
.player.show { transform: translateY(0); }

.play-btn {
  width: 52px; height: 52px; flex-shrink: 0;
  border: 1px solid var(--amber-dim);
  background: var(--bg-elev);
  color: var(--amber);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, box-shadow 0.15s;
}
.play-btn:hover { background: #221d18; box-shadow: 0 0 16px var(--copper-glow); }
.play-btn svg { width: 20px; height: 20px; }

.np-info { min-width: 0; flex: 1; max-width: 340px; }
.np-info .np-name {
  font-size: 15px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.np-info .np-detail {
  font-family: var(--mono); font-size: 11px; color: var(--text-dim);
  margin-top: 3px; display: flex; gap: 10px;
}
.np-info .np-detail .live-tag { color: var(--green); }

/* spectrum bars */
.spectrum { display: flex; align-items: flex-end; gap: 3px; height: 36px; width: 120px; }
.spectrum .bar {
  flex: 1; background: linear-gradient(180deg, var(--amber) 0%, var(--copper) 100%);
  height: 20%; opacity: 0.85; transition: height 0.1s;
}

.volume { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.volume svg { width: 16px; height: 16px; color: var(--text-dim); }
.volume input[type=range] {
  -webkit-appearance: none; width: 100px; height: 3px;
  background: var(--line-bright); outline: none; cursor: pointer;
}
.volume input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--amber); box-shadow: 0 0 6px var(--copper-glow);
}

/* ── Toasts ──────────────────────────────── */
.toast-wrap {
  position: absolute; bottom: 104px; left: 50%; transform: translateX(-50%);
  z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--line-bright);
  border-left: 3px solid var(--amber);
  padding: 11px 16px;
  font-family: var(--mono); font-size: 12px; color: var(--text);
  box-shadow: 0 10px 32px rgba(0,0,0,0.6);
  display: flex; align-items: center; gap: 14px;
  pointer-events: auto;
  animation: toastIn 0.25s cubic-bezier(0.16,1,0.3,1);
  max-width: 460px;
}
.toast.error { border-left-color: var(--red); }
.toast.fade { opacity: 0; transition: opacity 0.4s; }
.toast .toast-msg { overflow: hidden; text-overflow: ellipsis; }
.toast .toast-action {
  color: var(--amber); cursor: pointer; flex-shrink: 0;
  text-transform: uppercase; font-size: 10px; letter-spacing: 0.12em;
  border-bottom: 1px solid transparent; transition: border-color 0.15s;
}
.toast .toast-action:hover { border-bottom-color: var(--amber); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ── Mobile / small screens ──────────────── */
@media (max-width: 760px) {
  .topbar { height: 56px; padding: 0 16px; }
  .brand .sub { display: none; }
  .brand .mark { font-size: 18px; letter-spacing: 0.24em; }

  /* Width set to auto so it perfectly spans left to right without calc() bugs */
  .search-panel {
    width: auto;
    left: 12px; right: 12px;
    top: 64px;
    bottom: 90px;
    max-height: none;
    display: flex; flex-direction: column;
  }
  .tab-body { display: flex; flex-direction: column; min-height: 0; flex: 1; overflow: hidden; }
  .tab-body[hidden] { display: none; }
  
  /* OVERFLOW: HIDDEN added here to guarantee large lists respect the bottom edge */
  .panel-body { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 14px; overflow: hidden; }
  
  /* MIN-HEIGHT: 0 added here to prevent flex items from exploding out of view */
  .results {
    flex: 1; min-height: 0; max-height: none;
    margin-top: 12px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  }

  .player { height: 76px; padding: 0 16px; gap: 14px; }
  .np-info { max-width: none; flex: 1; }
  .spectrum, .volume { display: none; }
  .play-btn { width: 48px; height: 48px; }

  .toast-wrap { bottom: 88px; }
  #antenna-bg { align-items: flex-end; padding-bottom: 12vh; }
  #antenna-bg svg { width: 36vw; max-height: 26vh; opacity: 0.5; }
}