/* ==========================================================================
   練歌 — 樣式
   歌詞、黑膠、控制列、抽屜沿用 v2（我喜歡你/v2/style.css）的手機版；只做手機版面。
   ========================================================================== */
:root {
  --bg: #0a0b12;
  --surface-strong: rgba(14, 16, 26, 0.88);
  --fill-1: rgba(255, 255, 255, 0.05);
  --fill-2: rgba(255, 255, 255, 0.09);
  --fill-3: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);

  --text: #f6f7fb;
  --text-2: rgba(236, 238, 246, 0.74);
  --text-3: rgba(236, 238, 246, 0.52);

  --pink: #ff8fd6;
  --pink-strong: #ff66c4;
  --pink-soft: rgba(255, 143, 214, 0.16);
  --cyan: #63e4ee;
  --cyan-soft: rgba(99, 228, 238, 0.14);
  --cream: #ffe28a;
  --danger: #ff7a7a;

  --accent: var(--pink);
  --on-accent: #1a0b16;
  --ruby: var(--cream);
  --sung: var(--pink);
  --unsung: rgba(255, 255, 255, 0.94);

  --font-ui: 'Plus Jakarta Sans', 'Noto Sans TC', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-cjk: 'Noto Sans TC', 'Noto Sans CJK TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.18);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-3: 0 24px 60px rgba(0, 0, 0, 0.5), 0 8px 20px rgba(0, 0, 0, 0.3);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --dur-fast: 150ms;
  --dur-base: 240ms;
  --dur-slow: 420ms;

  --gutter: 16px;
  --topbar-h: 64px;
  --strip-h: 168px;
  --dock-space: 150px;
  --font-scale: 1;

  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
input { font: inherit; color: inherit; }
svg { display: block; flex-shrink: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- 背景：模糊封面 + 光暈（v2） ---------- */
.ambient { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.ambient-art {
  position: absolute; inset: -12%;
  background-size: cover; background-position: center;
  filter: blur(90px) saturate(1.6) brightness(0.42);
  transform: scale(1.1);
  animation: ambient-drift 40s ease-in-out infinite alternate;
  opacity: 0; transition: opacity 0.8s ease;
}
body.view-player .ambient-art.has-art { opacity: 1; }
.ambient-glow { position: absolute; width: 44vmax; height: 44vmax; border-radius: 50%; filter: blur(120px); opacity: 0.22; transition: opacity 1.2s var(--ease-out); }
.glow-pink { top: -14vmax; right: -8vmax; background: var(--pink-strong); }
.glow-cyan { bottom: -18vmax; left: -10vmax; background: #1fb6c9; }
body.is-playing .ambient-glow { opacity: 0.32; }
.ambient-shade {
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 80% at 70% 30%, transparent 0%, rgba(10, 11, 18, 0.55) 70%),
    linear-gradient(180deg, rgba(10, 11, 18, 0.35) 0%, rgba(10, 11, 18, 0.78) 100%);
}
@keyframes ambient-drift {
  from { transform: scale(1.1) translate3d(-2%, -1%, 0) rotate(0deg); }
  to { transform: scale(1.22) translate3d(2%, 2%, 0) rotate(4deg); }
}

/* ---------- 共用按鈕 ---------- */
.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; flex-shrink: 0;
  border-radius: 50%; color: var(--text-2);
  background: var(--fill-1); border: 1px solid var(--line);
  transition: background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { transform: scale(0.94); background: var(--fill-2); }

/* ==========================================================================
   選歌
   ========================================================================== */
.library {
  position: fixed; inset: 0; z-index: 10;
  overflow-y: auto; overscroll-behavior: contain;
  padding: calc(env(safe-area-inset-top) + 18px) 0 calc(110px + env(safe-area-inset-bottom));
}
.lib-top { padding: 0 var(--gutter) 10px; }
.lib-top h1 { font-family: var(--font-cjk); font-size: 28px; font-weight: 900; letter-spacing: 0.04em; }
.lib-search {
  margin: 0 var(--gutter) 12px; height: 44px; border-radius: var(--r-md);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--fill-2); border: 1px solid var(--line); color: var(--text-3);
}
.lib-search svg { width: 18px; height: 18px; }
.lib-search input { flex: 1; min-width: 0; background: none; border: none; outline: none; font-size: 15px; color: var(--text); }
.lib-search input::placeholder { color: var(--text-3); }
.lib-tabs { display: flex; gap: 8px; padding: 0 var(--gutter) 8px; overflow-x: auto; scrollbar-width: none; }
.lib-tabs::-webkit-scrollbar { display: none; }
.lib-tab {
  flex-shrink: 0; height: 34px; padding: 0 14px; border-radius: var(--r-full);
  background: var(--fill-2); color: var(--text-2); font-size: 14px; font-weight: 600;
}
.lib-tab[aria-selected="true"] { background: var(--text); color: var(--bg); font-weight: 800; }
.lib-group {
  padding: 16px calc(var(--gutter) + 4px) 6px; font-size: 12px; font-weight: 800;
  letter-spacing: 0.12em; color: var(--text-3);
}
.song-row {
  width: 100%; display: flex; align-items: center; gap: 14px;
  padding: 8px var(--gutter); text-align: left;
  transition: background var(--dur-fast) ease;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.song-row:active { background: var(--fill-1); }
.song-cover {
  width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0; overflow: hidden;
  display: grid; place-items: center; font-family: var(--font-cjk); font-size: 20px; font-weight: 900;
  color: rgba(0, 0, 0, 0.55); background: var(--fill-3); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.song-cover img { width: 100%; height: 100%; object-fit: cover; }
.song-meta { flex: 1; min-width: 0; }
.song-title, .song-artist { display: block; }
.song-title { font-family: var(--font-cjk); font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-artist { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-side { font-size: 12px; color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.song-side b { display: block; color: var(--cream); font-weight: 700; }
.lib-empty { padding: 60px 32px; text-align: center; color: var(--text-3); font-size: 14px; }
.lib-empty-title { font-size: 18px; font-weight: 800; color: var(--text-2); margin-bottom: 8px; }
.fab {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  height: 54px; padding: 0 22px 0 18px; border-radius: 27px;
  display: flex; align-items: center; gap: 8px;
  background: var(--pink); color: var(--on-accent); font-size: 16px; font-weight: 800;
  box-shadow: 0 10px 28px rgba(255, 102, 196, 0.38);
}
.fab svg { width: 20px; height: 20px; }
.fab:active { transform: scale(0.96); }
.fab:disabled { opacity: 0.6; }

/* ==========================================================================
   播放
   ========================================================================== */
.player {
  position: fixed; inset: 0; z-index: 10;
  display: grid;
  grid-template-rows: calc(var(--topbar-h) + env(safe-area-inset-top)) auto auto minmax(0, 1fr);
}
/* 固定列號：練習提示或音準帶隱藏時，其他區塊不會錯位 */
.player > .topbar { grid-row: 1; }
.player > .practice-banner { grid-row: 2; }
.player > .strip { grid-row: 3; }
.player > .stage { grid-row: 4; }

/* 標題列：黑膠 + 歌名 + 迷你頻譜（v2） */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
.np { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.np-vinyl {
  position: relative; width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.np-vinyl-disc {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--cover, none) 50% 46% / auto 100% no-repeat, #2a2433;
  will-change: transform;
}
.np-vinyl-disc::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 30%, rgba(0, 0, 0, 0.28) 30.5% 31.5%, transparent 32%),
    repeating-radial-gradient(circle, rgba(0, 0, 0, 0.16) 0 0.6px, transparent 0.6px 1.6px),
    radial-gradient(circle, transparent 0 86%, #0b0b10 87% 100%);
}
.np-vinyl-disc::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 13%; height: 13%;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: radial-gradient(circle, #05060a 0 42%, #e9e2cf 45% 100%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.np-vinyl-sheen {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: conic-gradient(from 20deg, transparent 0 8%, rgba(255, 255, 255, 0.28) 13%, transparent 19% 50%,
      rgba(255, 255, 255, 0.16) 63%, transparent 69% 100%);
  mix-blend-mode: screen;
  -webkit-mask: radial-gradient(circle, transparent 0 18%, #000 19%);
  mask: radial-gradient(circle, transparent 0 18%, #000 19%);
}
.np-text { min-width: 0; }
.np-title {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-cjk); font-size: 16px; font-weight: 800; line-height: 1.3; white-space: nowrap;
}
.np-title > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.np-bars { flex-shrink: 0; display: flex; align-items: flex-end; gap: 2px; height: 12px; }
.np-bars i {
  width: 2.5px; height: 16%; min-height: 2.5px; border-radius: var(--r-full);
  background: linear-gradient(0deg, var(--pink-strong), var(--pink) 45%, var(--cream)) bottom / 100% 12px;
}
.np-sub { display: flex; align-items: center; gap: 6px; font-size: 12.5px; line-height: 1.4; color: var(--text-3); white-space: nowrap; overflow: hidden; }
.np-sub > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.np-sub .dot { width: 3px; height: 3px; flex-shrink: 0; border-radius: 50%; background: currentColor; }
#np-section { flex-shrink: 0; font-weight: 700; color: var(--pink); }

/* 練習提示 */
.practice-banner {
  margin: 4px 12px 8px; padding: 8px 8px 8px 14px; border-radius: var(--r-lg);
  display: flex; align-items: center; gap: 12px;
  background: var(--cyan-soft); border: 1px solid rgba(99, 228, 238, 0.38);
  animation: badge-in var(--dur-base) var(--ease-out);
}
.practice-count {
  min-width: 30px; text-align: center; font-size: 26px; font-weight: 800; line-height: 1;
  color: var(--cyan); font-variant-numeric: tabular-nums;
}
.practice-count:empty { display: none; }
.practice-text { flex: 1; min-width: 0; }
.practice-text b { display: block; font-family: var(--font-cjk); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.practice-text small { display: block; font-size: 12px; color: var(--text-3); }
.practice-exit { height: 36px; padding: 0 14px; border-radius: var(--r-full); background: var(--fill-2); font-size: 13.5px; font-weight: 700; color: var(--text-2); }
@keyframes badge-in { from { opacity: 0; transform: translateY(4px); } }

/* 音準帶 */
.strip {
  position: relative; height: var(--strip-h); margin: 4px 12px 6px;
  border-radius: var(--r-lg); background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line);
  overflow: hidden;
}
body.pitch-off .strip { display: none; }
.strip canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.strip-tag, .strip-key {
  position: absolute; top: 7px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; color: var(--text-3); pointer-events: none;
}
.strip-tag { left: 10px; }
.strip-key { right: 10px; color: var(--cream); }

/* ---------- 歌詞（v2） ---------- */
.stage { position: relative; min-height: 0; display: flex; flex-direction: column; }
.lyrics-scroller {
  position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px, #000 66%, rgba(0, 0, 0, 0.3) 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 22px, #000 66%, rgba(0, 0, 0, 0.3) 100%);
}
.lyrics-scroller::-webkit-scrollbar { display: none; }
.lyrics-container { padding: 18vh var(--gutter) 46vh; -webkit-user-select: none; user-select: none; }

.lyric-section-label {
  display: flex; align-items: center; gap: 10px; margin: 30px 0 8px 12px;
  font-size: 12px; font-weight: 800; letter-spacing: 0.14em; color: var(--text-3);
  transition: color var(--dur-slow) ease;
}
.lyric-section-label::after { content: ""; flex: 0 0 40px; height: 1px; background: var(--line-strong); }
.lyric-section-label:first-child { margin-top: 0; }
.lyric-section-label.is-current { color: var(--pink); }

.lyric-line {
  position: relative; padding: 8px 12px; margin: 2px 0; border-radius: var(--r-lg);
  cursor: pointer; opacity: 0.34; transform-origin: left center; transform: scale(0.96); filter: blur(0.6px);
  transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out),
    filter var(--dur-slow) var(--ease-out), background var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.lyric-line.near-1 { opacity: 0.6; filter: none; }
.lyric-line.near-2 { opacity: 0.44; filter: blur(0.3px); }
.lyric-line.is-past { opacity: 0.26; }
.lyric-line.is-past.near-1 { opacity: 0.5; }
.lyric-line.active { opacity: 1; filter: none; transform: scale(1); }
.lyric-line.picked { opacity: 1; filter: none; transform: scale(1); background: var(--cyan-soft); box-shadow: inset 0 0 0 1.5px rgba(99, 228, 238, 0.55); }

/* 練習中：範圍外的歌詞更暗 */
body.practicing .lyric-line.out-of-range { opacity: 0.12; filter: blur(0.8px); }
/* 前導時正在播的前一句：半亮，方便抓進拍時機 */
body.practicing .lyric-line.out-of-range.active { opacity: 0.5; filter: none; }
body.practicing .lyric-section-label.out-of-range { opacity: 0.3; }

.lyric-content {
  font-family: var(--font-cjk); font-size: calc(23px * var(--font-scale)); font-weight: 800;
  line-height: 1.9; letter-spacing: 0.02em; color: var(--unsung); word-break: break-word;
}
body.ruby-hidden .lyric-content { line-height: 1.5; }
.lyric-line.english .lyric-content { font-family: var(--font-ui); font-weight: 700; letter-spacing: -0.005em; line-height: 1.45; }
.lyric-line.mandarin .lyric-content { letter-spacing: 0.06em; }
.lyric-line.interlude .lyric-content, .lyric-line.outro .lyric-content {
  display: inline-flex; align-items: center; gap: 12px;
  font-size: calc(17px * var(--font-scale)); font-weight: 600; line-height: 1.6; color: var(--text-2);
}
.lyric-line.interlude .lyric-content::before, .lyric-line.outro .lyric-content::before {
  content: ""; width: 22px; height: 22px; flex-shrink: 0; background: var(--cyan);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18V5l12-2v13'/%3E%3Ccircle cx='6' cy='18' r='3'/%3E%3Ccircle cx='18' cy='16' r='3'/%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 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18V5l12-2v13'/%3E%3Ccircle cx='6' cy='18' r='3'/%3E%3Ccircle cx='18' cy='16' r='3'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* 逐字填色（行內框，換行也連續） */
.lyric-line.active:not(.interlude):not(.outro) .lyric-content {
  --edge: calc(var(--p, 0) * 100%);
  background-image: linear-gradient(90deg, var(--sung) 0, var(--sung) calc(var(--edge) - 1.5%), var(--unsung) calc(var(--edge) + 1.5%), var(--unsung) 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 102, 196, 0.28));
}

ruby { ruby-align: center; ruby-position: over; }
rt {
  font-family: var(--font-ui); font-size: 0.42em; font-weight: 600; letter-spacing: 0.02em; line-height: 1.2;
  color: var(--ruby); -webkit-text-fill-color: var(--ruby); opacity: 0.85; -webkit-user-select: none; user-select: none;
}
:lang(ja) rt { font-family: var(--font-cjk); font-weight: 700; letter-spacing: 0; }
.lyric-line.active rt { opacity: 1; }
body.ruby-hidden rt { display: none; }

.btn-resume {
  position: absolute; left: 50%; bottom: calc(var(--dock-space) - 4px);
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 18px 0 14px;
  border-radius: var(--r-full); background: rgba(246, 247, 251, 0.95); color: #12131c;
  font-size: 14px; font-weight: 700; box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none; transform: translate(-50%, 12px);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out); z-index: 2;
}
.btn-resume svg { width: 18px; height: 18px; }
.btn-resume.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }

/* ---------- 控制列（v2 手機版的毛玻璃面板） ---------- */
.dock {
  position: fixed; z-index: 40;
  left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px; padding: 10px 12px 8px;
  border: 1px solid var(--line-strong); border-radius: 26px;
  background: rgba(22, 24, 36, 0.55);
  backdrop-filter: blur(30px) saturate(1.6); -webkit-backdrop-filter: blur(30px) saturate(1.6);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}
.transport { display: flex; align-items: center; justify-content: space-between; max-width: 440px; width: 100%; margin: 0 auto; }
.ctrl-btn {
  position: relative; width: 56px; height: 52px; display: grid; place-items: center; border-radius: var(--r-md);
  color: var(--text-2); transition: color var(--dur-fast) ease, background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.ctrl-btn svg { width: 22px; height: 22px; }
.ctrl-btn:active { transform: scale(0.92); }
.ctrl-lab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; }
.ctrl-lab span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.ctrl-chip {
  font-style: normal; font-size: 10px; font-weight: 800; padding: 0 5px; border-radius: var(--r-full);
  background: rgba(255, 226, 138, 0.16); color: var(--cream); font-variant-numeric: tabular-nums;
}
.ctrl-toggle[aria-pressed="true"] { color: var(--cyan); }
.ctrl-btn:disabled { opacity: 0.35; }
.ctrl-btn.ctrl-play {
  width: 60px; height: 60px; border-radius: 50%; background: #fff; color: #11121a; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.ctrl-btn.ctrl-play svg { width: 26px; height: 26px; }
.ctrl-play .icon-pause { display: none; }
body.is-playing .ctrl-play .icon-play { display: none; }
body.is-playing .ctrl-play .icon-pause { display: block; }

.timeline { display: flex; align-items: center; gap: 10px; }
.time { min-width: 36px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-3); }
.time:first-child { text-align: right; }
.scrubber { position: relative; flex: 1; height: 24px; display: flex; align-items: center; cursor: pointer; touch-action: none; border-radius: var(--r-full); }
.scrubber-rail { position: relative; width: 100%; height: 4px; border-radius: var(--r-full); background: var(--fill-3); overflow: hidden; transition: height var(--dur-fast) ease; }
.scrubber.is-dragging .scrubber-rail { height: 6px; }
.scrubber-fill {
  position: absolute; inset: 0; background: linear-gradient(90deg, var(--pink-strong), var(--pink));
  transform-origin: left; transform: scaleX(0); will-change: transform;
}
.scrubber-range { position: absolute; top: 0; bottom: 0; background: rgba(99, 228, 238, 0.45); }
.scrubber-markers span { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(10, 11, 18, 0.75); }
.scrubber-thumb {
  position: absolute; top: 50%; left: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45); transform: scale(0);
  transition: transform var(--dur-fast) var(--ease-out); pointer-events: none;
}
.scrubber.is-dragging .scrubber-thumb { transform: scale(1); }
.scrubber-tooltip {
  position: absolute; bottom: calc(100% + 8px); left: 0; padding: 5px 9px; border-radius: var(--r-sm);
  background: rgba(246, 247, 251, 0.96); color: #12131c; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  white-space: nowrap; box-shadow: var(--shadow-1); transform: translateX(-50%); opacity: 0; pointer-events: none;
  transition: opacity var(--dur-fast) ease;
}
.scrubber-tooltip small { margin-left: 6px; font-weight: 600; color: #5b5d70; }
.scrubber.is-dragging .scrubber-tooltip { opacity: 1; }

/* 載入中 */
.loading {
  position: absolute; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(10, 11, 18, 0.72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 14px; color: var(--text-2); text-align: center; padding: 24px;
}
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--fill-3); border-top-color: var(--pink); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   抽屜（v2）
   ========================================================================== */
.sheet {
  margin: auto; width: min(440px, calc(100vw - 32px)); padding: 8px 8px 12px;
  border-radius: var(--r-xl); border: 1px solid var(--line-strong); background: rgba(22, 24, 36, 0.98);
  color: var(--text); box-shadow: var(--shadow-3);
}
.sheet[open] { animation: sheet-in var(--dur-base) var(--ease-out); }
.sheet::backdrop { background: rgba(4, 5, 10, 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 8px 16px; }
.sheet-head h2 { font-size: 17px; font-weight: 800; }
.sheet-head-meta { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; padding-right: 8px; }
.sheet-head .icon-btn { width: 40px; height: 40px; background: none; border: none; }
.sheet-note { padding: 0 20px 10px; font-size: 13px; color: var(--text-3); }

.bottom-sheet {
  margin: auto 0 0; width: 100%; max-width: 100%; max-height: 86dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 0 0 max(16px, env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0; border-bottom: none; background: rgba(24, 26, 38, 0.97);
  transition: transform var(--dur-base) var(--ease-out);
}
.bottom-sheet.is-dragging { transition: none; }
.bottom-sheet[open] { animation: sheet-up var(--dur-slow) var(--ease-out); }
.bottom-sheet.is-closing { animation: sheet-down 220ms ease-in forwards; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-down { to { transform: translateY(100%); } }
.sheet-grabber { width: 40px; height: 5px; margin: 10px auto 2px; border-radius: var(--r-full); background: var(--fill-3); }
.bottom-sheet .sheet-head { padding: 4px 10px 8px 20px; }
.bottom-sheet .sheet-grabber, .bottom-sheet .sheet-head { touch-action: none; }

.setting-list { padding: 0 20px 4px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; border-top: 1px solid var(--line); }
.setting-block { padding: 14px 0 12px; border-top: 1px solid var(--line); }
.setting-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.setting-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.setting-name { font-size: 16px; font-weight: 700; }
.setting-value { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.setting-desc { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.setting-block .setting-desc { margin-top: 8px; }
.link-btn { margin-left: 6px; color: var(--cyan); font-weight: 700; font-size: 13px; }

.switch { position: relative; width: 30px; height: 18px; border-radius: var(--r-full); background: var(--fill-3); transition: background var(--dur-base) var(--ease-out); }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); transition: transform var(--dur-base) var(--ease-spring);
}
.switch-btn { flex-shrink: 0; width: 56px; height: 44px; display: grid; place-items: center; }
.switch-btn .switch { width: 50px; height: 30px; }
.switch-btn .switch::after { top: 3px; left: 3px; width: 24px; height: 24px; }
.switch-btn[aria-checked="true"] .switch { background: var(--cream); }
.switch-btn[aria-checked="true"] .switch::after { transform: translateX(20px); }

.stepper { height: 40px; display: inline-flex; align-items: center; border-radius: var(--r-full); background: var(--fill-1); border: 1px solid var(--line); padding: 0 3px; }
.stepper-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: var(--text-2); }
.stepper-btn:disabled { opacity: 0.35; }
.stepper-lg { flex-shrink: 0; height: 46px; padding: 0 4px; }
.stepper-lg .stepper-btn { width: 54px; height: 40px; border-radius: var(--r-full); }
.stepper-a { font-family: var(--font-ui); font-size: 21px; font-weight: 800; line-height: 1; }
.stepper-a.small { font-size: 14px; }
.stepper-divider { width: 1px; height: 20px; background: var(--line-strong); }

/* 導唱音量滑桿 */
.range { --v: 0%; -webkit-appearance: none; appearance: none; width: 100%; height: 32px; background: transparent; }
.range::-webkit-slider-runnable-track { height: 6px; border-radius: var(--r-full); background: linear-gradient(90deg, var(--pink) var(--v), var(--fill-3) var(--v)); }
.range::-moz-range-track { height: 6px; border-radius: var(--r-full); background: linear-gradient(90deg, var(--pink) var(--v), var(--fill-3) var(--v)); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; background: #fff; border: none; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45); }
.range::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: #fff; border: none; }

/* 升降 key */
.key-stepper { display: flex; align-items: center; gap: 12px; }
.key-btn { width: 56px; height: 48px; border-radius: var(--r-md); background: var(--fill-2); font-size: 24px; font-weight: 600; }
.key-btn:active { background: var(--fill-3); }
.key-btn:disabled { opacity: 0.35; }
.key-value { flex: 1; text-align: center; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.key-value.shifted { color: var(--cream); }

/* 段落 */
.chapter-list { list-style: none; display: flex; flex-direction: column; gap: 2px; padding: 0 12px 4px; }
.chapter-list li { display: flex; align-items: center; gap: 6px; }
.chapter-item {
  position: relative; flex: 1; min-width: 0; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 12px;
  min-height: 54px; padding: 0 12px 0 10px; border-radius: var(--r-md); text-align: left; color: var(--text-2); overflow: hidden;
}
.chapter-index { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-3); text-align: center; }
.chapter-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-time { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text-3); }
.chapter-progress { position: absolute; left: 10px; right: 12px; bottom: 5px; height: 2px; border-radius: 2px; background: var(--fill-2); overflow: hidden; opacity: 0; }
.chapter-progress::after { content: ""; position: absolute; inset: 0; background: var(--pink); transform-origin: left; transform: scaleX(var(--chapter-p, 0)); }
.chapter-item.is-active { background: var(--fill-2); color: var(--text); }
.chapter-item.is-active .chapter-progress { opacity: 1; }
.chapter-item.is-active .chapter-index { color: var(--pink); }
.chapter-item.is-past .chapter-name { color: var(--text-3); }
.chapter-practice {
  flex-shrink: 0; width: 48px; height: 44px; border-radius: var(--r-md);
  background: var(--cyan-soft); color: var(--cyan); font-size: 13px; font-weight: 800;
}

/* 動作按鈕格 */
.line-title { font-family: var(--font-cjk); font-size: 16px !important; font-weight: 700 !important; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 16px 6px; }
.action-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.action { min-height: 60px; border-radius: var(--r-lg); padding: 10px 14px; background: var(--fill-2); text-align: left; }
.action-grid.three .action { text-align: center; }
.action b { display: block; font-size: 15px; font-weight: 800; }
.action small { display: block; font-size: 12px; color: var(--text-3); margin-top: 2px; }
.action.main { background: var(--pink); color: var(--on-accent); }
.action.main small { color: rgba(26, 11, 22, 0.7); }
.action.danger { background: rgba(255, 122, 122, 0.16); color: var(--danger); }
.action:active { transform: scale(0.98); }
.action:disabled { opacity: 0.4; }

.result-plot { position: relative; height: 170px; margin: 0 16px 10px; border-radius: var(--r-lg); background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line); overflow: hidden; }
.result-plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

#confirm-dialog { padding-bottom: 16px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-space) + 16px + env(safe-area-inset-bottom)); z-index: 80;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: var(--r-full);
  background: rgba(246, 247, 251, 0.96); color: #12131c; font-size: 14px; font-weight: 700; text-align: center;
  box-shadow: var(--shadow-2); opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.view-library .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }

/* 矮螢幕：音準帶縮小 */
@media (max-height: 700px) { :root { --strip-h: 132px; } }

/* 電腦上開（開發測試用）：維持手機寬度置中 */
@media (min-width: 640px) {
  .library, .player { left: 50%; right: auto; width: 480px; transform: translateX(-50%); }
  .dock { left: 50%; right: auto; width: 460px; transform: translateX(-50%); }
  .fab { right: calc(50% - 240px + 16px); }
}
