:root {
  --cream: #faf6ee;
  --paper: #fffdf8;
  --ink: #2b2426;
  --muted: #7a6e70;
  --line: #eadfc8;
  --gold: #c9a13b;
  --gold-soft: #f3e6c0;
  --bordeaux: #b33753;
  --bg: var(--paper);
  --text: var(--ink);
  --chrome: rgba(255, 253, 248, .96);
  --fs: 19px;
  --reading: 'Literata', Georgia, serif;
  --ui: 'Montserrat', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="sepia"] { --bg: #f5ecd9; --text: #3b2f25; --muted: #85705c; --line: #e2d3b4; --chrome: rgba(245, 236, 217, .96); }
:root[data-theme="dark"] { --bg: #1b1718; --text: #e7ddd2; --muted: #a39690; --line: #3a3233; --chrome: rgba(27, 23, 24, .96); --gold-soft: #3d3222; }
:root[data-font="sans"] { --reading: 'Montserrat', system-ui, sans-serif; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { background: var(--cream); color: var(--ink); font-family: var(--ui); overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.screen { position: fixed; inset: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px; border-radius: 999px; font-weight: 700; font-size: 15px; text-decoration: none; transition: transform .15s ease, background .2s ease; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--bordeaux); color: #fff; box-shadow: 0 6px 18px rgba(179, 55, 83, .25); }
.btn-ghost { border: 1.5px solid var(--line); background: #fff; color: var(--ink); }
.icon-btn { min-width: 44px; min-height: 44px; padding: 0 10px; font-weight: 700; font-size: 16px; color: var(--text); }

/* ---------- gate ---------- */
#gate { display: grid; place-items: center; padding: 24px 16px; overflow: auto; }
.gate-card { max-width: 420px; text-align: center; }
.gate-cover { width: 170px; border-radius: 4px 10px 10px 4px; box-shadow: 0 18px 40px rgba(60, 40, 20, .25); }
.gate-card h1 { font-family: var(--reading); font-weight: 600; font-size: 26px; margin: 22px 0 10px; }
.gate-card p { font-size: 16px; line-height: 1.55; margin: 8px 0; }
.muted { color: var(--muted); }
.error { color: var(--bordeaux); font-weight: 600; }

/* ---------- home ---------- */
#home { overflow: auto; padding: calc(12px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); background:
  radial-gradient(1200px 500px at 50% -10%, #f7e7c9 0%, transparent 60%), var(--cream); }
.home-top { display: flex; justify-content: center; padding: 6px 0 14px; }
.home-logo { height: 46px; }
.home-main { display: flex; flex-direction: column; align-items: center; gap: 22px; max-width: 900px; margin: 0 auto; }
.home-cover { padding: 0; }
.home-cover img { width: min(58vw, 250px); display: block; border-radius: 3px 10px 10px 3px; box-shadow: 0 22px 45px rgba(60, 40, 20, .28), inset 0 0 0 1px rgba(0,0,0,.04); transition: transform .25s ease; }
.home-cover:active img { transform: scale(.98); }
.home-info { text-align: center; width: 100%; max-width: 440px; }
.kicker { text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 700; color: var(--gold); margin: 0 0 6px; }
.home-title { font-family: var(--reading); font-weight: 600; font-size: 24px; line-height: 1.25; margin: 0 0 6px; }
.home-authors { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.progress-line { height: 5px; background: var(--line); border-radius: 9px; overflow: hidden; }
.progress-line span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--bordeaux)); border-radius: 9px; transition: width .4s ease; }
.home-where { font-size: 13px; color: var(--muted); margin: 8px 0 18px; }
.home-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.home-actions .btn-primary { flex: 1 1 100%; }
.home-actions .btn-ghost { flex: 1 1 calc(50% - 5px); }
.lock { font-size: 13px; }
.install-tip { display: flex; align-items: center; gap: 12px; text-align: left; margin: 26px auto 0; max-width: 440px; width: 100%; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: 16px; font-size: 13.5px; line-height: 1.4; }
.install-tip img { width: 42px; height: 42px; border-radius: 10px; }

@media (min-width: 760px) {
  .home-main { flex-direction: row; justify-content: center; gap: 48px; margin-top: 40px; }
  .home-cover img { width: 280px; }
  .home-info { text-align: left; }
  .home-actions { justify-content: flex-start; }
}

/* ---------- reader ---------- */
#reader { background: var(--bg); color: var(--text); touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.bar { position: absolute; left: 0; right: 0; z-index: 5; background: var(--chrome); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: transform .25s ease, opacity .25s ease; }
.bar-top { top: 0; display: flex; align-items: center; gap: 6px; padding: var(--safe-top) 6px 0; height: calc(52px + var(--safe-top)); border-bottom: 1px solid var(--line); }
.bar-title { flex: 1; text-align: center; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-right { display: flex; }
.bar-bottom { bottom: 0; padding: 10px 18px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--line); }
.bar-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
#r-scrub { width: 100%; accent-color: var(--bordeaux); }
#reader.chrome-hidden .bar-top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
#reader.chrome-hidden .bar-bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.edge-meta { position: absolute; bottom: calc(14px + var(--safe-bottom)); left: 0; right: 0; padding: 0 var(--edge-mx, 22px); pointer-events: none; transition: opacity .25s ease; }
.edge-track { height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.edge-track span { display: block; height: 100%; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--gold), var(--bordeaux)); transition: width .3s ease; }
#edge-dbg { font-size: 10px; color: var(--muted); text-align: center; margin-top: 3px; }
#edge-dbg:empty { display: none; }
@media (min-width: 700px) { .edge-meta { --edge-mx: 56px; } }
#reader:not(.chrome-hidden) .edge-meta { opacity: 0; }

.pageview { position: absolute; top: calc(34px + var(--safe-top)); bottom: calc(34px + var(--safe-bottom)); left: var(--mx); right: var(--mx); overflow: hidden; --mx: 22px; --gap: 44px; }
.flow { height: 100%; column-fill: auto; will-change: transform;
  font-family: var(--reading); font-size: var(--fs); line-height: 1.62; hyphens: auto; -webkit-hyphens: auto; text-align: left; overflow-wrap: break-word; }
.flow.animate { transition: transform .32s cubic-bezier(.3, .7, .2, 1); }
@media (min-width: 700px) { .pageview { --mx: 56px; } }
@media (min-width: 900px) and (orientation: landscape) { .pageview { --mx: 64px; --gap: 80px; } }

.flow p { margin: 0 0 .8em; }
.flow .ch-head { break-inside: avoid; padding-top: 1.4em; margin-bottom: 1.6em; text-align: center; }
.flow .ch-kicker { font-family: var(--ui); text-transform: uppercase; letter-spacing: .14em; font-size: .62em; font-weight: 700; color: var(--gold); margin-bottom: .9em; }
.flow h2 { font-family: var(--reading); font-weight: 600; font-size: 1.42em; line-height: 1.25; margin: 0 0 .5em; }
.flow .ch-sub { font-style: italic; color: var(--muted); font-size: .92em; margin: 0; }
.flow .ch-crown { width: 34px; margin: 0 auto .9em; display: block; opacity: .9; }
.flow .plan-badge { display: inline-block; font-family: var(--ui); font-size: .6em; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--bordeaux); border: 1.5px solid currentColor; border-radius: 99px; padding: .3em .9em; margin-bottom: .9em; }
.flow .speaker { text-align: center; font-family: var(--ui); font-weight: 700; letter-spacing: .22em; font-size: .7em; color: var(--bordeaux); margin: 1.4em 0 1.1em; break-after: avoid; }
.flow .speaker::before, .flow .speaker::after { content: ''; display: inline-block; width: 26px; height: 1px; background: currentColor; vertical-align: middle; margin: 0 10px; opacity: .6; }
.flow .sep { text-align: center; color: var(--gold); margin: 1em 0; letter-spacing: .5em; }
.flow .heart { position: relative; padding-left: 1.5em; }
.flow .heart::before { content: '♥'; position: absolute; left: 0; top: 0; color: var(--bordeaux); font-size: .9em; }
.flow ol.li { margin: 0 0 .8em; padding-left: 1.6em; }
.flow ol.li li { margin: 0 0 .3em; }
.flow .q { font-weight: 600; font-style: italic; }
.flow .center { text-align: center; }
.flow figure { margin: 0 0 1em; break-inside: avoid; text-align: center; }
.flow figure img { max-width: 100%; max-height: calc(var(--page-h, 80vh) - 10px); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.flow .end-space { height: 1px; }

/* ---------- sheets & popovers ---------- */
.scrim { position: fixed; inset: 0; background: rgba(20, 12, 10, .35); z-index: 20; }
.sheet { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; max-height: 86vh; background: var(--paper); color: var(--ink); border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(0,0,0,.2); display: flex; flex-direction: column; padding-bottom: var(--safe-bottom); animation: up .28s ease; }
@media (min-width: 760px) { .sheet { left: auto; top: 0; bottom: 0; width: 420px; max-height: none; border-radius: 0; animation: side .28s ease; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes side { from { transform: translateX(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 8px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-family: var(--reading); font-size: 20px; margin: 0; }
.toc-list { list-style: none; margin: 0; padding: 6px 0 20px; overflow: auto; }
.toc-list button { display: flex; width: 100%; text-align: left; gap: 12px; align-items: baseline; padding: 11px 20px; font-size: 15px; line-height: 1.35; }
.toc-list .num { flex: 0 0 26px; font-weight: 800; color: var(--gold); font-size: 13px; }
.toc-list .plan button { padding-top: 4px; padding-left: 58px; font-size: 13.5px; color: var(--muted); }
.toc-list .plan .num { display: none; }
.toc-list .current > button { background: var(--gold-soft); font-weight: 700; }
.toc-list .done-mark { margin-left: auto; color: var(--gold); font-size: 12px; }

.popover { position: fixed; z-index: 30; top: calc(58px + var(--safe-top)); right: 10px; width: 270px; background: var(--paper); color: var(--ink); border-radius: 18px; box-shadow: 0 14px 40px rgba(0,0,0,.22); padding: 14px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 4px; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-btn { width: 64px; height: 42px; border-radius: 12px; border: 1.5px solid var(--line); font-family: 'Literata', serif; font-size: 15px; }
.set-btn.big { font-size: 24px; }
.set-size { font-size: 13px; color: var(--muted); }
.theme-dot { width: 54px; height: 42px; border-radius: 12px; border: 2px solid var(--line); }
.theme-dot[data-theme="light"] { background: #fffdf8; }
.theme-dot[data-theme="sepia"] { background: #f5ecd9; }
.theme-dot[data-theme="dark"] { background: #1b1718; }
.theme-dot.on, .set-font.on { border-color: var(--bordeaux); box-shadow: 0 0 0 2px rgba(179, 55, 83, .15); }
.set-font { flex: 1; height: 42px; border-radius: 12px; border: 2px solid var(--line); font-family: 'Literata', serif; font-size: 14px; }
.set-font.sans { font-family: 'Montserrat', sans-serif; }

.listen-card { padding: 26px 22px 30px; text-align: center; }
.listen-crown { width: 70px; }
.listen-card h3 { font-family: var(--reading); font-size: 22px; margin: 12px 0 8px; }
.listen-card p { line-height: 1.55; color: var(--muted); margin: 0 0 20px; }
.install-steps { margin: 0; padding: 16px 20px 26px 42px; line-height: 1.6; font-size: 16px; }
.install-steps li { margin-bottom: 10px; }
.share-ico { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: #eef3ff; color: #1a73e8; vertical-align: middle; }

/* ---------- front matter ---------- */
.flow .cover-page { height: calc(var(--page-h, 80vh) - 4px); margin: 0; display: grid; place-items: center; }
.flow .cover-page img { max-height: calc(var(--page-h, 80vh) - 12px); max-width: 100%; border-radius: 3px 10px 10px 3px; box-shadow: 0 16px 36px rgba(60, 40, 20, .25); }
.flow .title-page { min-height: calc(var(--page-h, 80vh) - 4px); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; break-inside: avoid; }
.flow .tp-name { font-family: var(--ui); font-weight: 800; letter-spacing: .12em; font-size: 1.7em; }
.flow .tp-sub { font-family: var(--reading); font-weight: 600; font-size: 1.15em; line-height: 1.3; margin: .6em 0 .4em; }
.flow .tp-tag { font-style: italic; color: var(--muted); }
.flow .tp-authors { margin-top: 2.2em; font-family: var(--ui); font-weight: 600; font-size: .78em; letter-spacing: .04em; }
.flow .copyright-page { font-size: .72em; line-height: 1.55; color: var(--muted); padding-top: 2em; }
.flow .copyright-page p:first-child { color: var(--text); font-weight: 600; }
.flow .cp-line { margin: 0; padding: .32em 0 .32em 2em; text-indent: -2em; font-size: .88em; line-height: 1.35; cursor: pointer; }
.flow .cp-line .num { display: inline-block; width: 2.353em; text-indent: 0; font-family: var(--ui); font-weight: 800; color: var(--gold); font-size: .85em; }
.flow .cp-line.plan { padding: 0 0 .45em 2.316em; text-indent: 0; font-size: .76em; color: var(--muted); }
