/* ==========================================================
   C++ Foundry — site styles
   ========================================================== */
:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1f2328;
  --muted: #5f6672;
  --border: #e2ded5;
  --accent: #0f6e78;
  --accent-2: #e0622b;
  --accent-soft: #e2f1f2;
  --link: #0b5f8a;
  --code-bg: #fbfaf7;
  --code-border: #e6e2d8;
  --code-text: #24292f;
  --tok-comment: #6e7781;
  --tok-keyword: #a1287f;
  --tok-type: #0f6e78;
  --tok-string: #2c7d1d;
  --tok-number: #b35900;
  --tok-pre: #8a5a00;
  --tok-func: #3b4fb5;
  --gutter: #b3aea3;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --radius: 10px;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --header-h: 60px;
}
[data-theme="dark"] {
  --bg: #14171c;
  --surface: #1b1f26;
  --surface-2: #232832;
  --text: #e6e8eb;
  --muted: #9aa3af;
  --border: #2e343f;
  --accent: #4fc1cc;
  --accent-2: #ff8a50;
  --accent-soft: #173238;
  --link: #6cb8f0;
  --code-bg: #111419;
  --code-border: #2a3039;
  --code-text: #d7dce2;
  --tok-comment: #7d8794;
  --tok-keyword: #e38ad1;
  --tok-type: #5fd0d9;
  --tok-string: #9ad37a;
  --tok-number: #f2a65a;
  --tok-pre: #e6c06e;
  --tok-func: #8fa8ff;
  --gutter: #4b525e;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--header-h) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 6px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1400px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 18px; padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 19px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; display: grid; place-items: center;
  font-family: var(--mono); font-size: 14px; font-weight: 700; letter-spacing: -.5px;
}
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); line-height: 1.1; }
.main-nav { display: flex; gap: 4px; margin-left: 8px; }
.main-nav a { color: var(--muted); padding: 6px 10px; border-radius: 7px; font-size: 15px; }
.main-nav a:hover, .main-nav a.active { color: var(--text); background: var(--surface-2); text-decoration: none; }
.header-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search-wrap { position: relative; }
.search-wrap input {
  width: 240px; padding: 7px 12px 7px 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 14px; outline: none; transition: width .2s, border-color .2s;
}
.search-wrap input:focus { border-color: var(--accent); width: 300px; background: var(--surface); }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-results {
  position: absolute; right: 0; top: calc(100% + 6px); width: 420px; max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; display: none;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: 8px 10px; border-radius: 7px; color: var(--text); line-height: 1.4; }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }
.search-results .sr-num { font-family: var(--mono); font-size: 12px; color: var(--accent); margin-right: 6px; }
.search-results .sr-snip { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.search-results mark { background: color-mix(in srgb, var(--accent-2) 30%, transparent); color: inherit; border-radius: 2px; }
.search-results .sr-empty { padding: 10px; color: var(--muted); font-size: 14px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.nav-toggle { display: none; }

/* ---------- Layout ---------- */
.page { max-width: 1400px; margin: 0 auto; padding: 0 20px; }
.lesson-layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 220px;
  gap: 40px; align-items: start;
}
.sidebar, .toc {
  position: sticky; top: calc(var(--header-h) + 20px);
  max-height: calc(100vh - var(--header-h) - 40px); overflow: auto;
  padding: 24px 0; font-size: 14px; line-height: 1.45;
}
.sidebar h4, .toc h4 { margin: 0 0 10px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sidebar .chapter-name { font-weight: 600; margin: 0 0 12px; color: var(--text); }
.sidebar ol, .toc ol { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
  display: flex; gap: 8px; padding: 5px 8px; border-radius: 6px; color: var(--muted);
}
.sidebar li a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar li a.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .num { font-family: var(--mono); font-size: 12px; min-width: 32px; padding-top: 1px; }
.sidebar .done-dot { margin-left: auto; color: var(--accent); }
.sidebar .other-chapters { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 14px; }
.sidebar .other-chapters a { display: block; padding: 4px 8px; color: var(--muted); border-radius: 6px; }
.sidebar .other-chapters a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.toc li a { display: block; padding: 4px 0 4px 12px; border-left: 2px solid var(--border); color: var(--muted); }
.toc li a:hover { color: var(--text); text-decoration: none; }
.toc li a.active { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.toc li.h3 a { padding-left: 24px; font-size: 13px; }

/* ---------- Article ---------- */
.article { padding: 34px 0 60px; min-width: 0; }
.breadcrumbs { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.breadcrumbs a { color: var(--muted); }
.article h1 {
  font-family: var(--serif); font-size: 38px; line-height: 1.2; margin: 0 0 12px; letter-spacing: -.01em;
}
.article h1 .lesson-num { color: var(--accent); }
.meta { display: flex; flex-wrap: wrap; gap: 16px; font-size: 14px; color: var(--muted); margin-bottom: 28px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.meta span { display: inline-flex; align-items: center; gap: 6px; }
.prose h2 {
  font-family: var(--serif); font-size: 27px; line-height: 1.3; margin: 44px 0 14px;
  padding-top: 18px; border-top: 1px solid var(--border);
}
.prose h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.prose h3 { font-size: 20px; margin: 30px 0 10px; }
.prose h2 .anchor, .prose h3 .anchor { opacity: 0; margin-left: 8px; color: var(--muted); font-weight: 400; }
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.prose p { margin: 0 0 18px; }
.prose ul, .prose ol { margin: 0 0 18px; padding-left: 26px; }
.prose li { margin: 4px 0; }
.prose strong.term { color: var(--accent); }
.prose code:not(pre code) {
  font-family: var(--mono); font-size: .86em; padding: 2px 6px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.prose table { border-collapse: collapse; width: 100%; margin: 0 0 22px; font-size: 15px; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.prose th, .prose td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 600; }
.prose tr:last-child td { border-bottom: 0; }
.table-scroll { overflow-x: auto; }

/* ---------- Code blocks ---------- */
.code-block {
  position: relative; margin: 0 0 22px; border: 1px solid var(--code-border);
  border-radius: var(--radius); background: var(--code-bg); overflow: hidden;
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 6px 14px; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--code-border); background: color-mix(in srgb, var(--code-bg) 80%, var(--surface-2));
  font-family: var(--mono); letter-spacing: .03em;
}
.copy-btn {
  font: inherit; font-size: 12px; border: 1px solid var(--code-border); background: var(--surface);
  color: var(--muted); padding: 2px 10px; border-radius: 6px; cursor: pointer;
}
.copy-btn:hover { color: var(--text); }
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }
.code-block pre { margin: 0; padding: 14px 0; overflow-x: auto; font-family: var(--mono); font-size: 14.5px; line-height: 1.6; color: var(--code-text); }
.code-block code { display: block; counter-reset: line; min-width: max-content; }
.code-block .ln { display: block; padding: 0 18px 0 0; }
.code-block .ln::before {
  counter-increment: line; content: counter(line);
  display: inline-block; width: 3.2em; padding-right: 1.2em; text-align: right; color: var(--gutter); user-select: none;
}
.code-block.output { background: var(--surface-2); }
.code-block.output .ln::before { content: ""; width: 1em; padding-right: 0; }
.code-block.bad { border-left: 4px solid #d1453b; }
.code-block.good { border-left: 4px solid #2f9e44; }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-keyword { color: var(--tok-keyword); font-weight: 600; }
.tok-type { color: var(--tok-type); }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-pre { color: var(--tok-pre); }
.tok-func { color: var(--tok-func); }

/* ---------- Callouts ---------- */
.note {
  margin: 0 0 22px; padding: 14px 18px; border-radius: var(--radius);
  border: 1px solid; border-left-width: 5px; background: var(--surface);
}
.note > .note-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.note > .note-body > :last-child { margin-bottom: 0; }
.note.key  { border-color: #9cc6e8; border-left-color: #2b7fc4; background: color-mix(in srgb, #2b7fc4 7%, var(--surface)); }
.note.best { border-color: #a8d8b0; border-left-color: #2f9e44; background: color-mix(in srgb, #2f9e44 7%, var(--surface)); }
.note.warn { border-color: #efb3ae; border-left-color: #d1453b; background: color-mix(in srgb, #d1453b 7%, var(--surface)); }
.note.tip  { border-color: #ecd59a; border-left-color: #d49b00; background: color-mix(in srgb, #d49b00 8%, var(--surface)); }
.note.term { border-color: var(--border); border-left-color: #7c8594; background: var(--surface-2); }
.note.adv  { border-color: #cdb8ea; border-left-color: #7b4fc4; background: color-mix(in srgb, #7b4fc4 7%, var(--surface)); }
.note.key  .note-title { color: #2b7fc4; }
.note.best .note-title { color: #2f9e44; }
.note.warn .note-title { color: #d1453b; }
.note.tip  .note-title { color: #b07f00; }
.note.term .note-title { color: var(--muted); }
.note.adv  .note-title { color: #7b4fc4; }
[data-theme="dark"] .note.key  .note-title { color: #7ab8ec; }
[data-theme="dark"] .note.best .note-title { color: #6fcf84; }
[data-theme="dark"] .note.warn .note-title { color: #f08a80; }
[data-theme="dark"] .note.tip  .note-title { color: #f0c552; }
[data-theme="dark"] .note.adv  .note-title { color: #b598ec; }
[data-theme="dark"] .note { border-color: var(--border); }

/* ---------- Quiz ---------- */
.quiz-header {
  display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 27px; font-weight: 700;
  margin: 44px 0 16px; padding-top: 18px; border-top: 1px solid var(--border);
}
.question {
  margin: 0 0 20px; padding: 18px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.question .q-label { font-weight: 700; color: var(--accent); font-size: 15px; margin-bottom: 8px; }
.question .q-body > :last-child { margin-bottom: 12px; }
.solution-toggle {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--accent); color: var(--accent); background: transparent;
  padding: 5px 14px; border-radius: 999px;
}
.solution-toggle:hover { background: var(--accent-soft); }
.solution { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.solution.open { display: block; animation: fade .2s ease; }
.solution > :last-child { margin-bottom: 0; }
@keyframes fade { from { transform: translateY(-4px); } to { transform: none; } }

/* ---------- Lesson footer ---------- */
.complete-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  margin: 40px 0 22px; padding: 16px 20px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.complete-btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; padding: 8px 18px;
}
[data-theme="dark"] .complete-btn { color: #0d1b1d; }
.complete-btn.is-done { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.prevnext { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; }
.pn {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); min-height: 74px;
}
.pn:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow); }
.pn small { color: var(--muted); font-size: 13px; }
.pn b { font-weight: 600; line-height: 1.35; }
.pn.next { text-align: right; }
.pn.index { justify-content: center; align-items: center; }
.pn.empty { visibility: hidden; }
.kbd-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 12px; }
kbd { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }

/* ---------- Home ---------- */
.hero { padding: 56px 0 30px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 40px; align-items: center; }
.hero h1 { font-family: var(--serif); font-size: 50px; line-height: 1.1; margin: 0 0 16px; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); font-size: 18px; margin: 0 0 14px; max-width: 60ch; }
.hero-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.btn { display: inline-block; padding: 10px 20px; border-radius: 9px; font-weight: 600; border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
[data-theme="dark"] .btn.primary { color: #0d1b1d; }
.hero-code { box-shadow: var(--shadow); }
.progress-card {
  margin: 10px 0 34px; padding: 18px 22px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.progress-card .label { font-weight: 600; }
.progress-track { flex: 1; min-width: 200px; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .4s; }
.progress-card .count { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.chapters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; align-items: start; padding-bottom: 60px; }
.chapter {
  break-inside: avoid; margin: 0 0 28px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.chapter-head { display: flex; align-items: baseline; gap: 12px; padding: 14px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.chapter-head .ch-num { font-family: var(--mono); font-size: 13px; color: var(--accent); font-weight: 700; white-space: nowrap; }
.chapter-head h2 { margin: 0; font-size: 18px; line-height: 1.35; flex: 1; }
.chapter-head .ch-count { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chapter ol { list-style: none; margin: 0; padding: 6px 0; }
.chapter li { display: flex; gap: 12px; padding: 5px 18px; font-size: 15.5px; line-height: 1.45; }
.chapter li:hover { background: var(--surface-2); }
.chapter li .num { font-family: var(--mono); font-size: 13px; color: var(--muted); min-width: 40px; padding-top: 2px; }
.chapter li .status { margin-left: auto; color: var(--accent); font-size: 14px; }
.chapter li.planned { color: var(--muted); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); vertical-align: 2px; margin-left: 6px; white-space: nowrap; }
.badge.soon { background: transparent; }
.chapter.is-planned .chapter-head .badge { margin-left: 0; }

/* ---------- Generic pages ---------- */
.narrow { max-width: 820px; margin: 0 auto; padding: 40px 0 70px; }
.narrow h1 { font-family: var(--serif); font-size: 40px; margin: 0 0 14px; }
.filter-input {
  width: 100%; padding: 12px 16px; font: inherit; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); margin: 8px 0 24px; outline: none;
}
.filter-input:focus { border-color: var(--accent); }
.index-list { list-style: none; padding: 0; margin: 0; }
.index-list .ix-chapter { margin: 24px 0 6px; font-weight: 700; font-size: 18px; }
.index-list .ix-lesson { display: flex; gap: 12px; padding: 4px 8px; border-radius: 6px; }
.index-list .ix-lesson:hover { background: var(--surface-2); }
.index-list .num { font-family: var(--mono); font-size: 13px; color: var(--muted); min-width: 44px; padding-top: 3px; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }
.site-footer .footer-inner { max-width: 1400px; margin: 0 auto; padding: 24px 20px; display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.to-top {
  position: fixed; right: 20px; bottom: 20px; opacity: 0; pointer-events: none; transition: opacity .2s;
  box-shadow: var(--shadow);
}
.to-top.show { opacity: 1; pointer-events: auto; }
.reading-progress { position: fixed; top: var(--header-h); left: 0; height: 3px; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); z-index: 49; }

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .lesson-layout { grid-template-columns: 250px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 980px) {
  .chapters { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .main-nav { display: none; }
  .nav-toggle { display: grid; }
  .lesson-layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0; width: 300px; max-height: none;
    background: var(--surface); border-right: 1px solid var(--border); padding: 20px 16px; z-index: 45;
    transform: translateX(-105%); transition: transform .25s; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  .search-wrap input, .search-wrap input:focus { width: 170px; }
  .search-results { width: min(420px, 92vw); right: -90px; }
}
@media (max-width: 600px) {
  body { font-size: 16px; }
  .brand small { display: none; }
  .hero h1 { font-size: 36px; }
  .article h1 { font-size: 30px; }
  .prevnext { grid-template-columns: 1fr 1fr; }
  .pn.index { grid-column: 1 / -1; order: 3; min-height: 0; }
  .search-wrap input, .search-wrap input:focus { width: 120px; }
}
@media print {
  .site-header, .sidebar, .toc, .prevnext, .complete-bar, .to-top, .copy-btn, .reading-progress, .kbd-hint { display: none !important; }
  .solution { display: block !important; }
  .solution-toggle { display: none; }
  .lesson-layout { display: block; }
}

/* ---------- "Made easy" reading boxes + reader tools ---------- */
html { font-size: calc(16px * var(--scale, 1)); }
body { font-size: calc(17px * var(--scale, 1)); }
.prose > .box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 22px 26px; margin: 0 0 22px; box-shadow: var(--shadow);
  transition: opacity .25s, transform .25s, border-color .25s;
}
.prose > .box > :last-child { margin-bottom: 0; }
.prose > .box h2 { margin: 0 0 12px; padding-top: 0; border-top: 0; color: var(--accent); font-size: 25px; }
.prose > .box.intro { border-left: 5px solid var(--accent); }
.prose > .box.quiz-box { background: transparent; border: 0; box-shadow: none; padding: 0; }
.prose > .box.quiz-box .quiz-header { margin-top: 10px; border-top: 0; padding-top: 0; }
body.calm .prose:hover > .box:not(:hover) { opacity: .2; }
body.calm .prose > .box:hover { border-color: var(--accent); }
.reader-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: -10px 0 26px; }
.reader-tools button {
  font: inherit; font-size: 13px; font-family: var(--mono); cursor: pointer;
  padding: 4px 10px; border-radius: 7px; border: 1px solid var(--accent); background: transparent; color: var(--accent);
}
.reader-tools button:hover, .reader-tools button[aria-pressed="true"] { background: var(--accent-soft); }
.reader-tools .hint { font-size: 13px; color: var(--muted); }
.prose ul.lines { list-style: none; padding-left: 0; }
.prose ul.lines li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.prose ul.lines li:last-child { border-bottom: 0; }
.chapter-intro { color: var(--muted); font-size: 15px; padding: 10px 18px 0; margin: 0; }
@media (max-width: 600px) {
  .header-inner { gap: 8px; padding: 0 10px; }
  .brand > span:last-child { display: none; }
  .search-wrap input, .search-wrap input:focus { width: 150px; }
  .search-results { right: -46px; }
  .prose > .box { padding: 16px 16px; }
  .code-block pre { font-size: 13px; }
}

/* ---------- Run button ---------- */
.code-tools { display: inline-flex; gap: 6px; align-items: center; }
.run-btn {
  font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 6px;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
}
.run-btn:hover { text-decoration: none; filter: brightness(1.1); }
[data-theme="dark"] .run-btn { color: #0d1b1d; }

/* ---------- Multiple-choice quick checks ---------- */
.mcq {
  margin: 0 0 20px; padding: 18px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.mcq .q-label { font-weight: 700; color: var(--accent-2); font-size: 15px; margin-bottom: 8px; }
.mcq .q-body > :last-child { margin-bottom: 12px; }
.mcq-options { display: grid; gap: 8px; }
.mcq-opt {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  font: inherit; font-size: 16px; color: var(--text); cursor: pointer;
  padding: 10px 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.mcq-opt:hover:not(:disabled) { border-color: var(--accent); }
.mcq-opt:disabled { cursor: default; }
.mcq-letter {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--mono); font-size: 13px; font-weight: 700; border: 1px solid var(--border); background: var(--surface);
}
.mcq-opt.right { border-color: #2f9e44; background: color-mix(in srgb, #2f9e44 14%, var(--surface)); }
.mcq-opt.right .mcq-letter { background: #2f9e44; border-color: #2f9e44; color: #fff; }
.mcq-opt.wrong { border-color: #d1453b; background: color-mix(in srgb, #d1453b 12%, var(--surface)); }
.mcq-opt.wrong .mcq-letter { background: #d1453b; border-color: #d1453b; color: #fff; }
.mcq-opt.faded { opacity: .55; }
.mcq-why { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.mcq-why > :last-child { margin-bottom: 0; }
.mcq-verdict { font-weight: 700; }
.mcq-verdict.ok { color: #2f9e44; }
.mcq-verdict.no { color: #d1453b; }
[data-theme="dark"] .mcq-verdict.ok { color: #6fcf84; }
[data-theme="dark"] .mcq-verdict.no { color: #f08a80; }
.mcq-score {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 0 0 24px; padding: 12px 18px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); font-weight: 600;
}
.mcq-score button { font: inherit; font-size: 14px; cursor: pointer; border: 1px solid var(--accent); color: var(--accent); background: transparent; padding: 4px 12px; border-radius: 99px; }

/* ---------- Glossary ---------- */
.letter-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 26px; }
.letter-nav a { font-family: var(--mono); font-weight: 700; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--accent); }
.letter-nav a:hover { border-color: var(--accent); text-decoration: none; }
.g-letter h2 { font-family: var(--serif); font-size: 30px; color: var(--accent); margin: 28px 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.g-entry { padding: 14px 18px; margin: 0 0 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.g-entry h3 { margin: 0 0 4px; font-size: 19px; }
.g-def p { margin: 0 0 8px; }
.g-def code { font-family: var(--mono); font-size: .86em; padding: 1px 5px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); }
.g-def strong.term { color: var(--accent); }
.g-src { font-size: 14px; }

/* ---------- See-assembly button / asm blocks ---------- */
.asm-btn { background: transparent; color: var(--accent); }
[data-theme="dark"] .asm-btn { color: var(--accent); }
.code-block.asm { border-left: 4px solid var(--accent-2); }

/* ---------- Resources ---------- */
.res-group h2 { font-family: var(--serif); font-size: 26px; margin: 34px 0 12px; }
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.res-card {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.res-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.res-card b { color: var(--accent); }
.res-card span { font-size: 14.5px; color: var(--muted); line-height: 1.5; }

/* ---------- Certificate ---------- */
.cert-link { font-weight: 600; white-space: nowrap; }
.cert-locked { padding: 22px 24px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.cert-locked .progress-track { margin: 10px 0 16px; }
.cert-status { font-weight: 700; font-size: 18px; }
.cert-name-label { display: block; font-weight: 600; }
.certificate {
  position: relative; text-align: center; margin: 10px 0 24px; padding: 56px 40px 44px;
  background: #fffdf7; color: #1f2328; border-radius: 6px;
  border: 10px double #0f6e78; box-shadow: var(--shadow); font-family: var(--serif);
}
.cert-mark {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(135deg, #0f6e78, #e0622b); color: #fff; font-family: var(--mono); font-weight: 700; font-size: 20px;
}
.cert-small { margin: 6px 0; color: #5f6672; font-size: 17px; }
.cert-name { margin: 10px 0; font-size: 42px; font-weight: 700; color: #0f6e78; border-bottom: 2px solid #e2ded5; display: inline-block; padding: 0 30px 6px; min-width: 60%; }
.cert-course { margin: 8px 0; font-size: 24px; font-weight: 700; }
.cert-date { margin-top: 24px; color: #5f6672; font-family: var(--sans); font-size: 14px; }
@media print {
  .no-print, .site-footer, .to-top { display: none !important; }
  .narrow { padding: 0; }
  .certificate { box-shadow: none; margin: 0; }
}

/* ---------- Hints + difficulty tags ---------- */
.hint-toggle { margin-right: 8px; border-color: var(--accent-2); color: var(--accent-2); }
.hint-toggle:hover { background: color-mix(in srgb, var(--accent-2) 12%, transparent); }
.solution.hint { border-top-color: color-mix(in srgb, var(--accent-2) 50%, transparent); margin-bottom: 12px; }
.solution.hint + .solution-toggle { margin-top: 0; }

/* ---------- Hover tooltips ---------- */
pre [data-tip] { cursor: help; border-radius: 3px; transition: background .12s; }
pre [data-tip]:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.has-tip { cursor: help; text-decoration: underline dotted color-mix(in srgb, var(--accent) 70%, transparent); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
code.has-tip:hover, code.has-tip:focus, strong.has-tip:hover, strong.has-tip:focus { background: var(--accent-soft); outline: none; }
.tip-box {
  position: fixed; z-index: 60; max-width: min(340px, calc(100vw - 16px));
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.22); padding: 10px 13px 11px; font: 14.5px/1.5 var(--sans);
  animation: tipIn .12s ease-out;
}
.tip-box[hidden] { display: none; }
.tip-box::after {
  content: ""; position: absolute; left: var(--arrow-x, 50%); bottom: -7px; width: 12px; height: 12px; margin-left: -6px;
  background: var(--surface); border: 1px solid var(--border); border-top: 0; border-left: 0; transform: rotate(45deg);
}
.tip-box.below::after { bottom: auto; top: -7px; transform: rotate(-135deg); }
.tip-title { font-family: var(--mono); font-weight: 700; color: var(--accent); font-size: 14px; margin-bottom: 3px; }
.tip-body p { margin: 0; }
.tip-body code { font-size: .9em; }
.tip-more { display: inline-block; margin-top: 7px; font-size: 13px; font-weight: 600; color: var(--link); }
@keyframes tipIn { from { transform: translateY(3px); } to { transform: none; } }
@media print { .tip-box { display: none !important; } .has-tip { text-decoration: none; } }
