:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --text: #1f2328;
  --muted: #5d6470;
  --border: #e3e0d8;
  --accent: #2f6fdb;
  --accent-soft: #e6eefc;
  --ok: #1d8a4e;
  --ok-soft: #e3f4ea;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --danger: #c0392b;
  --danger-soft: #fbe7e4;
  --code-bg: #f5f3ee;
  --radius: 12px;
  --maxw: 760px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a; --surface: #1b1e23; --surface-2: #23272e; --text: #e6e6e3; --muted: #a0a7b2;
    --border: #2f343c; --accent: #7aa7ff; --accent-soft: #1e2a40; --ok: #4cc98a; --ok-soft: #16301f;
    --warn: #f0b04a; --warn-soft: #33270f; --danger: #ff7b6b; --danger-soft: #3a1c18; --code-bg: #1f2329;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161a; --surface: #1b1e23; --surface-2: #23272e; --text: #e6e6e3; --muted: #a0a7b2;
  --border: #2f343c; --accent: #7aa7ff; --accent-soft: #1e2a40; --ok: #4cc98a; --ok-soft: #16301f;
  --warn: #f0b04a; --warn-soft: #33270f; --danger: #ff7b6b; --danger-soft: #3a1c18; --code-bg: #1f2329;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 64px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px; line-height: 1.7;
}
a { color: var(--accent); }
img, svg { max-width: 100%; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: var(--maxw); margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.topbar .home { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
.topbar .crumb { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px;
  min-width: 40px; height: 40px; font-size: 18px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.progress-line { height: 3px; background: var(--accent); width: 0; transition: width .1s; }

main { max-width: var(--maxw); margin: 0 auto; padding: 16px 16px 80px; }
h1 { font-size: 28px; line-height: 1.25; margin: 12px 0 6px; }
h2 { font-size: 22px; line-height: 1.3; margin: 40px 0 10px; padding-top: 8px; border-top: 1px solid var(--border); }
h3 { font-size: 19px; margin: 28px 0 8px; }
h4 { font-size: 17px; margin: 20px 0 6px; }
p, ul, ol { margin: 10px 0; }
li { margin: 4px 0; }
.lead { color: var(--muted); font-size: 16px; }
strong { font-weight: 650; }
hr { border: 0; border-top: 1px solid var(--border); margin: 28px 0; }

/* Code */
code { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: .88em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
pre { position: relative; background: var(--code-bg) !important; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; overflow-x: auto; font-size: 14px; line-height: 1.55; margin: 12px 0; }
pre code { background: none; padding: 0; font-size: inherit; }
.copy-btn { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; opacity: .9; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 650; }
tr:last-child td { border-bottom: 0; }

/* Callouts */
.callout { border-radius: var(--radius); padding: 12px 14px; margin: 14px 0; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.callout > :first-child { margin-top: 0; } .callout > :last-child { margin-bottom: 0; }
.callout.tip { border-color: var(--ok); background: var(--ok-soft); }
.callout.warn { border-color: var(--warn); background: var(--warn-soft); }
.callout.danger { border-color: var(--danger); background: var(--danger-soft); }
.callout .title { font-weight: 700; display: block; margin-bottom: 4px; }
.tldr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 16px 0; }
.tldr::before { content: "Tóm tắt nhanh"; display: block; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin-bottom: 6px; }

/* Q&A flashcards */
details.qa { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin: 10px 0; }
details.qa summary { cursor: pointer; padding: 12px 14px; font-weight: 600; list-style: none; position: relative; padding-right: 36px; }
details.qa summary::-webkit-details-marker { display: none; }
details.qa summary::after { content: "+"; position: absolute; right: 14px; top: 10px; font-size: 20px; color: var(--muted); }
details.qa[open] summary::after { content: "−"; }
details.qa .answer { padding: 0 14px 12px; border-top: 1px dashed var(--border); }

/* TOC */
.toc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin: 16px 0; }
.toc summary { cursor: pointer; font-weight: 700; }
.toc ol { padding-left: 20px; margin: 8px 0 4px; }
.toc a { text-decoration: none; }

/* Home cards */
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; margin: 16px 0; }
@media (min-width: 640px) { .grid { grid-template-columns: 1fr 1fr; } }
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); position: relative; }
.card:hover { border-color: var(--accent); }
.card .num { font-size: 13px; color: var(--muted); font-weight: 600; }
.card .t { font-weight: 700; font-size: 17px; margin: 2px 0 4px; }
.card .d { color: var(--muted); font-size: 14px; line-height: 1.5; }
.card .badge { position: absolute; top: 12px; right: 12px; font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.card.done .badge { background: var(--ok-soft); color: var(--ok); }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-right: 4px; }
.prio-high { background: var(--danger-soft); color: var(--danger); }
.prio-mid { background: var(--warn-soft); color: var(--warn); }
.prio-low { background: var(--surface-2); color: var(--muted); }

/* Bottom nav */
.pager { display: flex; gap: 10px; margin-top: 40px; }
.pager a { flex: 1; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; text-decoration: none; background: var(--surface); font-size: 15px; }
.pager a.next { text-align: right; }
.pager small { display: block; color: var(--muted); }
.done-toggle { display: flex; align-items: center; gap: 10px; margin: 32px 0 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-weight: 600; cursor: pointer; }
.done-toggle input { width: 22px; height: 22px; accent-color: var(--ok); }

.overall { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--ok); width: 0; }

.to-top { position: fixed; right: 16px; bottom: 16px; z-index: 30; display: none; }

/* Prism tokens (theme-aware) */
.token.comment, .token.prolog { color: var(--muted); font-style: italic; }
.token.keyword, .token.boolean, .token.important { color: #a626a4; }
.token.string, .token.attr-value { color: #2e7d32; }
.token.number { color: #b35900; }
.token.function, .token.class-name { color: #2f6fdb; }
.token.key, .token.property, .token.attr-name, .token.atrule { color: #c0392b; }
.token.variable, .token.parameter { color: #b35900; }
.token.punctuation, .token.operator { color: var(--muted); }
:root[data-theme="dark"] .token.keyword { color: #d38bff; }
:root[data-theme="dark"] .token.string, :root[data-theme="dark"] .token.attr-value { color: #8fd18f; }
:root[data-theme="dark"] .token.number, :root[data-theme="dark"] .token.variable { color: #f0b04a; }
:root[data-theme="dark"] .token.function, :root[data-theme="dark"] .token.class-name { color: #7aa7ff; }
:root[data-theme="dark"] .token.key, :root[data-theme="dark"] .token.property, :root[data-theme="dark"] .token.attr-name { color: #ff8f80; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .token.keyword { color: #d38bff; }
  :root:not([data-theme="light"]) .token.string, :root:not([data-theme="light"]) .token.attr-value { color: #8fd18f; }
  :root:not([data-theme="light"]) .token.number, :root:not([data-theme="light"]) .token.variable { color: #f0b04a; }
  :root:not([data-theme="light"]) .token.function, :root:not([data-theme="light"]) .token.class-name { color: #7aa7ff; }
  :root:not([data-theme="light"]) .token.key, :root:not([data-theme="light"]) .token.property, :root:not([data-theme="light"]) .token.attr-name { color: #ff8f80; }
}

/* Diagrams (inline SVG, theme-aware) */
figure.diagram { margin: 16px 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 8px 6px; }
figure.diagram svg { display: block; width: 100%; max-width: 520px; height: auto; margin: 0 auto; font-family: inherit; }
figure.diagram figcaption { font-size: 14px; color: var(--muted); text-align: center; margin-top: 6px; line-height: 1.45; }
.diagram .n { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.2; }
.diagram .n-edge { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.2; }
.diagram .n-cloud { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 1.2; }
.diagram .n-warn { fill: var(--warn-soft); stroke: var(--warn); stroke-width: 1.2; }
.diagram .n-red { fill: var(--danger-soft); stroke: var(--danger); stroke-width: 1.2; }
.diagram .zone { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 6 4; }
.diagram .t { fill: var(--text); font-size: 13.5px; font-weight: 650; }
.diagram .s { fill: var(--muted); font-size: 11.5px; }
.diagram .z { fill: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: .04em; }
.diagram .ar { stroke: var(--muted); stroke-width: 1.6; fill: none; }
.diagram .ar-d { stroke: var(--muted); stroke-width: 1.6; fill: none; stroke-dasharray: 4 3; }
.diagram .head { fill: var(--muted); }
.diagram .num { fill: var(--accent); }
.diagram .numt { fill: #fff; font-size: 12px; font-weight: 700; }
.checklist li { list-style: none; margin-left: -18px; }
.checklist li::before { content: "☐ "; color: var(--muted); }
