:root {
  --bg: #f4ede1;
  --surface: #fbf7ef;
  --ink: #2a241c;
  --muted: #7b6f5f;
  --line: #e2d7c3;
  --accent: #9b2c1f;
  --accent-ink: #fff8ee;
  --track: #e2d7c3;
  --danger: #b3261e;
  --serif: "Noto Serif", Georgia, "Times New Roman", serif;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs: 19px;
  --player-h: 0px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f; --surface: #1f1b16; --ink: #e6dccb; --muted: #9a8e7c;
    --line: #2f2922; --accent: #d9735f; --accent-ink: #1a120c; --track: #3a332a; --danger: #f2a093;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16130f; --surface: #1f1b16; --ink: #e6dccb; --muted: #9a8e7c;
  --line: #2f2922; --accent: #d9735f; --accent-ink: #1a120c; --track: #3a332a; --danger: #f2a093;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--player-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
main { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
.wrap { max-width: 680px; margin: 0 auto; padding: 0 16px; }

/* ---------- Muc luc ---------- */
.hero { padding: calc(36px + env(safe-area-inset-top)) 0 20px; text-align: center; }
.hero h1 { font-family: var(--serif); font-weight: 600; font-size: 30px; letter-spacing: .01em; margin: 0; text-wrap: balance; }
.hero .author { font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--accent); margin-top: 6px; }
.hero .tagline { font-family: var(--serif); font-style: italic; font-size: 16px; line-height: 1.7; color: var(--ink);
  margin: 18px auto 0; max-width: 320px; padding-top: 14px; border-top: 1px solid var(--line); }
.hero p { margin: 4px 0 0; color: var(--muted); font-size: 14px; letter-spacing: .08em; text-transform: uppercase; }
.seal { display: inline-block; width: 34px; height: 34px; border: 2px solid var(--accent); color: var(--accent);
  border-radius: 6px; font-family: var(--serif); font-weight: 600; line-height: 30px; margin-bottom: 12px; font-size: 15px; }

.resume { display: grid; gap: 10px; margin: 8px 0 20px; }
.card { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px; text-align: left; width: 100%; }
.card .ic { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; }
.card .ic svg { width: 20px; height: 20px; fill: currentColor; }
.card .ic.ghost { background: transparent; border: 1.5px solid var(--accent); color: var(--accent); }
.card small { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.card b { display: block; font-family: var(--serif); font-weight: 600; font-size: 16px; }
.card .sub { color: var(--muted); font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin: 0 0 14px; padding: 12px 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }
.stats b { display: block; font-family: var(--serif); font-weight: 600; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.ch-head .wc { color: var(--muted); font-size: 13px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.search { width: 100%; font: inherit; font-size: 16px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); margin-bottom: 8px; }
.search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.part { font-family: var(--serif); font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent);
  margin: 26px 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); min-height: 56px; }
.row .num { flex: none; width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.row .t { flex: 1; min-width: 0; }
.row .t b { display: block; font-family: var(--serif); font-weight: 400; font-size: 16.5px; line-height: 1.35; }
.row .meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.row .meta svg { width: 13px; height: 13px; fill: currentColor; vertical-align: -2px; }
.row .bar { height: 3px; background: var(--track); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.row .bar i { display: block; height: 100%; background: var(--accent); }
.row.done .num { color: var(--accent); }
.row.now b { color: var(--accent); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

/* ---------- Trang chuong ---------- */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; height: 50px; }
.top button, .top a { display: flex; align-items: center; gap: 4px; min-height: 44px; min-width: 44px; color: var(--muted); font-size: 15px; }
.top svg { width: 22px; height: 22px; fill: currentColor; }
.top .midnav { display: flex; align-items: center; gap: 2px; }
.top .midnav .arr { justify-content: center; width: 44px; color: var(--accent); }
.top .midnav .arr.off { visibility: hidden; }
.top .mid { font-size: 13px; color: var(--ink); letter-spacing: .06em; text-transform: uppercase; gap: 2px; padding: 0 4px; white-space: nowrap; }
.top .mid svg { width: 16px; height: 16px; color: var(--muted); }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--accent); width: 0; }

.ch-head { text-align: center; padding: 34px 0 10px; }
.ch-head .k { color: var(--accent); font-size: 13px; letter-spacing: .12em; text-transform: uppercase; }
.ch-head h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.25; margin: 6px 0 0; text-wrap: balance; }
.ch-head .pt { color: var(--muted); font-size: 13px; margin-top: 6px; }
.listen { display: inline-flex; align-items: center; gap: 8px; margin-top: 18px; padding: 10px 18px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 500; font-size: 15px; min-height: 44px; }
.listen svg { width: 18px; height: 18px; fill: currentColor; }
.listen.on { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }

.prose { font-family: var(--serif); font-size: var(--fs); line-height: 1.75; padding: 10px 0 20px; hyphens: auto; }
.prose p { margin: 0 0 1em; }
.prose blockquote { margin: 1.4em 0; text-align: center; color: var(--muted); font-size: .95em; line-height: 1.7; }
.prose blockquote p { margin: 0 0 .9em; }
.prose .lb { hyphens: manual; text-align: center; }
.prose .lb > span { display: block; }
.prose hr { border: 0; text-align: center; margin: 1.8em 0; }
.prose hr::after { content: "◆  ◆  ◆"; color: var(--muted); font-size: 10px; letter-spacing: .4em; }
.prose h3 { font-size: 1em; text-align: center; color: var(--accent); margin: 1.6em 0 1em; }

/* Chay chu theo audio */
.prose.synced .s { cursor: pointer; border-radius: 4px; transition: background-color .25s, box-shadow .25s; -webkit-tap-highlight-color: transparent; }
.prose .s.now { background: color-mix(in srgb, var(--accent) 26%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent); color: var(--ink);
  -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.prose blockquote .s.now { color: var(--ink); }
.jump { position: fixed; left: 50%; transform: translateX(-50%); z-index: 15;
  bottom: calc(var(--player-h) + 14px + env(safe-area-inset-bottom)); padding: 9px 16px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 500; box-shadow: 0 4px 14px rgba(0,0,0,.18); }

/* Giong may (thu nghiem) */
.listen.alt { display: inline-flex; margin: 8px 0 0; background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.prose.tts .s { cursor: pointer; border-radius: 4px; }
.prose .s.tts-now { background: color-mix(in srgb, var(--accent) 26%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent); color: var(--ink);
  -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.ttsbar { position: fixed; left: 50%; transform: translateX(-50%); z-index: 16; width: min(560px, calc(100% - 24px));
  bottom: calc(var(--player-h) + 10px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 6px 6px 6px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.ttsbar .tts-lbl { flex: 1; min-width: 0; line-height: 1.2; }
.ttsbar .tts-lbl b { display: block; font-size: 13px; color: var(--accent); }
.ttsbar .tts-lbl small { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ttsbar button { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); flex: none; }
.ttsbar button svg { width: 22px; height: 22px; fill: currentColor; }
.ttsbar .tts-play { background: var(--accent); color: var(--accent-ink); }
.ttsbar .tts-rate { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.jump { bottom: calc(var(--player-h) + var(--tts-h, 0px) + 14px + env(safe-area-inset-bottom)); }

.nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px 0 40px; }
.nav a { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 64px; }
.nav a small { display: block; color: var(--muted); font-size: 12px; }
.nav a span { font-family: var(--serif); font-size: 15px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a.next { text-align: right; grid-column: 2; }

/* ---------- Bang cai dat chu ---------- */
.sheet { position: fixed; inset: auto 0 0 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(0,0,0,.15); }
.sheet .wrap { padding: 0; display: grid; gap: 16px; }
.sheet .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; font-size: 15px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.scrim { position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.25); }

/* ---------- Trinh phat ---------- */
.player { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px rgba(0,0,0,.08); }
.player > * { max-width: 680px; margin-left: auto; margin-right: auto; }
.pl-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; height: 22px; }
.pl-title { flex: 1; font-family: var(--serif); font-size: 14.5px; line-height: 22px; height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pl-time { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
/* Thanh tua: cham hoac keo o bat ky dau (vung bam cao 32px cho de dung ngon tay) */
.pl-seek { position: relative; height: 32px; margin: 2px auto 0; touch-action: none; cursor: pointer; --p: 0%;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.pl-seek:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.pl-track { position: absolute; left: 0; right: 0; top: 14px; height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.pl-fill { height: 100%; width: var(--p); background: var(--accent); }
.pl-knob { position: absolute; top: 8px; left: var(--p); width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--accent);
  transition: transform .12s; }
.pl-seek.drag .pl-knob { transform: scale(1.4); }
.pl-ctrl { display: flex; justify-content: space-between; align-items: center; }
.pl-btn { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); position: relative; }
.pl-btn svg { width: 26px; height: 26px; fill: currentColor; }
.pl-btn svg text { font: 600 6.5px var(--sans); }
.pl-more { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 0; }
.pl-more button { display: flex; align-items: center; justify-content: center; gap: 5px; min-height: 44px; border-radius: 10px;
  font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pl-more button svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
.pl-more button.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pl-title.empty { color: var(--muted); font-style: italic; padding: 0; text-align: left; }

/* Danh sach chon chuong / nhac nen (bang truot tu duoi len) */
.sheet.tall { max-height: 78vh; display: flex; flex-direction: column; padding-left: 0; padding-right: 0; }
.sheet.tall .sh-head { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 10px; max-width: 680px; margin: 0 auto; width: 100%; }
.sheet.tall .sh-head b { font-family: var(--serif); font-size: 18px; }
.sheet.tall .sh-head button { color: var(--accent); min-height: 44px; padding: 0 4px; }
.sheet.tall .sh-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px; max-width: 680px; margin: 0 auto; width: 100%; }
.pk-top { position: sticky; top: 0; z-index: 1; background: var(--surface); padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.pk-top .seg { margin-bottom: 8px; }
.pk-jump { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.pk-jump::-webkit-scrollbar { display: none; }
.pk-jump button { flex: none; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pk-jump button.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 11px 4px; border-bottom: 1px solid var(--line); min-height: 52px; }
.pick .num { flex: none; width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.pick .t { flex: 1; min-width: 0; }
.pick .t b { display: block; font-family: var(--serif); font-weight: 400; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .t small { color: var(--muted); font-size: 12.5px; }
.pick.cur b { color: var(--accent); font-weight: 600; }
.pick .eq { flex: none; width: 18px; height: 18px; fill: var(--accent); }
.bgseek { display: flex; align-items: center; gap: 8px; padding-top: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bgseek .bgbar { flex: 1; margin: 0; }
.bgseek button { min-width: 44px; min-height: 44px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--ink); }
.vol { display: flex; align-items: center; gap: 12px; padding: 14px 0 6px; }
.vol svg { width: 20px; height: 20px; fill: var(--muted); flex: none; }
.vol input { flex: 1; accent-color: var(--accent); }
.note { color: var(--muted); font-size: 13px; padding: 12px 4px 4px; line-height: 1.5; }
.row-wrap { position: relative; }
.row-play { position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; display: grid; place-items: center;
  color: var(--accent); border-radius: 50%; }
.row-play svg { width: 22px; height: 22px; fill: currentColor; }
.row-wrap .row { padding-right: 48px; }
.pl-play { width: 56px; height: 56px; background: var(--accent); color: var(--accent-ink); }
.pl-play svg { width: 28px; height: 28px; }
.pl-play .i-pause, .player.playing .i-play { display: none; }
.player.playing .i-pause { display: block; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--player-h) + 20px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 18px; font-size: 14px; z-index: 40;
  max-width: calc(100% - 32px); width: max-content; text-align: center; }

/* Ngoai truyen (muc khoa) */
.nt { margin: 34px 0 10px; }
.nt-lock { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 auto; padding: 10px 18px; min-height: 44px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 14px; }
.nt-lock svg { width: 16px; height: 16px; fill: currentColor; }
.nt-lock.off { margin-top: 18px; border: 0; font-size: 13px; text-decoration: underline; }
.unlock { display: grid; gap: 12px; padding: 8px 4px 24px; }
.unlock p { margin: 0; color: var(--muted); }
.unlock input { font: inherit; font-size: 18px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface, var(--bg)); color: var(--ink); letter-spacing: .2em; }
.unlock button { padding: 12px; min-height: 44px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.unlock button:disabled { opacity: .6; }
.unlock .err { color: var(--danger); }
/* Ngoai truyen: moi phan la 1 muc thu gon duoc */
.ntp { border-bottom: 1px solid var(--line); }
.ntp summary { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 2px; cursor: pointer; list-style: none; }
.ntp summary::-webkit-details-marker { display: none; }
.ntp summary .t { flex: 1; min-width: 0; }
.ntp summary b { display: block; font-family: var(--serif); font-weight: 600; font-size: 17px; }
.ntp summary small { display: block; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.ntp .chev { flex: none; width: 22px; height: 22px; fill: var(--muted); transition: transform .2s; }
.ntp[open] .chev { transform: rotate(180deg); }
.ntp[open] summary b { color: var(--accent); }
.ntp .list { margin-bottom: 8px; }
.ntp .list li:last-child .row { border-bottom: 0; }
/* Ten arc o goc viet hoa khong deu -> hien dong nhat nhu tieu de quyen */
#toc .ntp summary b { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; }
