/* ==========================================================================
   The 3D Printing Compendium — design system
   Light/dark themes, responsive 3-column layout, content components,
   SVG diagram utility classes. See CONTRIBUTING.md for component docs.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --ink: #1a2330;
  --ink-2: #3a4757;
  --muted: #5a687b;
  --line: #d8dee6;
  --brand: #b25d2f;
  --brand-ink: #8d4217;
  --brand-soft: #fcede5;
  --on-brand: #ffffff;
  --link: #2f6094;

  --blue: #6994cb;   --blue-s: #e7f1ff;   --blue-ink: #446da1;
  --green: #57814e;  --green-s: #e9f4e6;  --green-ink: #4b7542;
  --orange: #ac6c27; --orange-s: #fbede1; --orange-ink: #9a5c10;
  --red: #c67067;    --red-s: #ffebe8;    --red-ink: #a5534a;
  --purple: #9a7bb8; --purple-s: #f4edfc; --purple-ink: #7c5e99;
  --teal: #529d99;   --teal-s: #e0f5f4;   --teal-ink: #297774;
  --yellow: #ae8e44; --yellow-s: #f7efe0; --yellow-ink: #866717;
  --pink: #975882;   --pink-s: #fbebf5;   --pink-ink: #965781;
  --gray: #6b7686;   --gray-s: #e9ecf0;

  --plastic: #daa668;
  --plastic-2: #c9884c;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 4px 16px rgba(20, 30, 45, .06);
  --radius: 12px;
  --header-h: 60px;
  --sidebar-w: 300px;
  --toc-w: 230px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #0e1319;
  --surface: #161d26;
  --surface-2: #1e2732;
  --ink: #e8edf3;
  --ink-2: #c5cfdb;
  --muted: #92a0b2;
  --line: #2b3745;
  --brand: #e3966a;
  --brand-ink: #f2ac81;
  --brand-soft: #321f14;
  --on-brand: #1b1208;
  --link: #8bbcef;

  --blue: #93bdf3; --green: #7fa875; --orange: #d49557; --red: #ef9a90;
  --purple: #c2a4e0; --teal: #7fc5c1; --yellow: #d6b672; --pink: #bf80a9; --gray: #98a4b4;
  --blue-s: #1c2736; --green-s: #1e2a1b; --orange-s: #322316; --red-s: #35201e;
  --purple-s: #2a2233; --teal-s: #122b2a; --yellow-s: #2d2514; --pink-s: #31202b; --gray-s: #222b36;
  --blue-ink: #93bdf3; --green-ink: #7fa875; --orange-ink: #d49557; --red-ink: #ef9a90;
  --purple-ink: #c2a4e0; --teal-ink: #7fc5c1; --yellow-ink: #d6b672; --pink-ink: #bf80a9;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16.5px/1.7 var(--font); -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand); }
::selection { background: var(--brand); color: var(--on-brand); }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.site-header .brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 800; letter-spacing: -.01em; white-space: nowrap; }
.site-header .brand svg { width: 30px; height: 30px; flex: none; }
.site-header .brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; line-height: 1; margin-top: 2px; }
.site-header .spacer { flex: 1; }
.ver-chip { font: 650 11.5px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; text-decoration: none; white-space: nowrap; letter-spacing: 0; text-transform: none; }
.ver-chip:hover { border-color: var(--brand); color: var(--brand); }
.kicker .ver-chip { margin-left: 10px; vertical-align: 1px; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; height: 38px; min-width: 38px; padding: 0 10px; cursor: pointer; font: inherit; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.menu-btn { display: none; }
.search-btn { min-width: 220px; justify-content: space-between; color: var(--muted); }
.search-btn kbd { font: 11px var(--mono); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; color: var(--muted); }
.progress-bar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--brand); z-index: 100; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w); max-width: 1640px; margin: 0 auto; }
.sidebar {
  position: sticky; top: var(--header-h); align-self: start; height: calc(100vh - var(--header-h));
  overflow-y: auto; padding: 18px 12px 40px 18px; border-right: 1px solid var(--line); font-size: 14.5px;
}
.sidebar::-webkit-scrollbar, .toc::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .toc::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.nav-part { margin-bottom: 4px; }
.nav-part > button {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer; padding: 7px 8px; border-radius: 8px;
  font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px;
}
.nav-part > button:hover { background: var(--surface-2); }
.nav-part > button .chev { margin-left: auto; transition: transform .2s; color: var(--muted); font-size: 12px; }
.nav-part.open > button .chev { transform: rotate(90deg); }
.nav-part ul { list-style: none; margin: 2px 0 8px 14px; padding: 0 0 0 10px; border-left: 2px solid var(--line); display: none; }
.nav-part.open ul { display: block; }
.nav-part li a { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 7px; color: var(--ink-2); text-decoration: none; line-height: 1.35; }
.nav-part li a:hover { background: var(--surface-2); color: var(--ink); }
.nav-part li a.current { background: var(--brand-soft); color: var(--brand-ink); font-weight: 650; }
.lvl-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--gray); }
.lvl-dot.l1 { background: var(--green); } .lvl-dot.l2 { background: var(--yellow); } .lvl-dot.l3 { background: var(--red); }

.content { min-width: 0; padding: 28px clamp(18px, 4vw, 56px) 80px; }
.content > * { max-width: 880px; margin-left: auto; margin-right: auto; }
.content > .wide { max-width: 1100px; }
.toc { position: sticky; top: var(--header-h); align-self: start; height: calc(100vh - var(--header-h)); overflow-y: auto; padding: 28px 16px 40px 8px; font-size: 13.5px; }
.toc h4 { margin: 0 0 8px; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.toc a { display: block; padding: 3px 0 3px 12px; color: var(--muted); text-decoration: none; border-left: 2px solid var(--line); line-height: 1.4; }
.toc a.h3 { padding-left: 24px; font-size: 12.5px; }
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--brand-ink); border-left-color: var(--brand); font-weight: 650; }

@media (max-width: 1300px) { .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); } .toc { display: none; } }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-flex; }
  .search-btn { min-width: 0; } .search-btn .lbl, .search-btn kbd { display: none; }
  .sidebar { position: fixed; z-index: 60; top: var(--header-h); left: 0; width: min(88vw, 340px); background: var(--surface); transform: translateX(-102%); transition: transform .25s; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: var(--header-h) 0 0 0; background: rgba(0,0,0,.4); z-index: 55; }
  .site-header .brand small { display: none; }}
@media (max-width: 520px) {
  .site-header { gap: 8px; padding: 0 10px; }
  .site-header .brand { min-width: 0; gap: 8px; }
  .site-header .brand > span { overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
  .site-header .ver-chip { display: none; }
}

/* ---------- Typography ---------- */
.content h1, .content h2, .content h3, .content h4 { line-height: 1.25; letter-spacing: -.015em; position: relative; }
.content h1 { font-size: clamp(2rem, 4.4vw, 2.9rem); margin: .2em 0 .35em; }
.content h2 { font-size: 1.75rem; margin: 2.3em 0 .6em; padding-bottom: .3em; border-bottom: 2px solid var(--line); }
.content h3 { font-size: 1.28rem; margin: 1.9em 0 .5em; }
.content h4 { font-size: 1.05rem; margin: 1.5em 0 .4em; color: var(--ink-2); }
.content p, .content li { color: var(--ink-2); }
.content strong { color: var(--ink); }
.content li { margin: .25em 0; }
.content ul, .content ol { padding-left: 1.4em; }
.content .anchor { position: absolute; left: -1.1em; opacity: 0; text-decoration: none; color: var(--muted); font-weight: 400; }
.content h2:hover .anchor, .content h3:hover .anchor, .content h4:hover .anchor { opacity: 1; }
p code, li code, td code, .pc-eq { overflow-wrap: anywhere; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: .08em .4em; }
pre { position: relative; font: 13.5px/1.55 var(--mono); background: #0f1722; color: #dbe6f3; border-radius: var(--radius); padding: 16px 18px; overflow-x: auto; border: 1px solid #1d2a3a; }
pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
pre .copy { position: absolute; top: 8px; right: 8px; font: 12px var(--font); border: 1px solid #33465c; background: #172334; color: #b8c8da; border-radius: 6px; padding: 3px 9px; cursor: pointer; opacity: 0; transition: opacity .15s; }
pre:hover .copy { opacity: 1; }
kbd { font: 12px var(--mono); background: var(--surface); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }
blockquote { margin: 1.2em 0; padding: .6em 1.2em; border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 0 var(--radius) var(--radius) 0; }
blockquote p { margin: .4em 0; }
mark { background: var(--yellow-s); color: inherit; padding: 0 .2em; border-radius: 3px; }
abbr[title] { text-decoration: underline dotted var(--muted); cursor: help; }

/* ---------- Page hero ---------- */
.hero { position: relative; margin: 0 auto 2em; padding: 30px 32px; border-radius: 18px; background: linear-gradient(135deg, var(--brand-soft), var(--surface)); border: 1px solid var(--line); overflow: hidden; box-shadow: var(--shadow); }
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 220px; height: 220px; border-radius: 50%; background: repeating-linear-gradient(0deg, color-mix(in srgb, var(--brand) 18%, transparent) 0 6px, transparent 6px 14px); opacity: .55; pointer-events: none; }
.hero .kicker { font-size: 12.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--brand-ink); }
.hero h1 { margin: .15em 0 .25em; }
.hero .lead { font-size: 1.15rem; color: var(--ink-2); max-width: 62ch; margin: 0 0 .8em; position: relative; z-index: 1; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; position: relative; z-index: 1; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 11px; font-size: 12.5px; font-weight: 650; background: var(--gray-s); color: var(--ink-2); border: 1px solid var(--line); }
.badge.beginner, .badge.l1 { background: var(--green-s); color: var(--green-ink); border-color: transparent; }
.badge.intermediate, .badge.l2 { background: var(--yellow-s); color: var(--yellow-ink); border-color: transparent; }
.badge.advanced, .badge.l3 { background: var(--red-s); color: var(--red-ink); border-color: transparent; }
.badge.expert, .badge.l4 { background: var(--purple-s); color: var(--purple-ink); border-color: transparent; }
.badge.x2d { background: var(--red-s); color: var(--red-ink); border-color: transparent; }
.badge.time { background: var(--blue-s); color: var(--blue-ink); border-color: transparent; }
.badge.verified { background: var(--teal-s); color: var(--teal-ink); border-color: transparent; }
.badge.verified.stale { background: var(--yellow-s); color: var(--yellow-ink); }

/* ---------- Callouts ---------- */
.callout { margin: 1.4em auto; padding: 14px 18px 14px 18px; border-radius: var(--radius); border: 1px solid var(--line); border-left-width: 5px; background: var(--surface); box-shadow: var(--shadow); }
.callout > :first-child { margin-top: 0; } .callout > :last-child { margin-bottom: 0; }
.callout-title { display: flex; align-items: center; gap: 8px; font-weight: 750; margin-bottom: .35em; color: var(--ink); }
.callout-title::before { font-size: 1.15em; }
.callout.tip { border-left-color: var(--green); background: var(--green-s); } .callout.tip .callout-title::before { content: "💡"; }
.callout.info { border-left-color: var(--blue); background: var(--blue-s); } .callout.info .callout-title::before { content: "ℹ️"; }
.callout.warn { border-left-color: var(--yellow); background: var(--yellow-s); } .callout.warn .callout-title::before { content: "⚠️"; }
.callout.danger { border-left-color: var(--red); background: var(--red-s); } .callout.danger .callout-title::before { content: "⛔"; }
.callout.trick { border-left-color: var(--purple); background: var(--purple-s); } .callout.trick .callout-title::before { content: "🪄"; }
.callout.fact { border-left-color: var(--teal); background: var(--teal-s); } .callout.fact .callout-title::before { content: "🔬"; }
.callout.x2d { border-left-color: var(--red); background: linear-gradient(90deg, var(--red-s), var(--surface)); } .callout.x2d .callout-title::before { content: "🖨️"; }
.callout.goal { border-left-color: var(--pink); background: var(--pink-s); } .callout.goal .callout-title::before { content: "🎯"; }

/* ---------- Figures & diagrams ---------- */
figure.fig { margin: 1.8em auto; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; }
figure.fig svg, figure.fig img { width: 100%; height: auto; display: block; margin: 0 auto; max-height: 560px; }
figure.fig.zoomable { cursor: zoom-in; }
figure.fig figcaption { margin-top: 10px; font-size: 14px; color: var(--muted); text-align: left; }
figure.fig figcaption b { color: var(--ink-2); }
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(8, 12, 18, .86); display: flex; align-items: center; justify-content: center; padding: 3vw; cursor: zoom-out; }
.lightbox > div { background: var(--surface); border-radius: 14px; padding: 18px; max-width: 96vw; max-height: 94vh; overflow: auto; }
.lightbox svg { width: min(92vw, 1400px); height: auto; max-height: 86vh; }

/* SVG utility classes (theme-aware). Use inside <svg class="diagram"> */
svg.diagram { font-family: var(--font); }
.d-ink  { stroke: var(--ink); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.d-thin { stroke: var(--ink); fill: none; stroke-width: 1; stroke-linecap: round; stroke-linejoin: round; }
.d-mute { stroke: var(--muted); fill: none; stroke-width: 1.5; stroke-linecap: round; }
.d-dash { stroke: var(--muted); fill: none; stroke-width: 1.5; stroke-dasharray: 6 5; stroke-linecap: round; }
.d-grid { stroke: var(--line); stroke-width: 1; fill: none; }
.d-solid { fill: var(--ink); stroke: none; }
.d-surface { fill: var(--surface); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.d-surface2 { fill: var(--surface-2); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.d-plastic { fill: var(--plastic); stroke: var(--plastic-2); stroke-width: 1.5; stroke-linejoin: round; }
.d-plastic2 { fill: var(--plastic-2); stroke: none; }
.d-metal { fill: #b9c3cf; stroke: #7d8a99; stroke-width: 1.5; stroke-linejoin: round; }
.d-metal2 { fill: #8f9cab; stroke: #66737f; stroke-width: 1.5; stroke-linejoin: round; }
.d-hot { fill: #ff7a45; stroke: #c4430f; stroke-width: 1.5; }
.d-cool { fill: #6ab7ff; stroke: #2a73bd; stroke-width: 1.5; }
.arrow { marker-end: url(#c3d-arrow); }
.arrow-start { marker-start: url(#c3d-arrow); }
:where(svg) text { fill: var(--ink); } /* default for unclassed labels; any class or inline fill wins */
.t { fill: var(--ink); font-size: 14px; } .t-sm { fill: var(--ink-2); font-size: 12px; } .t-xs { fill: var(--muted); font-size: 10.5px; }
.t-b { font-weight: 700; } .t-m { fill: var(--muted); } .t-c { text-anchor: middle; } .t-r { text-anchor: end; }
.t-lg { fill: var(--ink); font-size: 18px; font-weight: 700; } .t-xl { fill: var(--ink); font-size: 24px; font-weight: 800; }
.t-w { fill: #fff; } .t-mono { font-family: var(--mono); }
/* colour fills: f-<name> = soft fill with coloured stroke; s-<name> = solid fill; k-<name> = stroke only; c-<name> = text colour */
.f-blue   { fill: var(--blue-s);   stroke: var(--blue);   stroke-width: 2; } .s-blue   { fill: var(--blue); }   .k-blue   { stroke: var(--blue);   fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-blue   { fill: var(--blue-ink); }
.f-green  { fill: var(--green-s);  stroke: var(--green);  stroke-width: 2; } .s-green  { fill: var(--green); }  .k-green  { stroke: var(--green);  fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-green  { fill: var(--green-ink); }
.f-orange { fill: var(--orange-s); stroke: var(--orange); stroke-width: 2; } .s-orange { fill: var(--orange); } .k-orange { stroke: var(--orange); fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-orange { fill: var(--orange-ink); }
.f-red    { fill: var(--red-s);    stroke: var(--red);    stroke-width: 2; } .s-red    { fill: var(--red); }    .k-red    { stroke: var(--red);    fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-red    { fill: var(--red-ink); }
.f-purple { fill: var(--purple-s); stroke: var(--purple); stroke-width: 2; } .s-purple { fill: var(--purple); } .k-purple { stroke: var(--purple); fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-purple { fill: var(--purple-ink); }
.f-teal   { fill: var(--teal-s);   stroke: var(--teal);   stroke-width: 2; } .s-teal   { fill: var(--teal); }   .k-teal   { stroke: var(--teal);   fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-teal   { fill: var(--teal-ink); }
.f-yellow { fill: var(--yellow-s); stroke: var(--yellow); stroke-width: 2; } .s-yellow { fill: var(--yellow); } .k-yellow { stroke: var(--yellow); fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-yellow { fill: var(--yellow-ink); }
.f-pink   { fill: var(--pink-s);   stroke: var(--pink);   stroke-width: 2; } .s-pink   { fill: var(--pink); }   .k-pink   { stroke: var(--pink);   fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-pink   { fill: var(--pink-ink); }
.f-gray   { fill: var(--gray-s);   stroke: var(--gray);   stroke-width: 2; } .s-gray   { fill: var(--gray); }   .k-gray   { stroke: var(--gray);   fill: none; stroke-width: 2.5; stroke-linecap: round; } .c-gray   { fill: var(--gray); }
.s-white { fill: #fff; } .s-black { fill: #1b1f27; } .s-none { fill: none; }

/* ---------- Grids, cards, stats ---------- */
.grid { display: grid; gap: 16px; margin: 1.4em auto; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); } }
.card { display: block; padding: 18px 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); color: inherit; text-decoration: none; transition: transform .15s, border-color .15s; }
a.card:hover { transform: translateY(-2px); border-color: var(--brand); color: inherit; }
.card h3, .card h4 { margin: 0 0 .3em; font-size: 1.08rem; border: 0; padding: 0; }
.card p { margin: .3em 0; font-size: .95rem; }
.card .ico { font-size: 1.8rem; line-height: 1; display: block; margin-bottom: .4em; }
.card.accent-blue { border-top: 4px solid var(--blue); } .card.accent-green { border-top: 4px solid var(--green); } .card.accent-orange { border-top: 4px solid var(--orange); }
.card.accent-red { border-top: 4px solid var(--red); } .card.accent-purple { border-top: 4px solid var(--purple); } .card.accent-teal { border-top: 4px solid var(--teal); }
.card.accent-pink { border-top: 4px solid var(--pink); } .card.accent-yellow { border-top: 4px solid var(--yellow); } .card.accent-gray { border-top: 4px solid var(--gray); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 1.4em auto; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.45rem; line-height: 1.15; color: var(--brand-ink); letter-spacing: -.02em; }
.stat span { font-size: 13px; color: var(--muted); }
.pros-cons { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 1.4em auto; }
@media (max-width: 640px) { .pros-cons { grid-template-columns: 1fr; } }
.pros-cons > div { border-radius: var(--radius); padding: 12px 18px; border: 1px solid var(--line); }
.pros-cons .pros { background: var(--green-s); } .pros-cons .cons { background: var(--red-s); }
.pros-cons h4 { margin: .2em 0 .3em; } .pros-cons ul { margin: 0; padding-left: 1.2em; }
.pros-cons .pros li::marker { content: "＋ "; color: var(--green-ink); font-weight: 800; } .pros-cons .cons li::marker { content: "－ "; color: var(--red-ink); font-weight: 800; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.4em auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th, table.data td { padding: 9px 13px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data thead th { background: var(--surface-2); font-size: 12.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); position: sticky; top: 0; white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--brand) 6%, transparent); }
table.data td:first-child { font-weight: 650; color: var(--ink); }
table.data.compact th, table.data.compact td { padding: 5px 9px; font-size: 13.5px; }
.rate { display: inline-flex; gap: 3px; vertical-align: middle; }
.rate i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.rate i.on { background: var(--brand); }
.rate.g i.on { background: var(--green); }
.chip { display: inline-block; border-radius: 6px; padding: 1px 8px; font-size: 12.5px; font-weight: 650; background: var(--gray-s); color: var(--ink-2); white-space: nowrap; }
.chip.green { background: var(--green-s); color: var(--green-ink); } .chip.yellow { background: var(--yellow-s); color: var(--yellow-ink); }
.chip.red { background: var(--red-s); color: var(--red-ink); } .chip.blue { background: var(--blue-s); color: var(--blue-ink); }
.chip.purple { background: var(--purple-s); color: var(--purple-ink); } .chip.orange { background: var(--orange-s); color: var(--orange-ink); } .chip.teal { background: var(--teal-s); color: var(--teal-ink); }

/* ---------- Bars (CSS charts) ---------- */
.bars { margin: 1.4em auto; display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.bars .bars-title { font-weight: 750; margin-bottom: 2px; }
.bar { display: grid; grid-template-columns: minmax(90px, 170px) 1fr 70px; align-items: center; gap: 10px; font-size: 14px; }
.bar > span { color: var(--ink-2); } .bar > em { font-style: normal; color: var(--muted); font-size: 12.5px; text-align: right; }
.bar > i { display: block; height: 14px; border-radius: 8px; background: var(--surface-2); position: relative; overflow: hidden; }
.bar > i::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--v, 50%); background: linear-gradient(90deg, var(--c, var(--brand)), color-mix(in srgb, var(--c, var(--brand)) 70%, #fff)); border-radius: 8px; }
.bar.blue { --c: var(--blue); } .bar.green { --c: var(--green); } .bar.red { --c: var(--red); } .bar.purple { --c: var(--purple); } .bar.teal { --c: var(--teal); } .bar.yellow { --c: var(--yellow); }

/* ---------- Steps, flow, timeline ---------- */
ol.steps { list-style: none; counter-reset: step; padding: 0; margin: 1.4em auto; }
ol.steps > li { counter-increment: step; position: relative; padding: 4px 0 18px 54px; margin: 0; min-height: 44px; }
ol.steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: var(--on-brand); font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px color-mix(in srgb, var(--brand) 45%, transparent); }
ol.steps > li::after { content: ""; position: absolute; left: 17px; top: 40px; bottom: 4px; width: 2px; background: var(--line); }
ol.steps > li:last-child::after { display: none; }
ol.steps > li > strong:first-child { display: block; font-size: 1.05rem; color: var(--ink); }
ol.flow { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 1.4em auto; align-items: stretch; }
ol.flow > li { margin: 0; padding: 10px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; font-weight: 650; position: relative; box-shadow: var(--shadow); }
ol.flow > li:not(:last-child)::after { content: "→"; position: absolute; right: -15px; top: 50%; transform: translateY(-50%); color: var(--brand); font-weight: 900; z-index: 1; background: var(--bg); line-height: 1; }
ol.flow > li { margin-right: 14px; }
ul.timeline { list-style: none; margin: 1.4em auto; padding: 0 0 0 22px; border-left: 3px solid var(--brand); }
ul.timeline > li { position: relative; margin: 0 0 1.1em; }
ul.timeline > li::before { content: ""; position: absolute; left: -31px; top: .45em; width: 13px; height: 13px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand); }
ul.timeline > li b:first-child { color: var(--brand-ink); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: .6em 0; padding: 0; list-style: none; }
.tags li { margin: 0; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }
.swatch { display: inline-block; width: 1em; height: 1em; border-radius: 4px; border: 1px solid var(--line); vertical-align: -.12em; margin-right: .3em; }

/* ---------- Tabs, accordion ---------- */
.tabs { margin: 1.6em auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.tab-list { display: flex; gap: 2px; overflow-x: auto; background: var(--surface-2); border-bottom: 1px solid var(--line); padding: 6px 6px 0; }
.tab-list button { all: unset; box-sizing: border-box; cursor: pointer; padding: 8px 16px; border-radius: 8px 8px 0 0; font-weight: 650; color: var(--muted); white-space: nowrap; font-size: 14.5px; }
.tab-list button:hover { color: var(--ink); }
.tab-list button[aria-selected="true"] { background: var(--surface); color: var(--brand-ink); box-shadow: 0 -2px 0 var(--brand) inset; }
.tabs > .tab { display: none; padding: 6px 20px 14px; }
.tabs > .tab.active { display: block; }
details.accordion, details.hint { margin: 1em auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 0 18px; }
details.accordion > summary, details.hint > summary { cursor: pointer; padding: 11px 0; font-weight: 650; color: var(--ink); list-style: none; display: flex; gap: 8px; align-items: center; }
details > summary::-webkit-details-marker { display: none; }
details.accordion > summary::before, details.hint > summary::before { content: "▸"; color: var(--brand); transition: transform .15s; }
details[open].accordion > summary::before, details[open].hint > summary::before { transform: rotate(90deg); }
details[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: .6em; }
details.hint { background: var(--yellow-s); } details.hint > summary::after { content: "hint"; margin-left: auto; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--yellow-ink); }
details.solution { margin: 1em auto; border: 1px dashed var(--green); border-radius: var(--radius); background: var(--green-s); padding: 0 18px; }
details.solution > summary { cursor: pointer; padding: 11px 0; font-weight: 650; color: var(--green-ink); list-style: none; }
details.solution > summary::before { content: "✔ "; }

/* ---------- Exercises & quizzes ---------- */
section.exercise { margin: 2em auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
section.exercise > header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 20px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
section.exercise > header h3 { margin: 0; flex: 1 1 260px; font-size: 1.15rem; border: 0; padding: 0; }
section.exercise .ex-body { padding: 6px 22px 14px; }
section.exercise > footer { padding: 10px 20px; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; align-items: center; gap: 10px; }
section.exercise.done { border-color: var(--green); }
section.exercise.done > header { background: var(--green-s); }
.ex-done-btn { cursor: pointer; display: inline-flex; gap: 8px; align-items: center; font-weight: 650; color: var(--ink-2); }
.ex-done-btn input { width: 18px; height: 18px; accent-color: var(--green); }
.ex-label { font-weight: 750; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 1em 0 .2em; display: block; }
ul.checklist { list-style: none; padding-left: 0; }
ul.checklist li { display: flex; gap: 10px; align-items: flex-start; }
ul.checklist input { margin-top: .45em; width: 17px; height: 17px; accent-color: var(--brand); flex: none; }
ul.checklist li.checked > label { text-decoration: line-through; color: var(--muted); }
.progress-summary { display: flex; align-items: center; gap: 12px; margin: .6em 0; }
.progress-summary .track { flex: 1; height: 12px; border-radius: 8px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress-summary .fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--teal)); transition: width .4s; }
.quiz { margin: 1.4em auto; padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.quiz .q { font-weight: 700; color: var(--ink); margin: 0 0 .6em; }
.quiz .options { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.quiz .options li { margin: 0; padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--bg); }
.quiz .options li:hover { border-color: var(--brand); }
.quiz .options li.correct { background: var(--green-s); border-color: var(--green); color: var(--ink); }
.quiz .options li.wrong { background: var(--red-s); border-color: var(--red); }
.quiz.answered .options li { cursor: default; }
.quiz .explain { display: none; margin: .8em 0 0; padding: 10px 14px; border-radius: 10px; background: var(--blue-s); font-size: .95rem; }
.quiz.answered .explain { display: block; }
.score-board { position: sticky; top: calc(var(--header-h) + 8px); z-index: 5; margin: 1em auto; padding: 10px 16px; background: var(--surface); border: 1px solid var(--brand); border-radius: 12px; box-shadow: var(--shadow); font-weight: 650; display: flex; gap: 14px; align-items: center; }

/* ---------- Widgets / forms ---------- */
.tool { margin: 1.6em auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.tool > h3, .tool > .tool-title { margin: 0; padding: 12px 20px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 1.1rem; border-top: 0; }
.tool .tool-body { padding: 16px 20px 20px; display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 760px) { .tool .tool-body { grid-template-columns: 1fr; } }
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 13px; font-weight: 650; color: var(--ink-2); display: flex; justify-content: space-between; gap: 8px; }
.field label output { color: var(--brand-ink); font-family: var(--mono); }
.field input[type="number"], .field input[type="text"], .field select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }
.field input[type="range"] { width: 100%; accent-color: var(--brand); }
.field small { color: var(--muted); font-size: 12.5px; }
.result { background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line)); border-radius: 12px; padding: 14px 16px; }
.result .big { font-size: 1.9rem; font-weight: 800; color: var(--brand-ink); line-height: 1.1; letter-spacing: -.02em; }
.result dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: .6em 0 0; font-size: 14px; }
.result dt { color: var(--muted); } .result dd { margin: 0; text-align: right; font-family: var(--mono); color: var(--ink); }
.btn { appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 700; padding: 9px 18px; border-radius: 10px; background: var(--brand); color: var(--on-brand); }
.btn:hover { filter: brightness(1.08); } .btn.ghost { background: transparent; color: var(--brand-ink); border: 1px solid var(--brand); }
.no-zoom { cursor: default; }
a.btn, a.btn:hover { text-decoration: none; color: var(--on-brand); display: inline-block; } a.btn.ghost, a.btn.ghost:hover { color: var(--brand-ink); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 1em 0; }

/* ---------- Search ---------- */
.search-modal { position: fixed; inset: 0; z-index: 300; background: rgba(8, 12, 18, .6); display: none; align-items: flex-start; justify-content: center; padding-top: 10vh; }
.search-modal.open { display: flex; }
.search-box { width: min(680px, 94vw); background: var(--surface); border-radius: 16px; border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.4); overflow: hidden; }
.search-box input { width: 100%; font: inherit; font-size: 18px; padding: 16px 20px; border: 0; border-bottom: 1px solid var(--line); outline: none; background: transparent; color: var(--ink); }
.search-results { max-height: 56vh; overflow-y: auto; }
.search-results a { display: block; padding: 10px 20px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a.sel { background: var(--brand-soft); }
.search-results a b { display: block; } .search-results a span { font-size: 13px; color: var(--muted); }
.search-results .none { padding: 20px; color: var(--muted); }

/* ---------- Footer nav ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 4em !important; }
.pager a { display: block; padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.pager a:hover { border-color: var(--brand); }
.pager a small { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.pager a.next { text-align: right; grid-column: 2; }
.pager a { min-width: 0; overflow-wrap: anywhere; }
.site-footer { text-align: center; color: var(--muted); font-size: 13.5px; padding: 30px 18px 50px; border-top: 1px solid var(--line); }
.to-top { position: fixed; right: 18px; bottom: 18px; z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s; }
.to-top.show { opacity: 1; pointer-events: auto; }

/* ---------- Home page helpers ---------- */
.home-hero { text-align: center; padding: 56px 26px 46px; border-radius: 24px; border: 1px solid var(--line); background: radial-gradient(1200px 400px at 50% -10%, color-mix(in srgb, var(--brand) 22%, transparent), transparent), var(--surface); box-shadow: var(--shadow); position: relative; overflow: hidden; margin-bottom: 2em; }
.home-hero h1 { font-size: clamp(2.2rem, 6vw, 3.8rem); margin: .1em 0 .2em; letter-spacing: -.03em; }
.home-hero h1 span { background: linear-gradient(90deg, var(--brand), var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.home-hero p.lead { font-size: 1.25rem; max-width: 52ch; margin: 0 auto 1.2em; color: var(--ink-2); }
.home-hero .btn-row { justify-content: center; }
.home-hero svg.hero-art { width: min(640px, 90%); margin: 0 auto 10px; display: block; }

/* ---------- Print ---------- */
@media print {
  .site-header, .sidebar, .toc, .pager, .to-top, .progress-bar, .site-footer, pre .copy { display: none !important; }
  .layout { display: block; } .content { padding: 0; } .content > * { max-width: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .callout, figure.fig, .card, table.data, .exercise, .tool { box-shadow: none; break-inside: avoid; }
  details > * { display: block !important; }
  a { color: inherit; text-decoration: none; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }

/* shared by several pages */
.tol-note { color: var(--muted); font-size: 13px; }
.k-ink { stroke: var(--ink); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
