:root {
  --bg: #f3f6f6;
  --panel: #ffffff;
  --ink: #14232b;
  --muted: #53656d;
  --line: #d3dee0;
  --accent: #0a6c74;
  --accent-ink: #ffffff;
  --ok: #17703f;
  --ok-bg: #e2f3e9;
  --bad: #a4262c;
  --bad-bg: #fbe8e9;
  --code-bg: #eaf0f1;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a1e;
    --panel: #162329;
    --ink: #e6eef0;
    --muted: #9bb0b6;
    --line: #27383f;
    --accent: #5cc4c8;
    --accent-ink: #082126;
    --ok: #6fd09b;
    --ok-bg: #123022;
    --bad: #ff9a9f;
    --bad-bg: #3a181b;
    --code-bg: #1c2d34;
  }
}
* { box-sizing: border-box; }
html { scroll-padding-top: 1rem; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 .9375rem/1.65 var(--font); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--panel); padding: .5rem 1rem; z-index: 10; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto; padding: 1.5rem 1.25rem; border-right: 1px solid var(--line); background: var(--panel); }
.brand { display: block; font-weight: 700; font-size: .95rem; line-height: 1.35; color: var(--ink); text-decoration: none; margin-bottom: 1rem; }
.map summary { cursor: pointer; font-weight: 600; color: var(--muted); margin-bottom: .5rem; }
.map h2 { font-size: .76rem; font-weight: 600; color: var(--muted); margin: 1.1rem 0 .35rem; }
.map ol { list-style: none; margin: 0; padding: 0 0 0 .9rem; border-left: 2px solid var(--line); }
.map li { position: relative; margin: 0; }
.map li::before { content: ""; position: absolute; left: -1.28rem; top: .72rem; width: .55rem; height: .55rem; border-radius: 50%; background: var(--panel); border: 2px solid var(--line); }
.map li:has(a.started)::before { border-color: var(--accent); }
.map li:has(a.done)::before { background: var(--accent); border-color: var(--accent); }
.map li:has(a[aria-current])::before { border-color: var(--ink); box-shadow: 0 0 0 3px var(--line); }
.map a { display: block; padding: .3rem .4rem; font-size: .84rem; line-height: 1.4; color: var(--ink); text-decoration: none; border-radius: 4px; }
.map a:hover { background: var(--code-bg); }
.map a[aria-current] { font-weight: 700; }

main { padding: 2.5rem clamp(1.25rem, 5vw, 4rem) 4rem; max-width: 52rem; width: 100%; }
.lesson h1, .hero h1 { font-size: clamp(1.4rem, 3vw, 1.75rem); line-height: 1.2; margin: 0 0 1.25rem; letter-spacing: -.01em; }
.lesson h2 { font-size: 1.2rem; line-height: 1.3; margin: 2.25rem 0 .75rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.lesson h3 { font-size: 1.02rem; margin: 1.75rem 0 .5rem; }
.lesson p, .lesson li { max-width: 72ch; }
.lesson code { font: .86em var(--mono); background: var(--code-bg); padding: .1em .35em; border-radius: 4px; }
.lesson pre { background: var(--code-bg); padding: 1rem 1.15rem; border-radius: 6px; overflow-x: auto; line-height: 1.5; }
.lesson pre code { background: none; padding: 0; font-size: .8rem; }
.lesson table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; margin: 1rem 0; }
.lesson th, .lesson td { border: 1px solid var(--line); padding: .5rem .75rem; text-align: left; vertical-align: top; }
.lesson th { background: var(--code-bg); }
.lesson blockquote { margin: 1rem 0; padding: .1rem 1rem; border-left: 4px solid var(--accent); color: var(--muted); }

.hero { margin-bottom: 2rem; }
.hero p { max-width: 60ch; font-size: 1rem; color: var(--muted); }
.cta { display: inline-block; padding: .7rem 1.4rem; background: var(--accent); color: var(--accent-ink); font-weight: 600; border-radius: 6px; text-decoration: none; }
.toc { list-style: none; margin: 0; padding: 0; }
.toc li { padding: 1rem 0; border-top: 1px solid var(--line); }
.toc a { font-size: .95rem; text-decoration: none; }
.toc .meta { display: block; font-size: .85rem; color: var(--muted); }
.toc p { margin: .35rem 0 0; color: var(--muted); max-width: 66ch; }

#quiz { margin-top: 3rem; padding: 1.5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
#quiz h2 { margin-top: 0; }
.q { border: 0; border-top: 1px solid var(--line); padding: 1.1rem 0 .4rem; margin: 0; }
.q:first-of-type { border-top: 0; }
.q legend { font-weight: 600; padding: 0; margin-bottom: .6rem; max-width: 66ch; }
.opts { display: grid; gap: .5rem; }
.opt { text-align: left; font: inherit; font-size: .88rem; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .5rem .8rem; cursor: pointer; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 600; }
.opt.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.explain { margin: .6rem 0 .4rem; padding: .6rem .85rem; border-radius: 6px; background: var(--code-bg); font-size: .86rem; }
.quiz-summary { font-weight: 600; margin: 1.25rem 0 .5rem; }
.again { font: inherit; font-weight: 600; padding: .5rem 1.1rem; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 6px; cursor: pointer; }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; flex-wrap: wrap; }
.pager a { max-width: 22rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding-top: 1.5rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .opt { transition: border-color .15s, background-color .15s; }
}

.lesson ol > li, .lesson ul > li { margin: .4rem 0; }
.lesson blockquote { background: var(--code-bg); border-radius: 0 6px 6px 0; color: var(--ink); }
.lesson h2:first-of-type { border-top: 0; padding-top: 0; }

/* Hình minh họa SVG động */
.figure { margin: 1.5rem 0; padding: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.figure svg { width: 100%; height: auto; display: block; }
.figure figcaption { font-size: .8rem; color: var(--muted); margin-top: .5rem; }
svg .box { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
svg .box.hot { stroke: var(--accent); stroke-width: 2.5; }
svg .t { fill: var(--ink); font: 600 13px var(--font); }
svg .t2 { fill: var(--muted); font: 400 11.5px var(--font); }
svg .link { stroke: var(--muted); stroke-width: 2; fill: none; stroke-dasharray: 6 6; animation: flow 1s linear infinite; }
svg .mk { fill: var(--muted); }
svg .dot { fill: var(--accent); animation: travel 2.4s ease-in-out infinite; }
svg .dot.back { animation-delay: 1.2s; }
svg .node { animation: hl 6s linear infinite; animation-delay: var(--d, 0s); }
@keyframes flow { to { stroke-dashoffset: -12; } }
@keyframes travel { 0% { transform: translate(0, 0); opacity: 0; } 10%, 90% { opacity: 1; } 100% { transform: translate(var(--dx, 0), 0); opacity: 0; } }
@keyframes hl { 0%, 18% { stroke: var(--accent); stroke-width: 3; } 25%, 100% { stroke: var(--line); stroke-width: 1.5; } }
@media (prefers-reduced-motion: reduce) {
  svg .link, svg .node { animation: none; }
  svg .dot { animation: none; opacity: 1; }
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.search { margin-bottom: 1rem; }
.search input { width: 100%; font: inherit; font-size: .88rem; padding: .5rem .7rem; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
#results { margin-top: .5rem; }
#results a { display: block; padding: .5rem .55rem; border-radius: 6px; text-decoration: none; color: var(--ink); border: 1px solid transparent; }
#results a:hover, #results a:focus-visible { background: var(--code-bg); border-color: var(--line); }
#results .r-title { display: block; font-size: .8rem; font-weight: 600; line-height: 1.35; }
#results .r-title small { color: var(--muted); font-weight: 400; }
#results .r-snip { display: block; font-size: .78rem; color: var(--muted); line-height: 1.45; margin-top: .15rem; }
#results .r-empty { font-size: .82rem; color: var(--muted); padding: .3rem .1rem; }
mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: inherit; border-radius: 2px; padding: 0 .1em; }
.quiz-head { position: sticky; top: 0; z-index: 2; background: var(--panel); padding: .6rem 0 .5rem; border-bottom: 1px solid var(--line); }
.quiz-head .quiz-summary { margin: .3rem 0 0; font-size: .88rem; }
.progress { height: 6px; background: var(--code-bg); border-radius: 3px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.q .src { color: var(--muted); font-weight: 400; font-size: .8rem; }
.review-hint { margin: .75rem 0; font-size: .9rem; }
.review-hint a { margin-right: .6rem; }

.foot { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: .78rem; color: var(--muted); }
html.protected .lesson, html.protected #quiz { -webkit-user-select: none; user-select: none; }
@media print { html.protected body * { display: none !important; } html.protected body::before { content: "Nội dung này không cho phép in."; display: block; padding: 2rem; } }
