/* 视觉按 docs/design/ui.md。不引用外部字体或图片。 */

:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --line: #e3e1dc;
  --text: #1c1c1e;
  --muted: #6b6a66;
  --accent: #2f54d4;
  --accent-soft: #e6ebfb;
  --heard: #b9c3e6;
  --star: #c4841d;
  --warn: #b4532a;
  --ok: #2f7d4f;
  --mask: #d9d7d1;
  --on-accent: #ffffff;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Segoe UI", sans-serif;
  --font-serif: "Iowan Old Style", "Charter", "Georgia", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #16171a;
    --surface: #1f2024;
    --line: #2e3035;
    --text: #ececec;
    --muted: #9a9a9f;
    --accent: #7d97ff;
    --accent-soft: #262d4a;
    --heard: #3c4466;
    --star: #e0a94a;
    --warn: #e08a62;
    --ok: #6cc391;
    --mask: #3a3c42;
    --on-accent: #16171a;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --line: #e3e1dc;
  --text: #1c1c1e;
  --muted: #6b6a66;
  --accent: #2f54d4;
  --accent-soft: #e6ebfb;
  --heard: #b9c3e6;
  --star: #c4841d;
  --warn: #b4532a;
  --ok: #2f7d4f;
  --mask: #d9d7d1;
  --on-accent: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16171a;
  --surface: #1f2024;
  --line: #2e3035;
  --text: #ececec;
  --muted: #9a9a9f;
  --accent: #7d97ff;
  --accent-soft: #262d4a;
  --heard: #3c4466;
  --star: #e0a94a;
  --warn: #e08a62;
  --ok: #6cc391;
  --mask: #3a3c42;
  --on-accent: #16171a;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
}

button, input, a { font: inherit; color: inherit; }

button { cursor: pointer; }

h1, h2, p { margin: 0; }

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

.nums { font-variant-numeric: tabular-nums; }

/* 滚动条细且与背景同色系，不出现系统默认的粗滚动条。 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#star-button[aria-pressed="true"] .icon-star { fill: currentColor; }

.banner {
  margin: 0;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  color: var(--text);
}

.banner[data-kind="storage"],
.banner[data-kind="audio"],
.banner[data-kind="route"],
noscript .banner { color: var(--warn); }

.banner[data-kind="load"] { color: var(--muted); }

.banner[data-kind="expired"] { color: var(--warn); }

#renew-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

#renew-banner span { flex: 1 1 16em; }

.banner-action {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}

#app { min-height: 100vh; }

.starred-bar,
.starred-list,
.words-list,
#invalid {
  width: min(1200px, calc(100% - 64px));
  margin-left: auto;
  margin-right: auto;
}

.practice-bar,
.starred-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 24px 16px 12px;
}

.starred-bar h1,
.practice-title,
#invalid h1,
.help-dialog h2 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

.filter-button,
.control,
#help-close,
#export-progress,
#import-progress,
.account-logout,
.starred-item button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.filter-button,
#help-close,
#export-progress,
#import-progress,
.account-logout,
.starred-item button {
  padding: 0 12px;
}

.filter-button { color: var(--muted); }

.filter-button[aria-pressed="true"],
.control[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link { color: var(--muted); }

/* 篇目库：顶栏、概览、筛选条、篇目矩阵。矩阵按列排布，宽屏放三列，TPO 编号在每列内从上往下递增。 */
.library-head,
.overview,
.toolbar,
.catalog,
.catalog-empty {
  width: min(1360px, calc(100% - 64px));
  margin-left: auto;
  margin-right: auto;
}

.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 32px 0 24px;
}

.library-brand h1 {
  font-size: 1.35rem;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.library-sub {
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--muted);
}

.library-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  text-decoration: none;
  transition: border-color 150ms ease;
}

.nav-link:hover { border-color: var(--muted); }

#starred-link .icon { color: var(--star); }

#words-link .icon { color: var(--accent); }

.nav-count {
  min-width: 1.2em;
  color: var(--muted);
  text-align: right;
}

.library-head [data-tip]::after {
  top: calc(100% + 8px);
  bottom: auto;
  left: auto;
  right: 0;
  transform: translateY(-4px);
}

.library-head [data-tip]:hover::after,
.library-head [data-tip]:focus-visible::after { transform: translateY(0); }

.overview {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.continue-card {
  flex: 1 1 340px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "kicker go"
    "title go"
    "meta go";
  align-items: center;
  column-gap: 16px;
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  transition: border-color 150ms ease;
}

.continue-card[hidden] { display: none; }

.continue-card:hover { border-color: var(--accent); }

.continue-kicker {
  grid-area: kicker;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

.continue-title {
  grid-area: title;
  overflow: hidden;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.continue-meta {
  grid-area: meta;
  font-size: 0.85rem;
  color: var(--muted);
}

.continue-go {
  grid-area: go;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
}

.continue-go .icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke-width: 1.5;
}

.stats {
  flex: 2 1 480px;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  margin: 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.stat dt {
  font-size: 0.78rem;
  color: var(--muted);
}

.stat dd {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
}

.stat-of {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--muted);
}

.stat-bar {
  display: block;
  height: 4px;
  margin-top: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.stat-bar-fill {
  display: block;
  height: 100%;
  width: calc(var(--ratio, 0) * 100%);
  min-width: 0;
  border-radius: 2px;
  background: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  flex: 1 1 280px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 40px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  cursor: text;
}

.search-field:focus-within {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.search {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}

.search:focus-visible { outline: none; }

.search::placeholder { color: var(--muted); }

.search-key {
  color: var(--muted);
  background: transparent;
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.segmented .filter-button {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  transition: background-color 150ms ease, color 150ms ease;
}

.segmented .filter-button:hover { color: var(--text); }

.segmented .filter-button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.catalog { padding-bottom: 64px; }

.tpo-group + .tpo-group { margin-top: 32px; }

.tpo-heading {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 1rem;
  font-weight: 650;
}

.tpo-tally {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

.tpo-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(208px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 128px;
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

a.card:hover {
  border-color: var(--muted);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.card[data-progress="done"] { border-color: var(--heard); }

.card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.card-section {
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.card-progress { margin-left: auto; }

.card[data-progress="done"] .card-progress { color: var(--accent); }

.card-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
}

.card-sub {
  overflow: hidden;
  font-family: var(--font-serif);
  font-size: 0.88rem;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .cell-bar {
  display: block;
  margin-top: auto;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.cell-bar-fill {
  display: block;
  height: 100%;
  width: calc(var(--ratio, 0) * 100%);
  border-radius: 2px;
  background: var(--accent);
}

.card[data-state="gap"] {
  border-style: dashed;
  background: transparent;
  color: var(--muted);
}

.card[data-state="gap"] .card-section {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.gap-reason {
  margin-top: auto;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--warn);
  overflow-wrap: anywhere;
}

/* 练习页：内容居中，画面以当前句为主。次要设置收在托盘里，快捷键只在悬停提示和帮助里出现。 */

/* 练习页占满横幅以下的视口高度，控制区贴近底部。 */
body[data-view="practice"] {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

body[data-view="practice"] #app {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#practice {
  --column: min(1040px, 100% - 48px);
  width: var(--column);
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  margin-top: 0;
  margin-bottom: 0;
  margin-left: calc((100% - var(--column)) / 2);
  margin-right: calc((100% - var(--column)) / 2);
  padding: 0 0 28px;
  transition: margin-left 240ms ease-out, margin-right 240ms ease-out;
}

#practice > .practice-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 16px 0 12px;
}

#practice .back-link {
  justify-self: start;
  gap: 2px;
  margin-left: -6px;
  padding-right: 8px;
  border-radius: 8px;
  transition: color 150ms ease;
}

#practice .back-link:hover { color: var(--text); }

.practice-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.practice-end {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 4px;
}

.practice-position {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.setting-summary { display: none; }

.timeline {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 6px;
  margin: 4px 0 0;
  overflow: visible;
}

.segment {
  position: relative;
  flex: var(--span, 1) 1 0;
  min-width: 0;
  height: 6px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--text);
}

.segment-bar {
  display: block;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background-color: var(--line);
  position: relative;
  transition: height 120ms ease;
}

.segment[data-state="heard"] .segment-bar { background-color: var(--heard); }

.segment[data-state="current"] .segment-bar { background-color: var(--accent); }

.segment[data-low="true"] .segment-bar {
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 3px,
    var(--warn) 3px 4px
  );
}

.segment[data-starred="true"] .segment-bar::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 1px);
  height: 3px;
  border-radius: 2px;
  background: var(--star);
}

.segment:hover,
.segment:focus-visible { z-index: 2; }

.segment:hover .segment-bar,
.segment:focus-visible .segment-bar { height: 10px; }

.segment::after {
  content: none;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}

.timeline .segment:first-child::after {
  left: 0;
  transform: none;
}

.timeline .segment:last-child::after {
  left: auto;
  right: 0;
  transform: none;
}

.segment:hover::after,
.segment:focus-visible::after { content: attr(aria-label); }

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--ratio, 0) * 100%);
  width: 2px;
  transform: translateX(-1px);
  background: var(--bg);
  pointer-events: none;
}

.sentence-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 40px 0 32px;
  text-align: center;
}

.sentence-text {
  max-width: 26em;
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 1.05rem + 1.7vw, 2.75rem);
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
  overflow-wrap: break-word;
  text-wrap: balance;
}

.sentence-text[data-visible="true"] {
  animation: text-in 180ms ease;
}

/* 翻译挂在句子下方的空白处，不占文档流，句子位置不变。 */
.sentence-anchor {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.sentence-float {
  position: absolute;
  top: 100%;
  left: 50%;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(34em, 100%);
  transform: translateX(-50%);
}

.sentence-meta {
  display: flex;
  justify-content: center;
  max-width: 34em;
  margin-top: 20px;
  min-height: 1.4em;
}

.sentence-index { display: none; }

.low-note {
  font-size: 0.85rem;
  color: var(--warn);
}

@keyframes text-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mask-word {
  position: relative;
  display: inline-block;
  width: calc(var(--letters, 1) * 0.55em);
  height: 0.9em;
  border-radius: 4px;
  background: var(--mask);
  vertical-align: baseline;
  overflow: hidden;
}

.mask-initial {
  position: absolute;
  left: 0.08em;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 0.62em;
  line-height: 1;
}

.mask-punct { white-space: pre; }

/* 提示与设置托盘从控制条上方的空白处浮出，控制区高度不变，句子位置不变。
   --tray-space 是托盘展开后的高度，由 app.js 的 placeControls 写入。 */
.control-dock {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px + var(--tray-space, 0px));
  z-index: 7;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 200ms ease, transform 200ms ease, bottom 240ms ease-out;
}

.toast[data-show="true"] {
  opacity: 1;
  transform: translate(-50%, 0);
}

.icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  transition: background-color 150ms ease, color 150ms ease;
}

.icon-button:hover {
  background: var(--surface);
  color: var(--text);
}

.icon-button[aria-pressed="true"],
.icon-button[aria-expanded="true"] { color: var(--accent); }

#star-button[aria-pressed="true"] { color: var(--star); }

.icon-button .icon,
.control-play .icon {
  width: 20px;
  height: 20px;
  flex-basis: 20px;
}

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.transport > * { flex: 0 0 auto; }

.transport .step {
  width: 52px;
  height: 52px;
  color: var(--text);
}

.transport [data-action="prev"] { margin-left: 14px; }

.transport [data-action="next"] { margin-right: 14px; }

.control-play {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: transform 120ms ease, filter 150ms ease;
}

.control-play:hover { filter: brightness(1.08); }

.control-play:active { transform: scale(0.96); }

.control-play .icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke-width: 1.5;
}

.control-play .icon-pause { display: none; fill: none; stroke-width: 2.25; }

#practice[data-playing="true"] .control-play .icon-play { display: none; }

#practice[data-playing="true"] .control-play .icon-pause { display: block; }

.play-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* 悬停或键盘聚焦 0.5 秒后显示按钮名和快捷键。 */
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 8;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 4px);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}

/* 两端按钮的提示向内对齐，不伸出视口。 */
.transport > :first-child::after { left: 0; transform: translate(0, 4px); }

.transport > :last-child::after { left: auto; right: 0; transform: translate(0, 4px); }

.transport > :first-child:hover::after,
.transport > :first-child:focus-visible::after,
.transport > :last-child:hover::after,
.transport > :last-child:focus-visible::after { transform: translate(0, 0); }

.practice-bar [data-tip]::after {
  top: calc(100% + 8px);
  bottom: auto;
  left: auto;
  right: 0;
  transform: translateY(-4px);
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
  transition-delay: 500ms;
}

.practice-bar [data-tip]:hover::after,
.practice-bar [data-tip]:focus-visible::after { transform: translateY(0); }

@media (hover: none) {
  [data-tip]::after { display: none; }
}

.settings-tray {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  z-index: 6;
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 240ms ease-out, opacity 200ms ease-out;
}

#practice[data-tray="true"] .settings-tray {
  grid-template-rows: 1fr;
  opacity: 1;
}

.tray-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  padding: 0 4px;
}

#practice[data-tray="true"] .tray-inner { padding: 0 4px 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.chip:hover { color: var(--text); }

.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.rate-group {
  display: inline-flex;
  align-items: center;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.rate-group .chip-icon {
  width: 32px;
  height: 30px;
  padding: 0;
  border: 0;
}

.rate-group .chip-icon .icon {
  width: 16px;
  height: 16px;
  flex-basis: 16px;
}

.rate-readout {
  min-width: 2.4rem;
  font-size: 0.85rem;
  text-align: center;
  color: var(--text);
}

.transcript {
  max-height: 0;
  margin-top: 0;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface);
  opacity: 0;
  transition: max-height 220ms ease-out, opacity 220ms ease-out, margin-top 220ms ease-out;
}

#practice[data-panel="true"] > .transcript {
  max-height: 40vh;
  margin-top: 16px;
  overflow: auto;
  border-color: var(--line);
  opacity: 1;
}

.transcript h2 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 12px 12px 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.transcript-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
}

.transcript-item {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: start;
  padding: 8px;
  border-radius: 4px;
}

.transcript-item[data-state="current"] { background: var(--accent-soft); }

.transcript-index {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.transcript-item[data-low="true"] .transcript-index { color: var(--warn); }

.transcript-text {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}

.transcript-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  font-size: 0.78rem;
}

.transcript-star { color: var(--star); }

.starred-bar { padding-bottom: 8px; }

.starred-list { padding: 0 16px 48px; }

.starred-group { margin-top: 24px; }

.starred-group h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.starred-group ul {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.starred-item {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.starred-item a {
  flex: 1;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.5;
}

.starred-item button { flex: 0 0 auto; }

/* 生词本 */
/* 拖过几个词选短语，所以单词不参与文字选择，触屏拖动也不滚动页面。 */
.sentence-text .word {
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sentence-text .word:hover { background: var(--accent-soft); }

.word[data-saved="true"] {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.sentence-text .word[data-open="true"],
.sentence-text .word-gap[data-open="true"] { background: var(--accent-soft); }

/* 选中几个词时，词和中间的空格连成一段，相接处不留圆角。 */
.sentence-text .word[data-open="true"]:has(+ .word-gap[data-open="true"]) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.sentence-text .word-gap[data-open="true"] + .word[data-open="true"] {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.translation {
  max-width: 34em;
  margin-top: 4px;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text);
}

.translation[data-kind="status"],
.translation[data-kind="pending"] { color: var(--muted); }

.translation[data-kind="error"] { color: var(--warn); }

.translation[data-concealed="true"] { visibility: hidden; }

/* 查词卡片不占文档流，句子位置不变。位置由 app.js 的 placeLookup 按句子的实际位置算出：
   句子右侧放得下就放右侧，否则放在句子下方或上方空白较多的一侧。
   标题行和「加入生词本」固定显示，释义超出时才在卡片内滚动。 */
#practice { position: relative; }

#practice > .lookup {
  position: absolute;
  z-index: 6;
}

.lookup {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px 14px 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.08);
  text-align: left;
}

.lookup[hidden] { display: none; }

.lookup:not([hidden]) { animation: pop-in 200ms cubic-bezier(0.2, 0.8, 0.2, 1); }

.lookup-body[data-overflow="true"] {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 40px), transparent);
}

.lookup-bar,
.lookup-foot { flex: 0 0 auto; }

.lookup-bar {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.lookup-headline { flex: 1 1 auto; }

.lookup-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
}

.lookup-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  margin: -4px -6px 0 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  transition: background-color 150ms ease, color 150ms ease;
}

.lookup-close:hover {
  background: var(--bg);
  color: var(--text);
}

.lookup-close .icon {
  width: 16px;
  height: 16px;
  flex-basis: 16px;
}

.lookup-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  display: grid;
  align-content: start;
  gap: 8px;
  margin: 6px 0 10px;
}

.lookup-body::-webkit-scrollbar { display: none; }

.lookup-entry + .lookup-entry {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.lookup-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
}

.lookup-word {
  font-family: var(--font-serif);
  font-size: 1.02rem;
  font-weight: 600;
}

.lookup-phonetic {
  font-size: 0.88rem;
  color: var(--muted);
}

.lookup-base,
.lookup-tag {
  font-size: 0.7rem;
  line-height: 1.6;
  color: var(--muted);
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg);
}

.lookup-base {
  color: var(--accent);
  background: var(--accent-soft);
}

.lookup-lines {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  font-size: 0.88rem;
  line-height: 1.55;
}

.lookup-note {
  font-size: 0.9rem;
  color: var(--muted);
}

.lookup-note[data-kind="error"] { color: var(--warn); }

.lookup-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.lookup-save {
  flex: 0 0 auto;
  white-space: nowrap;
  min-height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.lookup-save:hover { border-color: var(--muted); }

.lookup-save[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.lookup-count {
  font-size: 0.8rem;
  color: var(--muted);
}

.translation:not([hidden]) { animation: rise-in 220ms ease-out; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.word-meaning {
  margin-top: 4px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--muted);
}

.words-tip {
  flex-basis: 100%;
  font-size: 0.85rem;
  color: var(--muted);
}

.words-list { padding: 0 16px 48px; }

.word-item {
  margin-top: 24px;
  padding-bottom: 8px;
}

.word-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.word-title {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.3;
}

.word-count {
  flex: 1 1 auto;
  font-size: 0.85rem;
  color: var(--muted);
}

.word-kind {
  flex: 0 0 auto;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  line-height: 1.7;
}

.word-head button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.word-note {
  width: 100%;
  height: 36px;
  margin-top: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.word-refs {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.word-refs .starred-item {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.word-refs mark {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
}

.word-source {
  font-size: 0.8rem;
  color: var(--muted);
}

#invalid { padding: 48px 16px; }

#invalid p {
  margin-top: 12px;
  font-size: 0.9rem;
}

#invalid .back-link { margin-top: 16px; }

.help {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
}

.help-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.help:not([hidden]) .help-backdrop { animation: fade-in 180ms ease-out; }

.help:not([hidden]) .help-dialog { animation: pop-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1); }

.help-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(640px, 100%);
  max-height: min(80vh, 100%);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}

.help-table {
  width: 100%;
  margin-top: 16px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.help-table th,
.help-table td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: baseline;
}

.help-table th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.help-table th:first-child,
.help-table td:first-child { width: 38%; }

.help-account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-top: 16px;
  font-size: 0.9rem;
}

.account-logout {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.account-note {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 0.78rem;
}

.account-logout[aria-disabled="true"] { opacity: 0.6; pointer-events: none; }

.account-message {
  flex-basis: 100%;
  font-size: 0.85rem;
}

.account-message:empty { display: none; }
.account-message[data-kind="error"] { color: var(--warn); }
.account-message[data-kind="ok"] { color: var(--ok); }

.account-renew {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.account-renew label {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 0.78rem;
}

#renew-code {
  flex: 1 1 12em;
  min-width: 0;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#renew-submit {
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.9rem;
  font-weight: 600;
}

#renew-submit:disabled { opacity: 0.6; }

.help-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}

@media (min-width: 1201px) {
  #practice {
    transition:
      width 280ms cubic-bezier(0.2, 0.8, 0.2, 1),
      margin-left 280ms cubic-bezier(0.2, 0.8, 0.2, 1),
      margin-right 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  /* 面板占右侧 380px 加两侧间距，主列在剩余宽度里居中，宽度和位置一起过渡。 */
  #practice[data-panel="true"] {
    --avail: calc(100% - 412px);
    --column: min(1040px, var(--avail) - 48px);
    margin-left: calc((var(--avail) - var(--column)) / 2);
    margin-right: calc(100% - var(--column) - (var(--avail) - var(--column)) / 2);
  }

  #practice > .transcript {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 4;
    width: 380px;
    height: calc(100vh - 32px);
    max-height: calc(100vh - 32px);
    margin-top: 0;
    overflow: auto;
    border-color: var(--line);
    transform: translateX(calc(100% + 16px));
    opacity: 0;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 200ms ease-out;
  }

  #practice[data-panel="true"] > .transcript {
    max-height: calc(100vh - 32px);
    margin-top: 0;
    transform: translateX(0);
    opacity: 1;
  }
}

@media (max-width: 799px) {
  .search,
  .filter-button,
  .control,
  #help-close,
  #export-progress,
  #import-progress,
  .starred-item button {
    min-height: 44px;
  }

  .timeline,
  .segment {
    height: 32px;
  }

  .segment {
    display: flex;
    align-items: center;
  }

  .segment-bar { height: 6px; }

  .sentence-block { padding: 24px 0; }
}

@media (max-width: 599px) {
  .library-head,
  .overview,
  .toolbar,
  .catalog,
  .catalog-empty { width: calc(100% - 24px); }

  .starred-bar,
  .starred-list,
  .words-list,
  #invalid { width: 100%; }

  .library-head { padding: 20px 0 16px; }

  .library-sub { display: none; }

  .nav-link { padding: 0 10px; }

  .library-head .icon-button { display: none; }

  .stats {
    gap: 12px;
    padding: 14px 16px;
  }

  .stat dd { font-size: 1.2rem; }

  .segmented { flex: 1 1 auto; }

  .segmented .filter-button { flex: 1 1 0; padding: 0 6px; }

  .search-key { display: none; }

  #practice { --column: calc(100% - 32px); }

  .back-link span,
  .practice-end .icon-button { display: none; }

  .transport { gap: 1px; }

  .transport [data-action="prev"],
  .transport [data-action="next"] { margin: 0; }

  .transport .step {
    width: 48px;
    height: 48px;
  }

  .control-play {
    width: 56px;
    height: 56px;
  }

  .starred-bar,
  .starred-list,
  .words-list { padding-left: 12px; padding-right: 12px; }

  .tpo-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .card {
    min-height: 112px;
    padding: 12px;
  }
}

@media (pointer: coarse) {
  .filter-button,
  .control,
  #help-close,
  #export-progress,
  #import-progress,
  .starred-item button,
  .word-head button,
  .back-link,
  .nav-link {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
