/* ---- :root ---- */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-read: Georgia, "Iowan Old Style", "Times New Roman", "Songti SC", serif;
  --font-sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;

  --bg: #fbf8f2;
  --bg-elev: #ffffff;
  --bg-soft: #f3ede2;
  --text: #2b2620;
  --muted: #8b8175;
  --line: #e7dfd2;
  --accent: #a8542f;
  --accent-soft: rgba(168, 84, 47, 0.12);
  --mark: rgba(214, 164, 78, 0.18);
  --shadow: 0 10px 30px rgba(60, 45, 25, 0.12);

  --read-size: 19px;
  --read-lh: 1.78;
  --read-font: var(--font-read);
}

[data-theme="sepia"] {
  --bg: #f3e9d2;
  --bg-elev: #fbf3e2;
  --bg-soft: #ece0c6;
  --text: #3a3025;
  --muted: #8a7a62;
  --line: #ded0b3;
  --accent: #96602f;
  --accent-soft: rgba(150, 96, 47, 0.14);
  --mark: rgba(190, 140, 60, 0.22);
}

[data-theme="dark"] {
  --bg: #14161a;
  --bg-elev: #1c1f24;
  --bg-soft: #23272e;
  --text: #d9d5cc;
  --muted: #8a8f98;
  --line: #2a2e35;
  --accent: #d9906a;
  --accent-soft: rgba(217, 144, 106, 0.16);
  --mark: rgba(214, 164, 78, 0.16);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

/* ---- [hidden] ---- */
[hidden] { display: none !important; }

/* 截图/自动化时用 ?anim=off 关掉过渡，避免抓到动画中间帧 */
html.no-anim *, html.no-anim *::before, html.no-anim *::after {
  transition: none !important;
  animation: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

button { font-family: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---- .topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 8px max(14px, calc((100vw - 760px) / 2 + 18px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar .titles { flex: 1; min-width: 0; }
.topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .actions { display: flex; gap: 4px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 17px;
  line-height: 1;
  color: var(--text);
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn.active { color: var(--accent); background: var(--accent-soft); }

.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: transparent;
}
.progress > div {
  height: 100%;
  width: 0;
  background: var(--accent);
  opacity: 0.65;
  transition: width 0.2s;
}

/* ---- main ---- */
main { max-width: 760px; margin: 0 auto; }
.view { padding: 20px 18px 96px; }
.view[hidden] { display: none; }

/* ---- .shelf-head ---- */
.shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 6px 0 18px;
}
.shelf-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.shelf-head .hint { font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
  font-size: 13.5px;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--bg-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: none;
  background: none;
  padding: 0;
  text-align: left;
}
.cover {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(155deg, var(--bg-soft), var(--line));
  box-shadow: 0 6px 16px rgba(50, 38, 22, 0.14);
  display: flex;
  align-items: flex-end;
  padding: 14px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card:hover .cover { transform: translateY(-3px); box-shadow: 0 12px 24px rgba(50, 38, 22, 0.2); }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover .cover-initial {
  position: absolute;
  top: 6px;
  left: 12px;
  font-family: var(--font-read);
  font-size: 58px;
  line-height: 1;
  opacity: 0.1;
  pointer-events: none;
}
.cover .cover-title {
  position: relative;
  font-family: var(--font-read);
  font-size: 15px;
  line-height: 1.3;
  color: var(--text);
  opacity: 0.85;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .name {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .meta { font-size: 11.5px; color: var(--muted); }
.card .bar { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.card .bar > i { display: block; height: 100%; background: var(--accent); opacity: 0.7; }
.card .del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .del { opacity: 1; }

.empty {
  padding: 64px 20px;
  text-align: center;
  color: var(--muted);
}
.empty h3 { margin: 0 0 8px; color: var(--text); font-size: 17px; }
.empty p { margin: 0 0 20px; font-size: 13.5px; line-height: 1.7; }

/* ---- .chapter ---- */
.chapter {
  font-family: var(--read-font);
  font-size: var(--read-size);
  line-height: var(--read-lh);
  max-width: 38rem;
  margin: 0 auto;
}
.chapter h1, .chapter h2, .chapter h3 {
  font-family: var(--font-ui);
  line-height: 1.35;
  margin: 1.6em 0 0.9em;
  letter-spacing: -0.01em;
}
.chapter h1 { font-size: 1.35em; }
.chapter h2 { font-size: 1.15em; }
.chapter p { margin: 0 0 0.95em; }
.chapter img { max-width: 100%; height: auto; border-radius: 6px; }
.chapter blockquote {
  margin: 1em 0;
  padding-left: 14px;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-style: italic;
}

.w {
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.w:hover { background: var(--accent-soft); }
.w.sent { background: var(--mark); }
.w.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- 原版 PDF 渲染 ---------- */
.pdf-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 0 24px;
}
.pdf-stage {
  position: relative;
  display: inline-block;
  background: #fff;
  box-shadow: 0 6px 28px rgba(40, 30, 18, 0.18);
  border-radius: 2px;
  line-height: 0;
}
.pdf-stage .pdf-canvas { display: block; max-width: 100%; }
.pdf-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.pdf-overlay .pdf-hit {
  position: absolute;
  background: rgba(168, 84, 47, 0.28);
  border: 1px solid rgba(168, 84, 47, 0.55);
  border-radius: 2px;
}
.pdf-stage .pdf-canvas { cursor: pointer; }

.pdf-nav {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  max-width: 100%;
  margin: 0 auto;
}
.pdf-pageinfo {
  font: 13px/1 ui-monospace, Consolas, monospace;
  color: var(--muted);
  min-width: 84px;
  text-align: center;
}

[data-theme="dark"] .pdf-stage { box-shadow: 0 6px 28px rgba(0, 0, 0, 0.6); }

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  max-width: 38rem;
  margin: 36px auto 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

/* ---- .sheet ---- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  max-width: 640px;
  margin: 0 auto;
  max-height: 74dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow), 0 0 0 1px var(--line);
  transform: translateY(102%);
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: translateY(0); }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head .word {
  font-family: var(--font-read);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sheet-head .phon {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
}
.sheet-head .spacer { flex: 1; }

.sheet-body {
  overflow-y: auto;
  padding: 12px 16px 20px;
  -webkit-overflow-scrolling: touch;
}

.block { margin-bottom: 16px; }
.block-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.block-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.dict-def {
  font-size: 14.5px;
  line-height: 1.75;
  white-space: pre-wrap;
}

/* 考试标签 / 柯林斯星级 / 词频 的小徽章 */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}
.badge {
  font-size: 11px;
  line-height: 1.6;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.hot {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 600;
}
.sentence {
  font-family: var(--font-read);
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 10px;
}
.sentence b { color: var(--text); font-weight: 600; }

/* 原句下方的中文译文 */
.trans {
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--accent-soft);
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  opacity: 0.92;
}
.trans::before {
  content: "译";
  display: inline-block;
  margin-right: 6px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  line-height: 1.6;
  vertical-align: 1px;
}

.ai {
  font-size: 14.5px;
  line-height: 1.8;
  white-space: pre-wrap;
  min-height: 1.8em;
}
.ai .sec { color: var(--accent); font-weight: 600; }
.ai .caret::after {
/* ---- @keyframes blink ---- */
  animation: blink 1s steps(2) infinite;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

.hint-line {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}

.sheet-foot {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
}
.sheet-foot .btn { flex: 1; }

/* ---- .vocab-item ---- */
.vocab-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.vocab-item .row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.vocab-item .w-word {
  font-family: var(--font-read);
  font-size: 17px;
  font-weight: 600;
}
.vocab-item .w-phon { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.vocab-item .w-tr { font-size: 13.5px; color: var(--muted); }
.vocab-item .w-sent {
  margin-top: 6px;
  font-family: var(--font-read);
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
}
.vocab-item .w-sent b { color: var(--text); }
.vocab-item .w-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
}
.vocab-item .w-meta button {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 11px;
  padding: 0;
}

/* ---- .modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 16, 10, 0.42);
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 18px 22px;
}
.modal-card h2 { margin: 0 0 4px; font-size: 17px; }
.modal-card .sub { margin: 0 0 16px; font-size: 12.5px; color: var(--muted); }

.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}
.field input[type="text"],
.field input[type="password"],
.field select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field input[type="range"] { accent-color: var(--accent); }
.field input[type="checkbox"] { accent-color: var(--accent); }
.field .note { margin-top: 5px; font-size: 11.5px; color: var(--muted); line-height: 1.55; }

.seg {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.seg button {
  flex: 1;
  min-width: 72px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  font-size: 12.5px;
}
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* ---- .toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 80;
  transform: translate(-50%, 12px);
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #2b2620;
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar-track { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar-track > i { display: block; height: 100%; width: 0; background: var(--accent); }

@media (max-width: 560px) {
  .view { padding: 14px 14px 96px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 12px; }
  .sheet { max-height: 80dvh; }
  .chapter { font-size: calc(var(--read-size) - 1px); }
}

/* 触屏没有 hover，删除按钮必须常显 */
@media (hover: none) {
  .card .del { opacity: 0.85; }
}

/* ---------- 平板（华为 MatePad / iPad 横竖屏） ---------- */
@media (min-width: 820px) {
  main { max-width: 980px; }
  .chapter { max-width: 46rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; }
  .sheet { max-width: 760px; }
  .topbar { padding-inline: max(18px, calc((100vw - 980px) / 2 + 18px)); }
  .view { padding: 26px 24px 110px; }
}

/* 宽屏不用底部弹层，改成右侧栏：正文让出栏宽，不会被盖住也不会被挤出去 */
@media (min-width: 900px) {
  /* 用网格把侧栏"占"出来，比 transform 位移稳：任何宽度都不会把正文挤出屏幕 */
  body.panel-open {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 430px;
  }
  body.panel-open .topbar { grid-column: 1 / -1; }
  body.panel-open main {
    grid-column: 1;
    max-width: 980px;
    margin: 0 auto;
  }

  .sheet {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: 430px;
    max-width: 430px;
    max-height: none;
    margin: 0;
    border-radius: 0;
    border-left: 1px solid var(--line);
    box-shadow: -12px 0 36px rgba(40, 30, 18, 0.10);
    transform: translateX(103%);
  }
  .sheet.open { transform: translateX(0); }
  .sheet-body { flex: 1; }
  .sheet-head { padding-top: 18px; }
}

/* 手指比鼠标粗：点按目标一律 ≥44px */
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; font-size: 19px; }
  .btn { height: 44px; padding: 0 18px; }
  .btn-sm { height: 38px; padding: 0 14px; }
  .w { padding: 2px 0; }
  .sheet-foot .btn { height: 46px; }
}
