:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f2f2f7;
  --text: #1c1c1e;
  --text-2: #6c6c70;
  --text-3: #a1a1a6;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #2961e6;
  --accent-soft: rgba(41, 97, 230, 0.12);
  --accent-text: #ffffff;
  --green: #1f9d55;
  --orange: #d97706;
  --red: #dc2626;
  --hl: rgba(41, 97, 230, 0.2);
  --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;
  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: #6e9bff;
    --accent-soft: rgba(110, 155, 255, 0.18);
    --accent-text: #11111a;
    --green: #4ade80;
    --orange: #fbbf24;
    --red: #f87171;
    --hl: rgba(110, 155, 255, 0.32);
    --bar-bg: rgba(0, 0, 0, 0.82);
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* 禁止双击放大（iOS 不认 user-scalable=no，双指缩放在 app.js 里拦） */
html, body, button, select, input, textarea, li { 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, select, input, textarea { 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; }

/* ---------- 页面结构 ---------- */
#pages { height: 100%; }
.page { position: fixed; inset: 0; display: flex; flex-direction: column; }
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) var(--gutter) 8px;
  background: var(--bg);
}
.bar h1 { font-size: 28px; font-weight: 700; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
#l-title { font-size: 20px; }
.bar-actions { display: flex; gap: 4px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px var(--gutter) calc(24px + env(safe-area-inset-bottom)); }

/* ---------- 卡片 / 行 ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 8px; }
.row + .row { margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.field-row { margin-bottom: 12px; }
.head-line { font-size: 14px; color: var(--text-2); font-weight: 500; text-align: center; margin-bottom: 10px; }
.status { font-size: 13px; color: var(--text-2); text-align: center; min-height: 1.2em; margin: 4px 0; }
.num { font-variant-numeric: tabular-nums; }

select {
  width: 100%; min-width: 0; appearance: none; -webkit-appearance: none;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center / 18px;
  border: 0.5px solid var(--line); border-radius: 10px; padding: 10px 34px 10px 12px; font-size: 16px;
}
.card select { background-color: var(--card-2); border-color: transparent; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 14px; border: 0; border-radius: 11px;
  background: var(--card-2); color: var(--text); font-size: 15px; font-weight: 500; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:active, .icon-btn:active, .skip:active, .play-btn:active { opacity: 0.6; }
.btn:disabled { opacity: 0.4; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.accent-soft { background: var(--accent-soft); color: var(--accent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.danger { color: var(--red); }
.btn.big { flex: 1.4; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 20px; background: none; color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.toggle { color: var(--text-3); }
.icon-btn.toggle[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.play-btn {
  width: 60px; height: 60px; border-radius: 30px; border: 0; flex: none;
  background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center;
}
.play-btn svg { width: 28px; height: 28px; }
.play-btn.busy { opacity: 0.55; }

.transport { display: flex; gap: 8px; align-items: center; }
.transport .btn { flex: 1; padding: 0 8px; }

/* 分段控件 */
.seg { display: inline-flex; background: var(--card-2); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: none; border-radius: 8px; padding: 6px 11px; font-size: 14px; color: var(--text); min-height: 32px; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg button[aria-pressed="true"] { background: #48484a; } }
.seg.tabs { display: flex; margin: 4px 0 12px; }
.seg.tabs button { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 0; border-radius: 16px; padding: 6px 12px; background: var(--card-2); font-size: 14px; min-height: 34px; }
.chips button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.opt-group { margin-top: 14px; }
.opt-group.two { display: flex; gap: 14px; flex-wrap: wrap; }
.opt-label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
label.opt-label { display: flex; align-items: center; gap: 8px; margin: 0; white-space: nowrap; }
label.opt-label select { width: auto; padding: 6px 30px 6px 10px; font-size: 14px; }

/* 开关 */
.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; margin-top: 14px; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 44px; height: 26px; border-radius: 13px; background: var(--card-2); position: relative; flex: none; transition: background .2s; border: 0.5px solid var(--line); }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 11px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }
.toggles { display: flex; gap: 18px; flex-wrap: wrap; }
.toggles .switch { margin-top: 4px; }

textarea {
  width: 100%; border: 0; border-radius: 10px; background: var(--card-2); padding: 12px; font-size: 18px; resize: vertical; outline: none;
}
textarea:focus { box-shadow: 0 0 0 2px var(--accent); }
.card textarea + .row { margin-top: 10px; }
.card textarea + .row .btn { flex: 1; }

/* ---------- 精听 ---------- */
.empty { text-align: center; color: var(--text-2); padding: 48px 12px; }
.empty .empty-icon { width: 56px; height: 56px; color: var(--accent); }
.empty p { margin: 8px 0; }
.empty p:first-of-type { font-size: 18px; color: var(--text); font-weight: 600; }
.empty .sub { font-size: 14px; max-width: 320px; margin: 0 auto 18px; }
.empty.small { padding: 24px 12px; font-size: 14px; }
.empty.small p:first-of-type { font-size: 15px; }

.player-card { padding: 14px 14px 16px; }
.track-sub { font-size: 13px; color: var(--text-2); text-align: center; margin-bottom: 8px; min-height: 1em; }
.pbar { position: relative; height: 34px; touch-action: none; cursor: pointer; }
.pbar-track { position: absolute; left: 0; right: 0; top: 14px; height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; }
.pbar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); }
.pbar-loop { position: absolute; top: 0; bottom: 0; background: var(--orange); opacity: 0.45; }
.pbar-marks { position: absolute; left: 0; right: 0; top: 8px; height: 18px; pointer-events: none; }
.pbar-marks i { position: absolute; top: 0; width: 2px; height: 18px; margin-left: -1px; background: var(--red); border-radius: 1px; }
.pbar-knob { position: absolute; top: 9px; width: 16px; height: 16px; margin-left: -8px; border-radius: 8px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
#l-loop-label { color: var(--orange); font-weight: 600; }
.transport.main { justify-content: space-between; margin: 10px -4px 6px; gap: 0; }
.transport.main .icon-btn { color: var(--text-2); }
.skip { position: relative; width: 46px; height: 46px; border: 0; background: none; color: var(--text); display: inline-flex; align-items: center; justify-content: center; }
.skip svg { width: 34px; height: 34px; stroke-width: 1.5; }
.skip b { position: absolute; font-size: 10px; font-weight: 700; top: 50%; left: 50%; transform: translate(-50%, -40%); }
.speed-row { justify-content: center; }
.speed-label { border: 0; background: none; font-size: 17px; font-weight: 600; min-width: 5em; color: var(--accent); }
.tools { margin-top: 12px; }
.tools .btn { padding: 0 12px; }
.tools .btn:first-child { flex: 1; }
.tools select { width: auto; flex: none; padding: 10px 30px 10px 10px; font-size: 14px; }
.tools .btn.set { background: var(--orange); color: #fff; }

.transcript { list-style: none; margin: 0; padding: 0; }
.transcript li { padding: 10px 12px; border-radius: 10px; font-size: 17px; line-height: 1.5; color: var(--text-2); cursor: pointer; }
.transcript li.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.transcript li .ts { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; font-variant-numeric: tabular-nums; }
.transcript li.marked .ts::after { content: " · 疑难点"; color: var(--red); }

.marks-tools { margin-bottom: 8px; flex-wrap: wrap; }
.marks { list-style: none; margin: 0; padding: 0; }
.marks li { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 10px 6px 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.marks .body { flex: 1; min-width: 0; cursor: pointer; }
.marks .t { font-weight: 600; color: var(--red); font-variant-numeric: tabular-nums; font-size: 14px; }
.marks .note { font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.marks .comment { font-size: 15px; color: var(--text); margin-top: 2px; white-space: pre-wrap; }
.marks .icon-btn { width: 36px; height: 36px; color: var(--text-3); }
.marks .icon-btn svg { width: 20px; height: 20px; }

/* ---------- 面板 / 提示 ---------- */
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); }
.sheet-head { display: flex; align-items: center; padding: 14px 8px 6px 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; }
.sheet-body input[type="text"] { width: 100%; border: 0; border-radius: 10px; background: var(--card); padding: 12px; font-size: 16px; outline: none; margin-bottom: 10px; }
.sheet-body textarea { background: var(--card); font-size: 16px; min-height: 36vh; }
.sheet-body .row { margin-top: 12px; }
.sheet-body .row .btn { flex: 1; }
.sheet-body .hint { font-size: 13px; color: var(--text-2); margin: 8px 0; }
.menu { list-style: none; margin: 0 0 12px; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.menu li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; min-height: 48px; }
.menu li + li { border-top: 0.5px solid var(--line); }
.menu li.danger { color: var(--red); }
.menu button.menu-item { all: unset; display: flex; align-items: center; gap: 10px; width: 100%; cursor: pointer; }
.lib li { padding: 8px 6px 8px 14px; }
.lib li.current { background: var(--accent-soft); }
.lib .meta { flex: 1; min-width: 0; cursor: pointer; }
.lib .name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib .info { font-size: 12px; color: var(--text-2); }
.lib .icon-btn { width: 34px; height: 34px; color: var(--text-3); }
.lib .icon-btn svg { width: 20px; height: 20px; }
.section-title { font-size: 13px; color: var(--text-2); margin: 16px 4px 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); 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)); }
}
