/* 文境 · 样式 */
:root {
  --bg: #f7f3ea;
  --panel: #fffdf7;
  --panel-2: #f1ece1;
  --ink: #241f19;
  --ink-2: #57503f;
  --muted: #948b7b;
  --line: #e4ddce;
  --accent: #a8452a;
  --accent-soft: #f4e4dc;
  --ok: #2f7a58;
  --warn: #b07a1e;
  --shadow: 0 1px 2px rgba(60, 45, 25, .05), 0 10px 30px rgba(60, 45, 25, .07);
  --reader: 21px;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #131418;
  --panel: #1a1c21;
  --panel-2: #22252c;
  --ink: #e9e4da;
  --ink-2: #b8b0a2;
  --muted: #807a6e;
  --line: #2b2e36;
  --accent: #e29a5a;
  --accent-soft: #2b241d;
  --ok: #6dbb92;
  --warn: #d8a54a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input, select, textarea { font-family: inherit; font-size: 15px; color: var(--ink); }
h1, h2, h3 { margin: 0; font-weight: 600; }
::selection { background: var(--accent-soft); color: var(--ink); }

/* ── 布局 ── */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: 0 0 auto;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 18px; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; letter-spacing: .04em; }
.brand-text small { color: var(--muted); font-size: 11px; letter-spacing: .04em; }

.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tabs button {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 8px 14px; border-radius: 8px; font-size: 13.5px;
  position: relative; transition: .15s;
}
.tabs button:hover { background: var(--panel-2); color: var(--ink); }
.tabs button.active { background: var(--ink); color: var(--panel); }
.badge {
  display: inline-block; min-width: 17px; padding: 0 4px;
  margin-left: 5px; border-radius: 9px;
  background: var(--accent); color: #fff;
  font-size: 10.5px; line-height: 17px; text-align: center; vertical-align: 1px;
}
.tabs button.active .badge { background: var(--panel); color: var(--ink); }
.top-right { margin-left: auto; display: flex; gap: 6px; }
.icon {
  border: 1px solid var(--line); background: var(--panel);
  width: 32px; height: 32px; border-radius: 8px;
  color: var(--ink-2); display: grid; place-items: center; font-size: 15px;
}
.icon:hover { background: var(--panel-2); }

.main { flex: 1 1 auto; min-height: 0; position: relative; }
.view { height: 100%; min-width: 0; }
.view[hidden] { display: none !important; }
#view-read { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: 0; }

/* ── 书架 ── */
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; font-size: 12px; letter-spacing: .12em; color: var(--muted);
}
.mini {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 7px; padding: 4px 9px; font-size: 12px; color: var(--ink-2);
}
.mini:hover { border-color: var(--accent); color: var(--accent); }
.chapters { overflow-y: auto; padding: 0 10px 14px; flex: 1 1 auto; min-width: 0; }
.ch-group { margin: 6px 0 12px; }
.ch-group > h4 {
  margin: 0 0 6px; padding: 0 6px;
  font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .1em;
}
.ch-item {
  display: block; width: 100%; text-align: left;
  border: 0; background: transparent;
  padding: 8px 10px; border-radius: 8px; color: var(--ink-2);
  font-size: 13px; line-height: 1.4; transition: .12s;
}
.ch-item:hover { background: var(--panel-2); }
.ch-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ch-item .ch-sub { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; font-weight: 400; }
.ch-item.active .ch-sub { color: var(--accent); opacity: .7; }
.side-foot {
  flex: 0 0 auto; border-top: 1px solid var(--line);
  padding: 12px 16px; font-size: 11.5px; color: var(--muted); line-height: 1.7;
}

/* ── 阅读区 ── */
.reader { overflow-y: auto; padding: 34px 32px 80px; scroll-behavior: smooth; min-width: 0; }
.reader-inner { max-width: 760px; margin: 0 auto; }
.reader-head { margin-bottom: 26px; }
.reader-head h1 {
  font-family: var(--serif); font-size: 29px; letter-spacing: .02em; line-height: 1.35;
}
.reader-meta {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 10px; font-size: 12px; color: var(--muted);
}
.pill {
  border: 1px solid var(--line); border-radius: 20px;
  padding: 2px 9px; font-size: 11.5px; color: var(--ink-2); background: var(--panel);
}
.pill.hot { border-color: var(--accent); color: var(--accent); }

.story { font-family: var(--serif); font-size: var(--reader); line-height: 2.05; color: var(--ink); }
.story p { margin: 0 0 1.15em; text-indent: 2em; }
.story .w {
  color: var(--accent); font-style: italic; font-weight: 600;
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  padding: 0 1px; cursor: pointer; position: relative;
  transition: background .12s;
}
.story .w:hover { background: var(--accent-soft); border-radius: 3px; }
.story .w.seen { opacity: .92; }
.story .w::after {
  content: attr(data-zh);
  position: absolute; left: 50%; bottom: 135%;
  transform: translateX(-50%) translateY(3px);
  background: var(--ink); color: var(--panel);
  font-family: var(--sans); font-style: normal; font-weight: 400;
  font-size: 12px; line-height: 1.5; padding: 3px 8px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: .14s; z-index: 6; box-shadow: var(--shadow);
}
.story .w:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.story .w.revealed::after { opacity: 1; }

.chapter-end { margin-top: 34px; border-top: 1px dashed var(--line); padding-top: 22px; }
.end-title { font-size: 12px; letter-spacing: .12em; color: var(--muted); margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 20px; padding: 5px 11px; font-size: 12.5px; color: var(--ink-2);
  transition: .12s;
}
.chip b { font-family: var(--serif); font-style: italic; color: var(--accent); font-weight: 600; }
.chip:hover { border-color: var(--accent); }
.chip .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: .5; }
.chip.done .dot { background: var(--ok); opacity: 1; }
.end-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: 9px; padding: 9px 16px; font-size: 13px;
  transition: .14s;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.btn.primary:hover { opacity: .9; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }

.empty { padding: 70px 20px; text-align: center; color: var(--muted); line-height: 2; }
.empty .big { font-family: var(--serif); font-size: 22px; color: var(--ink-2); margin-bottom: 8px; }

/* ── 复习 ── */
#view-review { overflow-y: auto; padding: 30px 22px 70px; }
.review-wrap { max-width: 660px; margin: 0 auto; }
.rv-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.rv-top h2 { font-family: var(--serif); font-size: 21px; }
.rv-stats { font-size: 12px; color: var(--muted); }
.progress { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .25s; }
.rv-counter { font-size: 11.5px; color: var(--muted); margin-bottom: 18px; letter-spacing: .04em; }

.qcard {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 30px 30px 24px; box-shadow: var(--shadow);
}
.q-zh {
  font-family: var(--serif); font-size: 36px; line-height: 1.3;
  letter-spacing: .06em; margin-bottom: 6px;
}
.q-pos { font-size: 12px; color: var(--muted); letter-spacing: .06em; }
.q-ctx {
  margin: 20px 0 4px; padding: 14px 16px;
  background: var(--panel-2); border-radius: 10px;
  font-family: var(--serif); font-size: 15.5px; line-height: 1.9; color: var(--ink-2);
}
.q-ctx em { font-style: normal; color: var(--accent); letter-spacing: 2px; }
.q-tip { font-size: 12px; color: var(--muted); margin-top: 10px; }
.q-input { display: flex; gap: 9px; margin-top: 18px; }
.q-input input {
  flex: 1; min-width: 0; padding: 13px 15px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); font-size: 16px; font-family: var(--serif); letter-spacing: .04em;
}
.q-input input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.answer {
  margin-top: 18px; padding: 16px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
}
.answer.good { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); background: color-mix(in srgb, var(--ok) 7%, var(--bg)); }
.answer.bad { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, var(--bg)); }
.answer-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.answer-en { font-family: var(--serif); font-style: italic; font-size: 24px; color: var(--accent); font-weight: 600; }
.answer-zh { color: var(--ink-2); font-size: 13px; }
.answer-flag { font-size: 12px; padding: 1px 8px; border-radius: 20px; }
.answer-flag.good { background: var(--ok); color: #fff; }
.answer-flag.bad { background: var(--accent); color: #fff; }
.answer-ex { margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.7; }
.rates { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.rates button {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 10px; padding: 11px 4px; font-size: 12.5px; color: var(--ink-2);
  display: flex; flex-direction: column; gap: 3px; align-items: center; transition: .12s;
}
.rates button:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.rates button small { color: var(--muted); font-size: 10.5px; }
.rates button.hint-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.kbd { font-family: var(--mono); font-size: 10px; color: var(--muted); }

.done-box { text-align: center; padding: 46px 20px; }
.done-box .big { font-family: var(--serif); font-size: 26px; margin-bottom: 10px; }
.done-box .sub { color: var(--muted); line-height: 2; margin-bottom: 22px; }
.done-stats { display: flex; justify-content: center; gap: 34px; margin: 24px 0 28px; }
.done-stats div { display: flex; flex-direction: column; gap: 4px; }
.done-stats b { font-family: var(--serif); font-size: 26px; color: var(--accent); }
.done-stats span { font-size: 11.5px; color: var(--muted); }

/* ── 生词本 ── */
#view-words { overflow-y: auto; padding: 28px 26px 70px; }
.words-wrap { max-width: 980px; margin: 0 auto; }
.words-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.words-head h2 { font-family: var(--serif); font-size: 22px; }
.words-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.words-tools input[type="search"] {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); width: 200px;
}
.filters { display: flex; gap: 4px; }
.filters button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 5px 10px; border-radius: 7px; font-size: 12.5px;
}
.filters button.on { background: var(--panel-2); color: var(--ink); border-color: var(--line); }

.wtable { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.wrow {
  display: grid; grid-template-columns: 1fr 52px 1.45fr 104px 100px 60px;
  gap: 12px; align-items: center;
  padding: 11px 16px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.wrow:last-child { border-bottom: 0; }
.wrow.head {
  background: var(--panel-2); color: var(--muted);
  font-size: 11.5px; letter-spacing: .06em; padding: 9px 16px;
}
.wrow .we { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--accent); font-weight: 600; }
.wrow .wz { color: var(--ink-2); font-size: 12.5px; }
.wrow .wf { color: var(--accent); font-size: 10px; letter-spacing: .06em; opacity: .85; }
.wrow .wd { color: var(--muted); font-size: 12px; }
.dots { display: flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); display: block; }
.dots i.on { background: var(--accent); }
.dots i.hi { background: var(--ok); }
.wrow .ops { display: flex; gap: 4px; justify-content: flex-end; }
.op { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 3px 5px; border-radius: 5px; }
.op:hover { background: var(--panel-2); color: var(--accent); }
.wrow:hover { background: color-mix(in srgb, var(--panel-2) 45%, transparent); }

/* ── 真题词组 ── */
#view-phrases { overflow-y: auto; padding: 28px 26px 70px; }
.wrow.p { grid-template-columns: 1.15fr 40px 1.6fr 48px 78px; }
.wrow .wrank { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.wrow .wsrc { color: var(--muted); font-size: 11px; letter-spacing: .04em; }
.wrow .wf.ph { color: var(--muted); font-size: 10.5px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; opacity: 1; }
.mini-tag { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.mini-tag.on { color: var(--accent); }
.op.add { color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent); border-radius: 6px; padding: 2px 7px; font-size: 11.5px; white-space: nowrap; }
.op.add:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.more-wrap { display: flex; justify-content: center; padding: 18px 0 4px; }

/* ── 设置 ── */
#view-settings { overflow-y: auto; padding: 28px 26px 80px; }
.settings-wrap { max-width: 720px; margin: 0 auto; }
.settings-wrap h2 { font-family: var(--serif); font-size: 22px; margin-bottom: 6px; }
.settings-wrap > p.sub { color: var(--muted); font-size: 12.5px; line-height: 1.9; margin: 0 0 22px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px 22px; margin-bottom: 16px;
}
.card h3 { font-size: 14px; margin-bottom: 4px; }
.card > p { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 0 0 16px; }
.field { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: center; margin-bottom: 12px; }
.field > label { font-size: 13px; color: var(--ink-2); }
.field input[type="text"], .field input[type="password"], .field select, .field input[type="number"] {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg);
}
.field input:focus, .field select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field .note { grid-column: 2; font-size: 11.5px; color: var(--muted); margin-top: -6px; }
.actions { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 6px; }
textarea.ta {
  width: 100%; min-height: 120px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); font-family: var(--mono); font-size: 12px; line-height: 1.7; resize: vertical;
}
.hr { height: 1px; background: var(--line); margin: 16px 0; }
.status { font-size: 12px; margin-top: 10px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.bad { color: var(--accent); }

/* ── 抽屉 ── */
.mask {
  position: fixed; inset: 0; background: rgba(20, 15, 8, .32);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 40;
  backdrop-filter: blur(1px);
}
.mask.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(102%); transition: transform .26s cubic-bezier(.3, .7, .3, 1);
  z-index: 50; overflow-y: auto; padding: 22px 24px 40px;
  box-shadow: -20px 0 50px rgba(40, 30, 10, .12);
}
.drawer.on { transform: translateX(0); }
.dw-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.dw-en { font-family: var(--serif); font-style: italic; font-size: 30px; font-weight: 600; color: var(--accent); line-height: 1.2; word-break: break-word; }
.dw-en.small { font-size: 22px; }
.dw-sub { color: var(--muted); font-size: 12px; letter-spacing: .05em; margin-top: 4px; }
.dw-zh { font-family: var(--serif); font-size: 19px; margin: 14px 0 18px; line-height: 1.7; }
.dw-freq { font-size: 11.5px; color: var(--accent); letter-spacing: .05em; margin: -10px 0 16px; }
.dw-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.dw-block { border-top: 1px solid var(--line); padding-top: 13px; margin-top: 13px; font-size: 13px; line-height: 1.85; color: var(--ink-2); }
.dw-block b { display: block; font-size: 11px; letter-spacing: .12em; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.dw-srs { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; font-size: 12px; color: var(--muted); }
.dw-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

/* ── 提示 ── */
.toasts { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--panel); font-size: 13px;
  padding: 9px 16px; border-radius: 22px; box-shadow: var(--shadow);
  animation: pop .2s ease-out; max-width: 86vw;
}
.toast.bad { background: var(--accent); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }

.loading { display: inline-flex; gap: 4px; align-items: center; }
.loading i {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  animation: blink 1.1s infinite;
}
.loading i:nth-child(2) { animation-delay: .15s; }
.loading i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ── 响应式 ── */

/* 平板 / 窄窗口：书架改成顶部横条 */
@media (max-width: 980px) {
  /* 窄屏不再让 .app 定高裁切，改成整页自然滚动：
     否则内容超出 100dvh 后被 .app 的 overflow:hidden 剪掉，手指怎么划都划不动 */
  html, body { height: auto; min-height: 100%; }
  body { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
  .app { height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .main { flex: 1 1 auto; min-height: 0; }
  .view { height: auto; min-height: 0; }
  #view-read .reader,
  #view-review,
  #view-words,
  #view-phrases,
  #view-settings { overflow: visible; }

  #view-read { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 132px; }
  .chapters { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 0 10px 10px; }
  .ch-group { margin: 0; flex: 0 0 auto; }
  .ch-group > h4 { display: none; }
  .ch-item { white-space: nowrap; border: 1px solid var(--line); }
  .side-foot { display: none; }
  .side-head { padding: 8px 12px; }
  .reader { padding: 24px 20px 80px; }
  .reader-head h1 { font-size: 24px; }
  .story { font-size: 19.5px; line-height: 1.98; }
  .qcard { padding: 22px 18px 18px; }
  .rates button { padding: 12px 4px; font-size: 13px; min-height: 62px; }
  .field { grid-template-columns: 1fr; gap: 6px; }
  .field .note { grid-column: 1; }
  .dw-block, .field > label { font-size: 14.5px; }
}

/* 手机：底部标签栏 + 单列卡片式列表 */
@media (max-width: 720px) {
  .app { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }

  /* 顶栏：只留品牌和主题按钮，标签栏沉到底部 */
  .topbar {
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    gap: 8px; background: var(--bg);
    border-bottom: 1px solid var(--line);
  }
  .brand { gap: 8px; }
  .logo { width: 28px; height: 28px; border-radius: 8px; font-size: 15px; }
  .brand-text strong { font-size: 16px; }
  .brand-text small { display: none; }

  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    margin: 0; gap: 0; padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    background: var(--panel); border-top: 1px solid var(--line);
    box-shadow: 0 -6px 18px rgba(40, 30, 10, .06);
  }
  .tabs button {
    flex: 1 1 0; min-width: 0; padding: 8px 2px 9px;
    font-size: 12.5px; line-height: 1.2; border-radius: 10px;
    display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 4px;
    position: relative;
  }
  .tabs button.active { background: transparent; color: var(--accent); font-weight: 600; }
  .tabs button.active::after {
    content: ""; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 18px; height: 2px; border-radius: 2px; background: var(--accent);
  }
  .badge { position: static; margin: 0; }

  .main { padding-bottom: 0; }

  /* 内容区给底部标签栏留出空间，滚动到底不会被挡住 */
  #view-review .review-wrap,
  #view-words .words-wrap,
  #view-phrases .words-wrap,
  #view-settings .settings-wrap { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }

  /* 书架横条：更快滑、点得动 */
  .sidebar { max-height: 104px; }
  .side-head { padding: 6px 12px 6px; font-size: 11px; }
  .mini { padding: 6px 10px; min-height: 32px; }
  .chapters { padding: 0 12px 8px; gap: 8px; scrollbar-width: none; }
  .chapters::-webkit-scrollbar { display: none; }
  .ch-item { padding: 8px 12px; font-size: 13.5px; border-radius: 9px; max-width: 78vw; overflow: hidden; text-overflow: ellipsis; }
  .ch-item .ch-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* 正文 */
  .reader { padding: 18px 16px 96px; }
  .reader-head { margin-bottom: 20px; }
  .reader-head h1 { font-size: 22px; }
  .reader-meta { font-size: 11.5px; gap: 8px; }
  .story { font-size: 18.5px; line-height: 1.95; }
  .story p { margin: 0 0 1.05em; }
  .story .w { padding: 2px 6px; font-size: .96em; }

  /* 复习卡 */
  .review-wrap { padding: 0 12px 40px; }
  .qcard { padding: 20px 16px 16px; border-radius: 14px; }
  .q-zh { font-size: 27px; }
  #ansInput { font-size: 17px; min-height: 50px; }
  .q-input { flex-wrap: wrap; gap: 8px; }
  .q-input .btn { flex: 1 1 100%; min-height: 44px; }
  .rates { grid-template-columns: 1fr 1fr; gap: 8px; }
  .rates button { min-height: 64px; font-size: 13.5px; padding: 12px 4px; }
  .kbd { display: none; }

  /* 生词本 / 词组：表格改卡片 */
  .view { height: auto; min-height: 100%; }
  #view-words, #view-phrases { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .words-wrap { padding: 16px 12px 28px; }
  .words-head h2 { font-size: 21px; }
  .words-tools { margin-top: 10px; }
  .words-tools input[type="search"], .words-tools input {
    font-size: 16px; min-height: 42px; width: 100%;
  }
  .filters { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .filters button { white-space: nowrap; min-height: 32px; }

  #wordTable, #phraseList { border: 0; background: transparent; box-shadow: none; }
  .wrow.head { display: none !important; }
  .wrow {
    display: grid; grid-template-columns: 1fr auto;
    grid-template-areas: "we ops" "wz wf";
    gap: 3px 10px; align-items: center;
    padding: 12px 4px; border-bottom: 1px solid var(--line);
  }
  .wrow .we { grid-area: we; font-size: 17px; }
  .wrow .wz { grid-area: wz; display: block; font-size: 13.5px; line-height: 1.5; }
  .wrow .wf { grid-area: wf; justify-self: end; align-self: start; }
  .wrow .wd, .wrow > span:not(.we):not(.wz):not(.wf):not(.ops) { display: none; }
  .wrow .ops { grid-area: ops; display: flex; gap: 2px; }
  .wrow .op { font-size: 15px; padding: 6px 7px; }

  .wrow.p {
    grid-template-columns: 1fr auto;
    grid-template-areas: "we ops" "wz ops";
  }
  .wrow.p .wrank, .wrow.p .wsrc { display: none; }
  .wrow.p .wz { grid-area: wz; }

  /* 设置项 */
  .settings-wrap { padding: 16px 12px 28px; }
  .settings-wrap h2 { font-size: 21px; }
  .card { padding: 16px 14px; border-radius: 12px; }
  .field { gap: 5px; margin-bottom: 14px; }
  .field input, .field select, .field textarea { font-size: 16px; min-height: 44px; }
  .field textarea { min-height: 90px; }

  /* 抽屉：手机上做成底部弹层 */
  .drawer {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-width: none;
    max-height: 88vh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0; padding: 18px 18px calc(26px + env(safe-area-inset-bottom));
    transform: translateY(103%); box-shadow: 0 -18px 50px rgba(40, 30, 10, .18);
  }
  .drawer.on { transform: translateY(0); }
  .drawer::before {
    content: ""; position: sticky; top: 0; margin: -6px auto 10px;
    width: 40px; height: 4px; border-radius: 3px; background: var(--line);
    display: block;
  }
  .dw-en { font-size: 26px; }
  .dw-zh { font-size: 18.5px; }
  .dw-actions .btn { flex: 1 1 100%; min-height: 46px; }

  .toasts { bottom: calc(72px + env(safe-area-inset-bottom)); }
  .toast { font-size: 13.5px; }
}

/* 超窄屏（iPhone SE 之类）再收一点 */
@media (max-width: 380px) {
  .story { font-size: 17.5px; }
  .tabs button { font-size: 11.5px; }
  .q-zh { font-size: 24px; }
}

