/* =========================================================================
   Giáo trình Quantization — giao diện đọc
   Mục tiêu: dòng chữ dài vừa mắt, công thức và hình không bao giờ tràn,
   và mọi thứ đọc được như nhau ở giao diện sáng lẫn tối.
   ========================================================================= */

/* ------------------------------------------------------------- tokens */
:root {
  --font-body: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-ui: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, 'Courier New', monospace;

  --sidebar-w: 17rem;
  --toc-w: 14rem;
  --content-w: 45rem;
  --topbar-h: 3.5rem;
  --radius: 0.625rem;
  --radius-sm: 0.375rem;

  --bg: #faf9f6;
  --bg-soft: #f1efe9;
  --surface: #ffffff;
  --text: #1f1d1a;
  --text-2: #4c4740;
  --text-3: #7d786d;
  --line: #e4e0d7;
  --line-2: #cfc9bc;
  --accent: #14625c;
  --accent-2: #0e4b46;
  --accent-soft: #e0efed;
  --code-bg: #f6f4ef;
  --warn: #8a5300;
  --warn-soft: #fbf0db;
  --danger: #a13328;
  --danger-soft: #fbe9e6;
  --ok: #2c6b39;
  --ok-soft: #e6f2e8;
  --shadow: 0 1px 2px rgba(31, 29, 26, .05), 0 6px 20px rgba(31, 29, 26, .06);
  --shadow-lg: 0 10px 40px rgba(31, 29, 26, .16);
}

:root[data-theme='dark'] {
  --bg: #14161a;
  --bg-soft: #191c22;
  --surface: #1c2027;
  --text: #e8e6e1;
  --text-2: #b5b1a9;
  --text-3: #8a857c;
  --line: #2b303a;
  --line-2: #3d434f;
  --accent: #5fd3c3;
  --accent-2: #8ae6d9;
  --accent-soft: #113330;
  --code-bg: #171a20;
  --warn: #e3b169;
  --warn-soft: #2c2415;
  --danger: #ec9285;
  --danger-soft: #30201d;
  --ok: #80c68e;
  --ok-soft: #1a2a1e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .55);
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 1.25rem); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 0.18em; }
a:hover { color: var(--accent-2); text-decoration-color: currentColor; }

img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 var(--radius) 0;
  font-family: var(--font-ui);
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ------------------------------------------------------------ topbar */
.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-ui);
}

.icon-btn {
  display: grid; place-items: center;
  width: 2.25rem; height: 2.25rem; flex: none;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn svg { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.menu-btn { display: none; }

:root[data-theme='dark'] .ic-sun { display: none; }
:root:not([data-theme='dark']) .ic-moon { display: none; }

.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); margin-right: auto; }
.brand-mark {
  width: 1.9rem; height: 1.9rem; flex: none; display: grid; place-items: center;
  background: var(--accent); color: #fff; border-radius: .5rem;
  font-weight: 700; font-size: .95rem; letter-spacing: -.02em;
}
:root[data-theme='dark'] .brand-mark { color: #10211f; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: .95rem; font-weight: 600; letter-spacing: -.01em; }
.brand-text i { font-style: normal; font-size: .72rem; color: var(--text-3); }

.search-btn {
  display: flex; align-items: center; gap: .5rem;
  min-width: 15rem; padding: .42rem .5rem .42rem .7rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text-3); font-size: .85rem; text-align: left;
}
.search-btn:hover { border-color: var(--line-2); color: var(--text-2); }
.search-btn svg { width: 1rem; height: 1rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.search-btn span { flex: 1; }
kbd {
  font-family: var(--font-mono); font-size: .68rem; padding: .1rem .35rem;
  background: var(--bg-soft); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; color: var(--text-3);
}

.read-progress {
  position: fixed; top: var(--topbar-h); left: 0; height: 2px; width: 0;
  background: var(--accent); z-index: 61; transition: width .1s linear;
}

/* ------------------------------------------------------------- shell */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  align-items: start;
  max-width: 96rem; margin: 0 auto;
}
body.is-home .shell, body.is-fulltext .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

/* ----------------------------------------------------------- sidebar */
.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  font-family: var(--font-ui);
}
.sidebar-inner { padding: 1.25rem .75rem 4rem; }
.nav-group {
  margin: 1.25rem .6rem .4rem; font-size: .7rem; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase; color: var(--text-3);
}
.nav-group:first-child { margin-top: .25rem; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: flex; align-items: baseline; gap: .55rem;
  padding: .36rem .6rem; border-radius: var(--radius-sm);
  color: var(--text-2); text-decoration: none; font-size: .875rem; line-height: 1.4;
}
.nav-list a:hover { background: var(--bg-soft); color: var(--text); }
.nav-list a.is-active { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
:root[data-theme='dark'] .nav-list a.is-active { color: var(--accent-2); }
.nav-num {
  flex: none; min-width: 1.35rem; text-align: right;
  font-variant-numeric: tabular-nums; font-size: .75rem; color: var(--text-3);
}
.nav-list a.is-active .nav-num { color: inherit; }
.nav-num--icon { font-size: .8rem; }

.scrim { display: none; }

/* ----------------------------------------------------------- content */
.content { min-width: 0; padding: 2.25rem 2.5rem 5rem; }
.prose { max-width: var(--content-w); margin: 0 auto; }
body.is-home .prose, body.is-fulltext .prose { max-width: 58rem; }

.chapter-kicker {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  font-family: var(--font-ui); font-size: .75rem; margin-bottom: .85rem;
}
.kicker-badge {
  padding: .18rem .55rem; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent-2); font-weight: 600; letter-spacing: .01em;
}
.kicker-time { color: var(--text-3); }

.chapter-lede {
  font-size: 1.08rem; color: var(--text-2); margin: 0 0 2rem;
  padding-bottom: 1.25rem; border-bottom: 1px solid var(--line);
}

/* --------------------------------------------------------- typography */
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-ui); font-weight: 650; line-height: 1.28;
  letter-spacing: -.015em; color: var(--text); scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.prose h1 { font-size: 2.1rem; margin: 0 0 .75rem; }
.prose h2 { font-size: 1.7rem; margin: 0 0 1rem; }
.prose h3 { font-size: 1.28rem; margin: 2.6rem 0 .85rem; padding-top: .3rem; }
.prose h4 { font-size: 1.06rem; margin: 2rem 0 .7rem; color: var(--text-2); }
.prose h3 + h4 { margin-top: 1.2rem; }

.anchor {
  margin-left: .4rem; color: var(--line-2); text-decoration: none;
  font-weight: 400; opacity: 0; transition: opacity .12s;
}
.heading:hover .anchor, .anchor:focus { opacity: 1; }
.anchor:hover { color: var(--accent); }

.prose p { margin: 0 0 1.15rem; }
.prose ul, .prose ol { margin: 0 0 1.15rem; padding-left: 1.4rem; }
.prose li { margin-bottom: .45rem; }
.prose li > ul, .prose li > ol { margin-top: .45rem; }
.prose strong { font-weight: 650; }
.prose hr { border: none; border-top: 1px solid var(--line); margin: 2.75rem 0; }

.prose blockquote {
  margin: 1.5rem 0; padding: .1rem 0 .1rem 1.15rem;
  border-left: 3px solid var(--accent); color: var(--text-2);
}
.prose blockquote p:last-child { margin-bottom: 0; }

a.xref {
  text-decoration: none; color: var(--accent);
  border-bottom: 1px dotted color-mix(in srgb, var(--accent) 45%, transparent);
  white-space: nowrap;
}
a.xref:hover { border-bottom-style: solid; }

/* -------------------------------------------------------------- code */
.prose :not(pre) > code {
  font-family: var(--font-mono); font-size: .855em;
  background: var(--code-bg); border: 1px solid var(--line);
  padding: .08em .35em; border-radius: 4px; word-break: break-word;
}

.code-block {
  margin: 1.5rem 0; background: var(--code-bg);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .3rem .5rem .3rem .85rem;
  background: color-mix(in srgb, var(--line) 30%, transparent);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-ui); font-size: .7rem;
  letter-spacing: .07em; text-transform: uppercase; color: var(--text-3);
}
.code-copy {
  border: 1px solid transparent; background: transparent; color: var(--text-3);
  padding: .2rem .5rem; border-radius: 4px;
  font-family: var(--font-ui); font-size: .7rem; text-transform: none; letter-spacing: 0;
}
.code-copy:hover { background: var(--surface); border-color: var(--line); color: var(--text); }
.code-copy.is-done { color: var(--ok); }

.code-block pre { margin: 0; padding: .9rem 1rem; overflow-x: auto; }
.code-block code {
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.65;
  white-space: pre; color: var(--text);
}
.code-block.is-output { background: var(--bg-soft); }
.code-block.is-output code, .code-block.is-tree code { color: var(--text-2); }
.code-block.is-tree { background: var(--bg-soft); }

/* highlight.js — bảng màu bám theo token của site */
.hljs-comment, .hljs-quote { color: var(--text-3); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in.hljs-keyword { color: #8a3c8f; }
.hljs-string, .hljs-meta .hljs-string { color: #2b6b3f; }
.hljs-number, .hljs-literal { color: #9a5b00; }
.hljs-title, .hljs-title.function_, .hljs-section { color: #1a5aa8; }
.hljs-title.class_, .hljs-type { color: #1a5aa8; }
.hljs-built_in { color: #0f6b73; }
.hljs-attr, .hljs-variable, .hljs-params { color: var(--text); }
.hljs-meta { color: var(--text-3); }
.hljs-punctuation, .hljs-operator { color: var(--text-2); }
:root[data-theme='dark'] .hljs-keyword { color: #d79fdc; }
:root[data-theme='dark'] .hljs-string { color: #8fcf9e; }
:root[data-theme='dark'] .hljs-number, :root[data-theme='dark'] .hljs-literal { color: #e0b070; }
:root[data-theme='dark'] .hljs-title, :root[data-theme='dark'] .hljs-title.function_,
:root[data-theme='dark'] .hljs-title.class_, :root[data-theme='dark'] .hljs-type,
:root[data-theme='dark'] .hljs-section { color: #8ab6ef; }
:root[data-theme='dark'] .hljs-built_in { color: #6fc9cf; }

/* ------------------------------------------------------------ bảng */
.table-wrap {
  margin: 1.6rem 0; overflow-x: auto;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.table-wrap table { border-collapse: collapse; width: 100%; font-family: var(--font-ui); font-size: .855rem; }
.table-wrap th, .table-wrap td {
  padding: .55rem .85rem; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--line); line-height: 1.55;
}
.table-wrap--dense th, .table-wrap--dense td { padding: .5rem .55rem; }
.table-wrap thead th {
  background: var(--bg-soft); font-weight: 600; font-size: .78rem;
  letter-spacing: .02em; color: var(--text-2);
}
.table-wrap tbody tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.table-wrap td:first-child { font-weight: 500; }

/* -------------------------------------------------------------- hình */
.figure { margin: 2rem 0; }
.figure-frame {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem; cursor: zoom-in; overflow: hidden;
  display: flex; justify-content: center;
}
.figure-frame:hover { border-color: var(--line-2); }
.figure-frame img { display: block; border-radius: 3px; }
.figure figcaption {
  margin-top: .7rem; font-family: var(--font-ui); font-size: .82rem;
  line-height: 1.6; color: var(--text-2);
}
.figure figcaption strong { color: var(--text); font-weight: 600; }

/* ----------------------------------------------------------- callout */
.callout {
  margin: 1.5rem 0; padding: 1rem 1.15rem;
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); background: var(--surface);
}
.callout > :last-child { margin-bottom: 0; }
.callout-note { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }

/* ------------------------------------------------- ghi chú biên tập */
.editor-note {
  margin: 2rem 0; padding: 1.1rem 1.3rem;
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 28%, transparent);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.note-head { margin-bottom: .4rem; }
.note-tag {
  display: inline-block; padding: .14rem .55rem; border-radius: 99px;
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  color: var(--warn); text-decoration: none;
  font-family: var(--font-ui); font-size: .7rem; font-weight: 600;
  letter-spacing: .03em;
}
a.note-tag:hover { background: color-mix(in srgb, var(--warn) 28%, transparent); color: var(--warn); }
.note-title {
  font-family: var(--font-ui); font-size: 1rem; font-weight: 650;
  margin: 0 0 .6rem; color: var(--text); line-height: 1.4;
}
.note-body { font-size: .95rem; }
.note-body > :last-child { margin-bottom: 0; }
.note-body .table-wrap { background: var(--surface); }
.note-body .code-block { background: var(--surface); }

.note-list { display: grid; gap: 1.5rem; }
.note-card {
  padding: 1.25rem 1.4rem; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: var(--radius); scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.note-card-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.note-src { margin-left: auto; font-family: var(--font-ui); font-size: .78rem; text-decoration: none; }
.note-card h3 { margin-top: .2rem; }

/* -------------------------------------------------------------- toc */
.toc { position: sticky; top: var(--topbar-h); max-height: calc(100vh - var(--topbar-h)); overflow-y: auto; }
.toc-inner { padding: 2.75rem 1.25rem 3rem .5rem; font-family: var(--font-ui); }
.toc-head {
  margin: 0 0 .6rem; font-size: .7rem; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase; color: var(--text-3);
}
.toc-list { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc-list a {
  display: block; padding: .26rem 0 .26rem .75rem; margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-3); text-decoration: none; font-size: .795rem; line-height: 1.45;
}
.toc-list a:hover { color: var(--text); }
.toc-list a.is-current { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.toc-l4 a { padding-left: 1.5rem; font-size: .76rem; }

/* ------------------------------------------------------------ pager */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  max-width: var(--content-w); margin: 3.5rem auto 0;
  padding-top: 2rem; border-top: 1px solid var(--line);
}
.pager-link {
  display: flex; flex-direction: column; gap: .2rem;
  padding: .85rem 1rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); text-decoration: none; font-family: var(--font-ui);
}
.pager-link:hover { border-color: var(--accent); }
.pager-next { text-align: right; }
.pager-dir { font-size: .72rem; color: var(--text-3); }
.pager-title { font-size: .92rem; font-weight: 500; color: var(--text); }

/* --------------------------------------------------------- trang chủ */
.hero { padding: 1rem 0 2.5rem; border-bottom: 1px solid var(--line); margin-bottom: 2.5rem; }
.hero-kicker {
  font-family: var(--font-ui); font-size: .75rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin: 0 0 .75rem;
}
.hero h1 { font-size: clamp(2rem, 4.5vw, 3rem); line-height: 1.15; margin: 0 0 1rem; max-width: 22ch; }
.hero-lede { font-size: 1.15rem; color: var(--text-2); max-width: 54ch; margin: 0 0 1.75rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 2.25rem; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: var(--radius-sm);
  font-family: var(--font-ui); font-size: .9rem; font-weight: 500;
  text-decoration: none; border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
:root[data-theme='dark'] .btn-primary { color: #10211f; }
.btn-primary:hover { background: var(--accent-2); color: #fff; }
:root[data-theme='dark'] .btn-primary:hover { color: #10211f; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.hero-stats {
  display: flex; flex-wrap: wrap; gap: 2.25rem; margin: 0;
  font-family: var(--font-ui);
}
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats dt { font-size: 1.65rem; font-weight: 650; color: var(--accent); line-height: 1.1; }
.hero-stats dd { margin: .15rem 0 0; font-size: .8rem; color: var(--text-3); }

.home-section { margin-bottom: 3.25rem; }
.home-h2 { font-family: var(--font-ui); font-size: 1.35rem; font-weight: 650; margin: 0 0 .5rem; letter-spacing: -.015em; }
.home-sub { color: var(--text-2); margin: 0 0 1.35rem; }

.path-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); }
.path-card { padding: 1.15rem 1.25rem 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.path-tag {
  margin: 0 0 .45rem; font-family: var(--font-ui); font-size: .7rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--accent);
}
.path-card h3 { font-family: var(--font-ui); font-size: 1.05rem; margin: 0 0 .4rem; font-weight: 600; }
.path-note { font-size: .88rem; color: var(--text-2); margin: 0 0 .9rem; }
.path-steps { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.path-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .5rem; border-radius: 99px; background: var(--bg-soft);
  border: 1px solid var(--line); font-family: var(--font-ui); font-size: .74rem;
  color: var(--text-2); text-decoration: none;
}
.path-chip b { color: var(--accent); font-weight: 650; }
.path-chip:hover { border-color: var(--accent); color: var(--text); }
.path-arrow { color: var(--line-2); font-size: .75rem; }

.tool-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.tool-card {
  display: block; padding: 1.15rem 1.25rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit;
}
.tool-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.tool-icon {
  display: grid; place-items: center; width: 2rem; height: 2rem; margin-bottom: .6rem;
  background: var(--accent-soft); color: var(--accent-2); border-radius: .45rem; font-size: .95rem;
}
.tool-card h3 { font-family: var(--font-ui); font-size: .98rem; font-weight: 600; margin: 0 0 .3rem; }
.tool-card p { font-size: .85rem; color: var(--text-2); margin: 0; line-height: 1.6; }

.ch-grid { display: grid; gap: .6rem; }
.ch-card {
  display: flex; gap: 1rem; padding: .95rem 1.1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: inherit;
}
.ch-card:hover { border-color: var(--accent); }
.ch-num {
  flex: none; width: 2.1rem; height: 2.1rem; display: grid; place-items: center;
  background: var(--bg-soft); border-radius: .45rem;
  font-family: var(--font-ui); font-weight: 650; font-size: .92rem; color: var(--accent);
}
.ch-card:hover .ch-num { background: var(--accent-soft); }
.ch-body { min-width: 0; }
.ch-kicker { font-family: var(--font-ui); font-size: .7rem; color: var(--text-3); letter-spacing: .02em; }
.ch-card h3 { font-family: var(--font-ui); font-size: 1rem; font-weight: 600; margin: .1rem 0 .25rem; }
.ch-card p { margin: 0; font-size: .855rem; color: var(--text-2); line-height: 1.6; }

/* ----------------------------------------------------------- bài tập */
.ex-jump {
  display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 2rem;
  font-family: var(--font-ui);
}
.ex-jump a {
  padding: .25rem .65rem; border-radius: 99px; background: var(--bg-soft);
  border: 1px solid var(--line); font-size: .78rem; color: var(--text-2); text-decoration: none;
}
.ex-jump a:hover { border-color: var(--accent); color: var(--accent); }

.ex-list { display: grid; gap: 1.1rem; }
.ex-card {
  padding: 1.25rem 1.4rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.ex-head { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: .75rem; }
.ex-num { font-family: var(--font-ui); font-weight: 650; font-size: 1rem; color: var(--accent); }
.ex-chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-right: auto; }
.ex-chip {
  padding: .12rem .5rem; border-radius: 99px; background: var(--bg-soft);
  border: 1px solid var(--line); font-family: var(--font-ui); font-size: .7rem; color: var(--text-3);
}
.ex-chip-link { text-decoration: none; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.ex-chip-link:hover { background: var(--accent-soft); }
.ex-chip-easy { color: var(--ok); background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.ex-chip-mid { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.ex-chip-hard { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.ex-anchor { color: var(--line-2); text-decoration: none; font-family: var(--font-ui); }
.ex-anchor:hover { color: var(--accent); }
.ex-statement > :last-child { margin-bottom: 0; }

.ex-hint, .ex-solution { margin-top: 1rem; }
.ex-hint summary, .ex-solution summary {
  cursor: pointer; font-family: var(--font-ui); font-size: .85rem; font-weight: 500;
  padding: .5rem .8rem; border-radius: var(--radius-sm);
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text-2);
  list-style: none; display: flex; align-items: center; gap: .45rem;
}
.ex-hint summary::-webkit-details-marker, .ex-solution summary::-webkit-details-marker { display: none; }
.ex-hint summary::before, .ex-solution summary::before {
  content: '▸'; color: var(--accent); font-size: .8rem; transition: transform .15s;
}
.ex-hint[open] summary::before, .ex-solution[open] summary::before { transform: rotate(90deg); }
.ex-solution summary { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--accent-2); }
.ex-hint summary:hover, .ex-solution summary:hover { border-color: var(--accent); }
.ex-hint-body { padding: .85rem .9rem 0; font-size: .92rem; color: var(--text-2); }
.ex-solution-body { padding: 1.25rem .25rem 0; }
.ex-solution-body > :last-child { margin-bottom: 0; }
.ex-solution-body h3 { font-size: 1.1rem; margin-top: 1.75rem; }

/* -------------------------------------------------------- trắc nghiệm */
.quiz {
  margin: 2.5rem 0; padding: 1.35rem 1.4rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.quiz-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.1rem; }
.quiz-title { font-family: var(--font-ui); font-size: 1.05rem; font-weight: 650; margin: 0; }
.quiz-sub { margin: .15rem 0 0; font-size: .8rem; color: var(--text-3); font-family: var(--font-ui); }
.quiz-head > div:first-child, .quiz-head > .quiz-title { margin-right: auto; }
.quiz-reset { margin-left: auto; padding: .3rem .7rem; font-size: .78rem; }
.quiz-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.5rem; }
.quiz-q { margin: 0; }
.quiz-prompt {
  display: flex; gap: .6rem; margin: 0 0 .7rem;
  font-size: .98rem; line-height: 1.6; font-weight: 500;
}
.quiz-idx {
  flex: none; width: 1.5rem; height: 1.5rem; display: grid; place-items: center;
  background: var(--bg-soft); border-radius: 50%;
  font-family: var(--font-ui); font-size: .74rem; font-weight: 600; color: var(--text-3);
  margin-top: .15rem;
}
.quiz-opts { display: grid; gap: .4rem; }
.quiz-opt {
  display: flex; align-items: flex-start; gap: .6rem; width: 100%; text-align: left;
  padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-family: var(--font-ui); font-size: .875rem; line-height: 1.55;
  color: var(--text-2);
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); background: var(--surface); }
.quiz-opt:disabled { cursor: default; }
.quiz-mark {
  flex: none; width: 1.05rem; height: 1.05rem; margin-top: .22rem;
  border: 1.5px solid var(--line-2); border-radius: 50%;
  display: grid; place-items: center; font-size: .68rem; line-height: 1;
}
.quiz-opt.is-correct { border-color: var(--ok); background: var(--ok-soft); color: var(--text); }
.quiz-opt.is-correct .quiz-mark { border-color: var(--ok); background: var(--ok); color: var(--surface); }
.quiz-opt.is-correct .quiz-mark::after { content: '✓'; }
.quiz-opt.is-wrong { border-color: var(--danger); background: var(--danger-soft); color: var(--text); }
.quiz-opt.is-wrong .quiz-mark { border-color: var(--danger); background: var(--danger); color: var(--surface); }
.quiz-opt.is-wrong .quiz-mark::after { content: '✕'; }
.quiz-why {
  margin-top: .65rem; padding: .7rem .85rem;
  background: var(--bg-soft); border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: .865rem; line-height: 1.6; color: var(--text-2);
}
.quiz-why b { color: var(--text); }
.quiz-score {
  margin: 1.25rem 0 0; padding-top: .9rem; border-top: 1px solid var(--line);
  font-family: var(--font-ui); font-size: .84rem; color: var(--text-3);
}
.quiz-score.is-done { color: var(--accent); font-weight: 500; }

.quiz-filter { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1.5rem; }
.chip {
  padding: .28rem .7rem; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line);
  font-family: var(--font-ui); font-size: .78rem; color: var(--text-2);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme='dark'] .chip.is-active { color: #10211f; }
.quiz-wrap[hidden] { display: none; }

/* ------------------------------------------------------ luyện tính tay */
.drill {
  margin: 1.5rem 0 2.5rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.drill-tabs { display: flex; flex-wrap: wrap; gap: .25rem; padding: .6rem; background: var(--bg-soft); border-bottom: 1px solid var(--line); }
.drill-tab {
  padding: .35rem .75rem; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent;
  font-family: var(--font-ui); font-size: .8rem; color: var(--text-2);
}
.drill-tab:hover { background: var(--surface); }
.drill-tab.is-active { background: var(--surface); border-color: var(--line); color: var(--accent); font-weight: 600; }
.drill-body { padding: 1.25rem 1.4rem 1.4rem; }
.drill-question { font-size: 1rem; margin: 0 0 1rem; line-height: 1.7; }
.drill-fields { display: flex; flex-wrap: wrap; gap: .9rem; margin-bottom: 1.1rem; }
.drill-field { display: flex; flex-direction: column; gap: .3rem; }
.drill-field label { font-family: var(--font-ui); font-size: .78rem; color: var(--text-3); }
.drill-field input {
  width: 11rem; padding: .45rem .6rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--bg); font-family: var(--font-mono); font-size: .85rem;
}
.drill-field input:focus { border-color: var(--accent); }
.drill-field.is-ok input { border-color: var(--ok); background: var(--ok-soft); }
.drill-field.is-bad input { border-color: var(--danger); background: var(--danger-soft); }
.drill-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.drill-actions .btn { padding: .45rem .9rem; font-size: .84rem; }
.drill-feedback { margin-top: 1rem; font-family: var(--font-ui); font-size: .87rem; line-height: 1.65; }
.drill-feedback:empty { margin: 0; }
.drill-feedback .ok { color: var(--ok); font-weight: 600; }
.drill-feedback .bad { color: var(--danger); font-weight: 600; }
.drill-feedback .why { display: block; margin-top: .4rem; color: var(--text-2); }
.drill-feedback code { font-family: var(--font-mono); font-size: .85em; background: var(--bg-soft); padding: .05em .3em; border-radius: 3px; }

/* --------------------------------------------------------- thuật ngữ */
.term-filter { margin: 0 0 1.5rem; }
.term-filter input {
  width: 100%; padding: .65rem .85rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface);
  font-family: var(--font-ui); font-size: .92rem;
}
.term-filter input:focus { border-color: var(--accent); }
.term-count { margin: .5rem 0 0; font-family: var(--font-ui); font-size: .78rem; color: var(--text-3); }
.term-group[hidden] { display: none; }
.term-list { margin: 0; display: grid; gap: .7rem; }
.term {
  padding: .9rem 1.1rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.term[hidden] { display: none; }
.term-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .55rem; margin: 0 0 .35rem; }
.term-vi { font-family: var(--font-ui); font-weight: 600; font-size: .98rem; color: var(--text); }
.term-en {
  font-family: var(--font-ui); font-size: .78rem; color: var(--accent);
  background: var(--accent-soft); padding: .1rem .5rem; border-radius: 99px;
}
.term-en .katex { font-size: .95em; color: inherit; }
.term-def { margin: 0; font-size: .93rem; color: var(--text-2); }
.term-def > :last-child { margin-bottom: 0; }

/* ------------------------------------------------------- thư viện hình */
.gal-grid { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }
.gal-card { margin: 0; display: flex; flex-direction: column; }
/* Cho mọi ô ảnh cùng chiều cao để phần chú thích thẳng hàng theo từng dòng. */
.gal-card .figure-frame { flex: none; height: 15rem; align-items: center; }
.gal-card .figure-frame img { max-height: 100%; object-fit: contain; }
.gal-card figcaption { margin-top: .7rem; font-family: var(--font-ui); }
.gal-num { margin: 0 0 .2rem; font-size: .8rem; font-weight: 650; color: var(--accent); }
.gal-cap { margin: 0 0 .4rem; font-size: .84rem; line-height: 1.55; color: var(--text-2); }
.gal-link { font-size: .78rem; text-decoration: none; }

/* --------------------------------------------------------- mã nguồn */
.src-list { display: grid; gap: 1.1rem; }
.src-card { padding: 1.15rem 1.3rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.src-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.src-title { margin: 0; font-size: 1rem; font-family: var(--font-ui); }
.src-title code { font-size: .9rem; }
.src-meta { font-family: var(--font-ui); font-size: .76rem; color: var(--text-3); margin-right: auto; }
.src-dl { font-family: var(--font-ui); font-size: .78rem; text-decoration: none; }
.src-note { margin: .6rem 0 .9rem; font-size: .9rem; color: var(--text-2); }
.src-details { margin-top: .6rem; }
.src-details summary {
  cursor: pointer; font-family: var(--font-ui); font-size: .82rem; color: var(--text-2);
  padding: .45rem .75rem; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); list-style: none; display: flex; align-items: center; gap: .45rem;
}
.src-details summary::-webkit-details-marker { display: none; }
.src-details summary::before { content: '▸'; color: var(--accent); transition: transform .15s; }
.src-details[open] summary::before { transform: rotate(90deg); }
.src-details summary:hover { border-color: var(--accent); }
.src-details .code-block { margin: .6rem 0 0; }
.src-details pre { max-height: 32rem; }

/* --------------------------------------------------- phòng thí nghiệm */
.lab {
  margin: 2rem 0 2.5rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.lab-head { padding: 1.2rem 1.4rem; background: var(--bg-soft); border-bottom: 1px solid var(--line); }
.lab-head h3 { font-family: var(--font-ui); font-size: 1.1rem; font-weight: 650; margin: 0 0 .35rem; }
.lab-head p { margin: 0; font-size: .875rem; color: var(--text-2); line-height: 1.6; }
.lab-grid { display: grid; grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); }
.lab-grid-2 { grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); }
.lab-controls { padding: 1.25rem 1.3rem; border-right: 1px solid var(--line); display: grid; gap: .85rem; align-content: start; }
.lab-panel { padding: 1.25rem 1.3rem; display: grid; gap: .85rem; align-content: start; }
.lab-panel + .lab-panel { border-left: 1px solid var(--line); }
.lab-sub { font-family: var(--font-ui); font-size: .8rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin: 0; }
.lab-output { padding: 1.25rem 1.3rem; min-width: 0; }

.ctl { display: grid; gap: .3rem; }
.ctl-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.ctl-label { font-family: var(--font-ui); font-size: .78rem; color: var(--text-3); }
.ctl input, .ctl select {
  width: 100%; padding: .42rem .55rem; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: .84rem;
}
.ctl select { font-family: var(--font-ui); }
.ctl input:focus, .ctl select:focus { border-color: var(--accent); }
.ctl-range input[type='range'] { padding: 0; accent-color: var(--accent); background: transparent; border: none; }
.ctl-label output { font-family: var(--font-mono); color: var(--accent); font-weight: 500; }
.ctl-note { margin: 0; font-family: var(--font-ui); font-size: .74rem; line-height: 1.55; color: var(--text-3); }
.chip-row { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip-row .chip { font-family: var(--font-mono); font-size: .72rem; padding: .2rem .55rem; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .75rem; margin-bottom: .9rem; }
.stat { display: flex; flex-direction: column; gap: .12rem; padding: .6rem .75rem; background: var(--bg-soft); border-radius: var(--radius-sm); }
.stat-label { font-family: var(--font-ui); font-size: .7rem; color: var(--text-3); letter-spacing: .01em; }
.stat-value { font-family: var(--font-mono); font-size: 1rem; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.stat-value.is-accent { color: var(--accent); }
.stat-value.is-warn { color: var(--warn); }
.stat-hint { font-family: var(--font-ui); font-size: .68rem; color: var(--text-3); }
.lab-note { margin: .25rem 0 0; font-family: var(--font-ui); font-size: .8rem; line-height: 1.6; color: var(--text-2); }
.lab-note:empty { margin: 0; }
.lab-note b { color: var(--text); }

.chart { margin: 1rem 0 .5rem; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-axis { stroke: var(--line-2); stroke-width: 1; }
.chart-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-label { fill: var(--text-3); font-family: var(--font-ui); font-size: 9px; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart-ideal { fill: none; stroke: var(--line-2); stroke-width: 1.4; stroke-dasharray: 4 3; }
.chart-err { fill: none; stroke: var(--danger); stroke-width: 1.6; }
.chart-clip { fill: var(--danger); opacity: .09; }
.chart-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-mark { stroke: var(--text-3); stroke-width: 1.2; stroke-dasharray: 4 3; }
.chart-mark2 { stroke: var(--line-2); stroke-width: 1.2; stroke-dasharray: 1 3; }
.chart-cap { margin: .35rem 0 0; font-family: var(--font-ui); font-size: .76rem; color: var(--text-3); line-height: 1.55; }

.bits { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: 1rem; font-family: var(--font-mono); }
.bit-group { display: flex; flex-direction: column; gap: .25rem; }
.bit-group-label { font-family: var(--font-ui); font-size: .68rem; color: var(--text-3); }
.bit-cells { display: flex; gap: 2px; flex-wrap: wrap; }
.bit {
  width: 1.15rem; height: 1.5rem; display: grid; place-items: center;
  border-radius: 3px; font-size: .74rem; font-weight: 500;
}
.bit-s { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.bit-e { background: #dceafb; color: #1a5aa8; border: 1px solid #b7d3f4; }
.bit-m { background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent); }
:root[data-theme='dark'] .bit-e { background: #17293f; color: #8ab6ef; border-color: #26405f; }

.formula-box {
  margin: .5rem 0 .75rem; padding: .75rem .9rem; background: var(--code-bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: .8rem; line-height: 1.8; overflow-x: auto; white-space: pre;
  color: var(--text-2);
}
.verdict {
  margin: 0 1.3rem 1.3rem; padding: .9rem 1.1rem;
  border-radius: var(--radius-sm); background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  font-family: var(--font-ui); font-size: .88rem; line-height: 1.65; color: var(--text);
}
.verdict:empty { display: none; }
.verdict b { color: var(--accent-2); }

/* ---------------------------------------------------------- lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 120;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  padding: 2rem; background: rgba(12, 12, 14, .88); backdrop-filter: blur(3px);
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: min(100%, 78rem); max-height: 82vh; background: #fff; padding: .75rem; border-radius: var(--radius); }
.lightbox-cap { max-width: 50rem; margin: 0; color: #e9e7e2; font-family: var(--font-ui); font-size: .85rem; text-align: center; line-height: 1.6; }
.lightbox-close {
  position: absolute; top: 1rem; right: 1.25rem;
  width: 2.5rem; height: 2.5rem; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, .12); color: #fff; font-size: 1.5rem; line-height: 1;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .22); }

/* ------------------------------------------------------------ tìm kiếm */
.searchpanel {
  position: fixed; inset: 0; z-index: 130;
  display: flex; justify-content: center; padding: 6vh 1rem 2rem;
  background: rgba(12, 12, 14, .45); backdrop-filter: blur(2px);
}
.searchpanel[hidden] { display: none; }
.searchpanel-box {
  width: min(42rem, 100%); max-height: 78vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden;
}
.searchpanel-field { display: flex; align-items: center; gap: .6rem; padding: .85rem 1rem; border-bottom: 1px solid var(--line); }
.searchpanel-field svg { width: 1.1rem; height: 1.1rem; flex: none; fill: none; stroke: var(--text-3); stroke-width: 1.8; stroke-linecap: round; }
.searchpanel-field input { flex: 1; border: none; background: transparent; font-family: var(--font-ui); font-size: 1rem; outline: none; }
.searchpanel-results { overflow-y: auto; padding: .5rem; }
.sr-item {
  display: block; padding: .6rem .75rem; border-radius: var(--radius-sm);
  text-decoration: none; color: inherit; font-family: var(--font-ui);
}
.sr-item:hover, .sr-item.is-active { background: var(--bg-soft); }
.sr-head { display: flex; align-items: baseline; gap: .5rem; }
.sr-ch { font-size: .68rem; color: #fff; background: var(--accent); padding: .05rem .4rem; border-radius: 99px; flex: none; }
:root[data-theme='dark'] .sr-ch { color: #10211f; }
.sr-title { font-size: .9rem; font-weight: 600; color: var(--text); }
.sr-snip { margin: .2rem 0 0; font-size: .8rem; color: var(--text-3); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sr-snip mark, .sr-title mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 2px; padding: 0 .1em; }
.sr-empty { padding: 1.5rem; text-align: center; color: var(--text-3); font-family: var(--font-ui); font-size: .88rem; }

/* --------------------------------------------------------------- math */
.katex { font-family: KaTeX_Main, 'Source Serif 4', 'Times New Roman', serif; }
.katex-display { margin: 1.4rem 0; padding: .2rem 0; overflow-x: auto; overflow-y: hidden; }
/* Công thức hiển thị không bị bẻ dòng giữa chừng trên màn hình rộng; chỉ
   trên điện thoại mới cho xuống dòng tại dấu quan hệ để khỏi phải cuộn ngang. */
.katex-display > .katex { white-space: nowrap; }
@media (max-width: 720px) { .katex-display > .katex { white-space: normal; } }
.table-wrap .katex { font-size: 1em; }

/* -------------------------------------------------------- toàn văn */
.fulltext-chapter { padding-top: 1.5rem; border-top: 1px solid var(--line); margin-top: 2.5rem; }
.fulltext-chapter:first-of-type { border-top: none; margin-top: 0; }

/* ---------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc { display: none; }
  .content { padding-inline: 2rem; }
}

@media (max-width: 860px) {
  :root { --topbar-h: 3.25rem; }
  body { font-size: 1.02rem; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: grid; }
  .search-btn { min-width: 0; flex: 1; }
  .search-btn span, .search-btn kbd { display: none; }
  .brand-text i { display: none; }

  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; z-index: 70;
    width: min(20rem, 85vw); background: var(--surface);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0; z-index: 65; background: rgba(12, 12, 14, .4); }
  .scrim[hidden] { display: none; }

  .content { padding: 1.5rem 1.15rem 4rem; }
  .prose h1 { font-size: 1.8rem; }
  .prose h2 { font-size: 1.45rem; }
  .prose h3 { font-size: 1.15rem; }
  .lab-grid, .lab-grid-2 { grid-template-columns: minmax(0, 1fr); }
  .lab-controls { border-right: none; border-bottom: 1px solid var(--line); }
  .lab-panel + .lab-panel { border-left: none; border-top: 1px solid var(--line); }
  .pager { grid-template-columns: 1fr; }
  .hero-stats { gap: 1.5rem; }
  .drill-field input { width: 100%; }
  .drill-field { flex: 1 1 9rem; }
}

/* -------------------------------------------------------------- print */
@media print {
  .topbar, .sidebar, .toc, .pager, .read-progress, .searchpanel, .lightbox,
  .quiz, .drill, .ex-jump, .skip-link, .code-copy { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .content { padding: 0; }
  .prose, body.is-fulltext .prose { max-width: none; }
  body { font-size: 11pt; background: #fff; color: #000; }
  .ex-solution[open] > summary { display: none; }
  details { break-inside: avoid; }
  .figure, .table-wrap, .code-block { break-inside: avoid; }
  a { color: #000; text-decoration: underline; }
}

.src-badge {
  padding: .12rem .5rem; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent-2);
  font-family: var(--font-ui); font-size: .68rem; font-weight: 600;
}

/* --------------------------------------------- bộ chuyển giáo trình */
.book-switch {
  display: flex; flex-wrap: wrap; gap: .25rem; padding: .25rem;
  margin: 0 .35rem .35rem; border-radius: var(--radius-sm);
  background: var(--bg-soft); border: 1px solid var(--line);
}
/* flex-basis 0 với grow cho các tab chia đều một hàng, nhưng nhãn dài thì
   xuống hàng nguyên khối thay vì bị ngắt giữa từ. */
.book-tab {
  flex: 1 1 auto; min-width: 0; white-space: nowrap;
  text-align: center; padding: .32rem .5rem; border-radius: 5px;
  font-family: var(--font-ui); font-size: .8rem; font-weight: 500;
  color: var(--text-3); text-decoration: none;
}
.book-tab:hover { color: var(--text); }
.book-tab.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* ------------------------------------------- trang chủ nhiều giáo trình */
.book-block { margin: 0 0 4rem; scroll-margin-top: calc(var(--topbar-h) + 1rem); }
.book-head { padding-bottom: 1.5rem; margin-bottom: 1.75rem; border-bottom: 1px solid var(--line); }
.book-kicker {
  margin: 0 0 .4rem; font-family: var(--font-ui); font-size: .72rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
}
.book-head h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin: 0 0 .6rem; line-height: 1.2; }
.book-head h2 a { color: inherit; text-decoration: none; }
.book-head h2 a:hover { color: var(--accent); }
.book-blurb { font-size: 1.02rem; color: var(--text-2); max-width: 58ch; margin: 0 0 1.25rem; }
.tool-pills { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1.25rem; }
.tool-pill {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .3rem .7rem; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line);
  font-family: var(--font-ui); font-size: .78rem; color: var(--text-2); text-decoration: none;
}
.tool-pill:hover { border-color: var(--accent); color: var(--accent); }
.tool-pill span { color: var(--accent); }
.home-h3 {
  font-family: var(--font-ui); font-size: 1.05rem; font-weight: 650;
  margin: 2rem 0 .9rem; letter-spacing: -.01em;
}
.path-card h4, .ch-card h4, .tool-card h3 {
  font-family: var(--font-ui); font-size: 1rem; font-weight: 600; margin: .1rem 0 .3rem;
}
.ch-card h4 { font-size: .98rem; }

/* ------------------------------------------------ máy tính ML Test Score */
.mts-wrap { padding: 1.25rem 1.3rem 1.4rem; }
.mts-total { margin-bottom: 1rem; }
.mts-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); margin: 1.25rem 0; }
.mts-group { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mts-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .85rem; background: var(--bg-soft); border-bottom: 1px solid var(--line);
}
.mts-head h4 { margin: 0; font-family: var(--font-ui); font-size: .92rem; font-weight: 650; }
.mts-score {
  font-family: var(--font-mono); font-size: .95rem; font-weight: 500; color: var(--accent);
}
.mts-list { list-style: none; margin: 0; padding: 0; }
.mts-item {
  display: flex; align-items: center; gap: .6rem; padding: .45rem .85rem;
  border-bottom: 1px solid var(--line); font-family: var(--font-ui); font-size: .82rem;
}
.mts-item:last-child { border-bottom: none; }
.mts-text { flex: 1; line-height: 1.4; color: var(--text-2); }
.mts-opts { display: flex; gap: 2px; flex: none; }
.mts-opt {
  padding: .18rem .45rem; border: 1px solid var(--line); background: var(--bg);
  font-family: var(--font-ui); font-size: .68rem; color: var(--text-3);
}
.mts-opt:first-child { border-radius: 4px 0 0 4px; }
.mts-opt:last-child { border-radius: 0 4px 4px 0; }
.mts-opt:hover { color: var(--text); }
.mts-opt.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme='dark'] .mts-opt.is-on { color: #10211f; }
.mts-opt[data-v="0"].is-on { background: var(--text-3); border-color: var(--text-3); color: var(--surface); }
.mts-opt[data-v="0.5"].is-on { background: var(--warn); border-color: var(--warn); color: var(--surface); }

@media (max-width: 860px) {
  .mts-item { flex-wrap: wrap; }
  .mts-text { flex: 1 1 100%; }
}

/* ------------------------------------------------------- trang Lộ trình */
.hero--tight { padding-bottom: 1.25rem; }
.lt-tong {
  font-family: var(--font-ui); font-size: .82rem; color: var(--text-3);
  letter-spacing: .02em; margin: 1rem 0 0;
}
.lt-figure { margin: 2rem 0 2.75rem; }
.lt-phan { margin: 0 0 3.25rem; scroll-margin-top: calc(var(--topbar-h) + 1rem); }
.lt-phan-head { padding-bottom: 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.lt-phan-kicker {
  margin: 0 0 .3rem; font-family: var(--font-ui); font-size: .72rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
}
.lt-phan-head h2 { margin: 0 0 .5rem; font-size: 1.5rem; line-height: 1.2; }
.lt-phan-head h2 a { color: inherit; text-decoration: none; }
.lt-phan-head h2 a:hover { color: var(--accent); }
.lt-phan-blurb { margin: 0 0 .6rem; color: var(--text-2); max-width: 62ch; font-size: .96rem; }
.lt-phan-meta { margin: 0; font-family: var(--font-ui); font-size: .78rem; color: var(--text-3); }

.lt-list { list-style: none; margin: 0; padding: 0; }
.lt-row { display: flex; gap: .85rem; align-items: flex-start; padding: .1rem 0; }
.lt-num {
  flex: 0 0 2.1rem; text-align: right; padding-top: .78rem;
  font-family: var(--font-ui); font-size: .95rem; font-weight: 650;
  color: var(--accent); font-variant-numeric: tabular-nums;
}
.lt-num--aux { color: var(--text-3); font-weight: 500; font-size: .78rem; padding-top: .9rem; }
.lt-link {
  flex: 1; display: block; padding: .65rem .85rem; border-radius: var(--radius-sm);
  text-decoration: none; color: inherit; border: 1px solid transparent;
}
.lt-link:hover { background: var(--bg-soft); border-color: var(--line); }
.lt-title {
  display: block; font-family: var(--font-ui); font-weight: 600;
  font-size: .98rem; color: var(--text); line-height: 1.35;
}
.lt-link:hover .lt-title { color: var(--accent); }
.lt-sub {
  display: block; margin-top: .12rem;
  font-family: var(--font-ui); font-size: .74rem; color: var(--text-3);
}
.lt-sum {
  display: block; margin-top: .3rem; font-size: .88rem; color: var(--text-2);
  line-height: 1.5; max-width: 72ch;
}
.lt-row--aux .lt-title { font-weight: 500; color: var(--text-2); font-size: .92rem; }
.lt-row--aux .lt-sum { display: none; }

@media (max-width: 640px) {
  .lt-num { flex-basis: 1.6rem; font-size: .85rem; }
  .lt-link { padding: .55rem .6rem; }
  .lt-sum { font-size: .85rem; }
}
.home-spine {
  margin: 1.5rem 0 0; padding: .75rem 1rem; border-radius: var(--radius-sm);
  background: var(--bg-soft); border: 1px solid var(--line);
  font-size: .92rem; color: var(--text-2); max-width: 62ch;
}
.home-spine a { color: var(--accent); font-weight: 600; }

/* phần nhỏ trong thanh bên */
.nav-group--part {
  display: flex; align-items: baseline; gap: .45rem;
  margin-top: 1.15rem; text-transform: none; letter-spacing: 0;
  font-size: .78rem; color: var(--text-2); font-weight: 600;
}
.nav-group--part:first-of-type { margin-top: .35rem; }
.nav-part-no {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.05rem; height: 1.05rem; border-radius: 3px;
  background: var(--accent); color: #fff;
  font-size: .62rem; font-weight: 700; flex: 0 0 auto;
}
.lt-phan--aux { margin: 0 0 2.5rem; padding-left: .2rem; }
.lt-aux-head {
  margin: 0 0 .5rem; font-family: var(--font-ui); font-size: .74rem;
  font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
}

/* nhịp chuyển trang của router: chỉ mờ đi một chút, không nhấp nháy */
.is-navigating .content { opacity: .55; transition: opacity .12s ease; }
.content { transition: opacity .12s ease; }

/* ------------------------------------------- hình tương tác trong lab */
.viz {
  width: 100%; display: block; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  touch-action: none;
}
.lab-output--2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.lab-grid--wide .lab-controls { max-width: 260px; }
.ctl-range { display: block; }
.ctl-range input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: .3rem; }
.ctl-out {
  float: right; font-variant-numeric: tabular-nums; color: var(--accent);
  font-weight: 650; font-style: normal;
}
.ctl-check { display: flex; align-items: center; gap: .5rem; }
.ctl-check input { accent-color: var(--accent); width: 15px; height: 15px; }
.ctl-check span { font-family: var(--font-ui); font-size: .84rem; color: var(--text-2); }
.lab-btns { display: flex; gap: .45rem; flex-wrap: wrap; }
.lab-btn {
  flex: 1 1 auto; padding: .42rem .7rem; border-radius: 6px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  font-family: var(--font-ui); font-size: .8rem; color: var(--text-2);
}
.lab-btn:hover { border-color: var(--accent); color: var(--accent); }
.lab-btn:active { background: var(--bg-soft); }
.lab-page .hero--tight { padding-bottom: 1rem; }

@media (max-width: 720px) {
  .lab-output--2 { grid-template-columns: 1fr; }
  .lab-grid--wide .lab-controls { max-width: none; }
}

/* Trang phòng thí nghiệm cần rộng hơn cột chữ thường: hình tương tác mà hẹp
   thì mất hết tác dụng quan sát. */
.lab-page { max-width: 980px; }
.lab-page > .lab { max-width: none; }
.lab-stats { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; align-content: start; }
@media (max-width: 720px) { .lab-stats { grid-template-columns: 1fr; } }

/* ---------------------------------------- ô xem trước khi rê lên liên kết */
.xpreview {
  position: absolute; z-index: 60; width: min(380px, calc(100vw - 24px));
  padding: .7rem .85rem; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
  font-family: var(--font-ui);
}
.xpreview-title {
  margin: 0 0 .3rem; font-size: .86rem; font-weight: 650; color: var(--accent);
  line-height: 1.35;
}
.xpreview-body { margin: 0; font-size: .8rem; line-height: 1.55; color: var(--text-2); }
.xpreview-hint {
  margin: .5rem 0 0; font-size: .66rem; color: var(--text-3);
  letter-spacing: .05em; text-transform: uppercase;
}

/* tên phần trên dòng kicker của trang chương */
.kicker-part { font-family: var(--font-ui); font-size: .76rem; color: var(--text-3); }
.kicker-part::before { content: "\00B7"; margin: 0 .45rem; opacity: .6; }

/* =====================================================================
   HỆ THỐNG GIAO DIỆN: icon Lucide, tiêu đề đánh số, hộp kiểu giáo trình
   ===================================================================== */

/* ------------------------------------------------------------- icon */
.ic { width: 1em; height: 1em; flex: 0 0 auto; vertical-align: -.14em; stroke-width: 2; }
.icon-btn .ic, .search-btn .ic { width: 18px; height: 18px; vertical-align: middle; }
.nav-num--icon .ic { width: 15px; height: 15px; vertical-align: -3px; opacity: .8; }
.nav-list a.is-active .nav-num--icon .ic { opacity: 1; }
.tool-pill .ic { width: 14px; height: 14px; color: var(--accent); }
.kicker-time { display: inline-flex; align-items: center; gap: .3rem; }
.kicker-time .ic { width: 13px; height: 13px; opacity: .75; }

/* ------------------------------------------------ tiêu đề đánh số */
/* Số mục đứng riêng, màu nhấn nhạt, cách chữ một khoảng cố định — lối
   đánh số của giáo trình in (CS229, d2l). Không còn dấu chấm cuối số. */
.prose h2.heading, .prose h3.heading, .prose h4.heading {
  display: flex; align-items: baseline; gap: .7rem; flex-wrap: wrap;
}
.prose .hnum {
  flex: 0 0 auto; font-variant-numeric: tabular-nums; font-weight: 600;
  color: var(--accent); opacity: .78; letter-spacing: -.01em;
}
.prose h2 .hnum {
  font-size: .62em; padding: .12em .5em; border-radius: 6px;
  background: var(--accent-soft, rgba(31,111,104,.10)); opacity: 1;
  align-self: center; transform: translateY(-.08em);
}
.prose h3 .hnum { min-width: 2.4em; }
.prose h4 .hnum { min-width: 3em; font-size: .92em; }
.prose h3.heading { margin-top: 2.6rem; padding-bottom: .35rem;
  border-bottom: 1px solid var(--line); }
.prose h4.heading { margin-top: 1.8rem; }
.prose .htext { flex: 1 1 auto; min-width: 0; }


/* --------------------------------------------- hộp kiểu giáo trình */
/* Định nghĩa · Định lý · Chứng minh · Ví dụ · Nhận xét · Lưu ý · Phỏng vấn.
   Mỗi loại một màu viền và một icon, nhãn in hoa nhỏ ở đầu hộp. */
.callout { --c: var(--accent); }
.prose .callout {
  margin: 1.6rem 0; padding: .15rem 1.05rem .95rem;
  border: 1px solid var(--line); border-left: 3px solid var(--c);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: color-mix(in srgb, var(--c) 5%, var(--surface));
  font-style: normal; color: var(--text);
}
.prose .callout > p:not(.callout-label) { margin: .55rem 0 0; }
.prose .callout > :last-child { margin-bottom: 0; }
.prose .callout-label {
  display: flex; align-items: baseline; gap: .5rem;
  margin: .75rem 0 .1rem; padding: 0;
  font-family: var(--font-ui); font-size: .88rem; font-weight: 650;
  line-height: 1.45; color: var(--c);
}
.prose .callout-label .ic { width: 16px; height: 16px; align-self: center; }
.prose .callout-label .katex { font-size: 1.05em; }
.callout--dinh-nghia { --c: #1f6f68; }
.callout--dinh-ly    { --c: #2f5f9f; }
.callout--chung-minh { --c: #6b6b6b; }
.callout--vi-du      { --c: #9a6a00; }
.callout--nhan-xet   { --c: #5b6b8a; }
.callout--luu-y      { --c: #b0413e; }
.callout--phong-van  { --c: #7a4fa0; }
.callout--tra-loi    { --c: #2e6f8e; }
/* Chứng minh: nhẹ hơn các hộp khác, không nền, như trong sách in. */
.prose .callout--chung-minh {
  background: transparent; border: none; border-left: 2px solid var(--line-2);
  border-radius: 0; padding-top: 0;
}
.prose .callout--chung-minh .callout-label { color: var(--text-2); font-style: italic; }

:root[data-theme='dark'] .callout--dinh-nghia { --c: #4fb3a8; }
:root[data-theme='dark'] .callout--dinh-ly    { --c: #7aa7e8; }
:root[data-theme='dark'] .callout--chung-minh { --c: #a7a7a7; }
:root[data-theme='dark'] .callout--vi-du      { --c: #e0b34a; }
:root[data-theme='dark'] .callout--nhan-xet   { --c: #9aa9c8; }
:root[data-theme='dark'] .callout--luu-y      { --c: #e07a76; }
:root[data-theme='dark'] .callout--phong-van  { --c: #b99ae0; }
:root[data-theme='dark'] .callout--tra-loi    { --c: #7cc3e0; }

/* công thức đóng khung trong hộp định lý nổi hơn một chút */
.prose .callout .katex-display { margin: .7rem 0; }

/* số mục trong mục lục bên phải: cột riêng, thẳng hàng */
.toc-list a { display: flex; gap: .5rem; align-items: baseline; }
.toc-num {
  flex: 0 0 auto; min-width: 1.9rem; color: var(--text-3);
  font-variant-numeric: tabular-nums; font-size: .92em;
}
.toc-l4 .toc-num { min-width: 2.5rem; }
.toc-list a.is-current .toc-num { color: var(--accent); }

/* ---------------------------------------------- lộ trình theo chặng */
.lt-strip {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr));
  gap: .5rem; margin: 1.5rem 0 .5rem;
}
.lt-strip-item {
  display: flex; align-items: center; gap: .55rem; padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  text-decoration: none; color: var(--text); font-family: var(--font-ui); font-size: .8rem;
  line-height: 1.3; transition: border-color .12s, background .12s;
}
.lt-strip-item:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.lt-strip-icon { color: var(--accent); display: inline-flex; }
.lt-strip-icon .ic { width: 17px; height: 17px; }
.lt-strip-no {
  flex: 0 0 auto; min-width: 1.35rem; text-align: center; font-weight: 700; font-size: .72rem;
  color: var(--accent); font-variant-numeric: tabular-nums;
}
.lt-strip-name { font-weight: 550; }

.lt-chang { margin: 0 0 3.25rem; scroll-margin-top: calc(var(--topbar-h) + 1rem); }
.lt-chang-head {
  display: flex; gap: 1rem; align-items: flex-start;
  padding-bottom: 1rem; margin-bottom: .9rem; border-bottom: 1px solid var(--line);
}
.lt-chang-icon {
  flex: 0 0 auto; width: 2.6rem; height: 2.6rem; border-radius: .7rem;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); margin-top: .15rem;
}
.lt-chang-icon .ic { width: 22px; height: 22px; }
.lt-chang-text { min-width: 0; }
.lt-chang-head h2 { margin: 0 0 .45rem; font-size: 1.45rem; line-height: 1.22; }
.lt-tags { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin: .2rem 0 0; }
.lt-tags-lead { font-family: var(--font-ui); font-size: .72rem; color: var(--text-3); margin-right: .15rem; }
.lt-tag {
  font-family: var(--font-ui); font-size: .72rem; padding: .12rem .5rem; border-radius: 99px;
  border: 1px solid var(--line-2); color: var(--text-2); background: var(--surface);
}

.lt-map, .lt-aux { margin: 3.5rem 0 2.5rem; scroll-margin-top: calc(var(--topbar-h) + 1rem); }
.lt-map-title { display: flex; align-items: center; gap: .6rem; font-size: 1.45rem; margin: 0 0 .5rem; }
.lt-map-title .ic { color: var(--accent); width: 22px; height: 22px; }
.lt-map-node { font-weight: 600; white-space: nowrap; }
.lt-map-refs { display: flex; flex-wrap: wrap; gap: .3rem; }
.lt-ref {
  display: inline-flex; gap: .3rem; align-items: baseline; padding: .12rem .5rem;
  border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-2);
  text-decoration: none; font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.lt-ref span { font-weight: 400; color: var(--text-2); font-size: .72rem; }
.lt-ref:hover { background: var(--accent); color: #fff; }
.lt-ref:hover span { color: #fff; }
:root[data-theme='dark'] .lt-ref:hover, :root[data-theme='dark'] .lt-ref:hover span { color: #10211f; }

.lt-aux-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem 1.5rem; }
.lt-aux-book ul { list-style: none; margin: 0; padding: 0; font-family: var(--font-ui); font-size: .85rem; }
.lt-aux-book li { margin: 0 0 .3rem; }
.lt-aux-book a { color: var(--text-2); text-decoration: none; }
.lt-aux-book a:hover { color: var(--accent); }
.lt-aux-no { display: inline-block; min-width: 1.6rem; color: var(--text-3); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .lt-map-node { white-space: normal; }
  .lt-chang-icon { width: 2.1rem; height: 2.1rem; }
}
