/* ============================================================
   Machines, Data & Learning — mdBook-inspired theme
   Five themes like mdBook: light, rust, coal, navy, ayu
   ============================================================ */

:root {
  --sidebar-width: 300px;
  --page-padding: 15px;
  --content-max-width: 760px;
  --menu-bar-height: 50px;
  --mono-font: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, monospace;
  --code-font-size: 0.875em;
}

/* ---------- themes ---------- */
.light, html:not(.rust):not(.coal):not(.navy):not(.ayu) {
  --bg: #ffffff; --fg: #1f1f1f; --muted: #6b6b6b;
  --sidebar-bg: #fafafa; --sidebar-fg: #1a1a1a; --sidebar-non-existant: #aaa; --sidebar-active: #1f1fff; --sidebar-spacer: #f4f4f4;
  --scrollbar: #8f8f8f; --icons: #747474; --icons-hover: #000;
  --links: #20609f; --inline-code-color: #301900;
  --theme-popup-bg: #fafafa; --theme-popup-border: #cccccc; --theme-hover: #e6e6e6;
  --quote-bg: #f2f6fa; --quote-border: #dbe5ef;
  --table-border-color: #e6e6e6; --table-header-bg: #f2f2f2; --table-alternate-bg: #f8f8f8;
  --searchbar-border-color: #aaa; --searchbar-bg: #fafafa; --searchbar-fg: #000; --search-mark-bg: #e69f67;
  --code-bg: #f6f7f6; --code-fg: #2b2b2b;
  --hl-kw: #a626a4; --hl-str: #50a14f; --hl-num: #986801; --hl-com: #8e8e8e; --hl-fn: #4078f2; --hl-bi: #c18401;
  --surface: #f7f8fa; --surface-2: #eef0f3; --border: #dde1e6;
  --accent: #2f6fdd; --accent-2: #e2622c; --good: #1f8a4c; --bad: #c8312e; --warn: #b7791f;
  --c-connect: #2f6fdd; --c-intuition: #7a4fd6; --c-exam: #c8312e; --c-warn: #b7791f; --c-lab: #1f8a4c; --c-bolt: #e2622c;
  color-scheme: light;
}
.rust {
  --bg: #e1e1db; --fg: #262625; --muted: #5d5d58;
  --sidebar-bg: #3b2e2a; --sidebar-fg: #c8c9db; --sidebar-non-existant: #505254; --sidebar-active: #e69f67; --sidebar-spacer: #45373a;
  --scrollbar: #8f8f8f; --icons: #737480; --icons-hover: #262625;
  --links: #2b79a2; --inline-code-color: #6e6b5e;
  --theme-popup-bg: #e1e1db; --theme-popup-border: #b38f6b; --theme-hover: #99908a;
  --quote-bg: #d7d4c9; --quote-border: #b38f6b;
  --table-border-color: #c9c6bc; --table-header-bg: #b3a497; --table-alternate-bg: #d7d4c9;
  --searchbar-border-color: #aaa; --searchbar-bg: #fafafa; --searchbar-fg: #000; --search-mark-bg: #e69f67;
  --code-bg: #f6f7f6; --code-fg: #262625;
  --hl-kw: #8959a8; --hl-str: #718c00; --hl-num: #f5871f; --hl-com: #8e908c; --hl-fn: #4271ae; --hl-bi: #c82829;
  --surface: #d9d8d0; --surface-2: #cfcdc3; --border: #bdb9ac;
  --accent: #b3541e; --accent-2: #2b79a2; --good: #3c7a2c; --bad: #b3261e; --warn: #8f6200;
  --c-connect: #2b79a2; --c-intuition: #7b4fa8; --c-exam: #b3261e; --c-warn: #8f6200; --c-lab: #3c7a2c; --c-bolt: #b3541e;
  color-scheme: light;
}
.coal {
  --bg: #1d1f21; --fg: #a7b0b8; --muted: #7d878f;
  --sidebar-bg: #292c2f; --sidebar-fg: #a1adb8; --sidebar-non-existant: #505254; --sidebar-active: #3473ad; --sidebar-spacer: #393939;
  --scrollbar: #6f6f6f; --icons: #43484d; --icons-hover: #b3c0cc;
  --links: #4a9ad6; --inline-code-color: #c5c8c6;
  --theme-popup-bg: #141617; --theme-popup-border: #43484d; --theme-hover: #1f2124;
  --quote-bg: #22262b; --quote-border: #2f343a;
  --table-border-color: #2e3236; --table-header-bg: #2b2f33; --table-alternate-bg: #232629;
  --searchbar-border-color: #505254; --searchbar-bg: #2b2f33; --searchbar-fg: #e0e0e0; --search-mark-bg: #355c7d;
  --code-bg: #15181a; --code-fg: #c5c8c6;
  --hl-kw: #b294bb; --hl-str: #b5bd68; --hl-num: #de935f; --hl-com: #969896; --hl-fn: #81a2be; --hl-bi: #f0c674;
  --surface: #23262a; --surface-2: #2b2f33; --border: #383d42;
  --accent: #5aa0e6; --accent-2: #f0965a; --good: #63c08a; --bad: #ef6b67; --warn: #e0b55a;
  --c-connect: #5aa0e6; --c-intuition: #b294bb; --c-exam: #ef6b67; --c-warn: #e0b55a; --c-lab: #63c08a; --c-bolt: #f0965a;
  color-scheme: dark;
}
.navy {
  --bg: #161923; --fg: #bcbdd0; --muted: #8a8ca3;
  --sidebar-bg: #282d3f; --sidebar-fg: #c8c9db; --sidebar-non-existant: #505274; --sidebar-active: #2b79a2; --sidebar-spacer: #2d334f;
  --scrollbar: #6f6f6f; --icons: #737480; --icons-hover: #b7b9cc;
  --links: #4a9fd6; --inline-code-color: #c5c8c6;
  --theme-popup-bg: #161923; --theme-popup-border: #737480; --theme-hover: #282e40;
  --quote-bg: #1e2333; --quote-border: #2c3350;
  --table-border-color: #2c3350; --table-header-bg: #282d3f; --table-alternate-bg: #1b1f2c;
  --searchbar-border-color: #5c5c68; --searchbar-bg: #2a2f42; --searchbar-fg: #e0e0e0; --search-mark-bg: #a2cff5;
  --code-bg: #10131b; --code-fg: #c5c8c6;
  --hl-kw: #b294bb; --hl-str: #b5bd68; --hl-num: #de935f; --hl-com: #8a8ca3; --hl-fn: #81a2be; --hl-bi: #f0c674;
  --surface: #1c2030; --surface-2: #242a3d; --border: #323a55;
  --accent: #5aa7e6; --accent-2: #f0965a; --good: #5fc290; --bad: #f07178; --warn: #e6c15a;
  --c-connect: #5aa7e6; --c-intuition: #b39ddb; --c-exam: #f07178; --c-warn: #e6c15a; --c-lab: #5fc290; --c-bolt: #f0965a;
  color-scheme: dark;
}
.ayu {
  --bg: #0f1419; --fg: #c5c5c5; --muted: #8b949e;
  --sidebar-bg: #14191f; --sidebar-fg: #c8c9db; --sidebar-non-existant: #5c6773; --sidebar-active: #ffb454; --sidebar-spacer: #2d334f;
  --scrollbar: #5c6773; --icons: #737480; --icons-hover: #b7b9cc;
  --links: #0096cf; --inline-code-color: #ffb454;
  --theme-popup-bg: #14191f; --theme-popup-border: #5c6773; --theme-hover: #191f26;
  --quote-bg: #182029; --quote-border: #273240;
  --table-border-color: #222a33; --table-header-bg: #1a2129; --table-alternate-bg: #141a20;
  --searchbar-border-color: #848484; --searchbar-bg: #424242; --searchbar-fg: #fff; --search-mark-bg: #e3b171;
  --code-bg: #191f26; --code-fg: #e6e1cf;
  --hl-kw: #ff7733; --hl-str: #b8cc52; --hl-num: #ffee99; --hl-com: #5c6773; --hl-fn: #ffb454; --hl-bi: #36a3d9;
  --surface: #151b21; --surface-2: #1c232b; --border: #29323c;
  --accent: #39bae6; --accent-2: #ffb454; --good: #91d076; --bad: #f07178; --warn: #ffb454;
  --c-connect: #39bae6; --c-intuition: #d2a6ff; --c-exam: #f07178; --c-warn: #ffb454; --c-lab: #91d076; --c-bolt: #ff8f40;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { font-family: "Open Sans", sans-serif; color: var(--fg); background-color: var(--bg); text-size-adjust: none; -webkit-text-size-adjust: none; scroll-padding-top: calc(var(--menu-bar-height) + 10px); }
body { margin: 0; font-size: 1.6rem; overflow-x: hidden; background: var(--bg); color: var(--fg); }
html { font-size: 62.5%; }
code { font-family: var(--mono-font) !important; font-size: var(--code-font-size); }
a { color: var(--links); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ---------- sidebar ---------- */
.sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-width); font-size: 0.875em; box-sizing: border-box; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; background-color: var(--sidebar-bg); color: var(--sidebar-fg); transition: transform 0.3s; z-index: 30; }
.sidebar-scrollbox { overflow-y: auto; position: absolute; inset: 0; padding: 10px 10px 40px; }
.sidebar-resize-handle { position: absolute; cursor: col-resize; width: 6px; right: 0; top: 0; bottom: 0; }
.sidebar a { color: var(--sidebar-fg); }
.sidebar ol.chapter { list-style: none outside none; padding-left: 0; line-height: 2.2em; margin: 0; }
.chapter li.chapter-item { line-height: 1.5em; margin-top: 0.6em; }
.chapter li.chapter-item.sub { padding-left: 20px; margin-top: 0.35em; }
.chapter li a { display: block; padding: 0; text-decoration: none; }
.chapter li a:hover { color: var(--sidebar-active); }
.chapter li a.active { color: var(--sidebar-active); }
.chapter li.part-title { color: var(--sidebar-fg); margin: 1.4em 0 0.2em; padding-top: 0.6em; font-weight: 700; font-size: 0.82em; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; border-top: 1px solid var(--sidebar-spacer); }
.chapter li strong { font-weight: 600; }
html.sidebar-hidden .sidebar { transform: translateX(calc(0px - var(--sidebar-width))); }
html.sidebar-visible .page-wrapper { transform: translateX(var(--sidebar-width)); }
@media only screen and (min-width: 1080px) {
  html.sidebar-visible .page-wrapper { transform: none; margin-left: var(--sidebar-width); }
}
.page-wrapper { box-sizing: border-box; transition: margin-left 0.3s ease, transform 0.3s ease; min-height: 100vh; }

/* ---------- menu bar ---------- */
.page { outline: 0; padding: 0 var(--page-padding); }
.menu-bar { position: sticky; top: 0; margin: auto calc(0px - var(--page-padding)); height: var(--menu-bar-height); display: flex; flex-wrap: wrap; background-color: var(--bg); border-bottom: 1px solid transparent; z-index: 20; align-items: center; transition: border-color .2s; }
.menu-bar.bordered { border-bottom-color: var(--table-border-color); }
#menu-bar-hover-placeholder { display: none; }
.left-buttons, .right-buttons { display: flex; margin: 0 5px; align-items: center; position: relative; }
.icon-button { border: none; background: none; padding: 0; color: var(--icons); cursor: pointer; width: 40px; height: var(--menu-bar-height); display: inline-flex; align-items: center; justify-content: center; transition: color 0.5s; }
.icon-button:hover { color: var(--icons-hover); text-decoration: none; }
.menu-title { display: inline-block; font-weight: 200; font-size: 2.2rem; line-height: var(--menu-bar-height); text-align: center; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-title a { color: inherit; }
.menu-title a:hover { text-decoration: none; }
.theme-popup { position: absolute; left: 10px; top: var(--menu-bar-height); z-index: 1000; border-radius: 4px; font-size: 0.75em; color: var(--fg); background: var(--theme-popup-bg); border: 1px solid var(--theme-popup-border); margin: 0; padding: 0; list-style: none; display: none; }
.theme-popup.open { display: block; }
.theme-popup .theme { width: 100%; border: 0; margin: 0; padding: 4px 12px; line-height: 25px; white-space: nowrap; text-align: left; cursor: pointer; color: inherit; background: inherit; font-size: inherit; }
.theme-popup .theme:hover, .theme-popup .theme.selected { background-color: var(--theme-hover); }

/* ---------- search ---------- */
#search-wrapper { max-width: var(--content-max-width); margin: 0 auto; padding: 10px 0 0; }
.hidden { display: none !important; }
#searchbar { width: 100%; margin: 5px auto 0; padding: 10px 16px; transition: box-shadow 300ms ease-in-out; border: 1px solid var(--searchbar-border-color); border-radius: 3px; background-color: var(--searchbar-bg); color: var(--searchbar-fg); font-size: 1.6rem; }
#searchbar:focus { box-shadow: 0 0 3px var(--searchbar-border-color); outline: none; }
.searchresults-header { font-weight: bold; font-size: 1em; padding: 18px 0 0 5px; color: var(--muted); }
.searchresults-outer { border-bottom: 1px dashed var(--searchbar-border-color); margin-bottom: 1em; }
ul#searchresults { list-style: none; padding-left: 20px; }
ul#searchresults li { margin: 10px 0; padding: 2px; border-radius: 2px; }
ul#searchresults li.focus { background-color: var(--theme-hover); }
ul#searchresults .teaser { color: var(--muted); font-size: 0.85em; margin-top: 2px; }
ul#searchresults mark { background: var(--search-mark-bg); color: inherit; border-radius: 2px; padding: 0 1px; }

/* ---------- content ---------- */
.content { overflow-y: auto; padding: 0 5px 50px; }
.content main { margin-left: auto; margin-right: auto; max-width: var(--content-max-width); }
.content p { line-height: 1.6em; }
.content ol, .content ul { line-height: 1.6em; }
.content li { margin: 0.25em 0; }
.content h1 { font-size: 2.6rem; margin-top: 1.4em; line-height: 1.25; }
.content h2 { font-size: 2.15rem; margin-top: 2.2em; line-height: 1.3; }
.content h3 { font-size: 1.8rem; margin-top: 2em; }
.content h4 { font-size: 1.6rem; margin-top: 1.6em; }
.content a.header { color: inherit; }
.content a.header:hover { text-decoration: none; }
.content a.header:target::before, .content :target > a.header::before { content: "»"; display: inline-block; margin-left: -30px; width: 30px; color: var(--muted); }
.content img, .content svg.fig { max-width: 100%; }
.content .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.content hr { border: 0; border-top: 1px solid var(--table-border-color); margin: 2.5em 0; }
:not(pre) > code { padding: 0.1em 0.3em; border-radius: 3px; color: var(--inline-code-color); background: var(--code-bg); overflow-wrap: break-word; }
.content strong { font-weight: 700; }
.content .lead { font-size: 1.12em; color: var(--fg); }
.content .small { font-size: 0.88em; color: var(--muted); }
kbd { font-family: var(--mono-font); font-size: .8em; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; background: var(--surface); }

/* code blocks */
.code-wrap { position: relative; }
pre { background: var(--code-bg); color: var(--code-fg); padding: 1em 1.1em; border-radius: 4px; overflow-x: auto; line-height: 1.5; font-size: 1.45rem; margin: 1.1em 0; }
pre code { font-size: 1em; background: none; padding: 0; color: inherit; }
pre.output { border-left: 3px solid var(--muted); background: var(--surface); font-size: 1.35rem; }
pre.output::before { content: "Output"; display: block; font-family: "Open Sans", sans-serif; font-size: .75em; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: .4em; }
.copy-btn { position: absolute; top: 6px; right: 6px; font-size: 1.15rem; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .2s; }
.code-wrap:hover .copy-btn, .copy-btn:focus { opacity: 1; }
.hl-kw { color: var(--hl-kw); } .hl-str { color: var(--hl-str); } .hl-num { color: var(--hl-num); }
.hl-com { color: var(--hl-com); font-style: italic; } .hl-fn { color: var(--hl-fn); } .hl-bi { color: var(--hl-bi); }

/* tables */
table { margin: 1.2em auto; border-collapse: collapse; font-size: 0.92em; display: block; overflow-x: auto; max-width: 100%; width: fit-content; }
table td, table th { padding: 4px 12px; border: 1px solid var(--table-border-color); }
table thead { background: var(--table-header-bg); }
table thead th { font-weight: 700; }
table tbody tr:nth-child(2n) { background: var(--table-alternate-bg); }

blockquote { margin: 20px 0; padding: 0 20px; color: var(--fg); background-color: var(--quote-bg); border-top: .1em solid var(--quote-border); border-bottom: .1em solid var(--quote-border); }

/* ---------- callouts ---------- */
.callout { border-left: 4px solid var(--cc, var(--accent)); background: color-mix(in srgb, var(--cc, var(--accent)) 8%, var(--bg)); padding: 0.75em 1.1em; margin: 1.5em 0; border-radius: 0 6px 6px 0; }
.callout > .ct { display: block; font-weight: 700; font-size: 0.8em; letter-spacing: .07em; text-transform: uppercase; color: var(--cc, var(--accent)); margin-bottom: .25em; }
.callout > :last-child { margin-bottom: 0.2em; }
.callout > p:first-of-type { margin-top: 0.3em; }
.callout.connect { --cc: var(--c-connect); }
.callout.intuition { --cc: var(--c-intuition); }
.callout.exam { --cc: var(--c-exam); }
.callout.warn { --cc: var(--c-warn); }
.callout.lab { --cc: var(--c-lab); }
.callout.bolt { --cc: var(--c-bolt); }
.callout.def { --cc: var(--muted); }

/* key idea box */
.keyidea { border: 1px solid var(--border); background: var(--surface); padding: 0.8em 1.2em; border-radius: 8px; margin: 1.5em 0; }
.keyidea::before { content: "Key idea"; display: block; font-size: .78em; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: .2em; }

/* chapter summary */
.summary-list { background: var(--surface); border-radius: 8px; padding: 0.8em 1.2em 0.8em 2.4em; border: 1px solid var(--border); }

/* figures */
figure { margin: 1.6em 0; text-align: center; }
figure svg { max-width: 100%; height: auto; }
figcaption { font-size: 0.86em; color: var(--muted); margin-top: 0.5em; text-align: center; }
svg.fig text { font-family: "Open Sans", sans-serif; fill: var(--fg); }
svg .stroke-fg { stroke: var(--fg); } svg .fill-fg { fill: var(--fg); }
svg .fill-bg { fill: var(--bg); } svg .fill-surface { fill: var(--surface); } svg .stroke-border { stroke: var(--border); }
svg .stroke-accent { stroke: var(--accent); } svg .fill-accent { fill: var(--accent); }
svg .stroke-accent2 { stroke: var(--accent-2); } svg .fill-accent2 { fill: var(--accent-2); }
svg .stroke-muted { stroke: var(--muted); } svg .fill-muted { fill: var(--muted); }
svg .fill-good { fill: var(--good); } svg .stroke-good { stroke: var(--good); }
svg .fill-bad { fill: var(--bad); } svg .stroke-bad { stroke: var(--bad); }

/* ---------- quiz (Brown-book style) ---------- */
.quiz { border: 1px solid var(--border); border-radius: 6px; margin: 2em 0; padding: 0; background: var(--bg); }
.quiz .qz-head { display: flex; justify-content: space-between; align-items: center; padding: 0.7em 1.1em; border-bottom: 1px solid var(--border); }
.quiz .qz-head h4 { margin: 0; font-size: 1.05em; }
.quiz .qz-head .qz-count { color: var(--muted); font-size: 0.88em; }
.quiz .qz-body { padding: 0.9em 1.2em 1.1em; }
.quiz .qz-q { margin-bottom: 0.8em; }
.quiz .qz-q > p:first-child { margin-top: 0.2em; }
.quiz .qz-opt { display: flex; gap: 0.6em; align-items: flex-start; padding: 0.5em 0.7em; border: 1px solid var(--border); border-radius: 5px; margin: 0.45em 0; cursor: pointer; transition: background .15s, border-color .15s; }
.quiz .qz-opt:hover { background: var(--surface); }
.quiz .qz-opt input { margin-top: 0.35em; accent-color: var(--accent); }
.quiz .qz-opt.chosen { border-color: var(--accent); }
.quiz .qz-opt.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--bg)); }
.quiz .qz-opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--bg)); }
.quiz button.qz-btn { font-size: 0.9em; padding: 0.4em 1.1em; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-2); color: var(--fg); cursor: pointer; }
.quiz button.qz-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.quiz button.qz-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.quiz .qz-explain { margin-top: 0.8em; padding: 0.6em 0.9em; border-radius: 5px; background: var(--surface); font-size: 0.95em; }
.quiz .qz-explain .verdict { font-weight: 700; }
.quiz .qz-explain .verdict.ok { color: var(--good); } .quiz .qz-explain .verdict.no { color: var(--bad); }
.quiz .qz-score { font-size: 1.1em; font-weight: 600; }
.quiz .qz-actions { display: flex; gap: 0.6em; margin-top: 0.9em; flex-wrap: wrap; }
.quiz .qz-review-item { border-top: 1px solid var(--border); padding-top: 0.8em; margin-top: 0.8em; }
.quiz input[type=text] { font-size: 1em; padding: 0.35em 0.6em; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); width: 12em; }

/* ---------- widgets ---------- */
.widget { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 1em 1.1em; margin: 1.8em 0; font-size: 0.93em; }
.widget .w-title { font-weight: 700; font-size: 0.82em; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.6em; display: flex; justify-content: space-between; gap: 1em; }
.widget .w-title span.try { color: var(--muted); font-weight: 600; text-transform: none; letter-spacing: 0; }
.widget canvas { width: 100%; display: block; background: var(--bg); border-radius: 6px; border: 1px solid var(--border); touch-action: none; }
.widget .w-row { display: flex; flex-wrap: wrap; gap: 0.6em 1.2em; align-items: center; margin: 0.7em 0 0.2em; }
.widget label { display: inline-flex; gap: 0.5em; align-items: center; }
.widget input[type=range] { accent-color: var(--accent); width: 150px; }
.widget input[type=number], .widget select, .widget input[type=text] { font: inherit; padding: 0.2em 0.4em; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); }
.widget input[type=number] { width: 4.5em; max-width: 100%; }
.widget button { font: inherit; font-size: 0.92em; padding: 0.3em 0.9em; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); cursor: pointer; }
.widget button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.widget button:hover { border-color: var(--accent); }
.widget .stat { font-family: var(--mono-font); font-size: 0.92em; }
.widget .stat b { color: var(--accent); }
.widget .w-note { color: var(--muted); font-size: 0.9em; margin-top: 0.5em; }
.widget table { font-size: 0.9em; margin: 0.6em 0; }
.widget .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1em; }
@media (max-width: 640px) { .widget .grid2 { grid-template-columns: 1fr; } }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

/* ---------- nav arrows ---------- */
.nav-wide-wrapper { display: none; }
/* full-height side strips (like mdBook / the Brown Rust book): the whole margin is the button */
.nav-chapters { position: fixed; top: var(--menu-bar-height); bottom: 0; margin: 0; z-index: 15;
  width: clamp(80px, calc((100vw - var(--nav-offset, 0px) - var(--content-max-width)) / 2 - 28px), 220px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-decoration: none; color: var(--icons); transition: color .5s, background-color .5s; }
.nav-chapters svg { width: 22px; height: 38px; fill: currentColor; opacity: .35; transition: opacity .25s, transform .25s; }
.nav-chapters .nav-label { font-size: 1.2rem; line-height: 1.35; text-align: center; padding: 0 10px; max-width: 100%;
  opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; color: var(--fg);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.nav-chapters:hover, .nav-chapters:focus-visible { text-decoration: none; background-color: var(--theme-hover); color: var(--icons-hover); transition: color .15s, background-color .15s; }
.nav-chapters:hover svg, .nav-chapters:focus-visible svg { opacity: 1; }
.nav-chapters.next:hover svg { transform: translateX(3px); }
.nav-chapters.previous:hover svg { transform: translateX(-3px); }
.nav-chapters:hover .nav-label, .nav-chapters:focus-visible .nav-label { opacity: .85; transform: none; }
.nav-chapters.next { right: 0; }
.nav-chapters.previous { left: 0; }
html.sidebar-visible .nav-chapters.previous { left: var(--sidebar-width); }
@media only screen and (min-width: 1080px) { html.sidebar-visible { --nav-offset: var(--sidebar-width); } }
@media (prefers-reduced-motion: reduce) { .nav-chapters, .nav-chapters svg, .nav-chapters .nav-label { transition: none; } }
.nav-wrapper { margin-top: 50px; display: flex; justify-content: space-between; gap: 1em; max-width: var(--content-max-width); margin-left: auto; margin-right: auto; }
.mobile-nav-chapters { font-size: 0.95em; text-align: center; padding: 0.6em 1em; border-radius: 5px; background: var(--surface); color: var(--fg); max-width: 48%; }
.mobile-nav-chapters:hover { text-decoration: none; background: var(--theme-hover); }
@media only screen and (min-width: 1380px) {
  .nav-wide-wrapper { display: block; }
  .nav-wrapper { display: none; }
}
@media only screen and (min-width: 1080px) and (max-width: 1379px) {
  html.sidebar-hidden .nav-wide-wrapper { display: block; }
  html.sidebar-hidden .nav-wrapper { display: none; }
}

/* mobile */
@media only screen and (max-width: 1079px) {
  html.sidebar-visible .page-wrapper { transform: translateX(var(--sidebar-width)); }
  html.sidebar-visible body { overflow: hidden; }
}
@media only screen and (max-width: 600px) {
  :root { --sidebar-width: 82vw; }
  .menu-title { font-size: 1.7rem; }
  #progress-btn { display: none; }
  body { font-size: 1.55rem; }
  .content h1 { font-size: 2.2rem; }
}

/* progress modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 10px; max-width: 560px; width: 100%; max-height: 80vh; overflow: auto; padding: 1.2em 1.4em; }
.modal h3 { margin-top: 0; }
.modal .bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 2px 0 10px; }
.modal .bar > i { display: block; height: 100%; background: var(--good); }
.modal table { width: 100%; display: table; }

/* print */
@media print {
  .sidebar, .menu-bar, .nav-wrapper, .nav-wide-wrapper, #search-wrapper, .copy-btn { display: none !important; }
  .page-wrapper { margin: 0 !important; transform: none !important; }
  .print-page { page-break-after: always; }
  html { --bg: #fff; --fg: #000; }
}

/* ---------- highlights & notes ---------- */
:root { --hl-yellow: rgba(255, 213, 0, .42); --hl-green: rgba(70, 200, 110, .35); --hl-blue: rgba(70, 150, 255, .33); --hl-pink: rgba(255, 90, 170, .32); }
.coal, .navy, .ayu { --hl-yellow: rgba(255, 213, 0, .30); --hl-green: rgba(90, 210, 130, .28); --hl-blue: rgba(90, 160, 255, .32); --hl-pink: rgba(255, 110, 180, .30); }
mark.hl { color: inherit; border-radius: 2px; padding: 0 1px; cursor: pointer; transition: box-shadow .2s; }
mark.hl-yellow { background: var(--hl-yellow); } mark.hl-green { background: var(--hl-green); }
mark.hl-blue { background: var(--hl-blue); } mark.hl-pink { background: var(--hl-pink); }
mark.hl-has-note { border-bottom: 2px dotted var(--fg); }
mark.hl-flash { box-shadow: 0 0 0 3px var(--accent); }
#hl-toolbar { position: absolute; z-index: 60; display: none; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; background: var(--theme-popup-bg); border: 1px solid var(--theme-popup-border); box-shadow: 0 4px 14px rgba(0,0,0,.18); font-size: 1.35rem; }
#hl-toolbar button { font: inherit; border: 0; background: none; color: var(--fg); cursor: pointer; padding: 4px 6px; border-radius: 5px; white-space: nowrap; }
#hl-toolbar button:hover { background: var(--theme-hover); }
#hl-toolbar .hl-sw { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 2px solid transparent; }
#hl-toolbar .hl-sw.hl-yellow { background: var(--hl-yellow); } #hl-toolbar .hl-sw.hl-green { background: var(--hl-green); }
#hl-toolbar .hl-sw.hl-blue { background: var(--hl-blue); } #hl-toolbar .hl-sw.hl-pink { background: var(--hl-pink); }
#hl-toolbar .hl-sw:hover, #hl-toolbar .hl-sw.on { border-color: var(--fg); background-clip: padding-box; }
#hl-toolbar .hl-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }
#hl-note { position: absolute; z-index: 61; display: none; width: min(340px, calc(100vw - 16px)); padding: 10px; border-radius: 8px; background: var(--theme-popup-bg); border: 1px solid var(--theme-popup-border); box-shadow: 0 6px 20px rgba(0,0,0,.22); }
#hl-note textarea { width: 100%; font: inherit; font-size: 1.45rem; padding: 6px 8px; border-radius: 5px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); resize: vertical; }
.hl-note-actions, .hl-panel-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.hl-note-actions button, .hl-panel-actions button, .hl-panel-actions .hl-import { font: inherit; font-size: .9em; padding: 4px 12px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-2); color: var(--fg); cursor: pointer; }
.hl-note-actions button.primary, .hl-panel-actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.hl-panel-actions button:disabled { opacity: .45; cursor: not-allowed; }
.hl-panel h4 { margin: 1.2em 0 .4em; font-size: .95em; color: var(--muted); }
.hl-panel .hl-item { display: block; padding: 6px 8px; border-radius: 6px; color: var(--fg); text-decoration: none; margin: 4px 0; }
.hl-panel .hl-item:hover { background: var(--surface); }
.hl-panel .hl-quote { padding: 1px 3px; border-radius: 2px; line-height: 1.7; }
.hl-panel .hl-quote.hl-yellow { background: var(--hl-yellow); } .hl-panel .hl-quote.hl-green { background: var(--hl-green); }
.hl-panel .hl-quote.hl-blue { background: var(--hl-blue); } .hl-panel .hl-quote.hl-pink { background: var(--hl-pink); }
.hl-panel .hl-note-text { display: block; font-size: .88em; color: var(--muted); margin-top: 3px; }
@media print { mark.hl { background: #fff3a0 !important; } #hl-toolbar, #hl-note, #highlights-btn { display: none !important; } }
