:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #ececf1;
  --text: #1c1c1e;
  --text-2: #6c6c70;
  --text-3: #a1a1a6;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #e8590c;
  --accent-soft: rgba(232, 89, 12, 0.12);
  --accent-text: #ffffff;
  --red: #dc2626;
  --bar-bg: rgba(242, 242, 247, 0.86);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 10px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --gutter: 16px;
  --tabbar-h: 56px;
  --mini-h: 0px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #f2f2f7;
    --text-2: #a1a1a6;
    --text-3: #6c6c70;
    --line: rgba(235, 235, 245, 0.14);
    --accent: #ff8a3d;
    --accent-soft: rgba(255, 138, 61, 0.18);
    --accent-text: #1a0d05;
    --red: #f87171;
    --bar-bg: rgba(18, 18, 20, 0.86);
    --shadow: none;
  }
}
body.has-mini { --mini-h: 64px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* 禁止双击放大（iOS 不认 user-scalable=no，双指缩放在 app.js 里拦） */
html, body, button, input, li, a { touch-action: manipulation; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 页面 ---------- */
.page { position: fixed; inset: 0 0 calc(var(--tabbar-h) + var(--mini-h) + env(safe-area-inset-bottom)) 0; display: flex; flex-direction: column; }
.bar { padding: calc(env(safe-area-inset-top) + 8px) var(--gutter) 6px; background: var(--bg); }
.bar h1 { font-size: 30px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px var(--gutter) 24px; }
h2.section { font-size: 20px; margin: 18px 2px 4px; }
.section-note { font-size: 13px; color: var(--text-2); margin: 0 2px 8px; }
.status { font-size: 14px; color: var(--text-2); text-align: center; margin: 14px 0; min-height: 1.2em; }
.empty-note { font-size: 14px; color: var(--text-2); margin: 4px 2px 8px; }

/* ---------- 电台列表 ---------- */
.stations { list-style: none; margin: 0 0 6px; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.stations:empty { display: none; }
.stations li { display: flex; align-items: center; gap: 12px; padding: 10px 6px 10px 12px; min-height: 64px; }
.stations li + li { border-top: 0.5px solid var(--line); }
.stations li.playing { background: var(--accent-soft); }
.st-main { all: unset; flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.st-text { min-width: 0; flex: 1; }
.st-name, .st-desc { display: block; }
.st-name { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-desc { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stations li.playing .st-name { color: var(--accent); }
.st-main .ext { color: var(--text-3); width: 18px; height: 18px; }
.fav-btn { width: 42px; height: 42px; border: 0; background: none; color: var(--text-3); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.fav-btn.on { color: var(--accent); }
.fav-btn svg { width: 22px; height: 22px; }

.logo {
  width: 44px; height: 44px; border-radius: 10px; flex: none; overflow: hidden; position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--logo-bg, var(--card-2)); color: #fff; font-weight: 700; font-size: 17px;
}
.logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; position: absolute; inset: 0; }
.eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; margin-left: 4px; vertical-align: -1px; }
.eq i { width: 3px; background: var(--accent); border-radius: 1px; animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -0.3s; } .eq i:nth-child(3) { animation-delay: -0.6s; }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 14px; } }

/* ---------- 分类栏（电台 / 电视页顶部，不随列表滚动） ---------- */
.catbar { padding: 0 0 8px; background: var(--bg); border-bottom: 0.5px solid var(--line); }
.cats, .subcats { display: flex; gap: 8px; overflow-x: auto; scroll-padding-inline: var(--gutter); -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 4px var(--gutter); }
.cats::-webkit-scrollbar, .subcats::-webkit-scrollbar { display: none; }
.cats button { flex: none; border: 0; border-radius: 18px; padding: 7px 16px; min-height: 36px; font-size: 16px; font-weight: 600; background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.cats button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.subcats button { flex: none; border: 0; background: none; padding: 5px 10px; min-height: 30px; font-size: 15px; color: var(--text-2); border-radius: 8px; }
.subcats button[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.subcats:empty { display: none; }
#radio-note:empty, #tv-note:empty { display: none; }
.catbar + .scroll { padding-top: 10px; }

/* ---------- 分类 / 搜索 ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.chips button { border: 0; border-radius: 18px; padding: 7px 14px; background: var(--card); box-shadow: var(--shadow); font-size: 15px; min-height: 36px; }
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.chips.small button { font-size: 14px; padding: 5px 12px; min-height: 32px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card-2); border-radius: 12px; padding: 0 12px; margin-bottom: 10px; }
.search svg { color: var(--text-3); }
.search input { flex: 1; border: 0; background: none; outline: none; font-size: 17px; padding: 11px 0; min-width: 0; }

/* ---------- 迷你播放条 / 标签栏 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar-bg); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
}
.tabbar button { flex: 1; border: 0; background: none; color: var(--text-3); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; }
.tabbar button svg { width: 25px; height: 25px; }
.tabbar button[aria-current="page"] { color: var(--accent); }
.mini {
  position: fixed; left: 8px; right: 8px; z-index: 21; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 6px); height: 56px;
  display: flex; align-items: center; gap: 4px; padding: 0 6px 0 6px; border-radius: 14px;
  background: var(--card); box-shadow: 0 2px 16px rgba(0, 0, 0, 0.14); border: 0.5px solid var(--line);
}
.mini-main { all: unset; flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.mini .logo { width: 42px; height: 42px; border-radius: 9px; }
.mini-text { min-width: 0; display: flex; flex-direction: column; }
.mini-text b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-text small { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-text small.rec { color: var(--red); font-weight: 600; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 22px; background: none; color: var(--text); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active, .round:active, .play-btn:active, .tool:active, .chips button:active { opacity: 0.6; }

/* ---------- 播放页 / 面板 ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92vh;
  border-radius: 16px 16px 0 0; background: var(--bg); color: var(--text); display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog.player { height: 92vh; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--text-3); opacity: 0.5; margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 4px var(--gutter); }
.sheet-head h2 { flex: 1; font-size: 18px; margin: 0; }
.sheet-body { padding: 4px var(--gutter) calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; }
.player-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 8px 24px calc(20px + env(safe-area-inset-bottom)); }
.art { width: min(62vw, 260px); aspect-ratio: 1; border-radius: 22px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18); margin: 12px 0 22px; }
.art.logo { height: auto; font-size: 72px; }
.player-body h2 { font-size: 24px; margin: 0; }
.p-desc { color: var(--text-2); margin: 6px 0 0; font-size: 15px; }
.p-status { color: var(--accent); font-size: 14px; font-weight: 600; margin: 10px 0 0; min-height: 1.3em; }
.p-status.err { color: var(--red); }
.p-controls { display: flex; align-items: center; justify-content: center; gap: 34px; margin: 22px 0 18px; }
.round { width: 54px; height: 54px; border-radius: 27px; border: 0; background: var(--card); box-shadow: var(--shadow); color: var(--text); display: inline-flex; align-items: center; justify-content: center; }
.round svg { width: 26px; height: 26px; }
.round.on { color: var(--accent); }
#p-rec.on { background: var(--red); color: #fff; }
.play-btn { width: 60px; height: 60px; border-radius: 30px; border: 0; background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.play-btn.big { width: 76px; height: 76px; border-radius: 38px; }
.play-btn svg { width: 34px; height: 34px; }
.p-tools { display: flex; gap: 10px; width: 100%; max-width: 360px; }
.tool { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; border: 0; border-radius: 12px; background: var(--card); box-shadow: var(--shadow); font-size: 15px; }
.tool.on { color: var(--accent); font-weight: 600; }
.p-note { font-size: 12px; color: var(--text-3); margin-top: 22px; max-width: 320px; }

/* 电视播放页 */
dialog.tvsheet { height: 92vh; }
.tv-body { flex: 1; overflow-y: auto; padding: 4px 0 calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; }
.tv-frame { width: 100%; aspect-ratio: 16 / 9; background: #000; }
.tv-frame video { width: 100%; height: 100%; display: block; background: #000; }
.tv-info { text-align: center; padding: 14px 20px 4px; }
.tv-info h2 { font-size: 22px; margin: 0; }
.tv-body .p-tools { padding: 10px 16px 0; max-width: 480px; }
.tv-body .p-note { padding: 0 20px; text-align: center; }

.menu { list-style: none; margin: 0 0 12px; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.menu li + li { border-top: 0.5px solid var(--line); }
.menu button { all: unset; display: flex; align-items: center; justify-content: space-between; width: 100%; box-sizing: border-box; padding: 14px 16px; cursor: pointer; font-size: 16px; }
.menu button.on { color: var(--accent); font-weight: 600; }
.menu button.danger { color: var(--red); }

.recs { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.recs:empty { display: none; }
.recs li { display: flex; align-items: center; gap: 6px; padding: 10px 6px 10px 14px; }
.recs li + li { border-top: 0.5px solid var(--line); }
.recs .meta { flex: 1; min-width: 0; }
.recs .name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recs .info { font-size: 12px; color: var(--text-2); }
.recs .icon-btn { color: var(--accent); width: 40px; height: 40px; }
.recs .icon-btn.del { color: var(--text-3); }
.recs .icon-btn svg { width: 22px; height: 22px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--mini-h) + env(safe-area-inset-bottom) + 18px); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  background: rgba(30, 30, 32, 0.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .scroll, .bar { padding-left: max(var(--gutter), calc((100% - 680px) / 2)); padding-right: max(var(--gutter), calc((100% - 680px) / 2)); }
  .mini { left: 50%; right: auto; width: 640px; transform: translateX(-50%); }
}
