:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --text: #2a2723;
  --muted: #6f685e;
  --line: #e2dccf;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --door: #2f6fa3;
  --door-glow: #c0392b;
  --reader-size: 19px;
  --serif: "Literata", "Noto Serif", Georgia, serif;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1c1f23;
    --text: #dcd7cd;
    --muted: #8f897f;
    --line: #2c3036;
    --accent: #6fb0e0;
    --accent-ink: #0f1a24;
    --door: #3d82bb;
    --door-glow: #e05a47;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1c1f23;
  --text: #dcd7cd;
  --muted: #8f897f;
  --line: #2c3036;
  --accent: #6fb0e0;
  --accent-ink: #0f1a24;
  --door: #3d82bb;
  --door-glow: #e05a47;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  transition: background-color .2s, color .2s;
}

a { color: var(--accent); }

/* Thanh trên cùng */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--serif);
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings { display: flex; gap: 4px; flex-shrink: 0; }
.settings button {
  font: 500 14px/1 var(--sans);
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 38px;
  height: 34px;
  cursor: pointer;
}
.settings button:hover { border-color: var(--accent); color: var(--accent); }

/* Thanh tiến độ đọc */
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 6; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); }

/* Nút */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }

/* Trang chủ */
.cover {
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 16px 32px;
  text-align: center;
}
.door {
  width: 88px;
  height: 140px;
  margin: 0 auto 28px;
  border-radius: 6px 6px 2px 2px;
  background: var(--door);
  position: relative;
  box-shadow: inset 0 0 0 6px color-mix(in srgb, var(--door) 70%, #000);
}
.door::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 74px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d9c27a;
}
.door::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -10px;
  width: 140%;
  height: 10px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--door-glow) 55%, transparent), transparent 70%);
}
.door span {
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  font: 600 15px/1 var(--serif);
  color: color-mix(in srgb, #fff 75%, var(--door));
  letter-spacing: 1px;
}
.cover h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(32px, 7vw, 46px);
  line-height: 1.15;
  margin: 0 0 8px;
}
.author { color: var(--muted); margin: 0 0 8px; }
.blurb {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.7;
  color: var(--text);
  margin: 20px auto 28px;
  max-width: 34em;
}
.cta { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.toc { margin-top: 48px; text-align: left; }
.toc h2 {
  font: 600 13px/1 var(--sans);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin: 0;
}
.toc .count { font-weight: 400; text-transform: none; letter-spacing: 0; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: grid;
  grid-template-columns: 84px 1fr auto;
  align-items: baseline;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}
.toc a:hover .toc-name { color: var(--accent); }
.toc-num { color: var(--muted); font-size: 14px; }
.toc-name { font-family: var(--serif); font-size: 18px; }
.toc-time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.toc a.read .toc-num::after { content: " ✓"; color: var(--accent); }
.toc a.current { background: color-mix(in srgb, var(--accent) 8%, transparent); }

@media (max-width: 480px) {
  .toc a { grid-template-columns: 1fr auto; gap: 2px 12px; }
  .toc-num { grid-column: 1; }
  .toc-name { grid-column: 1; grid-row: 2; }
  .toc-time { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
}

/* Trang đọc */
.chapter {
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 16px 48px;
}
.chapter-head { text-align: center; margin-bottom: 40px; }
.kicker {
  font: 600 13px/1 var(--sans);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 12px;
}
.chapter-head h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(28px, 6vw, 38px);
  line-height: 1.2;
  margin: 0 0 10px;
}
.meta { color: var(--muted); font-size: 14px; margin: 0; }

.prose {
  font-family: var(--serif);
  font-size: var(--reader-size);
  line-height: 1.8;
  hyphens: auto;
  overflow-wrap: break-word;
}
.prose p { margin: 0 0 1em; }
.prose em { font-style: italic; }
hr.scene {
  border: 0;
  margin: 2.2em 0;
  text-align: center;
  height: 1em;
}
hr.scene::before {
  content: "⁂";
  color: var(--muted);
  font-size: 1.1em;
}

.to-be-continued {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  margin: 40px 0 0;
}

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.chapter-nav > :first-child { justify-self: start; }
.chapter-nav > :last-child { justify-self: end; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px 16px 40px;
}
