/* AI Canuc80k — giao diện tài liệu. Phông chữ đi kèm: xem fonts/OFL.txt */
@font-face { font-family: "Lora"; src: url("fonts/lora.woff") format("woff"); font-weight: 400 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Lora"; src: url("fonts/lora-italic.woff") format("woff"); font-weight: 400 700; font-style: italic; font-display: swap; }
@font-face { font-family: "Lora"; src: url("fonts/inter-400.woff") format("woff"); font-weight: 400 700; unicode-range: U+2190-21FF; font-display: swap; }
@font-face { font-family: "Inter"; src: url("fonts/inter-400.woff") format("woff"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Inter"; src: url("fonts/inter-600.woff") format("woff"); font-weight: 500 700; font-style: normal; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono.woff") format("woff"); font-weight: 400; font-style: normal; font-display: swap; }

:root {
  color-scheme: light;
  --serif: "Lora", "Iowan Old Style", Cambria, Georgia, serif;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, ui-monospace, monospace;

  --bg: #faf9f5;
  --bg-side: #f4f2ea;
  --surface: #ffffff;
  --hover: #efece3;
  --active: #e8e4d8;
  --line: #e6e2d6;
  --line-strong: #d3cebf;
  --text: #1f1e1c;
  --text-2: #3d3c38;
  --muted: #73716a;
  --faint: #a19e94;
  --accent: #c2603e;
  --accent-strong: #a64f30;
  --accent-soft: #f5e6dd;
  --accent-ink: #9a4528;
  --ok: #5d7a4c;
  --code-bg: #f3f0e7;
  --code-head: #ebe7dc;
  --code-text: #2b2a27;
  --t-k: #9a4528;
  --t-s: #4d7337;
  --t-n: #2f6587;
  --t-c: #8d8a80;
  --shadow: 0 1px 2px rgba(31, 30, 28, .05), 0 6px 24px rgba(31, 30, 28, .07);
  --side-w: 288px;
  --top-h: 56px;
  --radius: 10px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #262624;
  --bg-side: #1f1e1d;
  --surface: #30302e;
  --hover: #2f2e2b;
  --active: #393834;
  --line: #3a3935;
  --line-strong: #4a4944;
  --text: #f2f0e9;
  --text-2: #d8d5cb;
  --muted: #a5a299;
  --faint: #7c7970;
  --accent: #d97757;
  --accent-strong: #e58b6d;
  --accent-soft: rgba(217, 119, 87, .14);
  --accent-ink: #eb9a7e;
  --ok: #9dba86;
  --code-bg: #1f1e1d;
  --code-head: #2a2927;
  --code-text: #e6e3da;
  --t-k: #eb9a7e;
  --t-s: #a9c48f;
  --t-n: #8fbad8;
  --t-c: #8a877e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #262624; --bg-side: #1f1e1d; --surface: #30302e; --hover: #2f2e2b; --active: #393834;
    --line: #3a3935; --line-strong: #4a4944; --text: #f2f0e9; --text-2: #d8d5cb; --muted: #a5a299; --faint: #7c7970;
    --accent: #d97757; --accent-strong: #e58b6d; --accent-soft: rgba(217, 119, 87, .14); --accent-ink: #eb9a7e; --ok: #9dba86;
    --code-bg: #1f1e1d; --code-head: #2a2927; --code-text: #e6e3da;
    --t-k: #eb9a7e; --t-s: #a9c48f; --t-n: #8fbad8; --t-c: #8a877e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 72px); overscroll-behavior-x: none; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: fixed; left: 12px; top: -48px; z-index: 50; padding: 8px 12px; background: var(--text); color: var(--bg); border-radius: 8px; }
.skip:focus { top: 12px; }

/* ---------- sidebar ---------- */
.side { position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 30; display: flex; flex-direction: column; background: var(--bg-side); border-right: 1px solid var(--line); }
.side-head { display: flex; align-items: center; gap: 4px; height: var(--top-h); padding: 0 14px 0 20px; flex: none; }
.wordmark { display: inline-flex; align-items: baseline; gap: 8px; font: 600 19px/1 var(--serif); letter-spacing: -.01em; color: var(--text); }
.wordmark-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--accent); transform: translateY(-1px); }
.wordmark-sub { font: 500 11px/1 var(--sans); letter-spacing: .08em; color: var(--muted); }
.icon-btn.side-close { display: none; }
.side-nav { display: grid; gap: 1px; padding: 6px 10px 10px; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; font-size: 14px; }
.side-link .i { color: var(--muted); }
.side-link:hover { background: var(--hover); }
.side-link.is-active { background: var(--active); color: var(--text); }
.side-link.is-active .i { color: var(--text); }
.side-scroll { flex: 1; overflow-y: auto; padding: 8px 10px 16px; border-top: 1px solid var(--line); scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.side-label { padding: 14px 10px 6px; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-group { margin: 1px 0; }
.side-phase { width: 100%; display: grid; grid-template-columns: 18px minmax(0, 1fr) 14px; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; border: 0; border-radius: 8px; background: transparent; font-size: 14px; text-align: left; color: var(--text-2); cursor: pointer; }
.side-phase:hover { background: var(--hover); }
.side-phase > .i { width: 14px; height: 14px; color: var(--faint); opacity: 0; transition: transform .2s ease, opacity .15s; }
.side-phase:hover > .i, .side-phase:focus-visible > .i, .side-phase[aria-expanded="true"] > .i { opacity: 1; }
.side-phase[aria-expanded="true"] > .i { transform: rotate(90deg); }
.side-phase[aria-expanded="true"] { color: var(--text); }
.side-group.is-current > .side-phase { color: var(--text); font-weight: 500; }
.side-phase-num { font: 500 13px/1 var(--serif); color: var(--faint); text-align: center; }
.side-group.is-current .side-phase-num { color: var(--accent); }
.side-phase-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-phase-count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; font-weight: 400; }
.side-lessons { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .22s ease; }
.side-lessons[data-open="true"] { grid-template-rows: 1fr; }
.side-lessons-inner { min-height: 0; overflow: hidden; margin-left: 19px; padding-left: 10px; border-left: 1px solid var(--line-strong); display: grid; gap: 1px; align-content: start; }
.side-lessons[data-open="true"] .side-lessons-inner { padding-top: 2px; padding-bottom: 8px; }
.side-lessons[data-open="false"] .side-lessons-inner { visibility: hidden; transition: visibility 0s .22s; }
.side-overview { padding: 5px 8px; border-radius: 6px; font-size: 13px; color: var(--muted); }
.side-overview:hover { background: var(--hover); color: var(--text-2); }
.side-overview.is-active { background: var(--active); color: var(--text); font-weight: 500; }
.side-lesson { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 4px; align-items: center; padding: 5px 8px; border-radius: 6px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.side-lesson:hover { background: var(--hover); color: var(--text-2); }
.side-lesson.is-active { background: var(--active); color: var(--text); font-weight: 500; }
.side-lesson-id { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; font-weight: 400; }
.side-lesson-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-lesson-done { color: var(--ok); display: inline-flex; }
.side-lesson-done .i { width: 14px; height: 14px; }
.side-foot { flex: none; padding: 12px 20px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.side-foot a { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.side-foot a:hover { color: var(--text); }
.side-foot .i { width: 13px; height: 13px; }
.scrim { display: none; }

/* ---------- top bar ---------- */
.shell { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; height: var(--top-h); padding: 0 24px 0 32px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.icon-btn.menu-btn { display: none; }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.crumbs a:hover { color: var(--text); }
.crumbs [aria-current] { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.crumb-sep { color: var(--faint); }
.top-tools { display: flex; align-items: center; gap: 10px; }
.search { position: relative; }
.search-box { display: flex; align-items: center; gap: 8px; width: 260px; height: 34px; padding: 0 8px 0 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--muted); transition: border-color .15s; }
.search-box:focus-within { border-color: var(--line-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: 14px var(--sans); }
.search-box input::placeholder { color: var(--faint); }
.search-box input::-webkit-search-cancel-button { display: none; }
kbd { font: 500 11px/1 var(--sans); color: var(--faint); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; }
.search-pop { position: absolute; right: 0; top: calc(100% + 6px); width: 340px; max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: none; }
.search-pop:not(:empty) { display: block; }
.hit { display: grid; grid-template-columns: 36px 1fr; gap: 6px; padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.hit:hover, .hit:focus-visible { background: var(--hover); }
.hit-none { margin: 0; padding: 10px; color: var(--muted); font-size: 14px; }
.top-progress { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; padding: 0 4px; }
.top-progress span { color: var(--faint); }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn .i { width: 18px; height: 18px; }

/* ---------- page frame ---------- */
.main { flex: 1; outline: 0; }
.page { width: 100%; max-width: 820px; margin: 0 auto; padding: 56px 32px 40px; }
.page-wide { max-width: 1080px; }
.kicker { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.kicker a { color: var(--accent-ink); }
.kicker a:hover { text-decoration: underline; text-underline-offset: 3px; }
.kicker-sep { margin: 0 8px; color: var(--faint); }
h1, h2, h3 { text-wrap: balance; }
.hero h1, .page-head h1, .lesson-head h1 { margin: 0; font: 500 40px/1.15 var(--serif); letter-spacing: -.015em; color: var(--text); }
.hero h1 { font-size: 46px; }
.lead { margin: 14px 0 0; max-width: 62ch; font-size: 17px; line-height: 1.6; color: var(--text-2); text-wrap: pretty; }
.page-head { margin-bottom: 32px; }
.page-meta { display: flex; align-items: center; gap: 14px; margin: 18px 0 0; font-size: 13px; color: var(--muted); }
.meter { display: inline-block; width: 64px; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; vertical-align: middle; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.block { margin-top: 48px; }
.block-title { margin: 0 0 14px; font: 500 22px/1.3 var(--serif); color: var(--text); }
.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--hover); }
.btn .i { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.page-head .actions { margin: 22px 0 0; }
.foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 72px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--faint); }
.foot nav { display: flex; gap: 18px; }
.foot a:hover { color: var(--text); }
.empty { padding: 48px 0; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 16px; }

/* ---------- home ---------- */
.hero { padding: 24px 0 8px; }
.resume { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 16px; margin-top: 36px; padding: 16px 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.resume:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.resume-label { font-size: 13px; font-weight: 500; color: var(--accent-ink); }
.resume-title { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume-id { margin-right: 10px; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.resume-meta { font-size: 13px; color: var(--muted); }
.resume > .i { color: var(--muted); }
.phases { border-top: 1px solid var(--line); }
.phase { display: grid; grid-template-columns: 44px 1fr auto; gap: 16px; align-items: start; padding: 20px 8px 20px 4px; border-bottom: 1px solid var(--line); transition: background .15s; border-radius: 0; }
.phase:hover { background: color-mix(in srgb, var(--hover) 60%, transparent); }
.phase-num { font: 400 30px/1 var(--serif); color: var(--faint); padding-top: 2px; text-align: center; transition: color .15s; }
.phase:hover .phase-num { color: var(--accent); }
.phase-body { display: grid; gap: 4px; }
.phase-title { font: 500 19px/1.35 var(--serif); color: var(--text); }
.phase-text { font-size: 14px; color: var(--muted); }
.phase-meta { display: grid; justify-items: end; gap: 6px; padding-top: 4px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.phase-progress { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.phase-progress .meter { width: 48px; }

/* ---------- lesson rows ---------- */
.rows { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: start; padding: 16px 8px 16px 4px; border-bottom: 1px solid var(--line); }
.row:hover { background: color-mix(in srgb, var(--hover) 60%, transparent); }
.row-id { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 1px; }
.row-body { display: grid; gap: 3px; min-width: 0; }
.row-title { font-weight: 500; font-size: 16px; color: var(--text); }
.row-text { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.row-end { display: inline-flex; align-items: center; gap: 8px; padding-top: 3px; color: var(--faint); }
.row-end > .i { opacity: 0; transform: translateX(-4px); transition: opacity .15s, transform .15s; }
.row:hover .row-end > .i { opacity: 1; transform: none; color: var(--muted); }
.row-done { color: var(--ok); display: inline-flex; }

/* ---------- pager ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 56px; }
.pager-link { display: grid; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; min-width: 0; transition: border-color .15s, background .15s; }
.pager-link:hover { border-color: var(--line-strong); background: var(--surface); }
.pager-link small { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.pager-link small .i { width: 14px; height: 14px; }
.pager-link span { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager-link.is-next { text-align: right; justify-items: end; }

/* ---------- lesson ---------- */
.lesson-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 24px; margin-bottom: 28px; }
.lesson-head .kicker, .lesson-head .lead { grid-column: 1 / -1; }
.lesson-head h1 { font-size: 38px; }
.mark { justify-self: end; align-self: start; display: inline-flex; align-items: center; gap: 7px; height: 34px; margin-top: 6px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.mark:hover { background: var(--hover); }
.mark.is-done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 9%, transparent); }
.tabs { position: sticky; top: var(--top-h); z-index: 15; display: flex; gap: 4px; margin: 0 0 32px; border-bottom: 1px solid var(--line); background: var(--bg); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; padding: 10px 12px 12px; font-size: 14px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); }
.tab.is-active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }

.learn { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 56px; align-items: start; }
.toc { position: sticky; top: calc(var(--top-h) + 76px); display: grid; gap: 2px; font-size: 13px; }
.toc-title { margin: 0 0 6px; font-weight: 500; color: var(--text-2); }
.toc a { padding: 4px 0 4px 12px; border-left: 1px solid var(--line); color: var(--muted); }
.toc a:hover { color: var(--text); }
.toc a.is-active { color: var(--text); border-left-color: var(--accent); font-weight: 500; }
.toc a { transition: color .15s, border-color .15s; }

/* long-form reading */
.prose { max-width: 70ch; font: 17px/1.75 var(--serif); color: var(--text-2); }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1em; }
.prose .hook { margin: 0 0 2em; padding-left: 18px; border-left: 2px solid var(--accent); font-size: 20px; line-height: 1.55; font-style: italic; color: var(--text); }
.prose h2 { margin: 2.2em 0 .6em; font: 500 24px/1.3 var(--serif); color: var(--text); letter-spacing: -.005em; }
.prose h3 { margin: 1.8em 0 .5em; font: 600 15px/1.4 var(--sans); color: var(--text); }
.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 1.3em; }
.prose li { margin: .35em 0; padding-left: .2em; }
.prose li::marker { color: var(--faint); }
.prose a { color: var(--accent-ink); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; }
.prose a:hover { text-decoration-color: currentColor; }
.prose .note { margin: 1.4em 0; padding: 2px 0 2px 16px; border-left: 2px solid var(--line-strong); font: 15px/1.6 var(--sans); color: var(--text-2); }
.prose pre, .doc pre, .output pre { margin: 1.2em 0; padding: 14px 16px; border-radius: 10px; background: var(--code-bg); color: var(--code-text); font: 13.5px/1.65 var(--mono); overflow-x: auto; tab-size: 4; }
.prose code, .doc code { font: .88em var(--mono); }
.prose :not(pre) > code, .doc :not(pre) > code, .quiz :not(pre) > code { overflow-wrap: anywhere; }
.prose details { margin: -0.4em 0 1.4em; }
.prose summary, .disclosure summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font: 500 14px var(--sans); color: var(--accent-ink); list-style: none; }
.prose summary::-webkit-details-marker, .disclosure summary::-webkit-details-marker { display: none; }
.prose summary::before, .disclosure summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin-right: 2px; }
.prose details[open] summary::before, .disclosure[open] summary::before { transform: rotate(45deg); }
.prose details pre { margin-top: .6em; }
.table-wrap { margin: 1.2em 0 1.6em; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.prose table { width: 100%; border-collapse: collapse; font: 14px/1.55 var(--sans); }
.prose th { text-align: left; font-weight: 500; color: var(--muted); background: var(--bg-side); }
.prose th, .prose td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose tr:last-child td { border-bottom: 0; }
.prose td:first-child { white-space: nowrap; color: var(--text); font-weight: 500; }
/* Lý thuyết: công thức KaTeX và hình SVG (màu theo currentColor nên tự hợp nền tối) */
.theory .katex { font-size: 1.08em; }
.theory .hook { font-style: normal; font-size: 18.5px; line-height: 1.65; color: var(--text); }
.theory td:first-child { white-space: normal; min-width: 7.5em; }
.theory td, .theory th { min-width: 6em; }
.theory .katex-display { margin: 1.4em 0; padding: 4px 0; overflow-x: auto; overflow-y: hidden; }
.theory .katex-display > .katex { font-size: 1.12em; }
.theory strong { font-weight: 600; color: var(--text); }
.theory ol > li::marker { color: var(--muted); font: 500 .9em var(--sans); }
.theory td .katex { font-size: 1em; }
.fig { margin: 2em 0; text-align: center; }
.fig svg { display: block; max-width: 100%; height: auto; margin: 0 auto; color: var(--text); }
.fig svg * { stroke-linejoin: round; stroke-linecap: round; }
.fig figcaption { max-width: 58ch; margin: .8em auto 0; font: 16px/1.5 var(--serif); color: var(--muted); text-align: center; }
/* Bài giảng: mỗi mục một nhịp, phần đặc biệt có nền riêng (giữ tiết chế) */
.theory .t-sec > h2 { padding-top: 1.3em; border-top: 1px solid var(--line); }
.theory > .t-sec:first-of-type > h2 { border-top: 0; padding-top: 0; }
.theory .t-sec.is-example, .theory .t-sec.is-exam, .theory .t-sec.is-summary { margin: 2.6em -24px 0; padding: 4px 24px 12px; border-radius: 14px; background: var(--bg-side); }
.theory .t-sec.is-example > h2, .theory .t-sec.is-exam > h2, .theory .t-sec.is-summary > h2 { margin-top: 1em; padding-top: 0; border-top: 0; }
.theory .t-sec.is-example + .t-sec > h2, .theory .t-sec.is-exam + .t-sec > h2, .theory .t-sec.is-summary + .t-sec > h2 { border-top: 0; }
.theory .t-sec.is-read { font-size: 15.5px; color: var(--muted); }
.theory .t-sec.is-read > h2 { font-size: 19px; }

.callout { margin: 1.8em 0; padding: 16px 20px 6px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; line-height: 1.65; }
.callout > p, .callout li { margin-bottom: .6em; }
.callout ul { margin-bottom: .6em; }
.callout-title { margin: 0 0 .5em !important; font: 600 12px/1.3 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.callout-goal { background: var(--bg-side); border-color: transparent; }
.callout-goal .callout-title { color: var(--accent-ink); }
.callout-trap { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.callout-trap .callout-title { color: var(--accent-ink); }
.callout-tip { border-style: dashed; }

.quiz { margin: 2em 0; padding: 18px 20px 18px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--surface); box-shadow: 0 1px 2px rgba(31, 30, 28, .04); }
.quiz-label { margin: 0 0 .5em !important; font: 600 12px/1.3 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--accent-ink); }
.quiz-q > p { margin: 0 0 .9em; color: var(--text); }
.quiz-q pre.snip { margin: 0 0 1em; padding: 12px 14px; font-size: 13px; }
.theory .quiz-opts { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.theory .quiz-opts li { margin: 0; padding: 0; }
.quiz-opt { display: flex; align-items: baseline; gap: 12px; width: 100%; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); text-align: left; cursor: pointer; transition: border-color .15s, background .15s, opacity .15s; }
.quiz-opt:hover { border-color: var(--line-strong); background: var(--hover); }
.quiz-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.quiz-opt code { font: .9em var(--mono); }
.quiz-key { flex: none; min-width: 1.1em; font: 600 12px var(--mono); color: var(--faint); }
.quiz.is-answered .quiz-opt { cursor: default; }
.quiz.is-answered .quiz-opt:not(.is-right):not(.is-wrong) { opacity: .55; }
.quiz.is-answered .quiz-opt:hover { background: var(--bg); }
.quiz-opt.is-right, .quiz.is-answered .quiz-opt.is-right:hover { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 11%, var(--bg)); }
.quiz-opt.is-right .quiz-key { color: var(--ok); }
.quiz-opt.is-wrong, .quiz.is-answered .quiz-opt.is-wrong:hover { border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--accent-soft); }
.quiz-opt.is-wrong .quiz-key { color: var(--accent-ink); }
.quiz-why { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-strong); font: 15px/1.6 var(--sans); color: var(--text-2); }
.quiz-why p { margin: 0 0 .4em; }
.quiz-verdict { font-weight: 600; color: var(--text); }
.quiz-src { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font: 13px/1.6 var(--sans); color: var(--muted); }
.quiz-src + .quiz-src { margin-top: 4px; padding-top: 0; border-top: 0; }
.quiz-src-kind { display: inline-block; margin-right: 8px; vertical-align: 1px; padding: 0 8px; border: 1px solid transparent; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); font: 600 11px/1.6 var(--sans); letter-spacing: .05em; text-transform: uppercase; }
.quiz-src-adapted .quiz-src-kind { border-color: var(--line-strong); background: transparent; color: var(--muted); }
.quiz-src a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 2px; }
.quiz-src a:hover { color: var(--text); }
/* Ôn lại: các mục lý thuyết cần học để trả lời câu (mục Trắc nghiệm) */
.quiz-learn { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; gap: 5px 10px; margin: .9em 0 0 !important; font: 14px/1.5 var(--sans); color: var(--muted); }
.quiz-learn > a { grid-column: 2; justify-self: start; }
.quiz-learn-kind { grid-row: 1; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted); font: 600 11px/1.6 var(--sans); letter-spacing: .05em; text-transform: uppercase; }
.quiz-learn a { color: var(--text-2); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.quiz-learn a:hover { color: var(--accent-ink); text-decoration-color: currentColor; }
.quiz-learn-at { margin-right: 6px; color: var(--accent-ink); font-weight: 600; }
.theory .t-sec.is-target > h2 { animation: sec-target 2.4s ease-out; }
@keyframes sec-target { 0%, 35% { color: var(--accent-ink); } 100% { color: var(--text); } }
/* Câu cần đọc khi mở bài từ “Ôn lại”: nền màu đất nung như bút dạ, đậm lên một nhịp rồi dịu lại và giữ nguyên.
   margin âm bù padding nên chữ không xê dịch; clone để mỗi dòng của câu dài có nền riêng. */
.quiz-learn a .i { width: 13px; height: 13px; margin-left: 5px; vertical-align: -1px; color: var(--faint); transition: color .15s, transform .15s; }
.quiz-learn a:hover .i { color: currentColor; transform: translate(1px, -1px); }
.theory .learn-mark { --hl: color-mix(in srgb, var(--accent) 16%, transparent); --hl-peak: color-mix(in srgb, var(--accent) 34%, transparent); background: transparent; color: inherit; }
.theory mark.learn-mark { margin: 0 -.15em; padding: .1em .15em; border-radius: 4px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.theory .katex-display.learn-mark { border-radius: 6px; }
.theory .learn-mark.is-on { background: var(--hl); animation: learn-in 1.8s cubic-bezier(.3, .6, .3, 1) .2s backwards; }
.theory .callout-trap .learn-mark { --hl: color-mix(in srgb, var(--accent) 26%, transparent); --hl-peak: color-mix(in srgb, var(--accent) 42%, transparent); }
@keyframes learn-in { 0% { background: transparent; } 30% { background: var(--hl-peak); } 100% { background: var(--hl); } }
:root[data-theme="dark"] .theory .learn-mark { --hl: color-mix(in srgb, var(--accent) 24%, transparent); --hl-peak: color-mix(in srgb, var(--accent) 44%, transparent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .theory .learn-mark { --hl: color-mix(in srgb, var(--accent) 24%, transparent); --hl-peak: color-mix(in srgb, var(--accent) 44%, transparent); } }
@media (prefers-reduced-motion: reduce) { .theory .t-sec.is-target > h2, .theory .learn-mark.is-on { animation: none; } }
.theory .t-sec.is-check .quiz { margin: 1.2em 0; }

.theory .t-code { margin: 1.4em 0; }
.theory .t-code.has-out { margin-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.theory .t-code .code-body { max-height: none; margin: 0; padding: 14px 18px 16px; border-radius: 0; background: transparent; }
.theory pre.out { position: relative; margin: 0 0 1.6em; padding: 28px 18px 14px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 12px 12px; background: transparent; color: var(--text-2); font: 13px/1.6 var(--mono); }
.out-label { position: absolute; top: 9px; left: 18px; font: 600 10.5px/1 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--faint); }
.toc-nb { display: inline-flex !important; align-items: center; gap: 7px; margin-top: 14px; padding: 7px 12px !important; border: 1px solid var(--line) !important; border-radius: 9px; color: var(--text-2) !important; font-weight: 500; }
.toc-nb:hover { border-color: var(--line-strong) !important; background: var(--hover); }
.toc-nb .i { width: 14px; height: 14px; }
.toc-dl { display: grid; justify-items: start; gap: 8px; margin-top: 14px; }
.toc-dl .toc-nb { margin-top: 0; }
.learn-actions { display: none; }
@media (max-width: 640px) {
  .theory .t-sec.is-example, .theory .t-sec.is-exam, .theory .t-sec.is-summary { margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px; border-radius: 0; }
  .quiz { padding: 16px; }
}

.prose.md { max-width: none; }
.prose.md > p, .prose.md > ul, .prose.md > ol, .prose.md > h2, .prose.md > h3, .prose.md > h4 { max-width: 70ch; }
.prose.md h4 { margin: 1.6em 0 .4em; font: 600 15px/1.4 var(--sans); color: var(--text); }
.prose.md .table-wrap { margin-bottom: 2em; }
.prose.md td { font-size: 14px; }
.prose.md td:nth-child(2) { min-width: 180px; }
.prose td a { white-space: nowrap; }
.prose:not(.md) td:last-child { white-space: nowrap; }

/* plain-text documents (statements, guides) */
.doc { max-width: 72ch; font-size: 15px; line-height: 1.7; color: var(--text-2); }
.doc > :first-child { margin-top: 0; }
.doc p { margin: 0 0 1em; white-space: pre-line; }
.doc .label { margin: 2em 0 .6em; font: 600 12px/1.4 var(--sans); letter-spacing: .06em; color: var(--muted); }
.doc > .label:first-child { margin-top: 0; }
.doc ul { margin: 0 0 1em; padding-left: 1.2em; }
.doc li { margin: .3em 0; }
.doc li::marker { color: var(--faint); }

/* slides */
.stage { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--bg-side); aspect-ratio: 16 / 10; }
.stage iframe { display: block; width: 100%; height: 100%; border: 0; background: var(--bg-side); }

/* code */
.code { margin: 0 0 20px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 8px 6px 16px; background: var(--code-head); border-bottom: 1px solid var(--line); }
.code-name { font: 13px var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-tools { display: flex; gap: 2px; }
.tool { display: inline-grid; place-items: center; width: 30px; height: 28px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; }
.tool:hover { background: var(--active); color: var(--text); }
.tool[aria-pressed="true"] { color: var(--accent-ink); }
.tool .i { width: 15px; height: 15px; }
.code-body { margin: 0; padding: 16px 18px 18px; max-height: 70vh; overflow: auto; color: var(--code-text); font: 13.5px/1.7 var(--mono); tab-size: 4; }
.code-body.is-wrap { white-space: pre-wrap; word-break: break-word; }
.t-k { color: var(--t-k); }
.t-s { color: var(--t-s); }
.t-n { color: var(--t-n); }
.t-c { color: var(--t-c); }
.output { margin-top: 28px; }
.output-title { margin: 0 0 10px; font: 500 15px/1.4 var(--sans); color: var(--text); }
.output pre { margin: 0; background: transparent; border: 1px solid var(--line); }
.disclosure { margin: 0 0 20px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; }
.disclosure[open] .doc { margin-top: 14px; }

/* homework */
.tasks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 24px; }
.task { display: grid; gap: 4px; align-content: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; transition: border-color .15s, background .15s; }
.task:hover { border-color: var(--line-strong); }
.task.is-active { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.task-num { font-size: 13px; font-weight: 500; color: var(--muted); }
.task.is-active .task-num { color: var(--accent-ink); }
.task-name { font-size: 14px; color: var(--text); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 28px; padding-bottom: 18px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.task-meta code { font: 12.5px var(--mono); color: var(--faint); }
.tag { display: inline-flex; padding: 2px 9px; border-radius: 999px; background: var(--hover); color: var(--text-2); font-size: 12px; font-weight: 500; }
.task-files { display: flex; flex-wrap: wrap; gap: 14px; margin-left: auto; }
.task-files a { color: var(--accent-ink); }
.task-files a:hover { text-decoration: underline; text-underline-offset: 3px; }
.statement { margin-bottom: 8px; }
.tasks { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.hw { max-width: 820px; }
.hw-head { margin: 6px 0 28px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.hw-kicker { margin: 0 0 6px; font: 600 12px/1.4 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--accent-ink); }
.hw-title { margin: 0 0 18px; font: 500 30px/1.25 var(--serif); color: var(--text); }
.hw-files { display: flex; flex-wrap: wrap; gap: 8px; }
.hw-doc { font-size: 16.5px; line-height: 1.75; }
.hw-legacy { max-width: none; color: var(--text); }
.hw-doc h2, .hw-doc h3 { margin: 1.9em 0 .55em; font: 600 15px/1.4 var(--sans); letter-spacing: 0; color: var(--text); }
.hw-doc > h2:first-child, .hw-doc > h3:first-child { margin-top: 0; }
.hw-io { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 1.6em 0; }
.hw-io > div { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--code-bg); }
.hw-io-label { margin: 0 !important; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--code-head); font: 600 11.5px/1.4 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: normal !important; }
.hw-io pre { margin: 0 !important; border-radius: 0 !important; background: transparent !important; white-space: pre-wrap; overflow-wrap: anywhere; }
.hw-check { list-style: none; padding-left: 0 !important; }
.hw-check li { position: relative; padding-left: 30px; }
.hw-check li::before { content: ""; position: absolute; left: 2px; top: .42em; width: 15px; height: 15px; border: 1.5px solid var(--line-strong); border-radius: 4px; }
.hw .block { margin-top: 40px; }

.pr-list { border-top: 1px solid var(--line); }
.pr { display: grid; grid-template-columns: 34px 28px 1fr auto; gap: 10px; align-items: center; padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.pr:hover { background: color-mix(in srgb, var(--hover) 60%, transparent); }
.pr-check { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--faint); cursor: pointer; }
.pr-check:hover { color: var(--muted); }
.pr.is-done .pr-check { color: var(--ok); }
.pr-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.pr-main { display: grid; gap: 2px; min-width: 0; padding: 4px 0; }
a.pr-main:hover .pr-name { color: var(--accent-ink); }
.pr-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-src { font-size: 12px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr.is-soon .pr-name { color: var(--muted); }
.pr-tail { display: inline-flex; align-items: center; gap: 4px; }
.pr-tag { font-size: 12px; color: var(--faint); white-space: nowrap; }
.pr-go { display: inline-flex; align-items: center; gap: 6px; padding: 6px 4px; font-size: 13px; color: var(--accent-ink); white-space: nowrap; }
.pr-go .i { width: 14px; height: 14px; }
.pr-go:hover span { text-decoration: underline; text-underline-offset: 3px; }

/* resources */
.res-list { border-top: 1px solid var(--line); }
.res { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.res .res-main { border-bottom: 0; }
.res-main { flex: 1; display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 15px 8px 15px 4px; border-bottom: 1px solid var(--line); }
.res-main:hover .res-title { color: var(--accent-ink); }
.res-title { font-weight: 500; color: var(--text); }
.res-text { grid-column: 1; font-size: 14px; color: var(--muted); }
.res-ext .i { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--faint); }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 12px); padding: 9px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- standalone lesson page (phase-*/buoi-*/BAI_HOC.html) ---------- */
.legacy-page { background: var(--bg); }
.legacy-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 16px; height: var(--top-h); padding: 0 24px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.legacy-bar .back { font-size: 14px; color: var(--accent-ink); }
.legacy-bar .back:hover { text-decoration: underline; text-underline-offset: 3px; }
.legacy-page .prose { margin: 0 auto; padding: 48px 24px 24px; max-width: 784px; }
.legacy-page .prose h1 { margin: 0 0 .6em; font: 500 38px/1.15 var(--serif); color: var(--text); letter-spacing: -.015em; }
.legacy-page .prose h1 + p { margin: 0 0 1.2em; padding-left: 18px; border-left: 2px solid var(--accent); font-size: 20px; line-height: 1.55; font-style: italic; color: var(--text); }
.legacy-page .prose h1 + p + p { font: 14px/1.6 var(--sans); margin-bottom: 2em; }
.legacy-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 784px; margin: 0 auto; padding: 24px 24px 56px; }
.legacy-footer a { padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; font-weight: 500; }
.legacy-footer a:hover { border-color: var(--line-strong); background: var(--surface); }
.legacy-footer a:last-child:not(:first-child) { text-align: right; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .learn { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
  .learn-actions { display: flex; }
}
@media (max-width: 920px) {
  .side { transform: translateX(-100%); transition: transform .22s ease; box-shadow: none; }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .icon-btn.side-close { display: inline-grid; }
  .scrim { position: fixed; inset: 0; z-index: 25; border: 0; background: rgba(20, 20, 19, .35); opacity: 0; pointer-events: none; transition: opacity .2s; display: block; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .shell { margin-left: 0; }
  .icon-btn.menu-btn { display: inline-grid; margin-left: -8px; }
  .top { padding: 0 16px; gap: 10px; }
  .search-box { width: 200px; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .page { padding: 32px 16px 32px; }
  .hero h1 { font-size: 36px; }
  .page-head h1, .lesson-head h1 { font-size: 30px; }
  .lead { font-size: 16px; }
  .crumbs { display: none; }
  .top-tools { flex: 1; justify-content: flex-end; }
  .search { flex: 1; }
  .search-box { width: 100%; }
  .search-box kbd { display: none; }
  .search-pop { width: calc(100vw - 32px); right: -60px; }
  .top-progress { display: none; }
  .resume { grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; }
  .resume-label { grid-column: 1 / -1; }
  .resume-title { white-space: normal; }
  .resume-meta { display: none; }
  .phase { grid-template-columns: 32px 1fr; gap: 12px; }
  .pr { grid-template-columns: 34px 1fr auto; gap: 8px; }
  .pr-num { display: none; }
  .phase-num { font-size: 24px; }
  .phase-meta { grid-column: 2; justify-items: start; grid-auto-flow: column; gap: 14px; padding-top: 0; }
  .row { grid-template-columns: 40px 1fr auto; gap: 10px; }
  .lesson-head { grid-template-columns: 1fr; }
  .mark { grid-row: 4; justify-self: start; margin-top: 18px; }
  .tasks { grid-template-columns: 1fr; }
  .hw-io { grid-template-columns: 1fr; }
  .hw-title { font-size: 25px; }
  .task-files { margin-left: 0; width: 100%; }
  .prose { font-size: 16.5px; }
  .prose .hook { font-size: 18px; }
  .pager { grid-template-columns: 1fr; }
  .pager-link.is-next { text-align: left; justify-items: start; }
  .ex-kind { display: none; }
  .stage { aspect-ratio: 4 / 3; }
  .legacy-footer { grid-template-columns: 1fr; }
  .legacy-footer a:last-child:not(:first-child) { text-align: left; }
  .legacy-page .prose h1 { font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; } }
@media print {
  .side, .top, .tabs, .pager, .foot, .toc, .actions, .mark, .legacy-bar, .legacy-footer { display: none !important; }
  .code-head button, .skip { display: none !important; }
  html, body, .shell, .page, .tab-body { background: #fff !important; }
  .theory pre, .theory pre code { white-space: pre-wrap !important; overflow-wrap: anywhere; }
  .theory figure.fig, .theory .quiz, .theory .callout { break-inside: avoid; }
  .theory tr { break-inside: avoid; }
  .theory figure.code, .theory .code-body { overflow: visible !important; }
  .theory h2, .theory h3 { break-after: avoid; }
  .shell { margin: 0; }
  .page { padding: 0; max-width: none; }
}

/* ---------- courses, drafts, parts ---------- */
.courses { display: grid; gap: 36px; }
.course-head { margin: 0 0 10px; font: 500 13px/1.4 var(--sans); color: var(--muted); }
.course-label { font: 500 13px/1 var(--sans); color: var(--accent-ink); white-space: nowrap; }
.course-text { margin: 0 0 16px; max-width: 64ch; font-size: 14px; color: var(--muted); }
.tag-draft { background: transparent; border: 1px solid var(--line); color: var(--faint); font-weight: 400; }
.tag-check { background: var(--accent-soft); color: var(--accent-ink); }
.row.is-draft .row-title { color: var(--text-2); font-weight: 400; }
.row-end .tag { white-space: nowrap; }
.side-lesson.is-draft { color: var(--faint); }
.draft { margin: 8px 0 0; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 15px; }
.parts { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: -10px 0 14px; }
.part { padding: 2px 0; font-size: 13px; color: var(--muted); border-bottom: 1px solid transparent; }
.part:hover { color: var(--text); }
.part.is-active { color: var(--text); border-bottom-color: var(--text); }
@media (max-width: 640px) {
  .courses { gap: 28px; }
  .row-end .tag { display: none; }
}

/* ---------- polish: no awkward wraps, toggles, helpers ---------- */
.btn, .tag, .part, .mark, .tool, .crumbs a, .kicker a, .resume-label, .course-label, .phase-meta, .row-id, .ex-num, .ex-kind, .task-num, .top-progress, .foot span, .foot a { white-space: nowrap; }
.kicker { text-wrap: balance; }
.row-title, .phase-title, .res-title { text-wrap: pretty; }
.task-files a { white-space: nowrap; }
.pager-link small { white-space: nowrap; }
.to-top { position: fixed; right: 24px; bottom: 24px; z-index: 40; display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--text-2); box-shadow: var(--shadow); cursor: pointer; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s; }
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { color: var(--text); }
.hit:focus-visible { outline: none; background: var(--hover); }
@media (max-width: 1180px) and (min-width: 921px) { .search-box { width: 200px; } }
@media (max-width: 640px) {
  .to-top { right: 16px; bottom: 16px; }
  .tabs { margin-left: -16px; margin-right: -16px; padding: 0 8px; }
  .parts, .tasks { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -16px; margin-right: -16px; padding: 4px 16px 6px; }
  .tasks { scroll-snap-type: x mandatory; scroll-padding: 0 16px; }
  .parts-label { flex: none; }
  .parts::-webkit-scrollbar, .tasks::-webkit-scrollbar { display: none; }
  .part { flex: none; }
  .tasks { display: flex; gap: 10px; }
  .task { flex: 0 0 78%; scroll-snap-align: start; }
}
@media (min-width: 641px) { .page-head > .kicker, .lesson-head > .kicker { display: none; } }

/* ---------- collapsible sidebar (desktop) ---------- */
.icon-btn.side-open { display: none; margin-left: -8px; }
html.side-anim .side, html.side-anim .shell { transition: transform .22s ease, margin-left .22s ease; }
@media (min-width: 921px) {
  html[data-side="closed"] .side { transform: translateX(-100%); visibility: hidden; }
  html.side-anim[data-side="closed"] .side { transition: transform .22s ease, visibility 0s .22s; }
  html[data-side="closed"] .shell { margin-left: 0; }
  html[data-side="closed"] .icon-btn.side-open { display: inline-grid; }
}
@media (max-width: 920px) { .icon-btn.side-collapse { display: none; } }
.side-head .wordmark { margin-right: auto; }

/* ---------- home (minimal) ---------- */
.page-home { max-width: 680px; padding-top: 72px; }
.home-title { margin: 0; font: 500 44px/1.15 var(--serif); letter-spacing: -.015em; color: var(--text); }
.page-home .courses { margin-top: 56px; gap: 40px; }
.page-home .course-head { margin: 0 0 6px; }
.page-home .phases { border-top: 0; }
.page-home .phase { grid-template-columns: 28px 1fr auto 16px; align-items: center; gap: 12px; padding: 11px 8px 11px 2px; border-bottom: 0; border-radius: 8px; }
.page-home .phase:hover { background: var(--hover); }
.page-home .phase-num { font: 400 17px/1 var(--serif); padding: 0; }
.page-home .phase-title { font: 400 18px/1.35 var(--serif); }
.page-home .phase > .i { color: var(--faint); opacity: 0; transition: opacity .15s; }
.page-home .phase:hover > .i { opacity: 1; }
.page-home .phase-progress .meter { width: 56px; }
.page-home .foot { margin-top: 64px; }
@media (max-width: 640px) {
  .page-home { padding-top: 40px; }
  .home-title { font-size: 34px; }
  .page-home .phase { grid-template-columns: 24px 1fr auto 16px; }
}

/* Code hiển thị đúng từng ký tự: tắt ligature của JetBrains Mono (!= <= <| không bị ghép). */
code, pre, kbd, samp, code * , pre * { font-variant-ligatures: none !important; font-feature-settings: "liga" 0, "calt" 0 !important; }

/* Bài tập soạn mới: mục lục chọn bài (vạch nhấn bên trái cho bài đang mở), tên bài và nút tải trên cùng một dòng, mục Nộp bài dùng hộp goal. */
.hw-tabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); max-width: 720px; margin: -10px 0 30px; }
.hw-tab { display: flex; align-items: baseline; gap: 10px; min-width: 0; padding: 9px 12px; border-left: 2px solid transparent; font-size: 13.5px; color: var(--muted); transition: color .15s, border-color .15s; }
.hw-tab:hover { color: var(--text); }
.hw-tab-num { flex: none; font: 400 12px/1 var(--sans); color: var(--faint); font-variant-numeric: tabular-nums; }
.hw-tab-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hw-tab.is-active { border-left-color: var(--accent); color: var(--text); }
.hw-tab.is-active .hw-tab-num { color: var(--accent-ink); }
/* Cả khung bài tập theo đúng bề rộng đọc của bài học: phần đầu, đường kẻ, ví dụ và đoạn văn cùng một mép phải. */
.hw-fresh { max-width: 720px; }
.hw-fresh .hw-doc { max-width: none; }
.hw-head-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px; }
.hw-head-row .hw-title { margin: 0; }
.hw-head-row .hw-files { margin-left: auto; }
@media (max-width: 640px) {
  .hw-head-row .hw-files { margin-left: 0; }
}

/* ---------- trắc nghiệm ---------- */
button.phase, button.resume { width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.phase { border: 0; border-bottom: 1px solid var(--line); background: transparent; }
.btn.is-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.btn.is-primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
.btn.is-primary .i { color: currentColor; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: var(--surface); }
.qz-n { color: var(--muted); font-variant-numeric: tabular-nums; }
.btn.is-primary .qz-n { color: inherit; opacity: .8; }
.qz-actions { margin: 28px 0 0; }
.qz-title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.qz-title-row .actions { margin: 0; flex: none; }
.qz-reset { margin-left: auto; padding: 0; border: 0; background: transparent; color: var(--muted); font: inherit; cursor: pointer; }
.qz-reset:hover { color: var(--text); }
.qz-page { max-width: 760px; }
.qz-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; font-size: 13px; color: var(--muted); }
.qz-pos { font-variant-numeric: tabular-nums; color: var(--text-2); }
.qz-pos span { color: var(--faint); }
.qz-bar { height: 3px; margin: 12px 0 28px; border-radius: 3px; background: var(--line); overflow: hidden; }
.qz-bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .2s; }
.quiz.qz-card { margin: 0; padding: 26px 28px 24px; overflow-wrap: anywhere; }
.qz-q { margin: 0 0 22px; font: 500 23px/1.45 var(--serif); letter-spacing: -.005em; color: var(--text); text-wrap: pretty; }
.qz-q code, .qz-card .quiz-opt code, .qz-card .quiz-why code { font: .86em var(--mono); padding: 1px 5px; border-radius: 5px; background: var(--code-bg); }
.qz-q code { font-size: .78em; }
.qz-code { margin: -6px 0 20px; padding: 14px 16px; border-radius: 10px; background: var(--code-bg); color: var(--code-text); font: 13px/1.6 var(--mono); overflow-x: auto; tab-size: 4; white-space: pre; }
.qz-card .quiz-opts { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.qz-card .quiz-opts li { margin: 0; }
.qz-card .quiz-opt { padding: 11px 14px; }
.qz-card .quiz-why { outline: 0; }
.qz-card .quiz-why p:last-child { margin-bottom: 0; }
.qz-nav { display: flex; justify-content: space-between; gap: 8px; margin: 20px 0 32px; }
.qz-grid { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 20px; border-top: 1px solid var(--line); }
.qz-cell { width: 34px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: transparent; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; cursor: pointer; transition: background .15s, border-color .15s; }
.qz-cell:hover { border-color: var(--line-strong); color: var(--text); }
.qz-cell.is-right { border-color: color-mix(in srgb, var(--ok) 55%, transparent); background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--text); }
.qz-cell.is-wrong { border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: var(--accent-soft); color: var(--text); }
.qz-cell.is-current { outline: 2px solid var(--text); outline-offset: 1px; color: var(--text); }
.qz-score { display: flex; align-items: baseline; gap: 14px; padding: 4px 0 8px; }
.qz-score-num { font: 500 56px/1 var(--serif); color: var(--text); font-variant-numeric: tabular-nums; }
.qz-score-num span { font-size: 28px; color: var(--faint); }
.qz-score-text { color: var(--muted); }
.qz-rows { border-top: 1px solid var(--line); }
.qz-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.qz-row .phase-progress { color: var(--muted); font-size: 13px; }
@media (max-width: 640px) {
  .quiz.qz-card { padding: 18px 16px; }
  .qz-q { font-size: 20px; }
  .qz-code { margin: -4px 0 16px; padding: 12px 13px; font-size: 12px; }
  .qz-bar { margin-bottom: 20px; }
  .qz-cell { width: 32px; }
  .qz-score-num { font-size: 46px; }
}
@media print { .qz-nav, .qz-grid { display: none !important; } }

/* ---------- kiểm tra: ẩn mọi đường rời trang cho đến khi nộp bài ---------- */
html.exam-lock .side, html.exam-lock .scrim, html.exam-lock .menu-btn, html.exam-lock .side-open, html.exam-lock .crumbs,
html.exam-lock .search, html.exam-lock .top-progress, html.exam-lock .skip { display: none !important; }
html.exam-lock .shell { margin-left: 0; }
html.exam-lock .top { justify-content: flex-end; }
.ex-bar { display: flex; align-items: center; gap: 16px; margin: 0 0 22px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.ex-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ex-clock { font: 500 20px/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
.ex-clock.is-low { color: var(--accent-ink); }
.quiz-opt.is-picked { border-color: var(--text-2); background: var(--active); }
.quiz-opt.is-picked .quiz-key { color: var(--text); }
.qz-cell.is-done { border-color: var(--line-strong); background: var(--active); color: var(--text); }
.ex-reviews .ex-review { margin: 0 0 16px; }
.ex-review .qz-q { font-size: 19px; margin-bottom: 16px; }
.ex-review .quiz-opt { cursor: default; }
.ex-review .quiz-opt:hover { background: var(--bg); }
.ex-num { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .ex-bar { gap: 10px; padding: 10px 12px; }
  .ex-clock { font-size: 17px; }
  .ex-review .qz-q { font-size: 17px; }
}
@media print { .ex-bar { display: none !important; } }

/* Trắc nghiệm: gom bộ theo mức */
.qz-level-head { width: 100%; grid-template-columns: 44px 1fr auto 20px; align-items: center; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.qz-level-head .phase-num, .qz-level-head .phase-meta { padding-top: 0; }
.qz-level-head > .i { width: 18px; height: 18px; color: var(--faint); transition: transform .2s ease, color .15s; }
.qz-level-head:hover > .i { color: var(--accent); }
.qz-level.is-open .qz-level-head { border-bottom-color: transparent; }
.qz-level.is-open .qz-level-head:hover { background: none; }
.qz-level.is-open .qz-level-head > .i { transform: rotate(90deg); color: var(--accent); }
.qz-level.is-open .qz-level-head .phase-num { color: var(--accent); }
.qz-level-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.qz-subs { border-bottom: 1px solid var(--line); padding: 0 8px 22px 64px; margin-top: -6px; animation: qz-sub-in .2s ease; }
.qz-subs[hidden] { display: none; }
.qz-subs-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.qz-sub { position: relative; display: grid; gap: 3px; padding: 11px 14px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); overflow: hidden; transition: border-color .15s, background .15s; }
.qz-sub:hover { border-color: var(--accent); background: color-mix(in srgb, var(--hover) 60%, transparent); }
.qz-sub-name { font: 500 16px/1.3 var(--serif); color: var(--text); }
.qz-sub-meta { font-size: 12.5px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qz-sub.is-started .qz-sub-meta { color: var(--muted); }
.qz-sub-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--line); }
.qz-sub-bar > span { display: block; height: 100%; background: var(--accent); }
@keyframes qz-sub-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .qz-subs { animation: none; } .qz-level-head > .i { transition: none; } }
@media (max-width: 640px) {
  .qz-level-head { grid-template-columns: 32px 1fr 20px; }
  .qz-level-head .phase-meta { grid-column: 2; grid-row: 2; }
  .qz-level-head > .i { grid-column: 3; grid-row: 1 / span 2; }
  .qz-subs { padding: 0 4px 18px 44px; margin-top: -4px; }
  .qz-subs-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .qz-sub { padding: 10px 12px 12px; }
}

/* ---------- hình động (lượt 9, ui/anim.js) ---------- */
.fig.anim .anim-stage { display: block; width: 100%; height: auto; margin: 0 auto; cursor: pointer; border-radius: 6px; }
.anim-bar { display: flex; align-items: center; gap: 10px; margin: .7em auto 0; font: 13px/1.4 var(--sans); color: var(--muted); text-align: left; }
.anim-play { flex: none; display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--text); cursor: pointer; }
.anim-play:hover { background: var(--hover); }
.anim-play svg { width: 13px; height: 13px; }
.anim-seek { flex: 0 1 180px; min-width: 80px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.anim-label { flex: 1 1 auto; min-width: 0; font-variant-numeric: tabular-nums; }
.anim-step { color: var(--faint); margin-right: .2em; }
.anim-label code { font: 12px var(--mono); }
.anim-keys { display: none; }
@media (max-width: 640px) { .anim-bar { flex-wrap: wrap; } .anim-label { flex-basis: 100%; } .anim-seek { flex: 1 1 auto; } }
@media print {
  .fig.anim .anim-live { display: none !important; }
  .anim-keys { display: grid; grid-template-columns: repeat(var(--pcols, 4), 1fr); gap: 10px 12px; align-items: start; }
  .anim-key canvas { display: block; width: 100%; height: auto; }
  .anim-key span { display: block; margin-top: 4px; font: 11px/1.35 var(--sans); color: var(--muted); }
  .anim-key code { font: 10px var(--mono); }
}

/* ---------- bổ sung 13/10: logo, liên kết phụ của bài, nút Chạy, trắc nghiệm và đề thật theo bài ---------- */
.wordmark .logo { flex: none; align-self: center; width: 26px; height: 24px; }

.run-btn { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px 0 7px; border: 0; border-radius: 7px; background: transparent; color: var(--accent-ink); font: 500 13px/1 var(--sans); cursor: pointer; }
.run-btn .i { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.run-btn:hover { background: var(--hover); }
.is-running .run-btn { color: var(--faint); cursor: default; }
.theory pre.out[hidden] { display: none; }
.theory .t-code.has-out:has(+ pre.out[hidden]) { margin-bottom: 1.4em; border-radius: 12px; }

.loading { margin: 0; font-size: 14px; color: var(--faint); }

.qz-lessons-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.qz-lchip { position: relative; display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 13px; color: var(--faint); }
.qz-lchip b { font-weight: 500; color: var(--text-2); font-variant-numeric: tabular-nums; }
.qz-lchip i { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); }
.qz-lchip:hover { border-color: var(--line-strong); background: var(--hover); }
.ch-chip { gap: 8px; }
.ch-chip b { color: var(--accent-ink); }

.pr-body { display: grid; min-width: 0; }
.pr-uses { margin: -2px 0 4px; font-size: 12px; color: var(--faint); }
.pr-uses a { color: var(--text-2); }
.pr-uses a:hover { color: var(--accent-ink); }
.toc { max-height: calc(100vh - var(--top-h) - 100px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding-bottom: 8px; }

/* Hàng liên kết đi kèm bài: trắc nghiệm, thực hành, Kaggle, PDF. */
.lesson-links { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 14px; font-size: 14px; }
.lesson-links a { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.lesson-links a:hover { color: var(--accent-ink); }
.lesson-links b { font-weight: 500; color: var(--faint); font-variant-numeric: tabular-nums; }
.lesson-links .i { width: 15px; height: 15px; }

/* Lõi chung (tools/site-kit): code C++ có chỉ thị tiền xử lý, khối input nằm giữa code và output, số đếm trên tab, gợi ý tìm kiếm không phải bài học. */
.t-p { color: var(--t-n); }
.tab b { margin-left: 4px; font-weight: 500; color: var(--faint); font-variant-numeric: tabular-nums; }
.hit-p { display: inline-flex; justify-content: center; }
.hit-p .i { width: 15px; height: 15px; color: var(--faint); }
.theory pre.out.io-in { margin-bottom: 0; border-radius: 0; border-bottom: 0; }
.theory pre.out.io-in:not(.io-mid) { margin: 0 0 1.6em; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 12px; }
.theory .t-code + pre.out.io-in { border-top: 0; }
.theory .t-code + pre.io-in.io-mid { border-radius: 0; border-bottom: 1px dashed var(--line); }
.theory .t-code + pre.io-mid + pre.out[hidden] { display: none; }
.theory .t-code.can-run + pre.io-mid { border-radius: 0 0 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 1.6em; }
.theory .t-code.can-run.is-running + pre.io-mid, .theory .t-code.can-run + pre.io-mid:has(+ pre.out:not([hidden])) { border-radius: 0; border-bottom: 1px dashed var(--line); margin-bottom: 0; }
