/*
 * 无线地球 · 样式
 *
 * 配色取自"夜间收听"的场景：深空底色 + 青色海岸线 + 琥珀色城市光点。
 * 琥珀色只给"有声音的东西"（城市点、正在播放），青色给地理信息，
 * 这样一眼能分清"地图"和"内容"。
 */

:root {
  --bg: #05070d;
  --ink: #e8eef6;
  --ink-dim: #93a4ba;
  --ink-faint: #5d6e85;
  --line: rgba(120, 160, 200, 0.16);
  --surface: rgba(10, 16, 28, 0.82);
  --surface-solid: #0a1020;
  --teal: #47d6c3;
  --amber: #ff9d3c;
  --amber-soft: #ffd9a0;
  --danger: #ff6b6b;
  --radius: 12px;
  --panel-width: 336px;
  --player-height: 76px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* 手机浏览器的地址栏会伸缩，100vh 会比可视区高一截，导致播放条被顶出屏幕。
     dvh 跟着可视区变，支持它的浏览器用它，不支持的退回上面那行 100%。 */
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;              /* 关掉下拉刷新与橡皮筋 */
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
        "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--teal); }

#globe {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;   /* 自己处理拖拽与双指缩放，交给浏览器会变成页面滚动 */
}

/* ------------------------------------------------------------------ 顶部 */
.hud-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  /* 顶部压一层渐变而不是实色条：地球在底下仍然看得见，层次更好 */
  background: linear-gradient(180deg, rgba(5, 7, 13, 0.92), rgba(5, 7, 13, 0));
  z-index: 20;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 26px; height: 26px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--teal);
  box-shadow: 0 0 0 4px rgba(71, 214, 195, 0.08), inset 0 0 10px rgba(71, 214, 195, 0.35);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; top: 3px; right: 2px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
}
.brand-text strong { display: block; font-size: 15px; letter-spacing: .04em; }
.brand-text small { display: block; color: var(--ink-faint); font-size: 11px; }

.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  backdrop-filter: blur(8px);
  outline: none;
}
.search input::placeholder { color: var(--ink-faint); }
.search input:focus { border-color: rgba(71, 214, 195, 0.55); }

.search-results {
  position: absolute;
  top: calc(100% + 8px); left: 0; right: 0;
  max-height: min(56vh, 420px);
  overflow-y: auto;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hud-actions { display: flex; gap: 8px; }
.icon-btn {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-dim);
  backdrop-filter: blur(8px);
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
}
.icon-btn:hover { color: var(--ink); border-color: rgba(71, 214, 195, 0.5); }
.icon-btn[aria-pressed="true"] { color: var(--amber); border-color: rgba(255, 157, 60, 0.6); }

/* ------------------------------------------------------------------ 侧栏 */
.panel {
  position: fixed;
  top: 68px; right: 14px;
  width: var(--panel-width);
  max-height: calc(100vh - 68px - var(--player-height) - 24px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 15;
  transition: transform .22s ease, opacity .22s ease;
}
.panel[hidden] { display: none; }
.panel.is-collapsed { transform: translateX(calc(100% + 20px)); opacity: 0; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  padding: 11px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-faint);
  font-size: 13px;
}
.tab:hover { color: var(--ink-dim); }
.tab.is-active { color: var(--amber); border-bottom-color: var(--amber); }

.panel-head {
  padding: 12px 14px 6px;
  border-bottom: 1px solid var(--line);
}
.panel-head:empty { display: none; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-head p { margin: 3px 0 0; color: var(--ink-faint); font-size: 12px; }

.panel-body { overflow-y: auto; padding: 6px 0; flex: 1; }
.panel-foot {
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 11.5px;
}
.panel-foot:empty { display: none; }
.hint { padding: 18px 16px; color: var(--ink-faint); margin: 0; }

/* 列表项：电台 / 国家 / 搜索结果共用 */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  text-align: left;
  border-left: 2px solid transparent;
}
.row:hover { background: rgba(71, 214, 195, 0.07); }
.row.is-playing { border-left-color: var(--amber); background: rgba(255, 157, 60, 0.09); }
.row-main { flex: 1; min-width: 0; }
.row-name {
  display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 13.5px;
}
.row.is-playing .row-name { color: var(--amber-soft); }
.row-sub {
  display: block;
  color: var(--ink-faint);
  font-size: 11.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-badge {
  flex: none;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}
.row-badge.is-relay { color: var(--amber); border-color: rgba(255, 157, 60, 0.35); }

/* ------------------------------------------------------------------ 播放条 */
.player {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--player-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: linear-gradient(0deg, rgba(5, 7, 13, 0.96), rgba(5, 7, 13, 0.72));
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
  z-index: 25;
  /* iPhone 的 Home 指示条会盖住底部约 34px，不留出来按钮就按不着 */
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--player-height) + env(safe-area-inset-bottom, 0px));
}

.play-btn {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 157, 60, 0.45);
  background: rgba(255, 157, 60, 0.12);
  display: grid; place-items: center;
}
.play-btn:hover { background: rgba(255, 157, 60, 0.22); }
/* 用 border 画三角形，省掉一个图标文件 */
.play-icon {
  width: 0; height: 0;
  border-left: 13px solid var(--amber);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  margin-left: 4px;
}
.player[data-state="playing"] .play-icon {
  width: 13px; height: 15px;
  border: none;
  margin-left: 0;
  background: linear-gradient(90deg, var(--amber) 0 4px, transparent 4px 9px, var(--amber) 9px 13px);
}
/* 缓冲时让按钮自己转，不额外加一个 spinner 元素 */
.player[data-state="loading"] .play-btn {
  animation: spin 1.1s linear infinite;
  border-style: dashed;
}
@keyframes spin { to { transform: rotate(360deg); } }

.now { flex: 1; min-width: 0; }
.now-name {
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.now-meta, .now-title {
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.now-title { color: var(--teal); }
.now-title::before { content: "♪ "; }

.player-actions { display: flex; align-items: center; gap: 8px; }
.volume { display: flex; align-items: center; }
#volume { width: 92px; accent-color: var(--amber); }

/* 触摸设备：按钮与列表项放大到 44px 的可点高度。
   这个尺寸不是凭感觉定的，是各家移动端人机界面指南的最小推荐触控区。 */
@media (pointer: coarse) {
  .icon-btn { padding: 11px 15px; }
  .row { padding: 12px 14px; min-height: 44px; }
  .tab { padding: 14px 4px; }
  .play-btn { width: 52px; height: 52px; }
  /* 手指按住列表滑动时，别让浏览器把它当成文字选择 */
  .row, .tab, .icon-btn { user-select: none; -webkit-user-select: none; }
}

/* ------------------------------------------------------------------ 杂项 */
.tooltip {
  position: fixed;
  z-index: 18;
  transform: translate(-50%, calc(-100% - 14px));
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(5, 7, 13, 0.92);
  border: 1px solid rgba(255, 157, 60, 0.35);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
}
.tooltip b { color: var(--amber-soft); font-weight: 600; }
.tooltip span { color: var(--ink-faint); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--player-height) + 18px);
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(10, 16, 28, 0.95);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  max-width: min(88vw, 520px);
}
.toast.is-error { border-color: rgba(255, 107, 107, 0.5); color: #ffd9d9; }

.loading {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid; place-content: center; justify-items: center; gap: 16px;
  background: var(--bg);
  color: var(--ink-faint);
  transition: opacity .4s ease;
}
.loading.is-done { opacity: 0; pointer-events: none; }
.loading-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 rgba(255, 157, 60, 0.6);
  animation: ping 1.4s ease-out infinite;
}
@keyframes ping {
  0%   { box-shadow: 0 0 0 0 rgba(255, 157, 60, 0.55); }
  100% { box-shadow: 0 0 0 28px rgba(255, 157, 60, 0); }
}

.about-btn {
  position: fixed;
  left: 16px;
  bottom: calc(var(--player-height) + 16px);
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-faint);
  z-index: 20;
}
.about-btn:hover { color: var(--ink); }

.about {
  position: fixed;
  left: 16px;
  bottom: calc(var(--player-height) + 56px);
  width: min(420px, calc(100vw - 32px));
  max-height: 60vh;
  overflow-y: auto;
  padding: 18px 20px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
}
.about h2 { margin: 0 0 10px; font-size: 16px; }
.about p { margin: 0 0 10px; color: var(--ink-dim); }
.about ul { margin: 0 0 12px; padding-left: 18px; color: var(--ink-dim); }
.about li { margin-bottom: 7px; }
.about-stats { color: var(--ink-faint); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ 窄屏 */
@media (max-width: 720px) {
  :root { --player-height: 112px; }

  .hud-top { flex-wrap: wrap; gap: 9px; padding: 10px 12px; }
  .brand-text small { display: none; }        /* 窄屏上这行副标题只是占地方 */
  .search { max-width: none; flex-basis: 100%; margin-left: 0; order: 3; }
  /* iOS 在聚焦小于 16px 的输入框时会把整页放大，而且退不回去。
     把字号顶到 16px 是唯一可靠的规避办法。 */
  .search input { font-size: 16px; padding: 11px 14px; }

  .panel {
    top: auto;
    bottom: calc(var(--player-height) + env(safe-area-inset-bottom, 0px) + 8px);
    left: 8px; right: 8px;
    width: auto;
    max-height: 50vh;
  }
  .search-results { max-height: 44vh; }

  /* 播放条在窄屏排成两行：上行台名，下行按钮。
     按钮一行放不下时优先砍掉"点赞"，台名和播放键永远在。 */
  .player {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }
  .now { order: -1; flex-basis: calc(100% - 66px); }
  .player-actions { width: 100%; justify-content: space-between; gap: 6px; }
  .player-actions .icon-btn { flex: 1; padding: 11px 6px; text-align: center; }

  .about-btn {
    bottom: calc(var(--player-height) + env(safe-area-inset-bottom, 0px) + 10px);
  }
  .about {
    bottom: calc(var(--player-height) + env(safe-area-inset-bottom, 0px) + 50px);
    max-height: 56vh;
  }
  .toast {
    bottom: calc(var(--player-height) + env(safe-area-inset-bottom, 0px) + 12px);
    max-width: calc(100vw - 24px);
  }
}

/* 极窄屏（约 iPhone SE 竖屏）：把次要按钮收起来，保住台名与播放键 */
@media (max-width: 400px) {
  #btn-vote, .brand-text { display: none; }
  .hud-actions .icon-btn { padding: 11px 10px; }
}

/* 有人把系统设成减少动态效果，就别让地球自转和脉冲圈闪 */
@media (prefers-reduced-motion: reduce) {
  .loading-dot, .player[data-state="loading"] .play-btn { animation: none; }
}
