/* ============ tokens ============ */
:root {
  --bg: #f5f1e8;
  --bg-2: #ece6d9;
  --panel: #fffdf8;
  --panel-2: #faf6ed;
  --ink: #20262c;
  --ink-2: #3b4650;
  --muted: #6b7783;
  --line: #e2dacb;
  --line-2: #d3c8b4;
  --accent: #0f766e;
  --accent-soft: #d9f0ec;
  --amber: #b45309;
  --amber-soft: #fbe8cf;
  --red: #b42318;
  --red-soft: #fbe3df;
  --blue: #1d4ed8;
  --blue-soft: #e0e8fb;
  --violet: #6d28d9;
  --violet-soft: #ece5fb;
  --rose: #be185d;
  --rose-soft: #fbe2ec;
  --code-bg: #0f1720;
  --code-ink: #e8eef5;
  --code-line: #223041;
  --shadow: 0 1px 0 rgba(32, 38, 44, .04), 0 8px 24px -18px rgba(32, 38, 44, .35);
  --radius: 14px;
  --sidebar: 280px;
  --content: 880px;
  --font: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  --serif: Georgia, "Songti SC", "SimSun", serif;
  --mono: "Cascadia Code", Consolas, "JetBrains Mono", "Courier New", monospace;
}

html[data-theme="dark"] {
  --bg: #0f1419;
  --bg-2: #131b22;
  --panel: #161e26;
  --panel-2: #1a232c;
  --ink: #e6edf3;
  --ink-2: #c2ccd6;
  --muted: #94a3b1;
  --line: #26313b;
  --line-2: #33414d;
  --accent: #2dd4bf;
  --accent-soft: #123b38;
  --amber: #f59e0b;
  --amber-soft: #3a2a10;
  --red: #f87171;
  --red-soft: #3a1b1b;
  --blue: #60a5fa;
  --blue-soft: #16263f;
  --violet: #a78bfa;
  --violet-soft: #241d3d;
  --rose: #f472b6;
  --rose-soft: #3a1728;
  --code-bg: #0a1017;
  --code-ink: #dbe7f3;
  --code-line: #1c2836;
  --shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 12px 30px -20px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(15, 118, 110, .08), transparent 60%),
    radial-gradient(900px 400px at 0% 0%, rgba(180, 83, 9, .06), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button, input, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

/* ============ topbar ============ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: 60px; display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--ink); color: var(--bg); font-family: var(--mono); font-size: 17px; font-weight: 700;
}
.crumb { color: var(--muted); font-size: 14px; margin-left: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  border-radius: 10px; padding: 7px 11px; cursor: pointer; font-size: 13px; line-height: 1.2;
}
.icon-btn:hover { border-color: var(--line-2); background: var(--panel-2); }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--muted); }
.timer {
  font-family: var(--mono); font-size: 14px; letter-spacing: .5px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: 6px 12px; cursor: pointer; color: var(--ink-2); min-width: 76px;
}
.timer.running { color: var(--accent); border-color: var(--accent); }
#menuBtn { display: none; }

/* ============ layout ============ */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); gap: 0; }
.sidebar {
  position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto;
  padding: 26px 18px 60px 22px; border-right: 1px solid var(--line);
}
.side-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; box-shadow: var(--shadow); }
.side-card-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.side-card-top strong { color: var(--ink); font-family: var(--mono); }
.bar { height: 6px; background: var(--bg-2); border-radius: 99px; overflow: hidden; margin: 10px 0 8px; }
.bar i { display: block; height: 100%; width: 0%; background: var(--accent); border-radius: 99px; transition: width .35s ease; }
.side-sub { font-size: 12px; color: var(--muted); }
.toc { display: flex; flex-direction: column; gap: 2px; }
.toc-item {
  display: flex; align-items: flex-start; gap: 9px; padding: 7px 9px; border-radius: 8px;
  color: var(--ink-2); font-size: 13.5px; line-height: 1.45;
}
.toc-item:hover { background: var(--panel-2); text-decoration: none; }
.toc-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toc-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); margin-top: 8px; flex: 0 0 6px; }
.toc-item.active .toc-dot, .toc-item.done .toc-dot { background: var(--accent); }
.toc-item.done { color: var(--muted); }
.side-link { display: block; margin-top: 22px; font-size: 13.5px; color: var(--muted); }
.scrim { display: none; }
.content { width: min(100%, calc(var(--content) + 80px)); padding: 34px 44px 90px; margin: 0 auto; min-width: 0; }

/* ============ home ============ */
.home { width: min(1120px, calc(100% - 48px)); margin: 0 auto; padding: 30px 0 80px; }
.home-top { position: sticky; }
.hero { display: grid; grid-template-columns: 1fr 220px; gap: 40px; align-items: center; padding: 58px 0 40px; }
.eyebrow { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.hero h1 { font-family: var(--serif); font-size: clamp(40px, 6vw, 72px); line-height: 1.1; margin: 14px 0 20px; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; color: var(--accent); position: relative; }
.hero h1 em::after { content: ""; position: absolute; left: 0; right: 0; bottom: 6px; height: 8px; background: var(--accent-soft); z-index: -1; border-radius: 3px; }
.hero p { color: var(--ink-2); font-size: 17px; max-width: 560px; }
.hero-actions { display: flex; gap: 12px; margin-top: 28px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 11px; border: 1px solid var(--line-2);
  background: var(--panel); color: var(--ink); cursor: pointer; font-size: 15px; font-weight: 600;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.ring-wrap { position: relative; display: grid; place-items: center; }
.ring { width: 210px; height: 210px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .6s ease; }
.ring-text { position: absolute; text-align: center; }
.ring-text strong { display: block; font-family: var(--mono); font-size: 32px; }
.ring-text span { font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 10px 0 54px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat strong { display: block; font-family: var(--mono); font-size: 26px; color: var(--accent); }
.stat span { font-size: 13px; color: var(--muted); }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 0 0 22px; }
.section-head h2 { font-family: var(--serif); font-size: 34px; margin: 6px 0 0; }
.section-note { color: var(--muted); font-size: 14px; max-width: 360px; text-align: right; }
.lesson-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.lesson-card {
  display: flex; flex-direction: column; gap: 10px; padding: 20px 20px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .18s ease, border-color .18s ease;
}
.lesson-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); opacity: .85; }
.lesson-card:hover { transform: translateY(-3px); border-color: var(--line-2); text-decoration: none; }
.lesson-card.color-amber::before { background: var(--amber); }
.lesson-card.color-blue::before { background: var(--blue); }
.lesson-card.color-violet::before { background: var(--violet); }
.lesson-card.color-rose::before { background: var(--rose); }
.card-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.chapter { font-weight: 700; color: var(--accent); letter-spacing: .04em; }
.lesson-card.color-amber .chapter { color: var(--amber); }
.lesson-card.color-blue .chapter { color: var(--blue); }
.lesson-card.color-violet .chapter { color: var(--violet); }
.lesson-card.color-rose .chapter { color: var(--rose); }
.lesson-card h3 { margin: 2px 0 0; font-size: 19px; line-height: 1.35; }
.lesson-card p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; flex: 1; }
.card-meta { display: flex; gap: 12px; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 10px; }
.card-foot { display: flex; justify-content: space-between; font-size: 12.5px; }
.card-pct { font-family: var(--mono); color: var(--accent); }
.card-go { color: var(--muted); }
.howto { margin-top: 70px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.step-n { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-family: var(--mono); font-weight: 700; }
.step h3 { margin: 12px 0 6px; font-size: 17px; }
.step p { margin: 0; color: var(--muted); font-size: 14px; }
.foot { border-top: 1px solid var(--line); margin-top: 64px; padding-top: 22px; color: var(--muted); font-size: 12.5px; }

/* ============ lesson page ============ */
.lesson-hero { padding: 20px 0 26px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.lesson-hero h1 { font-family: var(--serif); font-size: clamp(30px, 4vw, 46px); line-height: 1.2; margin: 8px 0 10px; }
.lede { color: var(--ink-2); margin: 0 0 14px; }
.hero-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 12px; color: var(--muted); border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 4px 11px; }
.tabs { display: flex; gap: 6px; margin: 0 0 10px; position: sticky; top: 60px; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); padding: 8px 0; }
.tabs a { padding: 7px 14px; border-radius: 9px; font-size: 14px; color: var(--muted); border: 1px solid transparent; }
.tabs a.active { background: var(--panel); border-color: var(--line); color: var(--ink); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ============ article ============ */
.article { font-size: 16.5px; }
.article h1.md-h1 { font-family: var(--serif); font-size: 34px; margin: 10px 0 18px; }
.article h2 {
  font-family: var(--serif); font-size: 27px; line-height: 1.3;
  margin: 54px 0 16px; padding-top: 8px; border-top: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 10px;
}
.article h2:first-of-type { border-top: 0; margin-top: 26px; }
.article h3 { font-size: 20px; margin: 36px 0 10px; color: var(--ink); }
.article h4 { font-size: 17px; margin: 26px 0 8px; color: var(--ink-2); }
.article p { margin: 12px 0; }
.article ul, .article ol { padding-left: 26px; margin: 10px 0 16px; }
.article li { margin: 5px 0; }
.article li > ul, .article li > ol { margin: 5px 0; }
.article strong { color: var(--ink); font-weight: 700; }
.article hr.rule { border: 0; border-top: 1px dashed var(--line-2); margin: 34px 0; }
.article blockquote {
  margin: 18px 0; padding: 14px 18px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 10px 10px 0; color: var(--ink-2);
}
.article blockquote p { margin: 6px 0; }
.article code {
  font-family: var(--mono); font-size: .88em; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; color: var(--ink);
}
.article mark { background: var(--amber-soft); color: inherit; padding: 0 3px; border-radius: 3px; }
.article .tag {
  display: inline-block; font-size: 11px; line-height: 1.6; font-weight: 700;
  padding: 0 7px; border-radius: 99px; margin-right: 5px; vertical-align: 1px;
}
.tag-warn { background: var(--red-soft); color: var(--red); }
.tag-exam { background: var(--amber-soft); color: var(--amber); }
.tag-opt { background: var(--blue-soft); color: var(--blue); }

/* section checkbox */
.sec-check {
  flex: 0 0 20px; width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--line-2);
  cursor: pointer; position: relative; top: 2px; background: var(--panel); transition: all .15s ease;
}
.sec-check:hover { border-color: var(--accent); }
h2.done .sec-check { background: var(--accent); border-color: var(--accent); }
h2.done .sec-check::after { content: "✓"; position: absolute; inset: -1px 0 0 0; color: #fff; font-size: 13px; text-align: center; line-height: 20px; }
h2.done { color: var(--muted); }

/* table */
.table-wrap { overflow-x: auto; margin: 16px 0 22px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.article table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.article th, .article td { border-bottom: 1px solid var(--line); padding: 9px 12px; vertical-align: top; }
.article th { background: var(--panel-2); font-weight: 700; font-size: 13.5px; color: var(--ink-2); white-space: nowrap; }
.article tr:last-child td { border-bottom: 0; }
.article td code { white-space: nowrap; }

/* code card */
.code-card { margin: 18px 0 22px; border-radius: 12px; overflow: hidden; border: 1px solid #1c2836; background: var(--code-bg); box-shadow: var(--shadow); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px 7px 14px; background: #121c26; border-bottom: 1px solid var(--code-line); }
.code-lang { font-family: var(--mono); font-size: 11px; color: #7f93a7; letter-spacing: .08em; text-transform: uppercase; }
.code-tools { display: flex; gap: 6px; }
.mini { background: #1a2733; color: #a9bacb; border: 1px solid #26374a; border-radius: 6px; padding: 3px 9px; font-size: 11.5px; cursor: pointer; }
.mini:hover { color: #fff; border-color: #3b526b; }
.code-card.done { outline: 1px solid #2dd4bf55; }
.code-card.done .done-btn { background: #123b38; color: #5eead4; border-color: #1f5f59; }
.code-body { display: grid; grid-template-columns: auto minmax(0, 1fr); }
.gutter { padding: 14px 8px 14px 12px; text-align: right; font-family: var(--mono); font-size: 12.5px; line-height: 1.65; color: #4b6076; user-select: none; border-right: 1px solid var(--code-line); white-space: pre; }
.code-card pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-card code { font-family: var(--mono); font-size: 13.5px; line-height: 1.65; color: var(--code-ink); background: none; border: 0; padding: 0; white-space: pre; }
.tok-com { color: #6b7f94; font-style: italic; }
.tok-str { color: #a5d6a7; }
.tok-num { color: #f0b37e; }
.tok-key { color: #7dd3fc; font-weight: 600; }
.tok-pre { color: #c4a7e7; }
.tok-fn { color: #fbbf24; }

/* exercise */
.article p.exercise {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--amber);
  border-radius: 0 10px 10px 0; padding: 12px 14px; margin: 18px 0 8px;
  position: relative;
}
.ex-actions { display: flex; gap: 8px; margin: -2px 0 18px 14px; }
.ex-actions.head { margin: 8px 0 14px 0; }
.article h3.exercise-h { border-left: 3px solid var(--amber); padding-left: 10px; }
.ex-btn { font-size: 12px; padding: 4px 10px; border-radius: 7px; border: 1px dashed var(--line-2); background: transparent; color: var(--muted); cursor: pointer; }
.ex-btn:hover { color: var(--accent); border-color: var(--accent); }
.ex-btn.answered { color: var(--accent); border-style: solid; background: var(--accent-soft); }

/* lesson nav */
.lesson-nav { display: flex; justify-content: space-between; gap: 14px; margin-top: 70px; }
.nav-card { flex: 1; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 14px 18px; color: var(--ink); max-width: 48%; }
.nav-card span { display: block; font-size: 12px; color: var(--muted); }
.nav-card strong { font-size: 15px; }
.nav-card.next { text-align: right; }
.nav-card:hover { border-color: var(--accent); text-decoration: none; }

/* ============ modals ============ */
.search-modal, .answer-modal {
  position: fixed; inset: 0; z-index: 90; display: none; align-items: flex-start; justify-content: center;
  background: rgba(15, 20, 25, .45); backdrop-filter: blur(3px); padding: 10vh 20px 20px;
}
.search-modal.open, .answer-modal.open { display: flex; }
.search-box { width: min(680px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.4); overflow: hidden; }
.search-row { display: flex; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
.search-row input { flex: 1; border: 0; background: transparent; outline: none; font-size: 17px; padding: 6px 8px; }
.search-results { max-height: 56vh; overflow-y: auto; padding: 8px; }
.sr-item { display: block; padding: 10px 12px; border-radius: 9px; color: var(--ink); }
.sr-item:hover, .sr-item.sel { background: var(--accent-soft); text-decoration: none; }
.sr-item strong { display: block; font-size: 14.5px; }
.sr-item span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.sr-empty { padding: 26px; text-align: center; color: var(--muted); font-size: 14px; }
.answer-box { width: min(620px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.4); padding: 18px; }
.answer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.answer-head strong { font-size: 16px; }
.answer-box textarea { width: 100%; min-height: 180px; resize: vertical; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 15px; line-height: 1.7; outline: none; }
.answer-box textarea:focus { border-color: var(--accent); }
.answer-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }

/* ============ toast ============ */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 120;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ interactive widgets ============ */
.widget { margin: 22px 0 26px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel); overflow: hidden; box-shadow: var(--shadow); }
.widget-head { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 13px 18px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.widget-head strong { font-size: 15px; }
.widget-head span { font-size: 12.5px; color: var(--muted); }
.widget-body { padding: 16px 18px 18px; }
.widget-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 14px; }
.widget-controls label { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.widget-controls input { width: 62px; padding: 5px 8px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--bg); font-family: var(--mono); }
.wbtn { border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2); border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.wbtn:hover { border-color: var(--accent); color: var(--accent); }
.wbtn.ghost { background: transparent; color: var(--muted); }
.loop-code { font-family: var(--mono); font-size: 13px; background: var(--code-bg); color: var(--code-ink); border-radius: 8px; padding: 10px 13px; margin-bottom: 14px; overflow-x: auto; }
.loop-vars { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.var-box { min-width: 96px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--bg); }
.var-box span { display: block; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.var-box strong { font-family: var(--mono); font-size: 22px; color: var(--accent); }
.var-box.cond strong { font-size: 16px; padding-top: 5px; display: block; }
.var-box.flash { animation: flash .5s ease; }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: var(--bg); } }
.loop-log { font-size: 13.5px; color: var(--ink-2); background: var(--bg); border-radius: 8px; padding: 10px 13px; min-height: 44px; white-space: pre-wrap; }
.mem-row { display: flex; gap: 22px; align-items: center; margin: 4px 0 6px; flex-wrap: wrap; }
.mem-box { border: 1.5px solid var(--line-2); background: var(--bg); border-radius: 10px; padding: 10px 16px; min-width: 120px; text-align: center; cursor: pointer; position: relative; }
.mem-box:hover { border-color: var(--accent); }
.mem-box.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mem-box.ptr .mem-val { color: var(--violet); }
.mem-name { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.mem-val { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--accent); }
.mem-addr { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.ptr-arrow { font-family: var(--mono); font-size: 13px; color: var(--violet); margin: 6px 0 4px 24px; }
.ptr-arrow span { font-weight: 700; }

/* ============ textbook traceability ============ */
.book-pin {
  margin: 10px 0 18px; padding: 14px 18px; border: 1px solid var(--line);
  border-left: 4px solid var(--amber); background: var(--panel); border-radius: 0 12px 12px 0;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; align-items: center;
}
.bp-main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.bp-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--amber); background: var(--amber-soft); padding: 2px 8px; border-radius: 99px; }
.bp-main strong { font-size: 15px; }
.bp-pages { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.bp-note { grid-column: 1 / 2; font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.bp-link { grid-column: 2 / 3; grid-row: 1 / 3; font-size: 13px; white-space: nowrap; }
.src-line { font-size: 12px; color: var(--muted); margin: -8px 0 14px 30px; font-family: var(--mono); }
.article h3 + .src-line { margin-left: 0; }
.article h4 + .src-line { margin-left: 0; font-size: 11.5px; }
.book-coverage { margin-top: 60px; padding-top: 8px; border-top: 2px solid var(--line-2); }
.book-coverage h2 { border-top: 0 !important; margin-top: 20px !important; }
.cov-intro { font-size: 14px; color: var(--ink-2); }
.cov-notes { font-size: 13px; color: var(--muted); padding-left: 22px; }
.cov-notes li { margin: 4px 0; }
.missing { color: var(--red); font-weight: 600; }
.book-table td:first-child, .book-table th:first-child { white-space: nowrap; }
.book-table .ch-row td { background: var(--panel-2); font-weight: 700; font-family: var(--serif); font-size: 16px; padding: 12px; }
.book-table tr.muted-row td { color: var(--muted); font-size: 12.5px; background: var(--bg); }
.ch-pages { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.book-home { padding-top: 10px; }
.book-hero { padding: 46px 0 24px; }
.book-hero h1 { font-family: var(--serif); font-size: clamp(36px, 5vw, 58px); line-height: 1.12; margin: 12px 0 16px; }
.book-hero h1 em { font-style: normal; color: var(--accent); }
.book-hero p { color: var(--ink-2); max-width: 680px; }
.lookup-card {
  display: flex; justify-content: space-between; align-items: center; gap: 24px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 18px 22px; margin: 26px 0 48px; box-shadow: var(--shadow);
}
.lookup-copy strong { display: block; font-size: 17px; }
.lookup-copy span { font-size: 13px; color: var(--muted); }
.lookup-form { display: flex; align-items: center; gap: 12px; }
.lookup-form input { width: 160px; padding: 10px 14px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--bg); font-family: var(--mono); font-size: 16px; outline: none; }
.lookup-form input:focus { border-color: var(--accent); }
#pageResult { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.book-table-wrap { max-height: 72vh; overflow: auto; }
.book-table.big { font-size: 13.5px; }
.book-table.big th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); }
.book-table tr.hit td { background: var(--accent-soft); }
.book-table tr.dim { display: none; }
.miss-block { margin-top: 60px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 26px; }
.miss-block h2 { font-family: var(--serif); font-size: 28px; margin: 0 0 14px; }
.miss-list { font-size: 14px; color: var(--ink-2); padding-left: 22px; }
.miss-list li { margin: 8px 0; }
.ok-note { color: var(--accent); font-weight: 600; }

/* ============ responsive ============ */
@media (max-width: 1080px) {
  .lesson-grid { grid-template-columns: repeat(2, 1fr); }
  .hero { grid-template-columns: 1fr; }
  .ring-wrap { display: none; }
}
@media (max-width: 900px) {
  #menuBtn { display: inline-block; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 60px; z-index: 60; width: 290px;
    background: var(--bg); transform: translateX(-102%); transition: transform .22s ease;
  }
  body.menu-open .sidebar { transform: translateX(0); }
  .scrim { position: fixed; inset: 60px 0 0 0; background: rgba(0,0,0,.35); z-index: 50; display: none; }
  body.menu-open .scrim { display: block; }
  .content { padding: 24px 20px 70px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .steps { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .lesson-grid { grid-template-columns: 1fr; }
  .crumb { display: none; }
  .article { font-size: 15.5px; }
  .article h2 { font-size: 23px; }
  .lesson-nav { flex-direction: column; }
  .nav-card { max-width: none; }
  .topbar { padding: 0 10px; gap: 8px; }
  .brand span { white-space: nowrap; }
  .brand span:not(.brand-mark) { display: none; }
  .top-actions { gap: 4px; }
  .icon-btn { white-space: nowrap; font-size: 12px; padding: 6px 7px; }
  .book-pin { grid-template-columns: 1fr; }
  .bp-note { grid-column: 1; }
  .bp-link { grid-column: 1; grid-row: auto; margin-top: 4px; }
  .search-open { padding: 7px 8px; font-size: 0; }
  .search-open::before { content: "🔍"; font-size: 14px; }
  .search-open kbd { display: none; }
  .timer { min-width: 54px; padding: 6px 5px; font-size: 12px; }
  .home { width: calc(100% - 24px); }
  .hero { padding-top: 34px; }
  .hero p { font-size: 15.5px; }
  .stat { padding: 14px 16px; }
  .stat strong { font-size: 22px; }
  html, body { overflow-x: hidden; }
}

@media print {
  .topbar, .sidebar, .tabs, .lesson-nav, .scrim, .search-modal, .answer-modal, .ex-actions { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; width: 100%; }
  .code-card { break-inside: avoid; }
}
