  /* Layout: một cột đọc ~65 ký tự, tab theo chặng, mỗi chặng đi từ Cơ bản xuống khối Nâng cao */
  :root {
    --bg: #f6f3ec;
    --surface: #fdfbf6;
    --fg: #1d1c19;
    --muted: #6a675e;
    --rule: #dcd6c8;
    --accent: #7a3e1d;
    --accent-soft: #efe2d6;
    --code-bg: #ece7db;
    --ok: #2f6b3a; --ok-soft: #e3efe3; --bad: #a3322a; --bad-soft: #f6e1de;
    --font-display: "Source Serif 4", Georgia, "Times New Roman", serif;
    --font-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #161513; --surface: #1f1e1b; --fg: #ece8df; --muted: #a29e93;
      --rule: #3a3833; --accent: #e0a073; --accent-soft: #2d241d; --code-bg: #26241f; --ok: #7cc58a; --ok-soft: #1d2e21; --bad: #ef8a80; --bad-soft: #3a1f1c;
      color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --bg: #161513; --surface: #1f1e1b; --fg: #ece8df; --muted: #a29e93;
    --rule: #3a3833; --accent: #e0a073; --accent-soft: #2d241d; --code-bg: #26241f; --ok: #7cc58a; --ok-soft: #1d2e21; --bad: #ef8a80; --bad-soft: #3a1f1c;
    color-scheme: dark;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
  }
  .wrap {
    max-width: 720px;
    margin: 0 auto;
    padding-block: 28px 56px;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .kicker { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
  h1, h2 { font-family: var(--font-display); font-weight: 600; text-wrap: balance; margin: 0; }
  h1 { font-size: clamp(28px, 6vw, 36px); line-height: 1.15; }
  .lede { color: var(--muted); margin: 10px 0 14px; font-size: 17px; max-width: 65ch; }
  .legend { font-size: 14px; color: var(--muted); margin: 0 0 22px; max-width: 65ch; }

  .tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--rule); margin-bottom: 26px; scrollbar-width: thin; }
  .tab {
    flex: 0 0 auto; background: none; border: none; border-bottom: 2px solid transparent;
    color: var(--muted); font: inherit; font-size: 14px; padding: 10px 10px; cursor: pointer; white-space: nowrap;
  }
  .tab:hover { color: var(--fg); }
  .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
  [hidden] { display: none !important; }

  .stage { font-size: 13px; color: var(--accent); font-weight: 600; letter-spacing: .04em; margin: 0 0 4px; }
  .panel h2 { font-size: 26px; line-height: 1.2; margin-bottom: 10px; }
  .goal { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 12px 16px; border-radius: 4px; margin: 0 0 22px; max-width: 65ch; }
  .goal b { color: var(--accent); }
  .panel h3 { font-family: var(--font-display); font-size: 19px; font-weight: 600; margin: 26px 0 8px; }
  .panel h4 { font-size: 15.5px; font-weight: 600; margin: 18px 0 6px; }
  .lvl {
    display: inline-block; font-family: var(--font-body); font-size: 11px; font-weight: 600; letter-spacing: .03em;
    padding: 2px 9px; margin-left: 8px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); vertical-align: middle;
  }
  .lvl.adv { background: var(--accent); color: var(--bg); }
  .panel p { margin: 8px 0; max-width: 65ch; }
  .analogy {
    background: var(--surface); border: 1px solid var(--rule); border-radius: 8px;
    padding: 10px 14px; margin: 12px 0; max-width: 65ch; font-size: 15px;
  }
  .analogy b { color: var(--accent); }
  .advbox { border: 1px dashed var(--accent); border-radius: 10px; padding: 2px 16px 14px; margin-top: 30px; }
  .advbox > h3:first-child { margin-top: 16px; }

  ol.steps, ul.checks, ol.flow { padding-left: 0; margin: 8px 0; list-style: none; }
  ol.steps { counter-reset: st; }
  ol.steps li, ol.flow li { position: relative; padding: 6px 0 6px 34px; max-width: 65ch; }
  ol.steps li { counter-increment: st; }
  ol.steps li::before, ol.flow li::before {
    position: absolute; left: 0; top: 8px; width: 22px; height: 22px; border-radius: 50%;
    font-size: 12px; text-align: center; line-height: 20px;
  }
  ol.steps li::before { content: counter(st); border: 1px solid var(--accent); color: var(--accent); }
  ol.flow { counter-reset: fl; }
  ol.flow li { counter-increment: fl; }
  ol.flow li::before { content: counter(fl); background: var(--accent); color: var(--bg); line-height: 22px; }
  ul.checks li { padding: 6px 0 6px 26px; position: relative; max-width: 65ch; }
  ul.checks li::before {
    content: ""; position: absolute; left: 2px; top: 13px; width: 12px; height: 12px;
    border: 1.5px solid var(--muted); border-radius: 2px;
  }
  ul.plain { margin: 8px 0; padding-left: 20px; max-width: 65ch; }
  ul.plain li { margin: 4px 0; }

  .scroll { overflow-x: auto; max-width: 100%; margin: 10px 0; }
  table { width: 100%; border-collapse: collapse; font-size: 14.5px; min-width: 320px; }
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
  th { color: var(--muted); font-weight: 600; }

  .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 10px 0; }
  .cell { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 10px 12px; font-size: 14.5px; min-width: 0; }
  .cell b { display: block; margin-bottom: 2px; }
  .cell span { color: var(--muted); }

  .stack { margin: 12px 0; }
  .tier { background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--accent); border-radius: 8px; padding: 12px 14px; min-width: 0; }
  .tier .t-name { display: block; font-weight: 600; }
  .tier .t-tag { font-weight: 400; color: var(--muted); font-size: 14px; }
  .tier .t-desc { display: block; color: var(--muted); font-size: 14.5px; margin-top: 2px; }
  .tier.base { border-left-color: var(--muted); }
  .join { color: var(--muted); font-size: 13px; padding: 5px 14px; }

  pre {
    background: var(--code-bg); border: 1px solid var(--rule); border-radius: 6px; padding: 12px 14px;
    overflow-x: auto; font-family: var(--font-mono); font-size: 13.5px; line-height: 1.5; margin: 12px 0; max-width: 100%;
  }
  code { font-family: var(--font-mono); font-size: .92em; }
  .note { font-size: 14px; color: var(--muted); border-top: 1px solid var(--rule); margin-top: 30px; padding-top: 12px; max-width: 65ch; }
  .sources { font-size: 13.5px; color: var(--muted); max-width: 65ch; }
  .sources a { color: var(--accent); }
  .stamp { margin-top: 18px; font-size: 13px; color: var(--muted); }
  .rolebar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 22px; }
  .rolebar-label { font-size: 13.5px; color: var(--muted); margin-right: 4px; }
  .chip { font: inherit; font-size: 13.5px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); color: var(--fg); cursor: pointer; }
  .chip:hover { border-color: var(--accent); }
  .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
  .rt td:first-child { white-space: nowrap; width: 1%; }
  .rt tr.off { display: none; }

  /* Menu ngang: các chặng (dính trên cùng). Menu dọc: mục lục chặng đang mở + lọc vai trò */
  .wrap { max-width: 1080px; }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
  .tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); }
  .layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 40px; align-items: start; scroll-margin-top: 60px; }
  .side { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 62px); max-height: calc(100vh - 84px); overflow-y: auto; font-size: 14px; padding-bottom: 12px; }
  .main { min-width: 0; max-width: 720px; }
  .side-title, .toc-box summary { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
  .toc-box summary { list-style: none; cursor: pointer; }
  .toc-box summary::-webkit-details-marker { display: none; }
  .toc { list-style: none; padding: 0; margin: 0 0 24px; border-left: 1px solid var(--rule); }
  .toc a { display: block; padding: 5px 10px; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.35; }
  .toc a:hover { color: var(--fg); }
  .toc a.on { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
  .toc a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  .toc .tag { font-size: 10.5px; color: var(--accent); margin-left: 6px; font-weight: 600; white-space: nowrap; }
  .toc .empty { padding: 5px 10px; color: var(--muted); }
  .side .rolebar { flex-direction: column; align-items: stretch; gap: 4px; margin: 0; }
  .side .chip { text-align: left; border-radius: 6px; }
  .panel h3 { scroll-margin-top: 72px; }
  .tabs-label { align-self: center; font-size: 13px; color: var(--muted); padding-right: 6px; white-space: nowrap; }
  .tab[aria-pressed="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
  .toc-cur { text-transform: none; letter-spacing: 0; color: var(--accent); font-weight: 600; margin-left: 4px; }
  @media (min-width: 861px) { .toc-cur { display: none; } }
  .tree, .tree ul { list-style: none; margin: 0; padding: 0; }
  .tree > li { margin: 0 0 2px; }
  .node { display: flex; width: 100%; align-items: center; gap: 6px; background: none; border: none; font: inherit; font-size: 14.5px; color: var(--fg); text-align: left; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
  .node:hover { background: var(--accent-soft); }
  .node:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  .node .caret { display: inline-block; width: 12px; flex: 0 0 12px; color: var(--muted); transition: transform .15s; }
  .node[aria-expanded="true"] .caret { transform: rotate(90deg); }
  .node.cur { color: var(--accent); font-weight: 600; }
  .tree .sub { margin: 2px 0 10px 14px; border-left: 1px solid var(--rule); }
  .tree .sub a { display: block; padding: 4px 10px; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.35; font-size: 13.5px; }
  .tree .sub a:hover { color: var(--fg); }
  .tree .sub a.on { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
  .tree .sub a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
  .tree .tag { font-size: 10.5px; color: var(--accent); margin-left: 6px; font-weight: 600; white-space: nowrap; }
  @media (prefers-reduced-motion: reduce) { .node .caret { transition: none; } }

  .foryou { margin: 0 0 26px; max-width: 65ch; }
  .fy { border: 1px solid var(--accent); border-radius: 10px; padding: 12px 16px; background: var(--surface); }
  .fy-title { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 600; margin: 0 0 6px !important; }
  .fy p { margin: 6px 0; }
  .fy-warn { color: var(--muted); }
  .fy-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
  .fy-all { margin: 0 0 24px; max-width: 65ch; }
  .view-note { font-size: 14px; color: var(--muted); margin-top: 24px; }
  @media (max-width: 860px) {
    .layout { grid-template-columns: minmax(0, 1fr); gap: 18px; }
    .side { position: static; max-height: none; overflow: visible; border: 1px solid var(--rule); border-radius: 8px; padding: 12px 14px; background: var(--surface); }
    .toc-box summary::after { content: " ▾"; }
    .toc { margin-bottom: 14px; }
    .side .rolebar { flex-direction: row; flex-wrap: wrap; }
    .side .chip { border-radius: 999px; }
  }
  @media (max-width: 400px) { h1 { font-size: 26px; } .panel h2 { font-size: 22px; } }

  /* Lộ trình theo vị trí */
  .chooser { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 8px 0 24px; }
  .card { text-align: left; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 14px 16px; font: inherit; color: var(--fg); cursor: pointer; min-width: 0; }
  .card:hover { border-color: var(--accent); }
  .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .card b { display: block; font-family: var(--font-display); font-size: 18px; margin-bottom: 4px; color: var(--accent); }
  .card span { color: var(--muted); font-size: 14px; line-height: 1.45; }
  .roadmap { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin: 0 0 22px; }
  .step { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 8px 10px; font: inherit; color: var(--fg); cursor: pointer; min-width: 0; text-align: left; }
  .step:hover { border-color: var(--accent); }
  .step:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .step .n { font-size: 11px; color: var(--muted); letter-spacing: .06em; }
  .step .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .step .s { font-size: 11.5px; color: var(--muted); min-height: 1em; }
  .step.cur { border-color: var(--accent); background: var(--accent-soft); }
  .step.done .s { color: var(--accent); }
  .lv { font-weight: 600; letter-spacing: .02em; }
  .lv-co-ban { color: var(--accent); }
  .lv-trung-cap { color: var(--accent); }
  .lv-nang-cao { color: var(--accent); }
  .star { color: var(--accent); font-weight: 600; margin-left: 6px; }
  .intro { border: 1px solid var(--accent); border-radius: 10px; padding: 12px 16px; background: var(--surface); margin: 0 0 8px; max-width: 65ch; }
  .intro p { margin: 6px 0; }
  .prompt { border: 1px solid var(--rule); border-radius: 8px; background: var(--code-bg); margin: 10px 0; max-width: 100%; overflow: hidden; }
  .prompt-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--rule); font-size: 12.5px; color: var(--muted); }
  .prompt pre { border: none; border-radius: 0; margin: 0; background: transparent; white-space: pre-wrap; }
  .copy { font: inherit; font-size: 12.5px; padding: 3px 10px; border-radius: 6px; border: 1px solid var(--rule); background: var(--surface); color: var(--fg); cursor: pointer; }
  .copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  ul.checks.live li::before { display: none; }
  ul.checks.live li { padding-left: 0; display: flex; gap: 10px; align-items: flex-start; }
  ul.checks.live input { margin-top: 5px; width: 16px; height: 16px; accent-color: var(--accent); flex: 0 0 auto; }
  .nextwrap { margin-top: 26px; }
  .next { font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--bg); cursor: pointer; }
  .next:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
  .done-note { margin-top: 24px; color: var(--accent); font-weight: 600; max-width: 65ch; }
  .nen { margin-top: 34px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); }
  .nen > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--fg); }
  .nen > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .nen-body { padding: 0 16px 14px; }
  .nen-body .kh { font-family: var(--font-display); font-size: 17px; margin: 18px 0 6px; }
  .nen-body .advbox { margin-top: 18px; }
  .lesson h3 { scroll-margin-top: 72px; }

  .tab-search { display: inline-flex; align-items: center; gap: 6px; }
  .tab-search .ico { width: 15px; height: 15px; }
  .tabs-sep { width: 1px; align-self: stretch; background: var(--rule); margin: 8px 6px; flex: 0 0 1px; }
  .search-panel { margin: 0 0 30px; max-width: 760px; }
  .sbox input { width: 100%; font: inherit; font-size: 16px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--rule); background: var(--surface); color: var(--fg); }
  .sbox input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
  .sall { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 10px 0 4px; cursor: pointer; }
  .sall input { accent-color: var(--accent); width: 15px; height: 15px; }
  .qcount { font-size: 13.5px; color: var(--muted); margin: 6px 0 10px; }
  .qres { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
  .qres button { display: block; width: 100%; text-align: left; font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px; cursor: pointer; }
  .qres button:hover { border-color: var(--accent); }
  .qres button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .qres .where { display: block; font-size: 12px; color: var(--accent); font-weight: 600; letter-spacing: .02em; margin-bottom: 2px; }
  .qres .head { display: block; font-weight: 600; }
  .qres .snip { display: block; font-size: 14px; color: var(--muted); margin-top: 2px; }
  .qres mark, .flash { background: var(--accent-soft); color: inherit; border-radius: 3px; }
  .flash { outline: 2px solid var(--accent); outline-offset: 4px; transition: outline-color 1.2s; }

  .quiz { margin-top: 32px; border: 1px solid var(--accent); border-radius: 10px; padding: 2px 18px 16px; background: var(--surface); }
  .quiz h3 { margin-top: 16px; }
  .qz-intro { color: var(--muted); font-size: 14px; }
  .qz-list { list-style: none; padding: 0; margin: 8px 0; counter-reset: qz; }
  .qz-q { counter-increment: qz; padding: 12px 0; border-top: 1px solid var(--rule); }
  .qz-text { font-weight: 600; margin: 0 0 6px !important; }
  .qz-text::before { content: "Câu " counter(qz) ". "; color: var(--accent); }
  .qz-q.right .qz-text::after { content: "  ✓ Đúng"; color: var(--ok); }
  .qz-q.wrong .qz-text::after { content: "  ✗ Sai"; color: var(--bad); }
  .qz-opts { display: flex; flex-direction: column; gap: 4px; }
  .qz-opts label { display: flex; gap: 10px; align-items: flex-start; padding: 6px 10px; border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
  .qz-opts label:hover { background: var(--accent-soft); }
  .qz-opts input { margin-top: 5px; accent-color: var(--accent); flex: 0 0 auto; }
  .qz-opts input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .qz-opts label.is-ans { border-color: var(--ok); background: var(--ok-soft); }
  .qz-opts label.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
  .qz-exp { font-size: 14px; color: var(--muted); margin: 8px 0 0 !important; padding-left: 10px; border-left: 2px solid var(--rule); }
  .qz-actions { display: flex; gap: 8px; margin-top: 12px; }
  .qz-submit, .qz-reset { font: inherit; font-weight: 600; padding: 8px 16px; border-radius: 8px; cursor: pointer; }
  .qz-submit { border: 1px solid var(--accent); background: var(--accent); color: var(--bg); }
  .qz-reset { border: 1px solid var(--rule); background: var(--surface); color: var(--fg); }
  .qz-submit:focus-visible, .qz-reset:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
  .qz-result { font-weight: 600; margin: 12px 0 0 !important; }
  .qz-result.pass { color: var(--ok); }
  .qz-result.fail { color: var(--bad); }
  .qz-result.warn { color: var(--accent); }
  .step.done .s { color: var(--ok); }
  @media (max-width: 860px) { .roadmap { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

  .backline { margin: 0 0 14px; font-size: 14px; }
  .back { color: var(--accent); text-decoration: none; }
  .back:hover { text-decoration: underline; }
