/* ============================================================
   京委本圣经 · 极简版
   设计系统：纸 / 墨 / 朱砂
   ============================================================ */

:root {
  --paper: #F6F2EA;          /* 暖白纸 */
  --panel: #FBF9F4;          /* 浮层纸 */
  --ink: #221E18;            /* 墨 · 正文 */
  --ink-2: #6E665A;          /* 次墨 */
  --ink-3: #A79D8D;          /* 弱墨 · 节号/注音 */
  --line: #E4DCCC;           /* 发丝线 */
  --cinnabar: #A63A2B;       /* 朱砂 · 唯一强调色 */
  --cinnabar-soft: rgba(166, 58, 43, .07);
  --desk: #DED8CC;           /* 桌面（仅原型外框） */
  --font-serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --font-sans: -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --fs-body: 17px;
  --shadow-pop: 0 -8px 32px rgba(34, 30, 24, .10);
  --ease: cubic-bezier(.22, .61, .36, 1);
  --tabbar-h: 80px;          /* 58 + 22 home */
}

body.dark {
  --paper: #16130F;          /* 夜墨 */
  --panel: #201B14;
  --ink: #E6DFD2;            /* 月白 */
  --ink-2: #ABA292;
  --ink-3: #8F8676;          /* 弱墨提亮：拼音/按键不再融进背景 */
  --line: #352F25;
  --cinnabar: #C4574A;
  --cinnabar-soft: rgba(196, 87, 74, .12);
  --desk: #0E0C09;
  --shadow-pop: 0 -8px 32px rgba(0, 0, 0, .45);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--desk);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; transition: opacity .12s; }
button:active { opacity: .55; }
button:focus-visible { outline: 2px solid var(--cinnabar); outline-offset: 2px; }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* ============ 设备外框（原型用；真机全屏由 media query 接管） ============ */
.stage { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 28px 16px; }

.phone {
  width: 390px; height: 844px;
  border-radius: 44px;
  background: var(--paper);
  position: relative; overflow: hidden;
  box-shadow: 0 24px 80px rgba(34, 30, 24, .28), 0 0 0 10px #1a1712, 0 0 0 12px #332e26;
}

.screen { position: absolute; inset: 0; overflow: hidden; background: var(--paper); }

/* ============ 页面骨架 ============ */
.page {
  position: absolute; top: 0; left: 0; right: 0; bottom: var(--tabbar-h);
  display: none; flex-direction: column; background: var(--paper);
}
.page.active { display: flex; }

.topbar {
  height: 52px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: env(safe-area-inset-top, 0px) 6px 0 20px; background: var(--paper);
  border-bottom: 1px solid transparent; transition: border-color .2s, background .2s;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar-title {
  display: flex; align-items: center; gap: 4px; min-height: 44px; padding-right: 8px;
  font-family: var(--font-serif); font-size: 20px; font-weight: 600; color: var(--ink);
}
.topbar-title.static { cursor: default; }
.ic-chev { width: 16px; height: 16px; color: var(--ink-3); margin-top: 2px; }

.iconbtn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--ink-2); border-radius: 50%; }
.iconbtn.active { color: var(--cinnabar); }

.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; touch-action: pan-y; padding-bottom: 70px; }
.scroll::-webkit-scrollbar { display: none; }

/* ============ 读经 · 经文流 ============ */
.verses { padding: 10px 20px 0; }

.verse {
  position: relative; margin: 0 -20px; padding: 10px 20px; cursor: pointer;
  transition: background .15s;
  -webkit-user-select: none; user-select: none;
}
.verse.selected, .verse.flash { background: var(--cinnabar-soft); }
.verse.multi-selected { background: var(--cinnabar-soft); }
.verse.multi-selected::after {
  content: "✓"; position: absolute; right: 14px; top: 8px;
  color: var(--cinnabar); font-size: 13px; font-family: var(--font-sans);
}

.vn {
  font-family: var(--font-serif); font-size: 11px; line-height: 1;
  color: var(--cinnabar); margin-right: 7px; position: relative; top: -1px;
}
.vbody {
  display: inline; font-family: var(--font-serif);
  font-size: var(--fs-body); line-height: 1.9; color: var(--ink);
  word-break: break-word;
}
.vbody ruby { ruby-position: over; }
.vbody rt { font-family: var(--font-sans); font-size: 11px; color: var(--ink-3); font-weight: 400; }

.vtitle {
  font-family: var(--font-serif); font-size: 12px; line-height: 1.6;
  color: var(--ink-2); margin: 10px 0 2px; letter-spacing: .06em;
}
.vnote {
  font-family: var(--font-sans); font-size: 12px; line-height: 1.7;
  color: var(--ink-3); margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--line);
}

/* 京委本人名/地名标记 */
.nm1 { text-decoration: underline; text-decoration-color: var(--ink-3); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.nm2 { text-decoration: underline double; text-decoration-color: var(--cinnabar); text-underline-offset: 3px; }
body.no-names .nm1, body.no-names .nm2 { text-decoration: none; }

.favdot {
  position: absolute; right: 20px; top: 18px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--cinnabar);
}

.read-foot { text-align: center; font-size: 11px; color: var(--ink-3); padding: 22px 20px 26px; letter-spacing: .05em; }

/* ============ 章导航（阅读模式，常驻底部） ============ */
.chapternav {
  position: absolute; left: 0; right: 0; bottom: 0; height: 53px;
  display: flex; align-items: center; background: var(--paper);
  border-top: 1px solid var(--line); z-index: 12;
}
.chapternav button {
  flex: 1; height: 100%; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; color: var(--ink-2);
}
.chapternav button .ic { width: 15px; height: 15px; }
.chapternav button + button { border-left: 1px solid var(--line); }
.chap-now {
  flex: none; max-width: 46%; text-align: center; padding: 0 10px;
  font-family: var(--font-serif); font-size: 14px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ============ 朗读面板（朗读模式） ============ */
.playerpanel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 14;
  background: var(--panel); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(34, 30, 24, .08);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0));
  transform: translateY(105%); transition: transform .26s var(--ease);
}
.playerpanel.show { transform: none; }

.pp-head { display: flex; align-items: center; gap: 10px; }
.pp-cover {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  background: var(--paper); border: 1px solid var(--line);
  font-family: var(--font-serif); font-size: 18px; color: var(--cinnabar); border-radius: 8px;
}
.pp-meta { flex: 1; min-width: 0; line-height: 1.3; }
.pp-meta b { display: block; font-family: var(--font-serif); font-size: 15px; font-weight: 600; color: var(--ink); }
.pp-meta span { font-size: 11px; color: var(--ink-3); }
.pp-state { color: var(--cinnabar) !important; }
.pp-close { width: 36px; height: 36px; display: grid; place-items: center; color: var(--ink-3); flex: none; }
.pp-play {
  width: 56px; height: 56px; flex: none; border-radius: 50%;
  background: var(--cinnabar); color: var(--paper); display: grid; place-items: center;
}
.pp-play .ic { width: 24px; height: 24px; }
.pp-play .ic-play { fill: currentColor; stroke: none; }

.pp-seek { position: relative; height: 30px; margin: 6px 2px 0; cursor: pointer; display: flex; align-items: center; }
.pp-seek::before { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--line); }
.pp-seek i { position: absolute; left: 0; height: 2px; width: 0; background: var(--cinnabar); }
.pp-seek b { position: absolute; left: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--cinnabar); transform: translateX(-50%); }

.pp-times { display: flex; justify-content: space-between; padding: 0 2px; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.pp-ctl { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.mode-seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mode-seg button { flex: 1; height: 36px; font-size: 13px; color: var(--ink-2); }
.mode-seg button + button { border-left: 1px solid var(--line); }
.mode-seg button.active { background: var(--ink); color: var(--paper); }
.pp-nav { display: flex; gap: 8px; flex: none; }
.pp-nav button { width: 42px; height: 36px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink-2); display: grid; place-items: center; }
.pp-nav .ic { width: 18px; height: 18px; }

.player-error {
  margin: 8px 0 0; padding: 10px 12px; display: none;
  border: 1px solid var(--cinnabar); color: var(--cinnabar);
  font-size: 12px; line-height: 1.7; word-break: break-all;
}
.player-error.show { display: block; }

/* ============ 查找 ============ */
.searchbox {
  margin: 14px 20px 0; height: 46px; display: flex; align-items: center; gap: 8px;
  padding: 0 6px 0 12px; background: var(--panel); border: 1px solid var(--line);
}
.searchbox:focus-within { border-color: var(--cinnabar); }
.ic-search { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.searchbox input {
  flex: 1; min-width: 0; height: 100%; border: none; outline: none; background: none;
  font-family: var(--font-sans); font-size: 15px; color: var(--ink);
}
.searchbox input::placeholder { color: var(--ink-3); }
.search-clear { width: 36px; height: 36px; display: grid; place-items: center; color: var(--ink-3); visibility: hidden; }
.search-clear.show { visibility: visible; }
.search-clear .ic { width: 15px; height: 15px; }

.find-actions { display: flex; gap: 8px; padding: 12px 20px 2px; flex-wrap: wrap; }
.chip {
  height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
}
.chip .ic { width: 15px; height: 15px; }
.chip.active { border-color: var(--cinnabar); color: var(--cinnabar); }
.chip b { font-weight: 600; }

.results-head { padding: 14px 20px 4px; font-size: 12px; color: var(--ink-3); }
.results .verse { border-bottom: 1px solid var(--line); }
.results .verse:last-child { border-bottom: none; }
.results .verse .res-copy {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; display: grid; place-items: center; color: var(--ink-3);
}
.results .verse .res-copy .ic { width: 16px; height: 16px; }
.results .verse .res-copy:active { color: var(--cinnabar); }
.results mark { background: none; color: var(--cinnabar); font-weight: 600; }

.results-empty { padding: 44px 20px 30px; text-align: center; color: var(--ink-3); }
.results-empty .ic { width: 30px; height: 30px; margin: 0 auto 12px; opacity: .45; }
.results-empty p { font-size: 13px; line-height: 1.8; }

.catalog-head { padding: 20px 20px 10px; font-size: 12px; color: var(--ink-3); letter-spacing: .18em; }

.seg { display: flex; margin: 2px 20px 14px; border: 1px solid var(--line); }
.seg button { flex: 1; height: 40px; font-size: 13px; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: var(--paper); }
.seg.small { margin: 0 20px 12px; }
.seg.small button { height: 36px; font-size: 13px; }

.catalog {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
  background: var(--line); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.cat-cell { background: var(--paper); padding: 13px 4px 11px; text-align: center; }
.cat-cell b { display: block; font-family: var(--font-serif); font-size: 14px; font-weight: 500; color: var(--ink); }
.cat-cell span { display: block; font-size: 10px; color: var(--ink-3); margin-top: 4px; }
.cat-cell.active b { color: var(--cinnabar); }
.cat-cell.active { background: var(--cinnabar-soft); }

/* ============ 底部导航 ============ */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
  display: flex; padding-bottom: 22px; background: var(--paper); border-top: 1px solid var(--line); z-index: 30;
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3);
}
.tabbar button .nav-ic { width: 24px; height: 24px; display: grid; place-items: center; }
.tabbar button .nav-ic .ic { width: 23px; height: 23px; }
.tabbar button .nav-lab { font-size: 11px; letter-spacing: .06em; }
.tabbar button.active { color: var(--cinnabar); }

.home-indicator {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  width: 134px; height: 5px; border-radius: 3px; background: var(--ink); opacity: .22;
  pointer-events: none; z-index: 31;
}

/* ============ 随机浮层 ============ */
.overlay {
  position: absolute; inset: 0; z-index: 80; display: none;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(34, 30, 24, .34);
}
.overlay.show { display: flex; }
.random-card {
  width: 100%; max-width: 330px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-pop);
  padding: 22px 20px;
}
.random-ref { font-family: var(--font-serif); font-size: 15px; font-weight: 600; color: var(--cinnabar); letter-spacing: .04em; }
.random-text { font-family: var(--font-serif); font-size: var(--fs-body); line-height: 1.9; color: var(--ink); margin: 14px 0 6px; }
.random-text .random-title { font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.random-actions { display: flex; gap: 8px; margin-top: 18px; }
.random-actions button {
  flex: 1; height: 42px; border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 5px; font-size: 13px;
}
.random-actions button .ic { width: 16px; height: 16px; }
.random-actions button.primary { background: var(--cinnabar); color: var(--paper); border-color: var(--cinnabar); }

/* ============ 抽屉与遮罩 ============ */
.scrim {
  position: absolute; inset: 0; background: rgba(34, 30, 24, .34);
  opacity: 0; pointer-events: none; transition: opacity .24s; z-index: 50;
}
.scrim.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 78%;
  display: flex; flex-direction: column;
  background: var(--paper); border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-pop); transform: translateY(103%);
  transition: transform .26s var(--ease); z-index: 60;
}
.drawer.show { transform: none; }
.drawer-grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 2px; flex: none; }
.drawer-title { padding: 10px 20px 12px; font-size: 16px; font-weight: 600; color: var(--ink); flex: none; }

.drawer-list { overflow-y: auto; padding: 0 20px 30px; scrollbar-width: none; }
.drawer-list::-webkit-scrollbar { display: none; }
.bl-row {
  display: flex; width: 100%; min-height: 52px; align-items: center; justify-content: space-between;
  padding: 0 2px; border-bottom: 1px solid var(--line);
  font-family: var(--font-serif); font-size: 16px; color: var(--ink); text-align: left;
}
.bl-row span { font-family: var(--font-sans); font-size: 11px; color: var(--ink-3); }
.bl-row.active { color: var(--cinnabar); }
.bl-row.active span { color: var(--cinnabar); }
.bl-row.bl-back { color: var(--ink-2); font-size: 14px; }
.bl-row.bl-back:active { color: var(--cinnabar); }

/* 章选择网格（书卷抽屉二级） */
.chapter-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.chapter-grid .bl-ch {
  background: var(--paper); min-height: 46px; display: grid; place-items: center;
  font-family: var(--font-serif); font-size: 15px; color: var(--ink);
}
.chapter-grid .bl-ch.active { background: var(--cinnabar-soft); color: var(--cinnabar); }
/* 节选择网格（书卷抽屉三级）：节数多，用更密的网格 */
.verse-grid { grid-template-columns: repeat(8, 1fr); }
.verse-grid .bl-ch { min-height: 40px; font-size: 13px; font-family: var(--font-sans); }

/* ============ 设置 ============ */
.setting-row {
  display: flex; min-height: 56px; align-items: center; justify-content: space-between;
  padding: 0 20px; border-bottom: 1px solid var(--line); font-size: 15px; color: var(--ink);
}
.font-ctl { display: flex; align-items: center; gap: 4px; }
.font-ctl button { width: 44px; height: 40px; font-family: var(--font-serif); font-size: 16px; color: var(--ink-2); border: 1px solid var(--line); }
.font-ctl b { min-width: 30px; text-align: center; font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }

.linkbtn-sm { font-size: 13px; color: var(--cinnabar); border: 1px solid var(--cinnabar); border-radius: 999px; padding: 6px 14px; }
.linkbtn-sm:active { opacity: .6; }

.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--paper); box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: left .2s var(--ease);
}
.switch.on { background: var(--cinnabar); }
.switch.on::after { left: 21px; }

.about { padding: 18px 20px 30px; font-size: 12px; line-height: 2; color: var(--ink-3); }
.about #about-data { color: var(--ink-2); }
.about a { color: var(--cinnabar); text-decoration: none; border-bottom: 1px solid var(--line); padding-bottom: 1px; }

/* ============ 节操作条 ============ */
/* 隐藏时必须 visibility:hidden + 延迟切换：纯 translateY 无法完全推出屏幕，
   顶部 ab-ref 条带会残留在 tabbar 下方（z-index 又高于 tabbar） */
.actionbar {
  position: absolute; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 54px);
  background: var(--panel); border-top: 1px solid var(--line); box-shadow: var(--shadow-pop);
  padding: 8px 10px 14px; transform: translateY(120%); transition: transform .24s var(--ease), visibility 0s .24s;
  visibility: hidden; z-index: 70;
}
.actionbar.show { transform: none; visibility: visible; transition: transform .24s var(--ease); }
.ab-ref { font-family: var(--font-serif); font-size: 14px; color: var(--cinnabar); padding: 4px 10px 8px; }
.ab-count { font-size: 12px; color: var(--ink-2); padding: 4px 10px 6px; }
.ab-btns { display: flex; }
.ab-btns button {
  flex: 1; min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; color: var(--ink-2);
}
.ab-btns button .ic { width: 20px; height: 20px; }
.ab-btns button.fav { color: var(--cinnabar); }
.ab-py {
  width: 20px; height: 20px; display: grid; place-items: center;
  font-family: var(--font-serif); font-size: 13px; font-weight: 600;
  border: 1.5px solid currentColor; border-radius: 4px; line-height: 1;
}
.ab-btns.multi button { color: var(--cinnabar); }

/* ============ Toast ============ */
.toast {
  position: absolute; left: 50%; bottom: 148px; transform: translateX(-50%) translateY(8px);
  max-width: 80%; background: var(--ink); color: var(--paper);
  font-size: 13px; padding: 9px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 90;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ============ 启动屏 ============ */
.splash {
  position: absolute; inset: 0; z-index: 100; background: var(--paper);
  display: grid; place-items: center; transition: opacity .3s;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; }
.splash-title { font-family: var(--font-serif); font-size: 30px; font-weight: 600; letter-spacing: .16em; color: var(--ink); text-indent: .16em; }
.splash-rule { width: 44px; height: 1px; background: var(--cinnabar); margin: 18px auto; }
.splash-status { font-size: 12px; color: var(--ink-3); letter-spacing: .1em; }
.splash-progress { width: 150px; height: 2px; background: var(--line); margin: 16px auto 0; display: none; }
.splash-progress.on { display: block; }
.splash-progress i { display: block; height: 100%; width: 0; background: var(--cinnabar); transition: width .18s; }

/* ============ 真机全屏 ============ */
@media (max-width: 430px) {
  .stage { padding: 0; }
  .phone { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}
