/* MyReader 阅读器 · 应用样式
   移动优先：手机上就是「简易安卓 APP」的观感 */
:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f2f1ee;
  --ink: #1f2328;
  --ink-soft: #525b67;
  --muted: #8b93a1;
  --line: #e6e4df;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #10b981;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --serif: "Noto Serif SC", "Songti SC", Georgia, serif;
  --sans: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
html[data-theme="dark"] {
  --bg: #101217;
  --surface: #171a21;
  --surface-2: #1e222b;
  --ink: #e8eaed;
  --ink-soft: #b3bac6;
  --muted: #7c859a;
  --line: #2a2f3a;
  --accent: #8b85f7;
  --accent-soft: #232139;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--sans);
  font-size: 16px; line-height: 1.6; -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; font-size: inherit; color: inherit; }
.app { max-width: 900px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + var(--safe-t)) 16px 10px;
}
.topbar-row { display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; }
.brand-logo {
  width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-size: 15px;
}
.spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
  font-size: 16px; transition: transform .12s;
}
.icon-btn:active { transform: scale(.94); }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 11px;
  padding: 9px 14px; cursor: pointer; font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

/* ---------- 搜索 ---------- */
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; margin-top: 10px;
}
.search input {
  flex: 1; border: 0; background: transparent; outline: none; color: var(--ink); font-size: 15px;
}

/* ---------- 分类 chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 7px 14px; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  color: var(--ink-soft);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip .n { opacity: .6; margin-left: 4px; font-size: 12px; }

/* ---------- 书架 ---------- */
.main { flex: 1; padding: 8px 16px calc(96px + var(--safe-b)); }
.section-title {
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  font-weight: 700; margin: 18px 0 10px;
}
/* 手机上一律两列并排（用固定 2 列而不是 auto-fill，
   否则 360px 宽的小屏算出来只有 1 列，卡片会大得离谱） */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; transition: transform .14s;
}
.card:active { transform: scale(.98); }
/* 封面用书本比例（竖版），比 16:9 更像一本书，也更省高度 */
.card-cover {
  aspect-ratio: 3 / 4; display: grid; place-items: center; font-size: 30px; position: relative;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; }
.card-prog {
  position: absolute; left: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .9);
}
.card-body { padding: 10px 11px 12px; }
.card-title {
  font-weight: 650; font-size: 13.5px; line-height: 1.42; margin: 0 0 5px; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.card-cat {
  display: inline-block; font-size: 10.5px; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.empty {
  text-align: center; color: var(--muted); padding: 56px 20px; font-size: 14.5px; line-height: 2;
}
.empty .big { font-size: 40px; display: block; margin-bottom: 12px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar-in { max-width: 900px; margin: 0 auto; display: flex; width: 100%; }
.tab {
  flex: 1; padding: 9px 0 7px; text-align: center; font-size: 11px; color: var(--muted);
  cursor: pointer; border: 0; background: transparent;
}
.tab .ic { display: block; font-size: 20px; line-height: 1.3; }
.tab.on { color: var(--accent); font-weight: 700; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(74px + var(--safe-b)); width: 54px; height: 54px;
  border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 26px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent); cursor: pointer;
  display: grid; place-items: center; z-index: 29;
}
.fab:active { transform: scale(.93); }

/* ---------- 弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(15, 18, 24, .42); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-mask.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 86vh; overflow: auto;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 18px calc(22px + var(--safe-b));
  transform: translateY(102%); transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  max-width: 900px; margin: 0 auto;
}
.sheet.on { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 6px auto 14px;
}
.sheet h3 { margin: 4px 0 14px; font-size: 17px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 11px; padding: 11px 13px; font-size: 15px; outline: none; font-family: inherit;
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.opt-list { display: flex; flex-direction: column; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 15px;
}
.opt .oi { font-size: 18px; }
.opt .os { margin-left: auto; color: var(--muted); font-size: 12.5px; }

/* ---------- 阅读页 ---------- */
.reader { max-width: 760px; margin: 0 auto; }
.reader-top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--line);
  padding: calc(9px + var(--safe-t)) 14px 9px;
}
.reader-top .rt-title {
  flex: 1; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--ink-soft);
}
.reader-prog { position: fixed; top: 0; left: 0; height: 2px; background: var(--accent); z-index: 40; width: 0; }
.ar-wrap { padding: 6px 20px calc(120px + var(--safe-b)); }
.ar-hero { padding: 26px 0 20px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.ar-cover {
  width: 100%; aspect-ratio: 16 / 8; border-radius: var(--radius-lg); display: grid;
  place-items: center; font-size: 60px; margin-bottom: 20px; overflow: hidden;
}
.ar-cover img { width: 100%; height: 100%; object-fit: cover; }
.ar-kicker {
  display: inline-block; font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); padding: 4px 10px; border-radius: 999px;
  font-weight: 700; margin-bottom: 12px;
}
.ar-title { font-family: var(--serif); font-size: 29px; line-height: 1.35; margin: 0 0 10px; font-weight: 700; }
.ar-sub { color: var(--muted); font-size: 15px; margin: 0 0 14px; }
.ar-meta { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 12.5px; align-items: center; }
.ar-tag { background: var(--surface); border: 1px solid var(--line); padding: 2px 9px; border-radius: 999px; font-size: 11.5px; }
.ar-toc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 18px; margin-bottom: 28px; }
.ar-toc-title { font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.ar-toc ol { margin: 0; padding-left: 18px; }
.ar-toc li { margin: 4px 0; font-size: 14.5px; }
.ar-toc a { color: var(--ink-soft); }
.ar-body { font-size: var(--fs, 17px); line-height: var(--lh, 1.85); }
.ar-h { font-family: var(--serif); scroll-margin-top: 66px; letter-spacing: -.01em; }
.ar-h2 { font-size: 1.42em; margin: 1.7em 0 .55em; padding-bottom: .25em; border-bottom: 1px solid var(--line); }
.ar-h3 { font-size: 1.18em; margin: 1.4em 0 .45em; }
.ar-h4 { font-size: 1.04em; margin: 1.2em 0 .35em; color: var(--ink-soft); }
.ar-p { margin: 0 0 .95em; position: relative; }
.ar-list { margin: 0 0 1em; padding-left: 1.4em; }
.ar-list li { margin: .3em 0; }
.ar-quote {
  margin: 1.2em 0; padding: .2em 0 .2em 1em; border-left: 3px solid var(--accent);
  color: var(--ink-soft); font-family: var(--serif);
}
.ar-quote cite { display: block; margin-top: .4em; font-size: .84em; color: var(--muted); font-family: var(--sans); font-style: normal; }
.ar-figure { margin: 1.3em 0; }
.ar-figure img { width: 100%; border-radius: 12px; display: block; background: var(--line); }
.ar-figure figcaption { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.ar-code {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 15px; overflow: auto; font-size: .84em; line-height: 1.7;
  font-family: ui-monospace, Consolas, monospace;
}
.ar-table-wrap { overflow: auto; margin: 1.2em 0; }
.ar-table { border-collapse: collapse; width: 100%; font-size: .9em; }
.ar-table th, .ar-table td { border: 1px solid var(--line); padding: 8px 11px; text-align: left; }
.ar-table th { background: var(--accent-soft); font-weight: 650; }
.ar-callout { border-radius: 12px; padding: 13px 16px; margin: 1.2em 0; background: var(--accent-soft); border-left: 4px solid var(--accent); }
.ar-callout-title { font-weight: 700; margin-bottom: 5px; }
.ar-warn { background: color-mix(in srgb, var(--warn) 14%, transparent); border-color: var(--warn); }
.ar-success { background: color-mix(in srgb, var(--ok) 14%, transparent); border-color: var(--ok); }
.ar-danger { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: var(--danger); }
.ar-divider { border: 0; border-top: 1px solid var(--line); margin: 1.8em 0; }
.ar-chat { display: flex; gap: 10px; margin: 0 0 1em; align-items: flex-start; }
.ar-chat-avatar {
  flex: 0 0 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--line); color: var(--ink-soft);
}
.ar-chat-user .ar-chat-avatar { background: var(--accent); color: #fff; }
.ar-chat-body { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 15px; }
.ar-chat-body > *:first-child { margin-top: 0; }
.ar-chat-body > *:last-child { margin-bottom: 0; }
.ar-foot { margin-top: 3em; padding-top: 1.4em; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }

/* ---------- 批注 ---------- */
.hl { border-radius: 3px; padding: 1px 0; cursor: pointer; }
.hl-y { background: #fff2a8; box-shadow: inset 0 -.55em 0 #fff2a8; }
.hl-g { background: #c8f3d4; box-shadow: inset 0 -.55em 0 #c8f3d4; }
.hl-b { background: #cfe4ff; box-shadow: inset 0 -.55em 0 #cfe4ff; }
.hl-p { background: #ffd3e4; box-shadow: inset 0 -.55em 0 #ffd3e4; }
html[data-theme="dark"] .hl-y { background: #5c5316; box-shadow: inset 0 -.55em 0 #5c5316; }
html[data-theme="dark"] .hl-g { background: #1f4a33; box-shadow: inset 0 -.55em 0 #1f4a33; }
html[data-theme="dark"] .hl-b { background: #1e3a5c; box-shadow: inset 0 -.55em 0 #1e3a5c; }
html[data-theme="dark"] .hl-p { background: #56243a; box-shadow: inset 0 -.55em 0 #56243a; }
.hl-u { border-bottom: 2px solid var(--accent); }
.hl-note { border-bottom: 2px dashed var(--warn); }

.blk { position: relative; }
.blk-mark {
  position: absolute; left: -30px; top: 2px; display: flex; flex-direction: column; gap: 3px;
  opacity: 0; transition: opacity .15s;
}
.blk:hover .blk-mark, .blk-mark.on { opacity: 1; }
.blk-mark button {
  width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); font-size: 11px; cursor: pointer; padding: 0; line-height: 1;
}
.blk-mark button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.blk-badges { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.blk-badge {
  font-size: 11px; padding: 0 5px; border-radius: 5px; background: var(--accent-soft);
  color: var(--accent); line-height: 1.5;
}
@media (max-width: 720px) {
  .blk-mark { left: auto; right: -6px; top: -2px; flex-direction: row; }
}

/* 选中工具条
   桌面端：浮动在选区上方（空间不足则落到下方）
   移动端：固定在屏幕底部，避开安卓/iOS 系统自带的「翻译·复制·分享」菜单，
           否则两者会叠在一起，用户点不到我们的按钮 */
.sel-bar {
  position: absolute; z-index: 60; display: none;
  align-items: center; justify-content: center;   /* 关键：让色点垂直居中 */
  gap: 2px; padding: 5px;
  background: var(--ink); border-radius: 13px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .28);
}
.sel-bar.on { display: flex; }
.sel-bar button {
  border: 0; background: transparent; color: #fff;
  width: 34px; height: 30px; padding: 0;          /* 统一尺寸，避免各按钮高矮不一 */
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px; cursor: pointer; font-size: 14px; line-height: 1;
}
.sel-bar button:active { background: rgba(255, 255, 255, .18); }
.sw {
  display: flex; align-items: center; justify-content: center;  /* 色点组自身居中 */
  gap: 5px; padding: 0 7px; height: 30px;                       /* 与按钮等高 */
}
.sw i {
  width: 18px; height: 18px; border-radius: 50%; display: block; cursor: pointer;
  border: 1.5px solid rgba(255, 255, 255, .4); box-sizing: border-box; flex: 0 0 auto;
}
.sw i.on { box-shadow: 0 0 0 2px rgba(255, 255, 255, .55); }

/* 触屏 / 窄屏覆盖：必须放在基础 .sel-bar 规则**之后**，
   否则同优先级下前面的 position:absolute 会盖掉这里的 fixed，修复失效。
   用 (hover:none)+(pointer:coarse) 而不只是宽度，是为了覆盖横屏手机
   —— 横屏时宽度可能超过 720px，但系统选择菜单一样会挡路 */
@media (hover: none) and (pointer: coarse), (max-width: 720px) {
  .sel-bar {
    position: fixed;
    top: auto !important;
    left: 50% !important;
    right: auto;
    bottom: calc(20px + var(--safe-b));
    transform: translateX(-50%);
    padding: 6px 8px;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .42);
    max-width: calc(100vw - 24px);
  }
  .sel-bar button { width: 40px; height: 34px; font-size: 15px; }
  .sw { height: 34px; gap: 6px; padding: 0 8px; }
  .sw i { width: 20px; height: 20px; }
}

/* ---------- 批注 / 词汇本 ---------- */
.list { display: flex; flex-direction: column; gap: 12px; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.item-src { font-size: 12px; color: var(--muted); }
.item-quote {
  border-left: 3px solid var(--warn); padding: 2px 0 2px 11px; color: var(--ink-soft);
  font-family: var(--serif); font-size: 15px; margin: 6px 0;
}
.item-note { font-size: 14.5px; margin-top: 6px; white-space: pre-wrap; }
.item-acts { display: flex; gap: 8px; margin-top: 10px; }
.vocab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.vocab-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; min-height: 120px; display: flex; flex-direction: column; cursor: pointer;
}
.vocab-word { font-weight: 700; font-size: 17px; margin-bottom: 4px; font-family: var(--serif); }
.vocab-ctx { font-size: 12.5px; color: var(--muted); line-height: 1.55; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.vocab-def { font-size: 13px; color: var(--ink-soft); margin-top: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(14px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px;
  z-index: 80; opacity: 0; transition: all .22s; pointer-events: none;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 720px) {
  /* 大屏恢复自适应列数，封面同样保持书本比例 */
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
  .card-title { font-size: 14.5px; }
  .card-cover { font-size: 34px; }
}
