:root {
  --bg: #f4ede1;
  --surface: #fbf7ef;
  --ink: #2a241c;
  --muted: #7b6f5f;
  --line: #e2d7c3;
  --accent: #9b2c1f;
  --accent-ink: #fff8ee;
  --track: #e2d7c3;
  --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;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16130f; --surface: #1f1b16; --ink: #e6dccb; --muted: #9a8e7c;
  --line: #2f2922; --accent: #d9735f; --accent-ink: #1a120c; --track: #3a332a;
  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; }
.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; }
.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 .mid { font-size: 13px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.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 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; }

.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: 4px; }
.pl-more button { display: flex; align-items: center; justify-content: center; gap: 5px; min-height: 36px; 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; }

/* 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%; }
.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); }
.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: 999px; font-size: 14px; z-index: 40; white-space: nowrap; }
