:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #f1f1f8;
  --text: #1b1b2b;
  --muted: #5d5d74;
  --line: #e2e2ee;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eceafe;
  --ok: #0f7a4a; --ok-bg: #e3f5ec;
  --part: #8a5a00; --part-bg: #fdf1d8;
  --enr: #5b5b72; --enr-bg: #ececf3;
  --ans-bg: #f0fbf5; --ans-line: #9ad7b6; --ans-ink: #0f6a41;
  --tip-bg: #fff7e6; --tip-line: #f2c46b;
  --wrong: #c0392b;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 2px rgba(20, 20, 50, .06), 0 4px 16px rgba(20, 20, 50, .05);
  --radius: 14px;
  --hdr: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f17; --surface: #171723; --surface-2: #1e1e2d; --text: #e9e9f2; --muted: #a1a1b8; --line: #2c2c40;
    --accent: #8b85ff; --accent-ink: #0f0f17; --accent-soft: #23214a;
    --ok: #6fdba6; --ok-bg: #12301f; --part: #f4c060; --part-bg: #33270e; --enr: #b5b5cc; --enr-bg: #26263a;
    --ans-bg: #10241a; --ans-line: #2f6b4b; --ans-ink: #7fe0ae; --tip-bg: #2a220f; --tip-line: #6b5420;
    --wrong: #ff7b6b; --code-bg: #0d1117; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.65 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
h1, h2, h3 { font-family: Outfit, Inter, sans-serif; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(1.8rem, 4.5vw, 2.8rem); margin: .2em 0 .35em; font-weight: 700; }
h2 { font-size: 1.5rem; margin: 0 0 .8em; font-weight: 700; }
h3 { font-size: 1.15rem; margin: 1.4em 0 .5em; font-weight: 600; }
a { color: var(--accent); }
p { margin: 0 0 .8em; }
code { font-family: "JetBrains Mono", ui-monospace, Menlo, monospace; font-size: .88em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
ul, ol { padding-left: 1.4em; margin: 0 0 .9em; }
li { margin: .2em 0; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 99; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-family: Outfit, sans-serif; font-size: 1.12rem; white-space: nowrap; }
.brand b { color: var(--accent); }
.topnav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.topnav a { text-decoration: none; color: var(--muted); padding: 7px 12px; border-radius: 9px; font-weight: 500; font-size: .95rem; }
.topnav a:hover, .topnav a[aria-current] { color: var(--accent); background: var(--accent-soft); }
.menu-btn { display: none; margin-left: auto; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 6px 12px; font: inherit; }
@media (max-width: 820px) {
  .menu-btn { display: block; }
  .topnav { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 16px 14px; flex-direction: column; }
  .topnav.open { display: flex; }
}

main { max-width: 1060px; margin: 0 auto; padding: 20px 16px 60px; }
main.wide { max-width: 1240px; }
.crumbs { font-size: .88rem; color: var(--muted); margin: 4px 0 14px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs span { margin: 0 2px; }

/* hero */
.hero { padding: 36px 0 18px; }
.hero.small { padding: 18px 0 6px; }
.hero > p { font-size: 1.1rem; color: var(--muted); max-width: 760px; }
.kicker, .ch-kicker { color: var(--accent); font-weight: 600; font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 26px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stats b { display: block; font-family: Outfit, sans-serif; font-size: 1.9rem; color: var(--accent); line-height: 1.1; }
.stats span { color: var(--muted); font-size: .9rem; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.block { margin: 34px 0; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 760px) { .two { grid-template-columns: minmax(0, 1fr); } }

.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 14px; font: 600 .92rem Inter, sans-serif; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost, .toolbar .btn { background: var(--surface); color: var(--accent); border-color: var(--line); }
.toolbar .btn:hover, .btn.ghost:hover { border-color: var(--accent); }

/* class columns on home */
.cls { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.cls-head { display: flex; justify-content: space-between; align-items: baseline; }
.cls-head h2 { margin-bottom: .5em; }
.cls-head a { font-size: .9rem; text-decoration: none; font-weight: 600; }
.ch-list { list-style: none; padding: 0; margin: 0; }
.ch-list li { margin: 0; border-top: 1px solid var(--line); }
.ch-list a { display: flex; align-items: center; gap: 12px; padding: 11px 4px; text-decoration: none; color: var(--text); }
.ch-list a:hover .t { color: var(--accent); }
.ch-list .n { flex: none; width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font: 600 .9rem Outfit, sans-serif; }
.ch-list .t { flex: 1; font-weight: 500; }
.ch-list .badge { flex: none; }

/* cards */
.cards { display: grid; gap: 14px; }
.cards.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) { .cards.three, .cards.two-col { grid-template-columns: minmax(0, 1fr); } }
.card { display: flex; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card h3 { margin: 0 0 .3em; }
.card p { color: var(--muted); margin: 0 0 .5em; font-size: .95rem; }
.card-num { flex: none; width: 46px; height: 46px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font: 700 1.1rem Outfit, sans-serif; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: .82rem; color: var(--muted); align-items: center; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.part { background: var(--part-bg); color: var(--part); }
.badge.enr { background: var(--enr-bg); color: var(--enr); }

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

/* chapter */
.ch-head { padding: 6px 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.ch-meta, .ch-stats { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; color: var(--muted); font-size: .92rem; margin: 6px 0; }
.ch-stats b { color: var(--text); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; font-weight: 600; font-size: .92rem; cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }
.ch-grid { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 34px; }
.toc { position: relative; min-width: 0; }
.toc-in { position: sticky; scrollbar-width: thin; top: 78px; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 100px); overflow: auto; }
.toc a { display: flex; justify-content: space-between; gap: 8px; text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: .93rem; font-weight: 500; }
.toc a small { color: var(--muted); opacity: .8; }
.toc a:hover, .toc a.on { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 900px) {
  .ch-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc { position: sticky; top: var(--hdr); z-index: 10; background: var(--bg); margin: 0 -16px 10px; padding: 6px 16px; border-bottom: 1px solid var(--line); }
  .toc-in { position: relative; top: auto; flex-direction: row; overflow-x: auto; max-height: none; max-width: 100%; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .toc-in::-webkit-scrollbar { display: none; }
  .toc a { white-space: nowrap; padding: 8px 12px; flex: none; }
}
.ch-body { min-width: 0; max-width: 860px; }
.ch-body p, .ch-body li, .ch-body dd, .card p, .lead { overflow-wrap: anywhere; }
.ch-body td { overflow-wrap: break-word; }
th { white-space: nowrap; }
.sec { margin-bottom: 44px; }
.sec > h2 { padding-bottom: .35em; border-bottom: 2px solid var(--accent-soft); }
.lead { font-size: 1.08rem; }
.callout { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: 8px; margin: 1em 0; }
.callout p:last-child { margin: 0; }
.callout.small { font-size: .92rem; }
.checks { list-style: none; padding: 0; }
.checks li { position: relative; padding-left: 26px; }
.checks li::before { content: "✓"; position: absolute; left: 4px; color: var(--ok); font-weight: 700; }
.plan { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.plan-row { display: grid; grid-template-columns: 130px 1fr; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.plan-row:last-child { border-bottom: 0; }
.plan-row p:last-child { margin: 0; }
.plan-when { font-weight: 600; color: var(--accent); font-size: .92rem; }
.plan-focus { font-weight: 600; margin-bottom: .2em; }
@media (max-width: 560px) { .plan-row { grid-template-columns: 1fr; gap: 4px; } }
.note { border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.note:last-child { border-bottom: 0; }
.note h3 { margin-top: 1.1em; }
.tip { background: var(--tip-bg); border-left: 4px solid var(--tip-line); padding: 10px 14px; border-radius: 8px; margin: .8em 0; font-size: .95rem; }
.tip b { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.tip p:last-child { margin: 0; }
.gloss { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 0; }
.gloss div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.gloss dt { font-weight: 600; }
.gloss dd { margin: 2px 0 0; color: var(--muted); font-size: .94rem; }
@media (max-width: 640px) { .gloss { grid-template-columns: 1fr; } }

/* code */
figure.code { margin: .8em 0 1.1em; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--code-bg); }
figure.code figcaption { display: flex; justify-content: space-between; align-items: center; font-size: .78rem; font-weight: 600; color: var(--muted); padding: 5px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.copy { font: 600 .75rem Inter, sans-serif; background: transparent; color: var(--accent); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; cursor: pointer; }
figure.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; font: 14px/1.55 "JetBrains Mono", ui-monospace, Menlo, monospace; }
figure.code pre code { background: none; padding: 0; font-size: inherit; }
pre code.hljs { background: transparent; padding: 0; }
.out { border-top: 1px solid var(--line); background: var(--surface); }
.out span { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 14px 0; }
.out pre { margin: 0; padding: 6px 14px 12px !important; color: var(--text); }

/* questions */
.hint { color: var(--muted); font-size: .92rem; }
.qs { padding-left: 1.6em; }
.qs > li { margin: 0 0 18px; padding-left: 4px; }
.qs > li::marker { font-weight: 700; color: var(--accent); }
.q-head { float: right; display: flex; gap: 6px; margin-left: 8px; }
.marks, .unit { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.q-text p:last-child { margin-bottom: .4em; }
.opts { padding-left: 0; list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0 8px; counter-reset: o; }
@media (max-width: 640px) { .opts { grid-template-columns: 1fr; } }
.opts li { margin: 0; counter-increment: o; }
.opt { width: 100%; text-align: left; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; cursor: pointer; display: flex; gap: 8px; }
.opt::before, .opts.static li::before { content: "(" counter(o, lower-alpha) ")"; color: var(--muted); font-weight: 600; flex: none; }
.opts.static li { display: flex; gap: 8px; padding: 2px 0; }
.opt:hover { border-color: var(--accent); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--wrong); text-decoration: line-through; opacity: .8; }
.ans { background: var(--ans-bg); border: 1px solid var(--ans-line); border-radius: 10px; padding: 10px 14px; margin: 8px 0 4px; }
.ans-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ans-ink); margin-bottom: 4px; }
.ans p:last-child, .ans ul:last-child, .ans ol:last-child { margin-bottom: 0; }
.ans figure.code { background: var(--code-bg); }
body.hide-ans .ans { display: none; }
body.hide-ans .mcq.revealed .ans { display: block; }
.or { text-align: center; font-weight: 700; color: var(--muted); margin: 10px 0; }
.case { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.case-title { font: 600 .82rem Inter, sans-serif; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-bottom: 6px; }
.prac { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.prac h3 { margin: 0 0 .5em; display: flex; gap: 10px; align-items: center; }
.prac .num { flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: .9rem; }
.viva { margin-top: 10px; }
.viva summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: .93rem; }
.mistakes { list-style: none; padding: 0; }
.mistakes li { border-left: 3px solid var(--wrong); padding: 4px 0 4px 14px; margin-bottom: 10px; }
.mistakes li p:last-child { margin: 0; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 30px; }
.pager a { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); font-weight: 600; }
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--muted); font-weight: 500; }
.pager .nx { text-align: right; }
.syl-unit { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin: 10px 0; }
.syl-unit h3 { margin: 0 0 .3em; }
.syl-unit p { margin: 0; color: var(--muted); font-size: .95rem; }
.steps { padding-left: 1.3em; }
.steps li { margin-bottom: .5em; }

.foot { border-top: 1px solid var(--line); background: var(--surface); }
.foot-in { max-width: 1060px; margin: 0 auto; padding: 24px 16px; color: var(--muted); font-size: .9rem; }

/* phones */
@media (max-width: 640px) {
  html { scroll-padding-top: 116px; }
  body { font-size: 15.5px; }
  main { padding: 12px 16px 72px; }
  .top-in { height: var(--hdr); padding: 0 16px; }
  .brand { font-size: 1.02rem; }
  .brand img { width: 26px; height: 26px; }
  .menu-btn { padding: 8px 14px; }
  .topnav a { padding: 12px; font-size: 1rem; }
  .crumbs { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 8px; }
  .crumbs [aria-current] { display: none; }
  .crumbs span:nth-last-child(2) { display: none; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.3rem; }
  .hero { padding: 18px 0 8px; }
  .hero > p { font-size: 1rem; }
  .stats { gap: 10px; margin-top: 18px; }
  .stats div { padding: 12px 14px; }
  .stats b { font-size: 1.6rem; }
  .stats span { font-size: .82rem; }
  .block { margin: 26px 0; }
  .cls { padding: 14px 14px 6px; }
  .ch-list a { padding: 12px 2px; }
  .ch-list .badge { display: none; }
  .card { padding: 14px; gap: 12px; }
  .card-num { width: 38px; height: 38px; font-size: 1rem; border-radius: 10px; }
  .ch-head { padding-bottom: 12px; margin-bottom: 0; border-bottom: 0; }
  .ch-meta, .ch-stats { font-size: .85rem; gap: 6px 12px; }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .toolbar .switch { grid-column: 1 / -1; justify-content: center; padding: 10px 12px; }
  .toolbar .btn { justify-content: center; padding: 9px 8px; font-size: .84rem; }
  .toolbar .btn.ghost { grid-column: 1 / -1; }
  .sec { margin-bottom: 34px; }
  .plan-row { padding: 12px 14px; }
  figure.code { margin-left: -4px; margin-right: -4px; }
  figure.code pre { font-size: 12.5px; padding: 10px 12px; }
  .copy { padding: 8px 14px; min-height: 34px; }
  table { font-size: .86rem; }
  th, td { padding: 7px 10px; }
  .qs { padding-left: 1.35em; }
  .q-head { float: none; margin: 0 0 4px; }
  .opt { padding: 10px 12px; }
  .ans { padding: 10px 12px; }
  .case, .prac { padding: 14px; }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager .nx { text-align: left; }
  .viva summary { padding: 6px 0; }
}
.totop { position: fixed; right: 16px; bottom: 18px; z-index: 15; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--accent); font-size: 1.2rem; box-shadow: var(--shadow); cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .2s; }
.totop.show { opacity: 1; pointer-events: auto; }

/* print */
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f3f3f3; --text: #000; --muted: #444; --line: #ccc; --code-bg: #fafafa; color-scheme: light; }
  body { font-size: 11.5pt; background: #fff; }
  .top, .foot, .toc, .totop, .toolbar, .crumbs, .pager, .hint, .copy, .no-print { display: none !important; }
  main, main.wide { max-width: none; padding: 0; }
  .ch-grid { display: block; }
  .card, .prac, .case, .stats div { box-shadow: none; }
  .sec, .prac, .case, .qs > li { break-inside: avoid-page; }
  .sec { break-inside: auto; }
  .opt { border: 0; padding: 1px 0; }
  .opts { grid-template-columns: 1fr 1fr; }
  details.viva { display: none; }
  body.print-worksheet #overview, body.print-worksheet #plan, body.print-worksheet #notes, body.print-worksheet #glossary, body.print-worksheet #mistakes { display: none; }
  body.print-worksheet .ans { display: none !important; }
  a { color: inherit; text-decoration: none; }
}
