/* ==========================================================================
   闲读 / 设计系统「白纸 · 朱印」
   - 冷纸白底 + 墨色文字，唯一彩色是朱砂：只用在「当前位置 / 主动作 / 进度」
   - 界面黑体粗字重做标题，阅读正文宋体；无卡片阴影、无表格头、无编号列
   - 零外部资源；移动优先的触摸目标与安全区
   ========================================================================== */

:root {
  color-scheme: light;

  --page:       #F5F7F3;
  --surface:    #FFFFFF;
  --surface-2:  #EFF2EC;
  --ink:        #1B1F1B;
  --ink-2:      #5E665D;
  --ink-3:      #939B90;
  --line:       #E2E7DE;
  --line-2:     #C6CEC1;
  --seal:       #C6402C;
  --seal-soft:  #FBEFEC;
  --danger:     #B4402F;
  --book-cloth: #232622;

  --reader-bg:  #FDFDFB;
  --reader-ink: #232622;

  --ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --serif: "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", "Courier New", monospace;

  --r: 3px;
  --t: 150ms ease-out;
}

html[data-mode="night"] {
  color-scheme: dark;
  --page:      #121613;
  --surface:   #1B201C;
  --surface-2: #242B25;
  --ink:       #E9EDE6;
  --ink-2:     #A7B1A5;
  --ink-3:     #707B6F;
  --line:      #2C332C;
  --line-2:    #3B443B;
  --seal:      #E8705A;
  --seal-soft: #33211D;
  --danger:    #E8705A;
  --reader-bg: #191D1A;
  --reader-ink:#D8DDD5;
}

/* 强调色只换这一处，纸色与字体仍由用户独立控制 */
html[data-accent="ink"]    { --seal: #3D4A40; --seal-soft: #ECEFEA; }
html[data-accent="indigo"] { --seal: #3C4E8A; --seal-soft: #ECEFF8; }
html[data-mode="night"][data-accent="ink"]    { --seal: #B3C2B4; --seal-soft: #252D26; }
html[data-mode="night"][data-accent="indigo"] { --seal: #94A8DE; --seal-soft: #212A3D; }
html[data-motion="off"] *, html[data-motion="off"] *::before,
html[data-motion="off"] *::after { animation: none !important; transition: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow-x: hidden; }
body {
  font-family: var(--ui); font-size: 15px; color: var(--ink); background: var(--page);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--seal); outline-offset: 3px; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.app {
  height: 100vh; height: 100dvh; min-height: 0;
  /* 列宽必须锁死：默认 auto 列会被顶栏/底栏的 nowrap 内容撑到视口之外 */
  display: grid; grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 60px minmax(0, 1fr) 30px;
}
.app--reader { grid-template-rows: 60px minmax(0, 1fr) 56px 30px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  padding: 0 clamp(16px, 4vw, 40px);
  background: var(--surface); border-bottom: 1px solid var(--line); z-index: 30;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 800; letter-spacing: -.045em; white-space: nowrap; }
.brand-mark { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--seal); }
.brand:hover { color: var(--seal); }
.crumb { color: var(--ink-3); font-size: 12.5px; margin-left: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28vw; }
.current-title { font-size: 12.5px; color: var(--ink-2); max-width: 24vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: 8px; }
.kbd { font-family: var(--mono); font-size: 10px; color: var(--ink-3); padding: 1px 4px; margin-left: 4px; border: 1px solid var(--line); border-radius: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 13px; font-size: 13px; color: var(--ink-2);
  border: 1px solid transparent; border-radius: var(--r); white-space: nowrap;
  transition: color var(--t), background var(--t), border-color var(--t);
}
.btn:hover { color: var(--seal); background: var(--seal-soft); }
.btn:active { transform: translateY(1px); }
.btn.on { color: var(--seal); background: var(--seal-soft); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn:disabled:hover { color: var(--ink-2); background: none; }
.btn.primary { background: var(--seal); color: #FFFFFF; border-color: var(--seal); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); color: #FFFFFF; }

.statusbar {
  display: flex; align-items: center; gap: 16px; padding: 0 clamp(16px, 4vw, 40px);
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: 11px; color: var(--ink-3);
}
.tweak-trigger { font-size: 11px; color: var(--ink-3); padding: 4px 6px; }
.tweak-trigger:hover { color: var(--seal); }

/* ---------- 页面骨架（入口列表 / 书架共用） ---------- */
.page-main { overflow-y: auto; overflow-x: hidden; min-height: 0; }
.page-inner { max-width: 980px; margin: 0 auto; padding: clamp(48px, 7vw, 88px) clamp(20px, 5vw, 56px) 88px; }
.kicker { font-size: 13px; color: var(--seal); letter-spacing: .1em; margin-bottom: 18px; }
.page-title {
  font-family: var(--ui); font-weight: 800; letter-spacing: -.055em;
  font-size: clamp(40px, 7vw, 72px); line-height: 1.04; margin: 0 0 20px;
  text-wrap: pretty;
}
.lede { color: var(--ink-2); font-size: 16px; line-height: 1.85; max-width: 44ch; text-wrap: pretty; margin: 0; }
.section-bar { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 64px 0 14px; }
.section-bar h2 { font-size: 13px; font-weight: 800; letter-spacing: .02em; margin: 0; }
.section-bar .count { font-size: 12px; color: var(--ink-3); }
.page-note { margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 12px; line-height: 2; color: var(--ink-3); }
.page-note a { color: var(--seal); text-decoration: underline; text-underline-offset: 3px; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.page-title { animation: rise 420ms cubic-bezier(.2,.7,.2,1) both; }
.lede { animation: rise 420ms cubic-bezier(.2,.7,.2,1) 70ms both; }

/* ---------- 书架 ---------- */
.shelf { display: grid; gap: 12px; }
.book-card {
  display: flex; align-items: center; gap: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 26px 28px; transition: border-color var(--t);
}
.book-card:hover { border-color: var(--seal); }
.book-main {
  display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 26px;
  align-items: center; flex: 1; min-width: 0;
}
.book-manage {
  flex: none; min-height: 40px; padding: 0 14px;
  font-size: 13px; font-weight: 700; color: var(--ink-2);
  border: 1px solid var(--line-2); border-radius: var(--r);
  transition: color var(--t), border-color var(--t), background var(--t);
}
.book-manage:hover { color: var(--seal); border-color: var(--seal); background: var(--seal-soft); }
.book-spine {
  width: 72px; height: 104px; border-radius: 2px 4px 4px 2px; background: var(--book-cloth);
  position: relative; box-shadow: inset 5px 0 0 rgba(255,255,255,.055);
}
.book-spine::after { content: ""; position: absolute; left: 16px; top: 16px; bottom: 16px; width: 2px; background: var(--seal); }
.book-title { font-size: 25px; font-weight: 800; letter-spacing: -.035em; line-height: 1.3; text-wrap: pretty; }
.book-meta { font-size: 12.5px; color: var(--ink-2); margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.book-meta b { color: var(--seal); font-weight: 700; }
.book-go { font-size: 13px; color: var(--seal); font-weight: 700; white-space: nowrap; transition: transform var(--t); }
.book-card:hover .book-go { transform: translateX(4px); }

/* ---------- 阅读页底部章节切换 ---------- */
.chapter-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0;
  padding: 0 clamp(12px, 4vw, 40px);
  background: var(--surface); border-top: 1px solid var(--line); z-index: 25;
}
.chapter-nav .nav-btn { min-width: 124px; border-color: var(--line-2); }
/* 中间的章节名同时是目录入口：点击 / 回车都能弹出目录 */
.nav-center {
  flex: 1; min-width: 0; height: 34px; margin: 0; padding: 0 12px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  align-self: center;
  border: 1px solid transparent; border-radius: var(--r); background: transparent;
  font: inherit; font-size: 13px; color: var(--ink-2); cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.nav-center:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.nav-center:active { background: var(--surface-2); }
.nav-center:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }
.nav-center-text {
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-caret { flex: 0 0 auto; font-size: 9px; line-height: 1; opacity: .42; transform: translateY(1px); }
.nav-center:hover .nav-caret { opacity: .75; }

/* ---------- 状态 ---------- */
.state-box { display: grid; place-items: center; gap: 12px; padding: 64px 20px; text-align: center; color: var(--ink-2); font-size: 14px; }
.state-box .state-title { font-size: 18px; font-weight: 800; color: var(--ink); }
.skeleton { height: 12px; border-radius: 2px; background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.toast {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%) translateY(8px);
  background: var(--surface); border: 1px solid var(--line-2); color: var(--danger);
  border-radius: var(--r); padding: 11px 18px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(20,24,20,.13); z-index: 12000;
  opacity: 0; pointer-events: none; transition: opacity var(--t), transform var(--t);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 面板（目录 / 设置） ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(18,22,18,.38); z-index: 40; opacity: 0; pointer-events: none; transition: opacity var(--t); }
.drawer-scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; bottom: 0; z-index: 50; width: min(380px, 92vw);
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(-100%); transition: transform var(--t);
}
.drawer.right { right: 0; left: auto; border-right: 0; border-left: 1px solid var(--line); transform: translateX(100%); }
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 20px 20px 16px; border-bottom: 1px solid var(--line); }
.drawer-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.drawer-head h2 { font-size: 20px; font-weight: 800; letter-spacing: -.03em; margin: 0; }
.drawer-head h2 span { font-size: 11px; color: var(--ink-3); font-weight: 400; letter-spacing: 0; margin-left: 8px; }
.drawer-close { font-size: 13px; color: var(--seal); font-weight: 700; min-height: 36px; padding: 0 6px; }
.drawer-close:hover { background: var(--seal-soft); border-radius: var(--r); }
.field { display: flex; gap: 8px; }
.input {
  width: 100%; height: 42px; padding: 0 12px; font-size: 15px;
  background: var(--page); border: 1px solid var(--line); border-radius: var(--r); color: var(--ink);
}
.input:focus { outline: none; border-color: var(--seal); }
.input::placeholder { color: var(--ink-3); }
.seg { display: flex; border: 1px solid var(--line-2); border-radius: var(--r); overflow: hidden; }
.seg button { flex: 1; min-height: 38px; padding: 0 4px; font-size: 12.5px; color: var(--ink-2); border-right: 1px solid var(--line); transition: background var(--t), color var(--t); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-2); }
.seg button.on { background: var(--seal-soft); color: var(--seal); font-weight: 700; }
.drawer-body { flex: 1; overflow-y: auto; padding: 6px 12px 32px; -webkit-overflow-scrolling: touch; }
.drawer-foot { padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); font-size: 11px; color: var(--ink-3); }

.toc-item {
  display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; align-items: center;
  width: 100%; min-height: 46px; text-align: left; padding: 8px 10px;
  font-size: 14px; color: var(--ink-2); border-bottom: 1px solid var(--line);
  content-visibility: auto; contain-intrinsic-size: auto 46px;
  transition: background var(--t), color var(--t);
}
.toc-item:hover { background: var(--surface-2); }
.toc-item.on { background: var(--seal-soft); color: var(--seal); font-weight: 700; }
.toc-item .n { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.toc-item.on .n { color: var(--seal); }
.toc-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 设置面板 ---------- */
.settings { padding: 18px 8px 32px; }
.set-group { margin-bottom: 24px; }
.set-group > h3 { font-size: 13px; font-weight: 800; color: var(--ink); margin: 0 0 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 13px; color: var(--ink-2); }
.set-row .val { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); min-width: 52px; text-align: right; }
input[type="range"] { width: 100%; height: 28px; accent-color: var(--seal); margin: 0; }
.swatches { display: flex; gap: 9px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 3px; border: 1px solid var(--line-2); }
.swatch.on { outline: 2px solid var(--seal); outline-offset: 2px; }
.color-custom { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; }
input[type="color"] { width: 40px; height: 36px; padding: 0; border: 1px solid var(--line-2); border-radius: var(--r); background: none; cursor: pointer; }
.set-hint { font-size: 12px; color: var(--ink-3); line-height: 1.85; margin-top: 10px; }
.set-actions { display: flex; gap: 8px; margin-top: 26px; }
.set-actions .btn { flex: 1; text-align: center; border-color: var(--line-2); }

/* ---------- 平板 ---------- */
@media (max-width: 900px) {
  .page-inner { padding: 48px 28px 72px; }
  .drawer { width: min(360px, 88vw); }
  .crumb, .current-title { display: none; }
}

/* ---------- 手机：一等公民 ---------- */
@media (max-width: 640px) {
  .app { grid-template-rows: 56px minmax(0, 1fr); }
  .app--reader { grid-template-rows: 56px minmax(0, 1fr) calc(58px + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 10px; gap: 2px; }
  .brand { font-size: 17px; gap: 8px; }
  .btn { min-height: 44px; padding: 0 10px; font-size: 13px; }
  .kbd, .statusbar { display: none; }
  .page-inner { padding: 36px 18px 56px; }
  .page-title { font-size: clamp(36px, 10.5vw, 50px); margin-bottom: 16px; }
  .lede { font-size: 15px; line-height: 1.8; }
  .kicker { font-size: 12px; margin-bottom: 14px; }
  .section-bar { margin: 44px 0 12px; }
  .page-note { margin-top: 40px; font-size: 11.5px; }

  .book-card { padding: 18px; gap: 10px; }
  .book-main { grid-template-columns: 52px minmax(0, 1fr); gap: 14px; }
  .book-spine { width: 52px; height: 76px; }
  .book-spine::after { left: 11px; top: 11px; bottom: 11px; }
  .book-title { font-size: 20px; }
  .book-meta { font-size: 11.5px; gap: 4px 12px; margin-top: 10px; }
  .book-manage { min-height: 44px; padding: 0 10px; font-size: 12.5px; }

  .chapter-nav { padding: 0 10px env(safe-area-inset-bottom); gap: 8px; }
  .chapter-nav .nav-btn { min-width: 0; flex: 0 0 auto; min-height: 44px; padding: 0 12px; border-color: var(--line-2); }
  .nav-center { font-size: 11.5px; min-height: 44px; height: auto; padding: 0 8px; gap: 4px; }

  /* 手机上抽屉铺满，必须自带关闭按钮 */
  .drawer { width: 100%; border: 0; }
  .drawer-head { padding: 14px 16px 14px; }
  .drawer-head h2 { font-size: 18px; margin-bottom: 12px; }
  .drawer-close { min-height: 44px; padding: 0 10px; }
  .drawer-body { padding: 4px 12px 40px; }
  .toc-item { min-height: 50px; font-size: 14px; }
  .seg button { min-height: 44px; font-size: 12.5px; }
  .input { height: 46px; font-size: 16px; }
  .settings { padding: 18px 4px 40px; }
  .swatch { width: 44px; height: 44px; }
  input[type="color"] { width: 46px; height: 42px; }
  input[type="range"] { height: 34px; }
  .set-actions .btn { min-height: 46px; }
  .toast { bottom: calc(78px + env(safe-area-inset-bottom)); max-width: 88vw; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
