/* ==========================================================================
   NounKiller · app.css
   纸张质感 + 墨绿印章的学习界面；移动端底部固定评级栏。
   ========================================================================== */

:root {
  --bg: #f3f0e8;
  --bg-deep: #ebe6da;
  --surface: #fbfaf5;
  --surface-2: #f7f4ec;
  --ink: #20241f;
  --ink-soft: #4b5049;
  --muted: #8b8d80;
  --line: #e5e0d3;
  --line-strong: #d5cdba;
  --accent: #2f6753;
  --accent-deep: #244f3f;
  --accent-tint: #e4eee7;
  --amber: #9a6b1e;
  --star: #e8b53a;
  --amber-deep: #7d5513;
  --amber-tint: #f7eed9;
  --amber-line: #e9d7b1;
  --brick: #9d4436;
  --brick-deep: #803527;
  --brick-tint: #f8e7e1;
  --brick-line: #ecd0c7;
  --block: #e5dfd0;
  --block-deep: #d8d0bd;
  --radius: 20px;
  --shadow-card: 0 1px 2px rgba(32, 36, 31, 0.04), 0 24px 48px -38px rgba(32, 36, 31, 0.5);
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --def-size: 18px;
  --line-height-def: 1.95;
}

* { box-sizing: border-box; }

/* hidden 属性必须始终压过组件的 display */
[hidden] { display: none !important; }

/* 禁止双击/双指缩放页面；滚动与点击不受影响 */
html, body { touch-action: pan-x pan-y; }

html, body { height: 100%; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 8% -8%, rgba(255, 255, 255, 0.75), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(228, 238, 231, 0.55), transparent 55%),
    linear-gradient(180deg, #f5f2ea 0%, #f0ece2 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

body.font-s { --def-size: 16.5px; }
body.font-l { --def-size: 20px; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }

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

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 10px;
  line-height: 1.4;
  text-align: center;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 36px);
  background: rgba(243, 240, 232, 0.82);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  backdrop-filter: blur(14px) saturate(1.1);
  border-bottom: 1px solid rgba(213, 205, 186, 0.6);
}

.brand {
  display: inline-flex;
  align-items: center;
  flex: 0 1 auto;
  gap: 10px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
}

.seal {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), transparent 55%),
    var(--accent-deep);
  color: #f7f3e7;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 4px 10px -6px rgba(36, 79, 63, 0.8);
}

.brand-name {
  overflow: hidden;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appbar-right {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.deck-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: min(46vw, 340px);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251, 250, 245, 0.72);
  color: var(--ink-soft);
  font-size: 13px;
  transition: border-color 0.18s, background 0.18s;
}

.deck-chip:hover { border-color: var(--line-strong); background: var(--surface); }

.deck-chip svg { width: 14px; height: 14px; flex: none; opacity: 0.6; }

.deck-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-soft);
  transition: background 0.18s, border-color 0.18s;
}

.icon-btn:hover { background: rgba(251, 250, 245, 0.9); border-color: var(--line); }
.icon-btn svg { width: 19px; height: 19px; }

/* ---------- 主区 ---------- */

.main {
  flex: 1;
  width: min(860px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3.4vw, 34px) clamp(16px, 4vw, 32px) 96px;
}

.screen { animation: screen-fade 0.24s ease both; }

/* 只做淡入：若给 .screen 加 transform，会让内部 position:fixed 的底部评级栏
   以 .screen 为包含块，移动端会错位。 */
@keyframes screen-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.study-top {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin: 2px 2px 16px;
}

.study-meta {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.study-nav {
  display: flex;
  flex: none;
  gap: 6px;
  padding-top: 1px;
}

.nav-btn {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: color 0.16s, border-color 0.16s, background 0.16s;
}

.nav-btn:hover:not(:disabled) {
  color: var(--accent-deep);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.nav-btn:disabled { opacity: 0.4; cursor: default; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.crumbs b { color: var(--ink-soft); font-weight: 600; }

.progress {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-deep);
}

.progress i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #4f8a70);
  transition: width 0.4s cubic-bezier(0.22, 0.7, 0.3, 1);
}

/* ---------- 卡片 ---------- */

.card {
  position: relative;
  padding: clamp(22px, 4.2vw, 44px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent 120px),
    var(--surface);
  box-shadow: var(--shadow-card);
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: clamp(22px, 4.2vw, 44px);
  width: 42px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--accent);
  opacity: 0.85;
}

.card-eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.1em;
}

.eyebrow-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--line-strong);
}

.term {
  margin: 0 0 clamp(18px, 3vw, 26px);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(26px, 3.6vw, 38px);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.015em;
  overflow-wrap: anywhere;
}

.term:empty::after { content: "（未命名词条）"; color: var(--muted); }

.term-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 clamp(18px, 3vw, 26px);
}

.term-row .term { flex: 1; min-width: 0; margin: 0; }

.fav-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-top: 4px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: none;
  color: var(--muted);
  transition: color 0.16s, background 0.16s, transform 0.12s;
}

.fav-btn svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.fav-btn:hover { background: var(--surface-2); color: var(--amber); }
.fav-btn:active { transform: scale(0.9); }
.fav-btn.on { color: var(--star); }
.fav-btn.on svg { fill: var(--star); stroke: var(--star); }

.answer { min-height: 150px; }

/* 待回忆占位 */

.prompt-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 190px;
  padding: 28px 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background:
    repeating-linear-gradient(180deg, transparent 0 30px, rgba(213, 205, 186, 0.28) 30px 31px);
  color: var(--muted);
  text-align: center;
}

.prompt-block .prompt-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
}

.prompt-block .prompt-icon svg { width: 19px; height: 19px; }

.prompt-block p { margin: 0; font-size: 13px; line-height: 1.8; }
.prompt-block .prompt-title { color: var(--ink-soft); font-size: 14.5px; font-weight: 600; }
.prompt-block .prompt-sub { max-width: 30em; }

/* 全文 */

.full-text {
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--def-size);
  line-height: var(--line-height-def);
  letter-spacing: 0.012em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}

.full-text .c { border-radius: 2px; }
.full-text .c.hl-yellow { --hl: #f3e2a0; --hl-ink: #c79a22; }
.full-text .c.hl-green { --hl: #cfe4c6; --hl-ink: #5b9364; }
.full-text .c.hl-pink { --hl: #f4cdd0; --hl-ink: #c26b78; }

.full-text .c.hl-style-marker { background: var(--hl); }

.full-text .c.hl-style-line {
  text-decoration: underline;
  text-decoration-color: var(--hl-ink);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.full-text .c.hl-style-wavy {
  text-decoration: underline wavy var(--hl-ink);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 5px;
}

/* 旧数据兼容 */
.full-text .c.hl-underline {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.full-text .c.sel {
  background: #cfded6 !important;
  box-shadow: inset 0 -2px 0 rgba(47, 103, 83, 0.55);
}

.answer.marking .full-text { cursor: crosshair; touch-action: none; }
.answer.marking .full-text .c { cursor: text; }

.text-caret-bar {
  display: inline-block;
  width: 2px;
  height: 1.15em;
  margin: 0 -1px;
  vertical-align: -0.18em;
  background: var(--accent);
  animation: caret-blink 1s steps(2) infinite;
}

@keyframes caret-blink { 50% { opacity: 0; } }

.answer-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12.5px;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
}

.tool-chip:hover { border-color: var(--line-strong); }
.tool-chip.active { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-deep); }
.tool-chip svg { width: 14px; height: 14px; }

.tool-left { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tool-hint { color: var(--muted); font-size: 12px; }

/* 逐字回忆 */

.recall-wrap { animation: screen-in 0.25s ease both; }

.recall-text {
  padding: 22px 22px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(140% 100% at 50% 0%, rgba(255, 255, 255, 0.7), transparent 70%),
    var(--surface-2);
  font-size: var(--def-size);
  line-height: var(--line-height-def);
  letter-spacing: 0.012em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: none;
  -webkit-user-select: none;
}

.recall-text .punct { color: #81847a; }

.recall-text .ph {
  color: transparent;
  background-image: linear-gradient(90deg, transparent 5%, var(--block) 5%, var(--block) 95%, transparent 95%);
  border-radius: 4px;
  box-shadow: inset 0 -1px 0 rgba(32, 36, 31, 0.05);
  cursor: pointer;
  transition: background-color 0.16s, filter 0.16s;
}

.recall-text .ph:hover { filter: brightness(0.965); }

.recall-text .ph:active {
  filter: brightness(0.92);
}

.recall-text .ph.on {
  color: var(--ink);
  background-image: none;
}

.recall-text .ph.flash {
  animation: ph-flash 0.9s ease-out;
}

@keyframes ph-flash {
  0% { color: var(--ink); background-color: #f2df9f; box-shadow: 0 0 0 3px rgba(242, 223, 159, 0.28); }
  100% { color: var(--ink); background-color: transparent; box-shadow: none; }
}

.recall-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.recall-hint b { color: var(--ink-soft); font-weight: 600; }
.recall-hint .hint-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(154, 107, 30, 0.12);
}

.link-btn {
  padding: 2px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(47, 103, 83, 0.35);
}

.link-btn:hover { text-decoration-color: var(--accent); }

/* ---------- 评级栏 ---------- */

.rating {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.rate-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-height: 92px;
  padding: 15px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  transition: transform 0.14s cubic-bezier(0.2, 0.8, 0.3, 1), box-shadow 0.18s, filter 0.18s, border-color 0.18s;
  will-change: transform;
}

.rate-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 22px -20px rgba(32, 36, 31, 0.6); }
.rate-btn:active { transform: translateY(0) scale(0.976); }

.rate-main { font-size: 17px; font-weight: 650; letter-spacing: 0.02em; }
.rate-sub { font-size: 11.5px; opacity: 0.72; }

.rate-key {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border: 1px solid currentColor;
  border-radius: 6px;
  font-size: 10px;
  opacity: 0.35;
}

.rate-btn.unknown { border-color: var(--brick-line); background: var(--brick-tint); color: var(--brick-deep); }
.rate-btn.fuzzy { border-color: var(--amber-line); background: var(--amber-tint); color: var(--amber-deep); }
.rate-btn.known {
  border-color: var(--accent-deep);
  background: var(--accent);
  color: #f8f5ea;
  box-shadow: 0 10px 24px -18px rgba(36, 79, 63, 0.9);
}
.rate-btn.known .rate-sub { color: rgba(248, 245, 234, 0.72); }

/* 下一条 */

.next-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  animation: screen-in 0.24s ease both;
}

.rating-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12.5px;
}

.rating-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.rating-badge.known .dot { background: var(--accent); }
.rating-badge.fuzzy .dot { background: var(--amber); }
.rating-badge.unknown .dot { background: var(--brick); }

.next-btn {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: #f9f6ec;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  box-shadow: 0 14px 26px -20px rgba(36, 79, 63, 0.9);
  transition: transform 0.14s, filter 0.18s, background 0.18s;
}

.next-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.next-btn:active { transform: scale(0.985); }
.next-btn svg { width: 17px; height: 17px; }

.next-hint { flex: none; color: var(--muted); font-size: 11.5px; }

.session-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 16px 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.kbd-hint { display: inline-flex; align-items: center; gap: 3px; }

/* ---------- 完成 / 空状态 ---------- */

.done-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(30px, 5vw, 54px) clamp(22px, 4vw, 46px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  text-align: center;
  animation: screen-in 0.3s ease both;
}

.done-seal {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  margin-bottom: 20px;
  border-radius: 20px;
  background: var(--accent-deep);
  color: #f7f3e7;
  font-family: var(--font-serif);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 16px 30px -22px rgba(36, 79, 63, 0.9);
}

.done-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: clamp(24px, 3.2vw, 30px);
  letter-spacing: 0.04em;
}

.done-sub { margin: 0 0 26px; color: var(--muted); font-size: 13.5px; line-height: 1.8; }

.done-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(460px, 100%);
  gap: 10px;
  margin-bottom: 26px;
}

.done-stat {
  padding: 16px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.done-stat b { display: block; font-family: var(--font-serif); font-size: 26px; line-height: 1.15; }
.done-stat span { display: block; margin-top: 4px; color: var(--muted); font-size: 11.5px; letter-spacing: 0.06em; }
.done-stat.known b { color: var(--accent); }
.done-stat.fuzzy b { color: var(--amber); }
.done-stat.unknown b { color: var(--brick); }

.done-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 12.5px;
}

.done-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.primary-btn, .ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  border-radius: 14px;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: transform 0.14s, filter 0.18s, border-color 0.18s, background 0.18s;
}

.primary-btn { border: 0; background: var(--accent); color: #f9f6ec; }
.primary-btn.danger { background: var(--brick); }
.confirm-text { margin: 0; color: var(--ink-soft); font-size: 13.5px; line-height: 1.85; }
.primary-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.primary-btn:active { transform: scale(0.985); }

.ghost-btn { border: 1px solid var(--line-strong); background: transparent; color: var(--ink-soft); }
.ghost-btn:hover { background: var(--surface-2); border-color: var(--muted); }

.empty-panel {
  padding: clamp(28px, 5vw, 48px);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(251, 250, 245, 0.55);
  text-align: center;
}

.empty-panel h2 { margin: 0 0 8px; font-family: var(--font-serif); font-size: 24px; }
.empty-panel p { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; line-height: 1.85; }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ---------- 弹层 ---------- */

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 29, 24, 0.42);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease both;
}

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

.modal-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(620px, 100%);
  max-height: min(86vh, 780px);
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 40px 90px -30px rgba(20, 24, 19, 0.55);
  animation: panel-in 0.24s cubic-bezier(0.22, 0.8, 0.3, 1) both;
  overflow: hidden;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 14px;
}

.modal-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.modal-head h2 { margin: 0; font-family: var(--font-serif); font-size: 23px; letter-spacing: 0.04em; }

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 4px 24px 18px;
  -webkit-overflow-scrolling: touch;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.modal-foot .foot-left { margin-right: auto; color: var(--muted); font-size: 12px; }

.modal-foot .primary-btn, .modal-foot .ghost-btn { min-height: 44px; padding: 0 18px; font-size: 13.5px; }

/* 题库列表 */

.deck-list { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 16px; }

.deck-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  transition: border-color 0.18s, background 0.18s;
}

.deck-row.active { border-color: var(--accent); background: var(--accent-tint); }

.deck-row.is-virtual { border-style: dashed; background: var(--surface); }
.deck-name-line { display: flex; align-items: center; gap: 7px; min-width: 0; }
.deck-name-line .deck-name { min-width: 0; }
.deck-pin {
  flex: none;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.deck-radio {
  display: grid;
  place-items: center;
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  background: transparent;
}

.deck-row.active .deck-radio { border-color: var(--accent); }
.deck-row.active .deck-radio::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.deck-info { flex: 1; min-width: 0; }
.deck-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}
.deck-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 11.5px; }

.deck-actions { display: flex; gap: 2px; flex: none; }

.mini-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.mini-btn:hover { background: rgba(32, 36, 31, 0.06); color: var(--ink); }
.mini-btn svg { width: 15px; height: 15px; }

.deck-rename-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
}

.deck-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* 导入 */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { color: var(--ink-soft); font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; }

.text-input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  font-size: 14px;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 103, 83, 0.12); }

.deck-editor-text {
  min-height: 260px;
  resize: vertical;
  line-height: 1.75;
  font-family: ui-monospace, "SF Mono", Menlo, "PingFang SC", monospace;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 26px 18px;
  margin-bottom: 12px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}

.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: var(--accent-tint); }
.drop-zone svg { width: 24px; height: 24px; color: var(--accent); }
.drop-zone b { color: var(--ink-soft); }
.drop-zone span { line-height: 1.7; }

.import-textarea {
  width: 100%;
  min-height: 190px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.8;
  resize: vertical;
}

.import-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 103, 83, 0.12); }

.import-help {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.8;
}

.import-preview {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.8;
}

.import-preview.ok { border-color: #c6dcc9; background: #eef5ec; color: var(--accent-deep); }
.import-preview.err { border-color: var(--brick-line); background: var(--brick-tint); color: var(--brick-deep); }
.import-preview .preview-items { margin: 6px 0 0; padding: 0; list-style: none; }
.import-preview .preview-items li {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
}
.import-preview .preview-items li + li { margin-top: 3px; }

/* 设置 */

.setting-group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.setting-group:last-child { border-bottom: 0; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}
.setting-row:last-child { margin-bottom: 0; }

.setting-label { font-size: 13.5px; font-weight: 600; }
.setting-desc { margin-top: 4px; color: var(--muted); font-size: 11.5px; line-height: 1.7; }

.stepper { display: inline-flex; align-items: center; gap: 0; border: 1px solid var(--line-strong); border-radius: 11px; overflow: hidden; background: var(--surface); }
.stepper button { width: 38px; height: 38px; border: 0; background: transparent; color: var(--ink-soft); font-size: 18px; line-height: 1; }
.stepper button:hover { background: var(--surface-2); }
.stepper input {
  width: 58px;
  height: 38px;
  border: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: transparent;
  text-align: center;
  font-size: 14px;
  -moz-appearance: textfield;
  appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); gap: 2px; }
.segmented button {
  min-width: 58px;
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(32, 36, 31, 0.12); }

.danger-btn {
  padding: 8px 14px;
  border: 1px solid var(--brick-line);
  border-radius: 10px;
  background: var(--brick-tint);
  color: var(--brick-deep);
  font-size: 12.5px;
  white-space: nowrap;
}
.danger-btn:hover { filter: brightness(0.97); }

.about-note { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.8; }
.about-note + .about-note { margin-top: 5px; }

.swatches { display: flex; flex: none; align-items: center; gap: 8px; }

.swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(32, 36, 31, 0.14);
  border-radius: 50%;
  transition: transform 0.12s, box-shadow 0.14s;
}

.swatch.yellow { background: #f3e2a0; }
.swatch.green { background: #cfe4c6; }
.swatch.pink { background: #f4cdd0; }
.swatch:active { transform: scale(0.92); }
.swatch.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--accent); }

.about-author {
  margin: 10px 0 3px;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.02em;
}

/* toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 90;
  transform: translate(-50%, 10px);
  max-width: min(88vw, 460px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(28, 32, 26, 0.94);
  color: #f4f1e7;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 16px 34px -18px rgba(16, 19, 15, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 移动端 ---------- */

/* 目录 */
.toc-list { display: flex; flex-direction: column; margin: -4px 0; }

.toc-group {
  padding: 14px 10px 6px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.toc-group:first-child { padding-top: 2px; }

.toc-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--line);
}

.toc-main {
  display: flex;
  flex: 1;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
  padding: 12px 4px 12px 10px;
  border: 0;
  background: none;
  color: var(--ink);
  font-size: 15.5px;
  text-align: left;
  transition: color 0.14s;
}

.toc-item .fav-btn { width: 36px; height: 36px; margin: 0; }
.toc-item .fav-btn svg { width: 20px; height: 20px; }

.toc-item:last-child { border-bottom: 0; }
.toc-main:hover { color: var(--accent-deep); }

.toc-num {
  flex: none;
  width: 22px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.toc-term { flex: 1; line-height: 1.5; }

.toc-item.is-current .toc-main { color: var(--accent-deep); font-weight: 600; }
.toc-item.is-current .toc-num { color: var(--accent); }

@media (max-width: 720px) {
  .appbar {
    gap: 8px;
    padding: 9px max(12px, env(safe-area-inset-right)) 9px max(12px, env(safe-area-inset-left));
  }
  .brand { gap: 7px; }
  .brand-name { max-width: 38vw; font-size: 17px; letter-spacing: 0.04em; }
  .seal { width: 31px; height: 31px; font-size: 19px; }
  .appbar-right { gap: 6px; }
  .deck-chip { max-width: 36vw; padding: 6px 9px; font-size: 12px; }
  .icon-btn { width: 34px; height: 34px; }

  .main { padding: 14px 14px 190px; }

  .study-top { margin-bottom: 12px; gap: 10px; }
  .nav-btn { min-height: 26px; padding: 0 8px; font-size: 11.5px; }
  .crumbs { font-size: 12px; }

  .card { padding: 20px 17px 20px; border-radius: 18px; }
  .card::before { left: 17px; }
  .card-eyebrow { margin-bottom: 14px; }

  .term { margin-bottom: 16px; font-size: clamp(25px, 7.2vw, 33px); }

  .prompt-block { min-height: 160px; padding: 22px 16px; }
  .full-text, .recall-text { padding: 17px 15px; border-radius: 13px; }

  .rating {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    gap: 7px;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(243, 240, 232, 0), rgba(243, 240, 232, 0.94) 26%, var(--bg) 60%);
  }

  .rate-btn { min-height: 74px; padding: 11px 10px 10px; border-radius: 14px; }
  .rate-main { font-size: 15.5px; }
  .rate-sub { font-size: 10px; }
  .rate-key { top: 8px; right: 8px; width: 16px; height: 16px; font-size: 9px; }

  @media (max-width: 370px) {
    .brand-name { font-size: 15.5px; max-width: 32vw; }
    .seal { width: 29px; height: 29px; font-size: 18px; }
    .deck-chip { max-width: 32vw; font-size: 11.5px; }
  }

  .next-row {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    gap: 8px;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(243, 240, 232, 0), rgba(243, 240, 232, 0.94) 30%, var(--bg) 65%);
  }

  .setting-row { flex-wrap: wrap; row-gap: 10px; }
  .setting-row .segmented { margin-left: auto; }

  .tool-hint { display: none; }
  .answer-tools { gap: 8px; }
  .tool-chip { padding: 7px 10px; font-size: 12px; }

  .rating-badge { padding: 9px 11px; font-size: 11.5px; }
  .next-btn { min-height: 50px; font-size: 15px; }
  .next-hint { display: none; }

  .session-foot { display: none; }

  .modal { padding: 0; align-items: end; }
  .modal-panel {
    width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    animation: sheet-in 0.26s cubic-bezier(0.22, 0.8, 0.3, 1) both;
  }

  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }

  .modal-head { padding: 20px 18px 12px; }
  .modal-body { padding: 4px 18px 14px; }
  .modal-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }

  .done-card { padding: 30px 18px; border-radius: 18px; }
  .done-stats { gap: 7px; }
  .done-stat b { font-size: 22px; }

  .toast { bottom: calc(104px + env(safe-area-inset-bottom)); }
}

@media (max-width: 400px) {
  .rate-sub { display: none; }
  .rate-btn { min-height: 66px; align-items: center; justify-content: center; text-align: center; }
  .rate-key { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .screen { animation: none; }
}
