:root { --fs: 1.125rem; --lh: 1.7; --font: "Be Vietnam Pro", "Inter", -apple-system, system-ui, sans-serif; }
html[data-theme="sepia"] { --bg: #f8f5ef; --fg: #1f1d17; --head: #1f1d17; --btn: #e8ddc4; --btn-fg: #1f1d17; --glass: rgba(248,245,239,.92); --line: rgba(0,0,0,.14); --field: #fffaf0; --mark: #ffeaa1; --mark-line: #d9b441; --mark-fg: #1f1d17; color-scheme: light; }
html[data-theme="paper"] { --bg: #ffffff; --fg: #202124; --head: #111; --btn: #eceef1; --btn-fg: #202124; --glass: rgba(255,255,255,.92); --line: rgba(0,0,0,.12); --field: #f7f8fa; --mark: #fff0b3; --mark-line: #d9b441; --mark-fg: #202124; color-scheme: light; }
html[data-theme="green"] { --bg: #dfeadb; --fg: #1d2a1e; --head: #16231a; --btn: #c6d8c1; --btn-fg: #1d2a1e; --glass: rgba(223,234,219,.92); --line: rgba(0,0,0,.14); --field: #eef5ea; --mark: #f4e7a0; --mark-line: #b9a437; --mark-fg: #1d2a1e; color-scheme: light; }
html[data-theme="dusk"] { --bg: #2b2a33; --fg: #d9d6cf; --head: #eeeae0; --btn: #3c3a47; --btn-fg: #eeeae0; --glass: rgba(43,42,51,.92); --line: rgba(255,255,255,.13); --field: #35333f; --mark: #52461f; --mark-line: #d9b441; --mark-fg: #fff8d8; color-scheme: dark; }
html[data-theme="dark"] { --bg: #14110d; --fg: #e8e2d1; --head: #f2e9ce; --btn: #2a2418; --btn-fg: #f2e9ce; --glass: rgba(20,17,13,.92); --line: #3a3225; --field: #2a2418; --mark: #3a2f12; --mark-line: #f2c14a; --mark-fg: #fff8d8; color-scheme: dark; }
html[data-theme="black"] { --bg: #000; --fg: #b9b4a7; --head: #d8d2c2; --btn: #1a1814; --btn-fg: #d8d2c2; --glass: rgba(0,0,0,.92); --line: #2a2720; --field: #1a1814; --mark: #2e2610; --mark-line: #b8923a; --mark-fg: #eadfb8; color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; background: var(--bg); }
body {
  max-width: 760px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 1rem) 1rem calc(env(safe-area-inset-bottom) + 5rem);
  font-family: var(--font); line-height: 1.6;
  background: var(--bg); color: var(--fg); overflow-wrap: break-word;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { text-align: center; font-size: 1.35em; color: var(--head); margin: 1rem 0 .25rem; }
.meta { text-align: center; font-size: .85em; opacity: .68; margin-bottom: 1.25rem; }
.muted { opacity: .62; }
.center { text-align: center; padding: 2.5rem 0; }

.card { display: block; width: 100%; text-align: left; padding: 1rem; margin: .6rem 0; border-radius: 10px; background: var(--btn); color: var(--btn-fg); border: 0; }
.card b { display: block; font-size: 1.08rem; }
.card span { font-size: .85rem; opacity: .72; }

.login { max-width: 360px; margin: 18vh auto 0; }
.field { width: 100%; padding: .6rem .75rem; border-radius: 8px; border: 1px solid var(--line); background: var(--field); font-size: 1rem; }
.primary { width: 100%; margin-top: .7rem; padding: .7rem; border: 0; border-radius: 8px; background: var(--btn); color: var(--btn-fg); font-weight: 700; }
.error { color: #c0392b; font-size: .9rem; margin-top: .6rem; }

.jump-bar { position: sticky; top: 0; z-index: 50; margin: 0 -1rem 1rem; padding: calc(env(safe-area-inset-top) + .55rem) 1rem .55rem; background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); display: flex; gap: .5rem; flex-wrap: wrap; }
.jump-bar .field { flex: 1 1 100%; font-size: 1rem; padding: .45rem .7rem; }
.chip { flex: 1; padding: .45rem .5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--btn); color: var(--btn-fg); font-weight: 600; font-size: .86rem; white-space: nowrap; }
.chip.on { outline: 2px solid var(--mark-line); outline-offset: -2px; }

ul.toc { padding: 0; list-style: none; margin: 0; }
ul.toc li { margin: .15rem 0; border-radius: 6px; }
ul.toc a { display: block; padding: .42rem .5rem; }
.last-read { background: var(--mark); color: var(--mark-fg); box-shadow: 0 0 0 2px var(--mark-line) inset; }
.badge { display: inline-block; font-size: .72em; padding: .05rem .45rem; border-radius: 999px; background: var(--mark-line); color: #1f1d17; margin-left: .4rem; font-weight: 600; }

.nav { display: flex; justify-content: space-between; gap: .5rem; margin: 1rem 0; }
.nav a { flex: 1; min-width: 80px; text-align: center; padding: .7rem .5rem; border-radius: 8px; background: var(--btn); color: var(--btn-fg); font-weight: 600; }
.nav a.disabled { opacity: .35; pointer-events: none; }
.nav a.index { flex: 0 1 auto; padding-inline: 1rem; }

#text { font-size: var(--fs); line-height: var(--lh); font-family: var(--reader-font, var(--font)); }
#text h1 { border-bottom: 1px solid var(--line); padding-bottom: .6rem; margin: 1rem 0 1.25rem; }
#text p { margin: 0 0 1em; text-indent: 1.5em; border-radius: 4px; }
#text p.here { background: var(--mark); color: var(--mark-fg); box-shadow: -.4rem 0 0 var(--mark), .4rem 0 0 var(--mark); transition: background 1.2s; }
mark { background: var(--mark-line); color: #1f1d17; border-radius: 2px; padding: 0 .08em; }

.fs-ctrl { position: fixed; right: 1rem; bottom: calc(env(safe-area-inset-bottom) + 1rem); z-index: 100; display: flex; gap: .35rem; padding: .3rem; border-radius: 999px; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.fs-ctrl button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--btn); color: var(--btn-fg); font-weight: 700; }
.fs-ctrl button:active { transform: scale(.9); }

.result { display: block; padding: .7rem .2rem; border-bottom: 1px solid var(--line); }
.result small { display: block; font-weight: 600; margin-bottom: .2rem; }
.answer { padding: .85rem 1rem; border-radius: 10px; background: var(--btn); color: var(--btn-fg); white-space: pre-wrap; margin-bottom: 1rem; }
.answer a { text-decoration: underline; font-weight: 600; }

.sheet { position: fixed; inset: auto 0 0 0; z-index: 200; max-width: 760px; margin: 0 auto; padding: 1rem 1rem calc(env(safe-area-inset-bottom) + 1rem); background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.28); }
.sheet h3 { margin: .7rem 0 .4rem; font-size: .85rem; opacity: .7; }
.row { display: flex; gap: .4rem; }
.swatch { flex: 1; height: 42px; border-radius: 8px; border: 1px solid var(--line); font-weight: 700; }
.swatch.on { outline: 2px solid var(--mark-line); outline-offset: 1px; }

/* Chế độ sách: lật trang ngang bằng CSS columns. */
body.paged { overflow: hidden; height: 100dvh; padding-bottom: 0; }
body.paged .nav, body.paged .fs-ctrl { display: none; }
#pager { display: none; position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + .3rem); text-align: center; font-size: .75rem; opacity: .55; }
body.paged #pager { display: block; }
body.paged #viewport { overflow: hidden; height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 3rem); }
body.paged #text { height: 100%; column-gap: 2rem; column-fill: auto; transition: transform .22s ease; }
body.paged #text.instant { transition: none; }
body.paged #text p { text-align: justify; hyphens: auto; }
