/* ===== Theme tokens ===== */
:root,
[data-theme="dark"] {
  --bg-0: #07091c;
  --bg-1: #0f1330;
  --panel: rgba(24, 28, 60, 0.55);
  --panel-solid: #1b1f44;
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);

  --text: #f3f4ff;
  --text-strong: #ffffff;
  --muted: #a4abdb;
  --muted-2: #6f76a8;

  --accent: #7cf3ff;
  --accent-2: #ff7ab8;
  --accent-3: #b388ff;
  --active: #ffd166;
  --danger: #ff8aa6;

  --chip-bg: rgba(255, 255, 255, 0.06);
  --chip-border: rgba(255, 255, 255, 0.10);
  --input-bg: rgba(15, 19, 48, 0.65);
  --input-border: rgba(255, 255, 255, 0.12);
  --hover: rgba(255, 255, 255, 0.06);
  --line-active-bg: linear-gradient(135deg, rgba(124, 243, 255, 0.14), rgba(255, 122, 184, 0.14));
  --line-active-shadow: 0 8px 32px rgba(124, 243, 255, 0.18);

  --aurora-1: rgba(124, 243, 255, 0.35);
  --aurora-2: rgba(255, 122, 184, 0.30);
  --aurora-3: rgba(179, 136, 255, 0.30);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-body-height: 65px;
  --app-header-height: calc(var(--header-body-height) + var(--safe-top));
}

[data-theme="light"] {
  --bg-0: #f5f7ff;
  --bg-1: #eaeefc;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-solid: #ffffff;
  --panel-border: rgba(20, 30, 80, 0.10);
  --panel-shadow: 0 12px 40px rgba(60, 80, 160, 0.15);

  --text: #1a1d36;
  --text-strong: #0a0d24;
  --muted: #5a607f;
  --muted-2: #8a90b0;

  --accent: #2d8cff;
  --accent-2: #ff5e9c;
  --accent-3: #8a5cff;
  --active: #f08a00;
  --danger: #d04848;

  --chip-bg: rgba(20, 30, 80, 0.05);
  --chip-border: rgba(20, 30, 80, 0.10);
  --input-bg: #ffffff;
  --input-border: rgba(20, 30, 80, 0.14);
  --hover: rgba(20, 30, 80, 0.05);
  --line-active-bg: linear-gradient(135deg, rgba(45, 140, 255, 0.10), rgba(255, 94, 156, 0.10));
  --line-active-shadow: 0 8px 28px rgba(45, 140, 255, 0.18);

  --aurora-1: rgba(45, 140, 255, 0.28);
  --aurora-2: rgba(255, 94, 156, 0.22);
  --aurora-3: rgba(138, 92, 255, 0.22);
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; max-width: 100%; overflow-x: hidden; }
html { color-scheme: dark; }
[data-theme="light"] html, html[data-theme="light"] { color-scheme: light; }

body {
  font-family: "Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 100%);
  color: var(--text);
  min-height: 100vh;
  height: 100vh;
  padding-top: var(--app-header-height);
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  overflow: hidden;
  touch-action: pan-y;
  transition: background-color .4s ease, color .4s ease;
}

/* ===== Aurora background ===== */
.bg-aurora {
  position: fixed; inset: 0; z-index: -1;
  overflow: hidden; pointer-events: none;
  filter: blur(60px) saturate(140%);
  opacity: 0.85;
}
.bg-aurora .blob {
  position: absolute;
  width: 55vmax; height: 55vmax;
  border-radius: 50%;
  mix-blend-mode: screen;
  animation: drift 22s ease-in-out infinite alternate;
}
[data-theme="light"] .bg-aurora .blob { mix-blend-mode: multiply; }
.bg-aurora .b1 { background: var(--aurora-1); top: -20%; left: -15%; }
.bg-aurora .b2 { background: var(--aurora-2); bottom: -25%; right: -10%; animation-delay: -7s; animation-duration: 26s; }
.bg-aurora .b3 { background: var(--aurora-3); top: 30%; right: -25%; animation-delay: -14s; animation-duration: 30s; }
@keyframes drift {
  0%   { transform: translate3d(0,0,0) scale(1); }
  50%  { transform: translate3d(4vw,-3vh,0) scale(1.08); }
  100% { transform: translate3d(-3vw,5vh,0) scale(0.95); }
}

/* ===== Glass surface ===== */
.glass {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}

/* ===== Header ===== */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  width: 100%;
  max-width: 100vw;
  min-height: var(--app-header-height);
  padding: calc(12px + var(--safe-top)) 18px 12px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  flex: 0 0 auto;
  border-radius: 0;
  border-left: none; border-right: none; border-top: none;
  box-shadow: 0 2px 24px rgba(0,0,0,0.20);
  transform: translateZ(0);
  overscroll-behavior: contain;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.logo {
  font-size: 22px;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 8px rgba(124,243,255,0.6));
}
.brand-sub {
  font-size: 10px; font-weight: 500; color: var(--muted);
  letter-spacing: 1.5px; text-transform: uppercase; margin-top: 2px;
}
.brand-mode { position: relative; display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-mode-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  padding: 2px 6px 2px 2px; margin: -2px -6px -2px -2px;
  color: var(--text-strong); font-size: 14px; font-weight: 700; letter-spacing: 0.3px;
  cursor: pointer; transition: background .2s, border-color .2s, transform .12s;
}
.brand-mode-btn:hover { background: var(--hover); }
.brand-mode-btn:active { transform: scale(0.97); }
.brand-mode-arrow {
  display: inline-flex; width: 14px; height: 14px; color: var(--muted);
  transition: transform .2s ease;
}
.brand-mode-arrow svg { width: 100%; height: 100%; display: block; }
body.brand-mode-open .brand-mode-arrow { transform: rotate(180deg); }
body.app-study .brand-mode-btn { color: var(--accent); }
.brand-mode-menu {
  position: fixed; top: calc(var(--app-header-height) + 8px); left: 12px; z-index: 50;
  min-width: 156px; padding: 5px; border-radius: 12px;
  box-shadow: var(--panel-shadow); animation: panelIn .2s ease;
  display: flex; flex-direction: column; gap: 2px;
}
.brand-mode-menu[hidden] { display: none; }
.brand-mode-option {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; background: transparent; border: none; border-radius: 8px;
  color: var(--text); font-size: 14px; font-weight: 500; text-align: left;
  cursor: pointer; transition: background .15s, color .15s;
}
.brand-mode-option:hover { background: var(--hover); }
.brand-mode-option.active { color: var(--accent); font-weight: 600; }
.brand-mode-opt-icon { font-size: 15px; flex: 0 0 auto; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.icon-btn {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--text);
  border-radius: 12px;
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer;
  transition: transform .15s, background .2s, border-color .2s;
}
.icon-btn:hover { background: var(--hover); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn-glyph {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  flex: 0 0 auto;
}
.icon-btn-glyph svg {
  width: 18px;
  height: 18px;
  display: block;
}
.icon-furigana {
  width: 20px;
  height: 20px;
}
.icon-furigana svg {
  width: 20px;
  height: 20px;
}
.icon-panel-toggle {
  transform: translateY(1px);
}
.theme-icon { transition: transform .4s cubic-bezier(.5,1.6,.5,1); display: inline-block; }
.icon-btn:active .theme-icon { transform: rotate(180deg); }

.overrides-popover {
  position: fixed;
  top: calc(var(--app-header-height) + 8px);
  right: 12px;
  z-index: 30;
  width: min(420px, calc(100vw - 24px));
  padding: 14px;
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
  animation: panelIn .25s ease;
}
.overrides-popover[hidden] { display: none; }
.export-checkboxes {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
#export-output {
  width: 100%;
  font-family: "Inter", "Noto Sans JP", monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  margin-bottom: 10px;
}
.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.popover-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
}
.popover-subtitle {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.popover-close {
  width: 32px;
  height: 32px;
  font-size: 18px;
  flex: 0 0 auto;
}
.overrides-popover textarea { margin-top: 10px; }
.history-popover {
  width: min(460px, calc(100vw - 24px));
}
.history-list {
  max-height: min(60vh, 520px);
  overflow-y: auto;
}
.history-empty,
.search-message {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 13px;
}
.search-message.error { color: var(--danger); }

/* ===== Romaji annotation editor ===== */
.annotation-popover {
  position: fixed;
  z-index: 70;
  width: min(390px, calc(100vw - 20px));
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  padding: 14px;
  border-radius: 14px;
  box-shadow: var(--panel-shadow);
  animation: panelIn .18s ease;
}
.annotation-popover[hidden] { display: none; }
.annotation-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.annotation-selection {
  max-width: 290px;
  margin-top: 3px;
  color: var(--accent);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.annotation-types {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}
.tone-types {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  padding: 3px;
  margin-bottom: 7px;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--input-bg) 82%, transparent);
}
.annotation-type {
  min-width: 0;
  padding: 8px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  border-radius: 8px;
  font-size: 12px;
}
.annotation-type.active {
  color: var(--text-strong);
  border-color: color-mix(in srgb, var(--accent) 58%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, var(--input-bg));
}
.tone-type {
  gap: 3px;
  padding: 7px 3px;
  border-color: transparent;
  background: transparent;
  white-space: nowrap;
}
.tone-number {
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
}
.tone-glyph {
  color: var(--active);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}
.annotation-sample {
  position: relative;
  color: var(--text-strong);
  font-size: 11px;
  line-height: 1.2;
}
.sample-phrase { border-bottom: 2px solid var(--accent); }
.sample-break { color: var(--accent-2); font-weight: 700; font-style: normal; }
.sample-note { border-bottom: 2px dotted var(--accent-2); }
#annotation-note {
  width: 100%;
  margin-bottom: 10px;
  border-radius: 8px;
}
#annotation-note:disabled { opacity: .48; cursor: not-allowed; }
.annotation-actions { justify-content: flex-end; }
.annotation-actions button { border-radius: 8px; font-size: 12px; padding: 8px 11px; }
.annotation-actions-wide { justify-content: stretch; }
.annotation-actions-wide button { flex: 1 1 auto; }
.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }

.mode-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07091c;
  border: none; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform .12s, filter .2s, background .3s;
}
.mode-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.mode-btn:active { transform: scale(0.96); }
.mode-btn .mode-icon { font-size: 14px; }
body.mode-read .mode-btn {
  background: var(--chip-bg);
  color: var(--text);
  border: 1px solid var(--chip-border);
  box-shadow: none;
}
body.app-study #panel,
body.app-study #lyrics-view,
body.app-study #player-bar,
body.app-study #timer-hud {
  display: none !important;
}
body.app-study {
  overflow-y: auto;
}

/* ===== Panel ===== */
.panel {
  margin: 12px;
  padding: 16px;
  width: calc(100% - 24px);
  max-width: calc(100vw - 24px);
  border-radius: 18px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--panel-shadow);
  animation: panelIn .35s ease;
  /* 盖住右上角的计时/播放小框：搜索面板展开时不被遮挡 */
  position: relative;
  z-index: 20;
}
.panel.hidden { display: none; }
@keyframes panelIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== Inputs ===== */
input, textarea, button, select {
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 12px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }

button {
  cursor: pointer;
  transition: transform .08s, background .2s, box-shadow .2s, border-color .2s;
  font-weight: 500;
}
button:hover { background: var(--hover); }
button:active { transform: scale(0.97); }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07091c;
  border: none;
  font-weight: 600;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
}
button.primary:hover { filter: brightness(1.08); }

/* ===== Search box ===== */
/* 搜索框与搜索按钮锁定一行，窄屏也不换行 */
.search-row { gap: 8px; flex-wrap: nowrap; }
#btn-search {
  flex: 0 0 auto;
  font-size: 13px;
  padding: 9px 12px;
  white-space: nowrap;
}
.search-box {
  position: relative; flex: 1 1 240px; min-width: 0;
  display: flex; align-items: center;
}
.search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 14px; opacity: 0.6; pointer-events: none;
}
.search-box input {
  width: 100%;
  padding-left: 38px;
  border-radius: 999px;
}

/* ===== Search results ===== */
.search-results {
  max-height: 42vh; overflow-y: auto;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 14px;
  padding: 6px;
  animation: panelIn .25s ease;
}
.search-section-head {
  padding: 10px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--muted-2);
  text-transform: uppercase;
}
.result-item {
  padding: 12px; border-radius: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  transition: background .18s, transform .18s;
}
.result-item:hover { background: var(--hover); transform: translateX(2px); }
.result-item .title { font-weight: 600; color: var(--text-strong); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result-item .meta { font-size: 12px; color: var(--muted); }
.badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: #07091c;
  letter-spacing: 0.5px;
}
.badge-cache {
  background: color-mix(in srgb, var(--accent-2) 70%, var(--accent));
  color: #07091c;
}

.assist-actions {
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.assist-actions[hidden] { display: none; }
.assist-actions-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.assist-actions-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--muted-2);
  text-transform: uppercase;
}
.assist-actions-meta {
  font-size: 12px;
  color: var(--muted);
}
.assist-actions-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
/* ===== 搜索源分栏 tab（缓存 / 网易云 / LRCLIB） ===== */
.search-source-tabs {
  display: flex; gap: 2px;
  padding: 2px;
  margin: -6px -6px 4px; /* 贴住 .search-results 的内边距 */
  border-bottom: 1px solid var(--input-border);
}
.search-source-tab {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: none; color: var(--muted);
  padding: 7px 10px; border-radius: 8px 8px 0 0;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.search-source-tab:hover { color: var(--text); background: var(--hover); }
.search-source-tab.active {
  color: var(--text-strong);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.src-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-2);
  flex: 0 0 auto;
  transition: background .2s, box-shadow .2s;
}
.src-dot[data-state="idle"],
.src-dot[data-state="empty"] { opacity: 0.35; }
.src-dot[data-state="loading"] {
  background: #fbbf24;
  animation: pulse 1.2s ease-in-out infinite;
}
.src-dot[data-state="done"] {
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
}
.src-dot[data-state="error"] { background: var(--danger); }
.search-source-pane[hidden] { display: none; }

.assist-btn {
  flex: 1 1 220px;
  min-width: 0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 12px;
}
.assist-btn[data-state="ready"] {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--text-strong);
}
.assist-btn[data-state="loading"] {
  opacity: 0.78;
}
.assist-btn:disabled {
  opacity: 0.56;
  cursor: default;
}

/* ===== Section labels ===== */
.section-label {
  font-size: 11px; font-weight: 600; letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 4px 4px -2px;
}

/* ===== Source tabs ===== */
.source-tabs {
  display: flex; gap: 4px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  padding: 4px; border-radius: 14px;
}
.tab {
  flex: 1; min-width: 0;
  background: transparent; border: none; color: var(--muted);
  padding: 9px 8px; border-radius: 10px;
  font-size: 13px; font-weight: 500;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--hover); }
.tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07091c;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
}
.tab-pane { display: none; flex-direction: column; gap: 8px; animation: panelIn .25s ease; }
.tab-pane.active { display: flex; }

/* ===== Sub tabs (inside a main tab pane) ===== */
.sub-tabs {
  display: flex; gap: 4px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  padding: 3px; border-radius: 10px;
}
.sub-tab {
  flex: 1; min-width: 0;
  background: transparent; border: none; color: var(--muted);
  padding: 7px 8px; border-radius: 8px;
  font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.sub-tab:hover { color: var(--text); background: var(--hover); }
.sub-tab.active {
  background: var(--input-bg);
  color: var(--text-strong);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.sub-pane { display: none; flex-direction: column; gap: 8px; animation: panelIn .2s ease; }
.sub-pane.active { display: flex; }

.btn-mini {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  background: var(--chip-bg); border: 1px solid var(--chip-border);
  color: var(--text);
}
.btn-mini:hover { background: var(--hover); border-color: var(--accent); color: var(--text-strong); }
.btn-mini.loading { opacity: 0.6; pointer-events: none; }

/* Source subsections inside the search results panel */
.source-section {
  margin-top: 6px; padding: 8px 6px 4px;
  border-top: 1px dashed var(--input-border);
}
.source-section .source-section-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 600; letter-spacing: 1.2px;
  color: var(--muted-2); text-transform: uppercase;
  padding: 0 6px 6px;
}

/* ===== File label ===== */
.file-label {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--input-bg);
  border: 1px dashed var(--input-border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s;
}
.file-label.block { display: flex; width: 100%; }
.file-label:hover { border-color: var(--accent); background: var(--hover); }
.file-cta {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07091c;
  font-weight: 600; font-size: 13px;
  padding: 6px 12px; border-radius: 8px;
}
.file-name { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hint-sm { font-size: 12px; color: var(--muted); margin: 4px 2px 0; }
.hint-sm code {
  background: var(--chip-bg); padding: 1px 6px; border-radius: 6px;
  font-size: 11.5px; color: var(--accent);
}

/* ===== Toggles (chips) ===== */
.toggles { gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--chip-bg); border: 1px solid var(--chip-border);
  padding: 7px 14px; border-radius: 999px;
  font-size: 13px; color: var(--muted);
  cursor: pointer; user-select: none;
  transition: background .2s, color .2s, border-color .2s, transform .12s;
}
.chip:hover { background: var(--hover); }
.chip:has(input:checked) {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, transparent), color-mix(in srgb, var(--accent-2) 22%, transparent));
  color: var(--text-strong);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}
.chip input { display: none; }
.chip span::before {
  content: ''; display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted-2);
  margin-right: 6px; vertical-align: middle;
  transition: background .2s, box-shadow .2s;
}
.chip:has(input:checked) span::before {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* ===== Status ===== */
.status {
  font-size: 13px; color: var(--muted); min-height: 18px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.status-text {
  min-width: 0;
}
.status-action {
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.status-action:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.status.error { color: var(--danger); }

/* ===== Lyrics view ===== */
.lyrics-view {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  padding: 16px 16px 220px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.lrc-spacer {
  width: 100%;
  pointer-events: none;
  flex: 0 0 auto;
}
.lrc-spacer-top {
  height: 34vh;
  min-height: 160px;
}
.lrc-spacer-bottom {
  height: 46vh;
  min-height: 220px;
}
.hint-card {
  max-width: 460px; margin: 8vh auto 0;
  text-align: center; padding: 32px 24px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 20px; backdrop-filter: blur(16px);
  box-shadow: var(--panel-shadow);
}
.hint-card p { margin: 8px 0; line-height: 1.7; color: var(--text); }
.hint-card .hint-sub { color: var(--muted); font-size: 13px; margin-top: 14px; }
.hint-emoji { font-size: 44px; margin-bottom: 8px; }

/* ===== Study view ===== */
.study-view {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  overflow-y: auto;
}
.study-view[hidden] { display: none; }
.study-panel {
  padding: 16px;
  border-radius: 18px;
  box-shadow: var(--panel-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.study-panel.hidden { display: none; }
.study-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.study-title {
  color: var(--text-strong);
  font-size: 18px;
  font-weight: 700;
}
.study-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}
.study-actions { justify-content: flex-start; }
.study-voice-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}
.study-voice-select {
  width: 100%;
  min-width: 0;
}
.study-results {
  padding: 12px 0 0;
}
.lrc-line.study-line {
  position: relative;
  padding-right: 58px;
  opacity: 1;
  filter: none;
  text-align: left;
  cursor: default;
  transform: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border: 1px solid transparent;
}
.lrc-line.study-line:hover {
  background: var(--hover) !important;
}
.lrc-line.study-line .jp,
.lrc-line.study-line .romaji,
.lrc-line.study-line .zh {
  max-width: none;
  margin-left: 0;
  margin-right: 0;
  text-align: left;
}
.lrc-line.study-line .zh {
  min-height: 0;
}
.study-speak-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.lrc-speak-btn {
  display: none;
}

.lrc-line {
  position: relative;
  padding: 16px 18px;
  margin: 8px auto;
  width: min(100%, 760px);
  max-width: 760px;
  overflow: hidden;
  border-radius: 18px;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity .3s, background .3s, transform .35s cubic-bezier(.5,1.5,.5,1), filter .3s;
  text-align: center;
  filter: blur(0.4px);
}
.lrc-line:hover { opacity: 0.85; background: var(--hover); filter: blur(0); }
.lrc-line.active {
  opacity: 1;
  filter: blur(0);
  background: var(--line-active-bg);
  transform: scale(1.025);
  box-shadow: var(--line-active-shadow);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.lrc-line.active .jp {
  color: var(--active);
  text-shadow: 0 2px 18px color-mix(in srgb, var(--active) 40%, transparent);
}

/* KTV karaoke effect: text gradually turns gold left-to-right (sing mode only) */
body:not(.mode-read) .lrc-line.active .jp {
  color: var(--text-strong);
}
/* 字符变色平滑过渡，避免逐字高亮时的生硬跳变 */
body:not(.mode-read) .lrc-line.active .jp .karaoke-char {
  transition: color 0.35s ease, text-shadow 0.35s ease;
}
body:not(.mode-read) .lrc-line.active .jp .karaoke-sung {
  color: var(--active);
  text-shadow: 0 2px 18px color-mix(in srgb, var(--active) 40%, transparent);
}
body:not(.mode-read) .lrc-line.active .jp rt {
  color: var(--accent);
}

/* KTV karaoke effect for romaji */
body:not(.mode-read) .lrc-line.active .romaji {
  color: color-mix(in srgb, var(--accent) 50%, transparent);
}
body:not(.mode-read) .lrc-line.active .romaji .karaoke-char {
  transition: color 0.35s ease;
}
body:not(.mode-read) .lrc-line.active .romaji .karaoke-sung {
  color: var(--active);
}

/* Reading mode: all lines fully readable, current line subtly marked */
body.mode-read .lrc-line {
  opacity: 1;
  filter: none;
  text-align: left;
  padding: 10px 56px 10px 16px;
  margin: 4px auto;
  max-width: 760px;
  border: 1px solid transparent;
  cursor: pointer;
  transform: none !important;
  background: transparent !important;
  box-shadow: none !important;
}
body.mode-read .lrc-speak-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
body.mode-read .lrc-line .romaji,
body.mode-read .lrc-line .zh { text-align: left; }
body.mode-read .lrc-line:hover {
  background: var(--hover) !important;
}
body.mode-read .lrc-line.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent) !important;
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
body.mode-read .lrc-line.active .jp { text-shadow: none; color: var(--text-strong); }
body.mode-read .lyrics-view {
  padding: 8px 16px 32px;
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
}
@media (min-width: 720px) {
  body.mode-read .lyrics-view { padding: 12px 24px 40px; }
}

.jp {
  font-family: "Zen Maru Gothic", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 24px; line-height: 2.0; font-weight: 500;
  color: var(--text-strong);
  max-width: 100%;
  margin: 0 auto;
  line-break: loose;
  word-break: normal;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
.jp ruby {
  margin: 0 1px;
  white-space: normal;
}
.jp ruby rt {
  font-size: 0.5em;
  color: var(--accent);
  font-weight: 400;
  letter-spacing: 0.5px;
  font-family: "Noto Sans JP", sans-serif;
}
.romaji {
  font-family: "Inter", sans-serif;
  font-size: 16px; color: var(--accent);
  margin-top: 8px;
  letter-spacing: 0.6px;
  font-style: italic;
  opacity: 0.85;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  overflow-wrap: break-word;
  word-break: normal;
  text-wrap: pretty;
}
.romaji-markup-mode .romaji {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}
.romaji-markup-mode .romaji::selection,
.romaji-markup-mode .romaji *::selection {
  color: var(--text-strong);
  background: color-mix(in srgb, var(--accent-2) 48%, transparent);
}
.romaji-mark {
  position: relative;
  color: inherit;
  font-style: inherit;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.romaji-mark-phrase {
  padding: 0 1px 2px;
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 88%, var(--text-strong));
}
.romaji-mark-tone1,
.romaji-mark-tone2,
.romaji-mark-tone3,
.romaji-mark-tone4 {
  padding-top: 7px;
  background-repeat: no-repeat;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.romaji-mark-tone1 {
  background-image: linear-gradient(var(--active), var(--active));
  background-position: left 2px;
  background-size: 100% 2px;
}
.romaji-mark-tone2 {
  background-image: linear-gradient(to bottom right,
    transparent 42%, var(--active) 44%, var(--active) 56%, transparent 58%);
  background-position: left top;
  background-size: 100% 7px;
}
.romaji-mark-tone3 {
  background-image:
    linear-gradient(to top right, transparent 40%, var(--active) 43%, var(--active) 57%, transparent 60%),
    linear-gradient(to bottom right, transparent 40%, var(--active) 43%, var(--active) 57%, transparent 60%);
  background-position: left top, right top;
  background-size: 52% 7px, 52% 7px;
}
.romaji-mark-tone4 {
  background-image: linear-gradient(to top right,
    transparent 42%, var(--active) 44%, var(--active) 56%, transparent 58%);
  background-position: left top;
  background-size: 100% 7px;
}
.romaji-mark-tone1::after,
.romaji-mark-tone2::after,
.romaji-mark-tone3::after,
.romaji-mark-tone4::after {
  content: attr(data-tone);
  position: absolute;
  top: -8px;
  right: -2px;
  color: var(--active);
  font-size: 8px;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
}
.romaji-break {
  position: relative;
  display: inline-block;
  width: .5em;
  height: 1em;
  vertical-align: -.08em;
}
.romaji-break::after {
  content: '/';
  position: absolute;
  left: 50%;
  top: 50%;
  color: var(--accent-2);
  font-size: 1.05em;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
  transform: translate(-50%, -50%);
}
.romaji-mark-note {
  padding-bottom: 2px;
  border-bottom: 2px dotted var(--accent-2);
}
.romaji-mark-note::before {
  content: attr(data-note);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 3px);
  max-width: 160px;
  padding: 1px 5px;
  transform: translateX(-50%);
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent-2) 18%, var(--panel-solid));
  color: var(--text-strong);
  font-family: "Noto Sans SC", sans-serif;
  font-size: 10px;
  font-style: normal;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .16);
}
.romaji.has-romaji-note { margin-top: 26px; }
.zh {
  font-family: "Noto Sans SC", sans-serif;
  font-size: 14px; color: var(--muted); margin-top: 4px;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body.mode-read .jp,
body.mode-read .romaji,
body.mode-read .zh {
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

.lrc-line.hide-furigana ruby rt { display: none; }
.lrc-line.hide-romaji .romaji { display: none; }
.lrc-line.hide-zh .zh { display: none; }

/* ===== Player bar ===== */
.player-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  z-index: 15;
  border-radius: 0;
  border-left: none; border-right: none; border-bottom: none;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.30);
  transform: translateY(0);
  transition: transform .3s ease, opacity .3s ease;
}
body.no-player .player-bar {
  transform: translateY(110%);
  opacity: 0;
  pointer-events: none;
}
body.no-player .lyrics-view { padding-bottom: 32px; }
@media (min-width: 720px) {
  body.no-player .lyrics-view { padding-bottom: 40px; }
}
#audio { width: 100%; height: 40px; }
#audio::-webkit-media-controls-panel {
  background-color: var(--input-bg);
}

.yt-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto 8px;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* ===== Timer HUD ===== */
.timer-hud {
  position: fixed;
  top: calc(var(--app-header-height) + 8px); right: 14px;
  z-index: 12;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  padding: 6px 10px;
  border-radius: 999px;
  box-shadow: var(--panel-shadow);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  animation: panelIn .25s ease;
}
.timer-hud[hidden] { display: none; }
.hud-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted-2);
  transition: background .2s, box-shadow .2s;
}
.timer-hud.running .hud-dot {
  background: #4ade80;
  box-shadow: 0 0 10px #4ade80;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.5; } }
#timer-display { min-width: 64px; text-align: center; color: var(--text-strong); }
.hud-btn {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--text);
  width: 28px; height: 28px; padding: 0;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px;
}
.hud-btn:hover { background: var(--hover); }

/* ===== Responsive ===== */
@media (min-width: 720px) {
  .panel { margin: 16px auto; max-width: 920px; }
  .jp { font-size: 30px; line-height: 2.1; }
  .romaji { font-size: 18px; }
  .zh { font-size: 16px; }
  .lyrics-view { padding-bottom: 240px; }
  .yt-wrap { max-width: 560px; }
}

@media (max-width: 480px) {
  :root { --header-body-height: 58px; }
  .brand-mode-btn { font-size: 13px; }
  .brand-sub { display: none; }
  .icon-btn { width: 38px; height: 38px; }
  .app-header { padding-left: 10px; padding-right: 10px; }
  .brand { gap: 8px; }
  .logo { font-size: 20px; }
  .header-actions { gap: 6px; }
  .mode-btn { padding: 0 10px; }
  .mode-btn .mode-text { display: none; }
  .panel {
    margin: 8px;
    padding: 12px;
    width: calc(100% - 16px);
    max-width: calc(100vw - 16px);
  }
  .jp {
    font-size: clamp(20px, 5.8vw, 21px);
    line-height: 1.85;
    word-break: break-word;
  }
  .romaji {
    font-size: clamp(14px, 4vw, 16px);
    letter-spacing: 0.35px;
  }
  .zh { font-size: clamp(13px, 3.8vw, 14px); }
  .lyrics-view {
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: 200px;
  }
  .lrc-line {
    width: 100%;
    padding: 14px 12px;
  }
  body.mode-read .lrc-line { padding-right: 50px; }
  body.mode-read .lrc-speak-btn { right: 8px; }
  .study-view { padding: 10px 10px 28px; }
  .study-panel { padding: 12px; }
  .study-head { align-items: flex-start; }
  .study-voice-row { grid-template-columns: 1fr; gap: 6px; }
  .study-line { padding-right: 50px; }
  .annotation-popover {
    left: 10px !important;
    right: 10px;
    width: auto;
    padding: 12px;
  }
  .annotation-types { gap: 4px; }
  .annotation-type { gap: 5px; padding-left: 4px; padding-right: 4px; }
  .annotation-actions { justify-content: stretch; }
  .annotation-actions button { flex: 1 1 auto; }
  .tab { font-size: 12px; padding: 8px 4px; }
}

/* ===== Scrollbar ===== */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--chip-border);
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.05ms !important;
  }
}
