/* 屠龙读本 —— 学术纸感 · iPhone 12 优先 */
:root {
  --paper: #f4f1e8;
  --ink: #2a2620;
  --ink-2: #4d463b;
  --ink-3: #8a8272;
  --red: #a8342a;
  --green: #3f6b4f;
  --line: #e3ddcd;
  --line-2: #d5cdb8;
  --card: #faf8f1;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --rd-bg: #f4f1e8;
  --rd-fg: #2a2620;
  --rd-size: 18px;
  --rd-lh: 1.9;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px; line-height: 1.6;
  padding-bottom: calc(58px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; } /* ≥16px 防 iOS 聚焦放大 */

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(244,241,232,.94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.seal {
  width: 34px; height: 34px; border-radius: 8px; background: var(--red); color: #f6ead9;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 21px; font-weight: 700;
  box-shadow: inset 0 0 0 1.5px rgba(246,234,217,.5);
}
.seal.big { width: 52px; height: 52px; font-size: 32px; border-radius: 12px; }
.brand-t { font-family: var(--serif); font-size: 18px; font-weight: 700; line-height: 1.2; }
.brand-t small { display: block; font-family: inherit; font-size: 10px; color: var(--ink-3); font-weight: 400; letter-spacing: 1px; }
.tb-btn { border: 0; background: none; font-size: 20px; padding: 4px; }

/* 阅读 */
.read-meta { display: flex; justify-content: space-between; padding: 10px 18px 4px; font-size: 11px; color: var(--ink-3); }
.progress-track { height: 2px; background: var(--line); margin: 0 18px; }
.progress-fill { height: 100%; width: 0; background: var(--red); transition: width .3s; }

.reader {
  background: var(--rd-bg); color: var(--rd-fg);
  padding: 14px 20px 90px; min-height: 60vh;
  transition: background .25s, color .25s;
}
.rd-title { font-family: var(--serif); font-size: 21px; line-height: 1.5; margin: 6px 0 18px; }
#rdBody p {
  font-size: var(--rd-size); line-height: var(--rd-lh);
  margin: 0 0 1em; text-align: justify; word-break: break-word;
}
#rdBody p mark { background: rgba(168,52,42,.22); color: inherit; padding: 0 1px; border-radius: 2px; }
#rdBody p.flash { animation: flash 2s; }
@keyframes flash { 0%,40% { background: rgba(168,52,42,.16); } 100% { background: transparent; } }
.rd-nav { display: flex; gap: 8px; margin-top: 24px; }
.rd-nav .ghost { flex: 1; }

.read-tools {
  position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); z-index: 25;
  display: flex; gap: 8px; padding: 8px 14px;
  background: rgba(244,241,232,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.rt {
  flex: 1; border: 1px solid var(--line-2); background: var(--card); border-radius: 10px;
  padding: 6px 0; font-size: 15px; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.rt small { font-size: 10px; }
.rt-red { background: var(--red); color: #f6ead9; border-color: var(--red); }

/* 通用 */
.pad { padding: 14px; }
.ghost {
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink-2);
  border-radius: 9px; padding: 8px 10px; font-size: 12.5px;
}
.ghost.danger { color: var(--red); }
.link { border: 0; background: none; color: var(--red); font-size: 13px; padding: 4px; }
.w44 { width: 44px; }
.chip {
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink-2);
  border-radius: 999px; padding: 5px 12px; font-size: 12px;
}
.chip.on { background: var(--red); border-color: var(--red); color: #f6ead9; }
.act-btn {
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 10px; font-size: 13px;
}
.act-btn.wide { width: 100%; background: var(--red); color: #f6ead9; border-color: var(--red); font-weight: 600; }

/* 底部 tab */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; background: #faf8f1; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; border: 0; background: none; padding: 8px 0 6px; font-size: 17px; color: var(--ink-3); display: flex; flex-direction: column; align-items: center; }
.tab small { font-size: 10px; margin-top: 1px; }
.tab.on { color: var(--red); }

/* 研究页 */
.lab-hero h2 { font-family: var(--serif); font-size: 20px; margin: 4px 0 8px; }
.lab-hero p { font-size: 12.5px; color: var(--ink-2); line-height: 1.9; margin: 0 0 12px; }
.lab-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.lab-card > b { font-size: 14px; display: block; margin-bottom: 8px; }
.lab-desc { font-size: 12px; color: var(--ink-3); line-height: 1.8; margin: 0 0 10px; }
.lab-row { margin-bottom: 10px; }
.lab-row select, #labCustom, #searchInput {
  width: 100%; border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; background: #fff; color: var(--ink);
}
.angles { display: flex; flex-wrap: wrap; gap: 7px; }
.lab-status { font-size: 12px; color: var(--ink-2); margin-top: 10px; line-height: 1.8; }
.lab-bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.lab-bar > div { height: 100%; width: 0; background: var(--red); transition: width .3s; }
.cnt { color: var(--ink-3); font-weight: 400; font-size: 12px; }
.lab-list .item { border-top: 1px solid var(--line); padding: 10px 0; }
.lab-list .item:first-child { border-top: 0; }
.lab-list .item b { font-size: 12.5px; display: block; }
.lab-list .item p { font-size: 11.5px; color: var(--ink-3); margin: 3px 0 0; }
.lab-list .item .row { display: flex; gap: 12px; margin-top: 5px; }

/* 我的 */
.mi-book { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 14px; margin-bottom: 16px; }
.mi-book b { font-family: var(--serif); font-size: 16px; }
.mi-book p { font-size: 11.5px; color: var(--ink-2); margin: 3px 0 0; }
.mi-book .dim { color: var(--ink-3); }
.mi-list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.mi-row {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  border: 0; border-bottom: 1px solid var(--line); background: none; padding: 14px; font-size: 13.5px; color: var(--ink);
}
.mi-row:last-child { border-bottom: 0; }
.mi-row em { font-style: normal; font-size: 12px; color: var(--ink-3); }
.mi-row.danger span { color: var(--red); }
.foot-note { font-size: 11.5px; color: var(--ink-3); text-align: center; line-height: 1.9; margin: 18px 10px; }

/* 弹层 */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(30,25,18,.45); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-height: 86vh; background: var(--paper); border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column; overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.tall { height: 86vh; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.sheet .pad { overflow-y: auto; }

.toc-list { overflow-y: auto; padding: 6px 0 20px; }
.toc-item { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.toc-item .no { color: var(--red); font-family: var(--serif); font-size: 15px; min-width: 26px; }
.toc-item .tt { flex: 1; font-size: 13.5px; line-height: 1.5; }
.toc-item .cc { font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }
.toc-item.on { background: rgba(168,52,42,.07); }

.search-result { margin-top: 12px; }
.sr-item { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; margin-bottom: 9px; width: 100%; text-align: left; }
.sr-item b { font-size: 11px; color: var(--red); display: block; margin-bottom: 3px; }
.sr-item span { font-size: 12.5px; line-height: 1.7; color: var(--ink-2); }
.sr-item mark { background: rgba(168,52,42,.2); color: var(--red); }

.fld { display: block; font-size: 12px; color: var(--ink-3); margin: 14px 0 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.sw { width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--line-2); }
.sw.on { border-color: var(--red); box-shadow: 0 0 0 2px rgba(168,52,42,.2); }
input[type=range] { width: 100%; accent-color: var(--red); }

.field { margin-bottom: 16px; }
.field label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select { width: 100%; border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; background: #fff; color: var(--ink); }
.field .rv { color: var(--ink-3); font-size: 11px; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.btn-row .ghost { flex: 1; }
.msg { font-size: 11.5px; color: var(--ink-3); line-height: 1.7; margin: 8px 0 0; word-break: break-all; }
.msg.ok { color: var(--green); }
.msg.err { color: var(--red); }
.msg.hint { margin: 6px 0 8px; }

/* 选段气泡 */
.sel-pop {
  position: fixed; z-index: 70; display: flex; gap: 4px;
  background: #2a2620; border-radius: 10px; padding: 5px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.sel-pop button { border: 0; background: none; color: #f0e9db; font-size: 12px; padding: 6px 10px; white-space: nowrap; }

/* Markdown 渲染 */
.md { font-size: 14px; line-height: 1.95; }
.md h1, .md h2, .md h3 { font-family: var(--serif); line-height: 1.5; margin: 16px 0 8px; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 20px; margin: 0 0 10px; }
.md li { margin-bottom: 5px; }
.md strong { color: var(--red); }
.md blockquote { border-left: 3px solid var(--red); margin: 10px 0; padding: 4px 12px; color: var(--ink-2); background: var(--card); }
.md code { background: var(--card); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

/* 遮罩 / toast */
.veil { position: fixed; inset: 0; z-index: 90; background: rgba(30,25,18,.5); display: flex; align-items: center; justify-content: center; }
.veil-card { background: var(--paper); border-radius: 16px; padding: 26px 30px; text-align: center; width: 78%; max-width: 320px; }
.veil-card b { display: block; margin: 12px 0 6px; font-size: 14px; }
.veil-card p { font-size: 12px; color: var(--ink-3); margin: 0; min-height: 18px; }
.veil-spin { width: 30px; height: 30px; margin: 0 auto; border: 3px solid var(--line-2); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 130px; transform: translateX(-50%); z-index: 100;
  background: #2a2620; color: #f0e9db; font-size: 12.5px; padding: 9px 16px; border-radius: 999px;
  max-width: 84%; text-align: center; line-height: 1.6;
}
.toast.err { background: var(--red); }

@media (min-width: 560px) {
  body { max-width: 560px; margin: 0 auto; box-shadow: 0 0 40px rgba(0,0,0,.06); }
}

/* 单条编号段落：保留 AI 原始编号 */
.mnum { margin: 0 0 .8em; }
.mnum b { color: var(--red); margin-right: 4px; }
