/* 5E 不全书 · 阅读器外壳样式 */
:root {
  --fs: 17px;
  --measure: 58rem;
  --side-w: 330px;
  --out-w: 250px;
  --serif: "Source Han Serif SC", "Noto Serif SC", "Songti SC", "STZhongsong", "SimSun", serif;
  --sans: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", "Source Han Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
kbd { font: 11px/1 var(--sans); padding: 3px 6px; border-radius: 5px; border: 1px solid currentColor; opacity: .6; }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- 整体布局 ---------- */
.app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--out-w);
  grid-template-rows: 56px minmax(0, 1fr);
  height: 100vh; height: 100dvh;
}
.app.no-outline { --out-w: 0px; }
.app.no-outline .outline { display: none; }

/* ---------- 顶栏 ---------- */
.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: linear-gradient(180deg, var(--leather-2), var(--leather));
  color: var(--leather-ink);
  border-bottom: 2px solid var(--gold);
  position: relative; z-index: 30;
}
.topbar::after {
  content: ""; position: absolute; left: 0; bottom: -2px; height: 2px; width: calc(var(--prog, 0) * 100%);
  background: var(--gold-hi); box-shadow: 0 0 8px var(--gold-hi); transition: width .12s linear;
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 38px; height: 38px; padding: 0 9px;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  color: inherit;
}
.icon-btn:hover { background: rgba(255, 255, 255, .09); }
.icon-btn[aria-pressed="true"], .icon-btn.on { color: var(--gold-hi); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .star-on { fill: currentColor; }
#btnMenu { display: none; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; margin-right: 6px; }
.brand svg { width: 34px; height: 34px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .4)); }
.brand b { display: block; font: 700 18px/1.15 var(--serif); letter-spacing: .06em; color: #f6e9c8; }
.brand small { display: block; font-size: 11px; color: var(--leather-soft); letter-spacing: .08em; }
.searchbtn {
  flex: 1; max-width: 460px; margin: 0 auto 0 14px;
  display: flex; align-items: center; gap: 9px; height: 38px; padding: 0 12px;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .14); border-radius: 11px;
  color: var(--leather-soft); text-align: left;
}
.searchbtn:hover { background: rgba(255, 255, 255, .12); border-color: var(--gold); }
.searchbtn span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.searchbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tools { display: flex; align-items: center; gap: 2px; margin-left: auto; position: relative; }

/* 弹出面板：外观设置 */
.pop {
  position: absolute; top: 46px; right: 0; width: 290px; padding: 14px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); z-index: 60;
}
.pop h4 { margin: 0 0 8px; font: 700 13px var(--sans); color: var(--ink-soft); letter-spacing: .08em; }
.pop .row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.pop .row:last-child { margin-bottom: 0; }
.chip {
  padding: 5px 11px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line); font-size: 13px;
}
.chip:hover { border-color: var(--gold); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.pop input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---------- 侧边目录 ---------- */
.side {
  grid-row: 2; display: flex; flex-direction: column; min-height: 0;
  background: var(--leather); color: var(--leather-ink);
  border-right: 1px solid rgba(0, 0, 0, .35);
  position: relative; z-index: 20;
}
.side-head { padding: 12px 12px 8px; }
.side-head input {
  width: 100%; height: 36px; padding: 0 12px; border-radius: 10px;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .13); color: var(--leather-ink);
  font: inherit; font-size: 14px;
}
.side-head input::placeholder { color: var(--leather-soft); }
.side-head input:focus { outline: none; border-color: var(--gold); background: rgba(255, 255, 255, .1); }
.tree { flex: 1; overflow: auto; padding: 4px 8px 24px; scrollbar-width: thin; scrollbar-color: #5b4835 transparent; }
.tree::-webkit-scrollbar { width: 8px; }
.tree::-webkit-scrollbar-thumb { background: #5b4835; border-radius: 4px; }
.nrow {
  display: flex; align-items: center; gap: 4px; min-height: 32px; padding: 2px 8px 2px 4px;
  border-radius: 8px; cursor: pointer; position: relative; user-select: none;
  color: var(--leather-ink); text-decoration: none;
}
.nrow:hover { background: rgba(255, 255, 255, .07); }
.nrow.active { background: linear-gradient(90deg, color-mix(in srgb, var(--accent-2) 62%, transparent), color-mix(in srgb, var(--accent-2) 16%, transparent)); color: #fff; }
.nrow.active::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 2px; background: var(--gold-hi); }
.caret { flex: none; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 5px; opacity: .75; }
.caret::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
.tn.open > .nrow > .caret::before { transform: rotate(45deg); }
.caret.none::before { display: none; }
.caret:hover { background: rgba(255, 255, 255, .12); opacity: 1; }
.nico { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--leather-soft); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.nrow.active .nico { stroke: var(--gold-hi); }
.lbl { flex: 1; min-width: 0; font-size: 14px; line-height: 1.35; padding: 3px 0; overflow-wrap: anywhere; }
.nrow.miss { cursor: default; }
.nrow.miss .lbl { opacity: .45; text-decoration: line-through; text-decoration-color: rgba(255, 255, 255, .3); }
.nrow.inc .lbl::after { content: "待完善"; margin-left: 6px; font-size: 10px; padding: 1px 5px; border-radius: 4px; border: 1px solid rgba(216, 183, 101, .5); color: var(--gold-hi); vertical-align: 1px; }
.kids { margin-left: 11px; padding-left: 6px; border-left: 1px solid rgba(255, 255, 255, .1); }
.tn:not(.open) > .kids { display: none; }
.sep { margin: 14px 8px 4px; padding-top: 10px; font: 700 12px var(--serif); letter-spacing: .16em; color: var(--gold-hi); text-align: center; }
.sep.plain { height: 1px; padding: 0; margin: 10px 14px; background: rgba(255, 255, 255, .12); }
.frow .path { display: block; font-size: 11px; color: var(--leather-soft); }
.side-foot { padding: 8px 14px 10px; font-size: 11px; color: var(--leather-soft); border-top: 1px solid rgba(255, 255, 255, .08); letter-spacing: .03em; }

/* ---------- 主区 ---------- */
.main { grid-row: 2; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); position: relative; }
.crumbs {
  flex: none; display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; overflow-x: auto; white-space: nowrap;
  padding: 0 18px; min-height: 40px; background: var(--paper-2); border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--ink-soft); scrollbar-width: none;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs a { text-decoration: none; padding: 3px 6px; border-radius: 6px; }
.crumbs a:hover { background: color-mix(in srgb, var(--gold) 25%, transparent); color: var(--ink); }
.crumbs .sep-c { opacity: .45; }
.crumbs .here { color: var(--ink); font-weight: 700; padding: 3px 6px; }
.crumbs .sp { flex: 1; }
iframe#view { flex: 1; width: 100%; min-height: 0; border: 0; background: var(--paper); display: block; }
.pager { flex: none; display: flex; align-items: stretch; border-top: 1px solid var(--line); background: var(--paper-2); }
.pager button {
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 1px;
  padding: 6px 16px; background: transparent; border: 0; text-align: left; color: var(--ink);
}
.pager button:hover:not(:disabled) { background: color-mix(in srgb, var(--gold) 20%, transparent); }
.pager button:disabled { opacity: .3; cursor: default; }
.pager button + button { text-align: right; border-left: 1px solid var(--line); }
.pager small { font-size: 11px; color: var(--ink-soft); letter-spacing: .06em; }
.pager b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 搜索命中条 */
.hlbar {
  position: absolute; left: 50%; bottom: 62px; transform: translateX(-50%); z-index: 15;
  display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 14px;
  background: var(--leather); color: var(--leather-ink); border: 1px solid var(--gold); border-radius: 999px; box-shadow: var(--shadow); font-size: 13px;
}
.hlbar button { width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .1); color: inherit; }
.hlbar button:hover { background: rgba(255, 255, 255, .2); }

/* ---------- 本页目录 ---------- */
.outline { grid-row: 2; overflow: auto; padding: 18px 14px 30px 8px; background: var(--paper); border-left: 1px solid var(--line); font-size: 13px; }
.outline h5 { margin: 0 0 8px 10px; font: 700 12px var(--sans); letter-spacing: .12em; color: var(--ink-soft); }
.outline a {
  display: block; padding: 4px 10px; margin: 1px 0; color: var(--ink-soft); text-decoration: none; border-left: 2px solid transparent; line-height: 1.4;
  border-radius: 0 6px 6px 0;
}
.outline a:hover { color: var(--ink); background: color-mix(in srgb, var(--gold) 14%, transparent); }
.outline a.l3 { padding-left: 22px; }
.outline a.l4 { padding-left: 34px; font-size: 12px; }
.outline a.on { color: var(--accent); border-left-color: var(--accent); font-weight: 700; background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---------- 首页 ---------- */
.home { flex: 1; overflow: auto; min-height: 0; background: var(--paper); }
.main:not(.is-home) .home { display: none; }
.is-home iframe#view, .is-home .pager, .is-home .hlbar { display: none; }
.is-home .crumbs { display: none; }
.hero {
  position: relative; text-align: center; padding: 54px 20px 46px; color: #f6e9c8; overflow: hidden;
  background:
    radial-gradient(1200px 340px at 50% -10%, var(--hero-glow), transparent 70%),
    radial-gradient(600px 300px at 15% 120%, var(--hero-glow-2), transparent 70%),
    linear-gradient(180deg, var(--hero-1), var(--hero-2));
  border-bottom: 3px solid var(--gold);
}
.hero::before {
  content: ""; position: absolute; inset: 0; opacity: .08; pointer-events: none;
  background-image: repeating-linear-gradient(45deg, #fff 0 1px, transparent 1px 14px), repeating-linear-gradient(-45deg, #fff 0 1px, transparent 1px 14px);
}
.hero > * { position: relative; }
.hero .die { width: 92px; height: 92px; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .55)); animation: bob 5s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(3deg); } }
.hero h1 { margin: 14px 0 4px; font: 700 clamp(30px, 5vw, 46px)/1.15 var(--serif); letter-spacing: .14em; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.hero p { margin: 0; color: #d9c79d; letter-spacing: .18em; font-size: 14px; }
.hero .bigsearch {
  display: flex; align-items: center; gap: 10px; width: min(560px, 100%); margin: 26px auto 0; height: 52px; padding: 0 18px;
  background: color-mix(in srgb, var(--paper) 94%, #fff); color: var(--ink-soft); border: 2px solid var(--gold-hi); border-radius: 14px; font-size: 16px; text-align: left;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.hero .bigsearch:hover { background: color-mix(in srgb, var(--paper) 80%, #fff); }
.hero .bigsearch svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.hero .bigsearch span { flex: 1; }
.hero .bigsearch kbd { color: var(--ink-soft); }
.hero .ver { margin-top: 14px; font-size: 12px; color: #b9a98b; letter-spacing: .1em; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 28px 22px 60px; }
.sec { margin-top: 30px; }
.sec:first-child { margin-top: 0; }
.sec h2 {
  display: flex; align-items: center; gap: 12px; margin: 0 0 14px; font: 700 20px var(--serif); letter-spacing: .1em; color: var(--accent);
}
.sec h2::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--gold), transparent); }
.sec h2 small { font: 12px var(--sans); color: var(--ink-soft); letter-spacing: .04em; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-align: left; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 1px 0 rgba(255, 255, 255, .4) inset;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--gold); }
.seal {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  font: 700 21px var(--serif); color: #f6e9c8;
  background: radial-gradient(circle at 30% 25%, var(--die-1), var(--die-2) 85%);
  box-shadow: 0 0 0 2px var(--card), 0 0 0 3px var(--gold), 0 3px 6px rgba(0, 0, 0, .25);
}
.tile b { display: block; font-size: 15px; }
.tile small { display: block; color: var(--ink-soft); font-size: 12px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.book {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; min-height: 104px; padding: 14px 16px 12px 22px;
  text-align: left; text-decoration: none; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 6px 12px 12px 6px; box-shadow: 0 2px 0 rgba(0, 0, 0, .06);
  transition: transform .15s, box-shadow .15s;
}
.book::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 11px; border-radius: 6px 0 0 6px; background: var(--spine, var(--accent)); box-shadow: inset -2px 0 0 rgba(0, 0, 0, .18), inset 2px 0 0 rgba(255, 255, 255, .18); }
.book:hover { transform: translateY(-3px) rotate(-.4deg); box-shadow: var(--shadow); }
.book b { font: 700 16px/1.35 var(--serif); letter-spacing: .02em; }
.book small { color: var(--ink-soft); font-size: 12px; margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.book .tag { padding: 0 6px; border-radius: 4px; border: 1px solid var(--gold); color: var(--accent); font-size: 11px; }
.listing { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); text-decoration: none; font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill:hover { border-color: var(--gold); background: var(--paper-2); }
.foot { margin-top: 44px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-soft); line-height: 1.9; }
.foot a { color: var(--accent); }

/* ---------- 搜索弹窗 ---------- */
.sm { position: fixed; inset: 0; z-index: 100; display: flex; justify-content: center; align-items: flex-start; padding: 8vh 14px 0; background: rgba(15, 10, 6, .6); backdrop-filter: blur(3px); }
.sm-box { width: min(720px, 100%); max-height: 80vh; display: flex; flex-direction: column; background: var(--card); color: var(--ink); border: 1px solid var(--gold); border-radius: 16px; box-shadow: 0 24px 70px rgba(0, 0, 0, .55); overflow: hidden; }
.sm-in { display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 58px; border-bottom: 1px solid var(--line); }
.sm-in svg { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; flex: none; }
.sm-in input { flex: 1; height: 100%; border: 0; background: transparent; color: inherit; font: 17px var(--sans); outline: none; min-width: 0; }
.sm-res { flex: 1; overflow: auto; padding: 8px; min-height: 80px; }
.sm-h { padding: 10px 10px 4px; font: 700 12px var(--sans); letter-spacing: .1em; color: var(--ink-soft); display: flex; justify-content: space-between; align-items: center; }
.sm-it { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; text-decoration: none; }
.sm-it.sel, .sm-it:hover { background: color-mix(in srgb, var(--gold) 24%, transparent); }
.sm-it b { display: block; font-size: 15px; }
.sm-it .ctx { display: block; font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sm-it .snip { display: block; margin-top: 2px; font-size: 13px; color: var(--ink-soft); line-height: 1.55; }
.sm-it mark { background: color-mix(in srgb, var(--gold-hi) 55%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.sm-empty { padding: 26px 16px; text-align: center; color: var(--ink-soft); font-size: 14px; }
.sm-ft { display: flex; align-items: center; gap: 10px; margin: 6px; padding: 10px 12px; border: 1px dashed var(--gold); border-radius: 10px; background: transparent; color: var(--accent); text-align: left; font-size: 14px; width: calc(100% - 12px); }
.sm-ft:hover { background: color-mix(in srgb, var(--gold) 16%, transparent); }
.bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin: 6px 12px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--gold-hi)); transition: width .2s; }
.sm-foot { display: flex; gap: 16px; padding: 8px 16px; font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--line); background: var(--paper-2); }

.scrim { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .outline {
    position: fixed; top: 56px; right: 0; bottom: 0; width: min(86vw, 320px); z-index: 40; display: none;
    box-shadow: var(--shadow);
  }
  .app.out-open .outline { display: block; }
  .app.no-outline .outline { display: none; }
  .app.no-outline.out-open .outline { display: block; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  #btnMenu { display: inline-flex; }
  .side { position: fixed; top: 56px; left: 0; bottom: 0; width: min(88vw, 360px); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .app.side-open .side { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 56px 0 0 0; z-index: 15; background: rgba(0, 0, 0, .45); }
  .brand small, .searchbtn kbd, .hide-m { display: none; }
  .brand b { white-space: nowrap; font-size: 16px; }
  .searchbtn { min-width: 0; }
  .searchbtn { margin-left: 4px; }
  .crumbs { padding: 0 10px; }
  .hero { padding: 36px 16px 32px; }
  .wrap { padding: 20px 14px 50px; }
  .sm { padding-top: 3vh; }
}
@media (max-width: 520px) {
  .brand span { display: none; }
  .tools { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- 侧栏标签页 ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; }
.tab {
  flex: 1; height: 32px; border: 0; border-radius: 9px 9px 0 0; background: transparent; color: var(--leather-soft);
  font-size: 13px; letter-spacing: .1em; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--leather-ink); background: rgba(255, 255, 255, .05); }
.tab.on { color: var(--gold-hi); border-bottom-color: var(--gold-hi); font-weight: 700; }
.side-head.off { display: none; }
.nrow .x { flex: none; width: 24px; height: 24px; border-radius: 6px; border: 0; background: transparent; color: var(--leather-soft); opacity: 0; }
.nrow:hover .x { opacity: 1; }
.nrow .x:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.emptytip { padding: 26px 14px; text-align: center; color: var(--leather-soft); font-size: 13px; line-height: 1.8; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25) inset; }

/* ---------- 搜索选项 ---------- */
.sm-opts { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--paper-2); }
.sm-opts .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.sm-opts .hint { font-size: 12px; color: var(--ink-soft); }
.sm-sub { font-size: 12px; color: var(--ink-soft); }
/* 设置面板里的示例文字：随字号滑块实时变化 */
.pop .sample { margin: 2px 0 8px; padding: 8px 10px; border-radius: 10px; background: var(--paper-2); border: 1px solid var(--line); font: var(--fs)/1.6 var(--serif); color: var(--ink); }
.pop .note { margin: 0; font-size: 12px; color: var(--ink-soft); line-height: 1.6; }