/* RAZ 分级阅读 —— 无依赖样式表 */

:root {
  --bg: #FBFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F2ED;
  --text: #1C1917;
  --text-dim: #6F6862;
  --text-faint: #A8A29E;
  --border: #E7E3DD;
  --accent: #B45309;
  --accent-soft: #FEF3C7;
  --shadow: 0 1px 2px rgba(28,25,23,.06), 0 8px 24px -12px rgba(28,25,23,.18);
  --radius: 14px;
  --ui: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Songti SC", serif;
  --fs: 19px;
  --lh: 1.85;
  --measure: 34em;
  --card-shadow: 0 1px 2px rgba(20,16,12,.16), 0 8px 20px -10px rgba(20,16,12,.42);
  --card-shadow-h: 0 2px 5px rgba(20,16,12,.2), 0 18px 34px -14px rgba(20,16,12,.5);
}

html[data-theme="sepia"] {
  --bg: #F3E9D2;
  --surface: #FBF3E2;
  --surface-2: #EADFC4;
  --text: #3B2F1F;
  --text-dim: #7C6A4E;
  --text-faint: #A99878;
  --border: #DCCBAB;
  --accent: #92400E;
  --accent-soft: #EADFC4;
  --shadow: 0 1px 2px rgba(59,47,31,.08), 0 8px 24px -12px rgba(59,47,31,.25);
}

html[data-theme="dark"] {
  --bg: #0F1115;
  --surface: #171A20;
  --surface-2: #1F242C;
  --text: #E7E5E4;
  --text-dim: #9AA0A8;
  --text-faint: #6B7178;
  --border: #272D36;
  --accent: #F0A02C;
  --accent-soft: #2A2114;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px -12px rgba(0,0,0,.7);
  --card-shadow: 0 1px 3px rgba(0,0,0,.55), 0 10px 24px -12px rgba(0,0,0,.8);
  --card-shadow-h: 0 3px 8px rgba(0,0,0,.6), 0 20px 40px -16px rgba(0,0,0,.9);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.skip { position: absolute; left: -9999px; top: 0; background: var(--accent); color: #fff; padding: 10px 16px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 650; letter-spacing: -.01em; font-size: 15px; white-space: nowrap;
}
.topbar .brand .dot {
  width: 10px; height: 10px; border-radius: 3px;
  background: linear-gradient(135deg, #F0A02C, #C2410C);
  box-shadow: 0 0 0 3px color-mix(in srgb, #C2410C 14%, transparent);
}
.topbar .spacer { flex: 1; }

.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  color: var(--text-dim); transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }

.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 12px 0 8px; border-radius: 10px;
  color: var(--text-dim); font-size: 14px;
  transition: background .15s, color .15s;
  max-width: 60vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.back-btn:hover { background: var(--surface-2); color: var(--text); }
.back-btn svg { width: 18px; height: 18px; flex: none; }

/* ============ 程序化书封 ============ */
.cover {
  position: relative; display: block;
  aspect-ratio: 3 / 4;
  border-radius: 7px; overflow: hidden;
  container-type: inline-size;
  background: linear-gradient(var(--ang, 135deg), var(--c1), var(--c2));
  box-shadow: var(--card-shadow);
  transition: box-shadow .2s ease, transform .2s ease;
  isolation: isolate;
}
/* 底部压暗，保证封面标题在任何底色上都清晰 */
.cover::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background: linear-gradient(180deg, transparent 38%, rgba(0,0,0,.16) 62%, rgba(0,0,0,.42));
}
/* 书脊暗部 + 纸纹 */
.cover::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0,0,0,.26) 0, rgba(0,0,0,.06) 5%, transparent 11%),
    linear-gradient(200deg, rgba(255,255,255,.14), transparent 42%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.045) 0 1px, transparent 1px 3px);
}
.cover .motif {
  position: absolute; inset: 0; width: 100%; height: 100%;
  color: #fff; opacity: .2; z-index: 1;
}
.cover .cv-lv {
  z-index: 2;
  position: absolute; top: 7.5%; left: 8%;
  font-family: var(--ui); font-style: normal; font-weight: 650;
  font-size: 4.4cqw; line-height: 1.5; letter-spacing: .08em;
  text-transform: uppercase; color: rgba(255,255,255,.94);
  border: 1px solid rgba(255,255,255,.45); border-radius: 3px;
  padding: 0 .38em;
}
.cover .cv-meta {
  z-index: 2;
  position: absolute; top: 8.6%; right: 8%;
  font-family: var(--ui); font-style: normal;
  font-size: 3.5cqw; color: rgba(255,255,255,.72);
}
.cover .cv-title {
  z-index: 2;
  position: absolute; left: 8%; right: 8%; bottom: 9.5%;
  font-family: var(--serif); font-weight: 600;
  font-size: var(--fs, 12cqw); line-height: 1.24;
  letter-spacing: -.012em; color: #fff;
  text-shadow: 0 1px 10px rgba(0,0,0,.3);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 封面很小时（阅读页缩略、搜索面板），文字会糊成一团，直接隐藏 */
@container (max-width: 104px) {
  .cover .cv-title, .cover .cv-meta { display: none; }
  .cover .cv-lv { font-size: 9cqw; }
}

/* ============ 首页 ============ */
.hero {
  position: relative;
  padding: 52px 20px 34px; max-width: 940px; margin: 0 auto;
}
.hero::before {
  content: ""; position: absolute; left: 50%; top: -180px;
  width: min(900px, 130vw); height: 520px; transform: translateX(-50%);
  background:
    radial-gradient(46% 60% at 28% 42%, color-mix(in srgb, #F0A02C 26%, transparent), transparent 70%),
    radial-gradient(42% 56% at 72% 34%, color-mix(in srgb, #7C6BF0 22%, transparent), transparent 70%),
    radial-gradient(40% 50% at 50% 60%, color-mix(in srgb, #2BB3A3 18%, transparent), transparent 72%);
  filter: blur(56px); opacity: .9; pointer-events: none;
}
.hero > * { position: relative; }
.hero h1 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-size: clamp(32px, 6.4vw, 48px);
  line-height: 1.12; letter-spacing: -.025em; font-weight: 650;
  background: linear-gradient(135deg, var(--text) 42%, color-mix(in srgb, var(--accent) 88%, var(--text)));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p { margin: 0; color: var(--text-dim); font-size: 15px; max-width: 46ch; }
.hero .stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.hero .stats div {
  display: flex; align-items: baseline; gap: 6px;
  padding: 7px 13px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
}
.hero .stats b {
  font-size: 17px; font-weight: 680; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.hero .stats span { font-size: 11.5px; color: var(--text-faint); }

.levels {
  display: grid; gap: 11px;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  max-width: 940px; margin: 0 auto; padding: 0 20px 64px;
}
.level-card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
  min-height: 108px; padding: 15px 16px 14px;
  border-radius: 15px;
  background: linear-gradient(150deg,
    color-mix(in srgb, var(--lv) 24%, var(--surface)),
    color-mix(in srgb, var(--lv) 6%, var(--surface)) 72%);
  border: 1px solid color-mix(in srgb, var(--lv) 34%, var(--border));
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.level-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--lv) 62%, transparent);
}
.level-card .lv-big {
  position: absolute; right: 6px; top: -6px;
  font-family: var(--serif); font-size: 58px; font-weight: 700; line-height: 1;
  letter-spacing: -.05em; color: var(--lv); opacity: .17;
  pointer-events: none; user-select: none;
}
.level-card .lv-meta {
  position: relative; font-size: 11.5px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.level-card .lv-bar {
  position: relative; height: 3px; margin-top: 9px; border-radius: 2px;
  background: color-mix(in srgb, var(--lv) 16%, transparent); overflow: hidden;
}
.level-card .lv-bar i { display: block; height: 100%; border-radius: 2px; background: var(--lv); }

/* 继续阅读 */
.resume {
  display: flex; align-items: center; gap: 14px;
  max-width: 940px; margin: 0 auto 24px; padding: 13px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.resume:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  transform: translateY(-1px); box-shadow: var(--shadow);
}
.resume-cover { flex: none; width: 44px; }
.resume-cover .cover { border-radius: 4px; }
.resume-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.resume .rlabel { font-size: 11px; color: var(--accent); font-weight: 650; letter-spacing: .06em; }
.resume .rtitle {
  font-size: 14.5px; font-weight: 550; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.resume .rmeta { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.resume .arrow { color: var(--text-faint); flex: none; }

/* ============ 级别页 ============ */
.page-head { max-width: 1000px; margin: 0 auto; padding: 26px 20px 12px; }
.page-head h1 {
  margin: 0 0 6px; font-family: var(--serif); font-size: 30px;
  font-weight: 650; letter-spacing: -.025em;
}
.page-head .sub { color: var(--text-dim); font-size: 13.5px; font-variant-numeric: tabular-nums; }

.toolbar {
  position: sticky; top: 56px; z-index: 20;
  display: flex; gap: 8px; align-items: center;
  max-width: 1000px; margin: 0 auto; padding: 10px 20px 14px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.search-input {
  flex: 1; height: 40px; padding: 0 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-input::placeholder { color: var(--text-faint); }
.search-input:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

/* 书架 */
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 22px 15px;
  max-width: 1000px; margin: 0 auto; padding: 6px 20px 90px;
}
.book-card { display: flex; flex-direction: column; gap: 7px; }
.book-card .cover { transition: transform .2s ease, box-shadow .2s ease; }
.book-card:hover .cover { transform: translateY(-4px); box-shadow: var(--card-shadow-h); }
.bc-meta { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.empty { grid-column: 1 / -1; padding: 60px 20px; text-align: center; color: var(--text-faint); font-size: 14px; }

/* ============ 阅读页 ============ */
.reader { min-height: 100dvh; display: flex; flex-direction: column; }

.reader-head {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.reader-head .title-mini {
  flex: 1; min-width: 0; font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim);
}

.reader-body {
  flex: 1; width: 100%; max-width: calc(var(--measure) + 40px);
  margin: 0 auto; padding: 30px 20px 140px;
}

.book-head {
  display: flex; gap: 18px; align-items: flex-start;
  padding-bottom: 22px; margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.book-cover { flex: none; width: 96px; }
.book-cover .cover { border-radius: 5px; }
.book-headtext { flex: 1; min-width: 0; }

.book-title {
  margin: 0 0 8px; font-family: var(--serif);
  font-size: clamp(22px, 4.6vw, 30px);
  line-height: 1.18; font-weight: 650; letter-spacing: -.025em;
}
.book-sub {
  display: flex; flex-wrap: wrap; gap: 5px 13px;
  color: var(--text-faint); font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.book-info {
  margin-bottom: 26px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; font-size: 13.5px; color: var(--text-dim);
}
.book-info summary {
  cursor: pointer; color: var(--text-dim); font-size: 13px;
  list-style: none; display: flex; align-items: center; gap: 6px;
}
.book-info summary::-webkit-details-marker { display: none; }
.book-info summary::before {
  content: "▸"; font-size: 10px; transition: transform .18s; display: inline-block;
}
.book-info[open] summary::before { transform: rotate(90deg); }
.book-info dl { margin: 12px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.book-info dt { color: var(--text-faint); font-size: 12.5px; }
.book-info dd { margin: 0; font-size: 13px; }

.prose {
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: var(--lh);
  color: var(--text);
  letter-spacing: .002em;
}
.prose p { margin: 0 0 1.15em; }
.prose p:last-child { margin-bottom: 0; }

.page-note {
  margin: 26px 0 0; padding: 12px 14px;
  border-left: 2px solid var(--border);
  color: var(--text-faint); font-size: 12.5px; font-family: var(--ui); line-height: 1.6;
}

.page-image {
  display: grid; place-items: center; gap: 10px;
  padding: 60px 20px; margin: 10px 0;
  border: 1px dashed var(--border); border-radius: 12px;
  color: var(--text-faint); font-size: 13px; font-family: var(--ui);
}
.page-image .glyph { font-size: 30px; opacity: .5; }

.pg-sep { border: 0; border-top: 1px solid var(--border); margin: 34px 0; }

/* 分页控件 */
.pager {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.pager-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 14px; color: var(--text-dim);
  transition: background .14s, color .14s, border-color .14s;
}
.pager-btn:hover:not(:disabled) { color: var(--text); border-color: var(--text-faint); }
.pager-btn:disabled { opacity: .35; cursor: default; }
.pager-btn svg { width: 16px; height: 16px; }
.pager-mid { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pager-count { font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.dots { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
.dots button {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border); transition: background .15s, transform .15s;
}
.dots button:hover { transform: scale(1.4); }
.dots button.on { background: var(--accent); }

.progress-line {
  position: fixed; top: 0; left: 0; height: 2px; z-index: 40;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 40%, #7C6BF0));
  transition: width .2s ease;
}

/* 设置面板 */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.34);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-backdrop.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 51;
  left: 50%; bottom: 0; transform: translate(-50%, 100%);
  width: min(480px, 100%); padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  background: var(--surface); border-radius: 18px 18px 0 0;
  border: 1px solid var(--border); border-bottom: 0;
  transition: transform .26s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -8px 40px -12px rgba(0,0,0,.3);
}
.sheet.on { transform: translate(-50%, 0); }
.sheet h3 {
  margin: 0 0 18px; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
}
.sheet-row { margin-bottom: 18px; }
.sheet-row > label {
  display: block; font-size: 12px; color: var(--text-faint);
  margin-bottom: 8px; letter-spacing: .02em;
}
.seg { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 10px; }
.seg button {
  flex: 1; height: 34px; border-radius: 7px;
  font-size: 13px; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.seg button.on {
  background: var(--surface); color: var(--text);
  font-weight: 550; box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

/* 搜索面板 */
.palette {
  position: fixed; inset: 0; z-index: 60;
  display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 16px 16px;
  background: rgba(0,0,0,.38);
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.palette.on { opacity: 1; pointer-events: auto; }
.palette-box {
  width: min(560px, 100%); max-height: 66vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 70px -20px rgba(0,0,0,.45);
  transform: translateY(-8px) scale(.99); transition: transform .18s;
}
.palette.on .palette-box { transform: none; }
.palette input {
  height: 52px; padding: 0 18px; border: 0; border-bottom: 1px solid var(--border);
  background: none; color: var(--text); font-size: 15px; outline: none;
}
.palette input::placeholder { color: var(--text-faint); }
.palette-results { overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px; border-radius: 9px; cursor: pointer;
}
.palette-item[aria-selected="true"], .palette-item:hover { background: var(--surface-2); }
.palette-item .mini-cover { flex: none; width: 26px; }
.palette-item .mini-cover .cover { border-radius: 2px; }
.palette-item .t {
  flex: 1; min-width: 0; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.palette-item .w { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.palette-empty { padding: 28px; text-align: center; color: var(--text-faint); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 12px);
  z-index: 70; padding: 9px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: sk 1.2s infinite;
  border-radius: 6px; color: transparent;
}
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 700px) {
  :root { --fs: 18px; --lh: 1.8; }
  .hero { padding: 34px 18px 24px; }
  .levels { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); padding: 0 18px 54px; }
  .level-card { min-height: 96px; }
  .level-card .lv-big { font-size: 48px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(102px, 1fr)); gap: 18px 11px; padding: 6px 18px 90px; }
  .bc-title { font-size: 11.5px; }
  .reader-body { padding: 22px 18px 150px; }
  .book-cover { width: 76px; }
  .pager { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .pager-btn { padding: 0 12px; font-size: 13px; }
  .pager-btn span { display: none; }
}

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

@media print {
  .topbar, .pager, .reader-head, .toolbar, .book-cover { display: none !important; }
  .reader-body { padding: 0; max-width: none; }
  .prose { font-size: 12pt; }
}
