*, *::before, *::after { box-sizing: border-box; }

:root {
  --fs: 19px;
  --fg: #1f1f1f;
  --muted: #8a8a8a;
  --bg: #ffffff;
  --line: #e6e6e6;
  --accent: #2a6df4;
  --hover: rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e7e7e7;
    --muted: #979797;
    --bg: #191919;
    --line: #333333;
    --accent: #7aa7ff;
    --hover: rgba(255,255,255,.07);
  }
}

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.hidden { display: none; }
.wrap { max-width: 680px; margin: 0 auto; padding: 44px 20px 80px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }

/* ---------- trang chủ ---------- */
.home h1 { font-size: 30px; line-height: 1.3; margin: 0 0 6px; }
.home .author {
  margin: 0 0 22px; color: var(--muted);
  font-family: system-ui, -apple-system, sans-serif; font-size: 14px;
}
.home .intro { margin: 0; font-size: 16.5px; white-space: pre-line; }

.toc { list-style: none; margin: 0; padding: 0; }
.toc li + li { border-top: 1px solid var(--line); }
.toc a { display: flex; gap: 12px; padding: 13px 2px; font-size: 17px; }
.toc a:hover { text-decoration: none; color: var(--accent); }
.toc .num { min-width: 2.2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc .loading { padding: 13px 2px; }

/* ---------- trang đọc ---------- */
.bar {
  display: flex; align-items: center; gap: 8px;
  font-family: system-ui, -apple-system, sans-serif; font-size: 14px;
}
.bar.bottom { margin-top: 52px; padding-top: 18px; border-top: 1px solid var(--line); }
.reader h1 { font-size: 26px; line-height: 1.35; margin: 26px 0 30px; }
.reader article p { font-size: var(--fs); margin: 0 0 1.15em; text-align: justify; }

/* ---------- nút mở sidebar ---------- */
.tab {
  position: fixed; top: 50%; right: 0; transform: translateY(-50%); z-index: 10;
  padding: 12px 9px; cursor: pointer; line-height: 1; font-size: 15px;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); border-right: 0; border-radius: 6px 0 0 6px;
}
.tab:hover { color: var(--fg); }

/* ---------- sidebar ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.35);
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; z-index: 20;
  height: 100%; width: 320px; max-width: 86vw;
  display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--line);
  transform: translateX(101%); transition: transform .18s ease;
  font-family: system-ui, -apple-system, sans-serif;
}
.drawer.open { transform: none; }

.drawer header {
  display: flex; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.drawer header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.x { padding: 0; border: 0; background: none; cursor: pointer; font-size: 17px; line-height: 1; color: var(--muted); }
.x:hover { color: var(--fg); }

.font-row {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 18px; border-bottom: 1px solid var(--line);
  font-size: 13.5px; color: var(--muted);
}
.font-row button {
  width: 34px; height: 29px; cursor: pointer; font-size: 13px;
  background: none; color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px;
}
.font-row button:hover { background: var(--hover); }
.fval { min-width: 2em; text-align: center; font-variant-numeric: tabular-nums; }

.d-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.d-item {
  display: flex; gap: 10px; padding: 10px 18px;
  font-size: 14.5px; line-height: 1.45;
}
.d-item:hover { background: var(--hover); text-decoration: none; }
.d-item .num { min-width: 1.8em; color: var(--muted); font-variant-numeric: tabular-nums; }
.d-item.active { color: var(--accent); font-weight: 600; }
.d-item.active .num { color: inherit; }
