/* Engineering With Bandarage — shared site theme
   Light/dark tokens, docs layout (sidebar · article · on-page TOC), components. */

:root {
  --bg: #fbfaf7;
  --bg-elev: #ffffff;
  --bg-sunk: #f3f1ec;
  --text: #1c1f24;
  --text-muted: #5b6270;
  --text-faint: #8a909b;
  --border: #e4e1d9;
  --border-strong: #cfcac0;
  --accent: #0f6e66;
  --accent-soft: #e2f1ef;
  --accent-text: #0b5a53;
  --link: #0f6e66;

  --code-bg: #f6f4ef;
  --code-text: #23272e;
  --code-border: #e7e3da;
  --tok-comment: #7c8591;
  --tok-keyword: #8a3ffc;
  --tok-string: #2a7a3b;
  --tok-number: #b35c00;
  --tok-func: #1f5fbf;
  --tok-jinja: #c2410c;
  --tok-jinja-bg: #fff1e8;
  --tok-key: #1f5fbf;
  --tok-flag: #8a3ffc;

  --tip: #0f6e66;      --tip-bg: #e9f5f3;
  --warn: #a34b00;     --warn-bg: #fdf1e4;
  --danger: #b4232f;   --danger-bg: #fcebec;
  --deep: #4b3fb5;     --deep-bg: #efedfb;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 4px 16px rgba(20, 20, 30, .05);
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --topbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a; --bg-elev: #181c22; --bg-sunk: #0e1115;
    --text: #e6e8eb; --text-muted: #a3aab5; --text-faint: #737b87;
    --border: #262c35; --border-strong: #353d48;
    --accent: #3cc2b4; --accent-soft: #15302e; --accent-text: #6fd8cc; --link: #5cd0c3;
    --code-bg: #0f1216; --code-text: #d8dde4; --code-border: #232932;
    --tok-comment: #6f7a88; --tok-keyword: #c49bff; --tok-string: #8fd18f; --tok-number: #f0a35e;
    --tok-func: #7fb4ff; --tok-jinja: #ff9a62; --tok-jinja-bg: #2a1b12; --tok-key: #7fb4ff; --tok-flag: #c49bff;
    --tip: #5cd0c3; --tip-bg: #12292a; --warn: #f0a35e; --warn-bg: #2b2014;
    --danger: #ff7b86; --danger-bg: #2e1619; --deep: #a79bff; --deep-bg: #1e1b33;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151a; --bg-elev: #181c22; --bg-sunk: #0e1115;
  --text: #e6e8eb; --text-muted: #a3aab5; --text-faint: #737b87;
  --border: #262c35; --border-strong: #353d48;
  --accent: #3cc2b4; --accent-soft: #15302e; --accent-text: #6fd8cc; --link: #5cd0c3;
  --code-bg: #0f1216; --code-text: #d8dde4; --code-border: #232932;
  --tok-comment: #6f7a88; --tok-keyword: #c49bff; --tok-string: #8fd18f; --tok-number: #f0a35e;
  --tok-func: #7fb4ff; --tok-jinja: #ff9a62; --tok-jinja-bg: #2a1b12; --tok-key: #7fb4ff; --tok-flag: #c49bff;
  --tip: #5cd0c3; --tip-bg: #12292a; --warn: #f0a35e; --warn-bg: #2b2014;
  --danger: #ff7b86; --danger-bg: #2e1619; --deep: #a79bff; --deep-bg: #1e1b33;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.7 var(--font-sans); font-feature-settings: "cv11", "ss01";
}
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
img, svg { max-width: 100%; }
code, kbd, pre { font-family: var(--font-mono); font-variant-ligatures: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.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: 16px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--bg); font: 700 13px/1 var(--font-mono);
}
.brand-name small { display: block; font-weight: 500; font-size: 11px; color: var(--text-faint); letter-spacing: .04em; text-transform: uppercase; line-height: 1.2; }
.brand-name span { display: block; line-height: 1.2; font-size: 15px; }
.topbar-spacer { flex: 1; }
.search { position: relative; width: min(320px, 40vw); }
.search input {
  width: 100%; height: 36px; padding: 0 12px 0 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); font: inherit; font-size: 14px;
}
.search svg { position: absolute; left: 10px; top: 10px; width: 16px; height: 16px; color: var(--text-faint); }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0; max-height: 60vh; overflow: auto;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px; display: none;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--text); font-size: 14px; line-height: 1.4; }
.search-results a small { display: block; color: var(--text-faint); font-size: 12px; }
.search-results a:hover, .search-results a.active { background: var(--accent-soft); }
.search-results .empty { padding: 10px; color: var(--text-faint); font-size: 14px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.menu-btn { display: none; }

/* ---------- Docs layout ---------- */
.layout {
  display: grid; grid-template-columns: 280px minmax(0, 1fr) 230px;
  max-width: 1440px; margin: 0 auto;
}
.sidebar {
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 24px 16px 40px 20px; border-right: 1px solid var(--border); font-size: 14px;
}
.sidebar h4 { margin: 18px 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); font-weight: 600; }
.sidebar h4:first-child { margin-top: 0; }
.sidebar .tut-title { display: block; margin: 0 0 12px 8px; font-weight: 700; color: var(--text); text-decoration: none; line-height: 1.35; font-size: 15px; }
.sidebar ol { list-style: none; margin: 0; padding: 0; }
.sidebar li a, .sidebar li span {
  display: flex; gap: 10px; padding: 6px 8px; border-radius: 6px; color: var(--text-muted); text-decoration: none; line-height: 1.4;
}
.sidebar li a:hover { background: var(--bg-sunk); color: var(--text); }
.sidebar li a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.sidebar li span { color: var(--text-faint); cursor: default; }
.sidebar .num { font: 500 12px/1.6 var(--font-mono); color: var(--text-faint); min-width: 22px; }
.sidebar .soon { margin-left: auto; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; align-self: center; }
.sidebar .other-tuts { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }

main.content { min-width: 0; padding: 36px clamp(16px, 4vw, 56px) 80px; }
.doc { max-width: 780px; margin: 0 auto; }

.toc { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 36px 20px 40px 8px; font-size: 13px; }
.toc h5 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.toc a { display: block; padding: 4px 0 4px 12px; border-left: 2px solid var(--border); color: var(--text-muted); text-decoration: none; line-height: 1.4; }
.toc a.h3 { padding-left: 24px; font-size: 12.5px; }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--accent-text); border-left-color: var(--accent); }

/* ---------- Article typography ---------- */
.breadcrumbs { font-size: 13px; color: var(--text-faint); margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 6px; }
.breadcrumbs a { color: var(--text-muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--accent-text); }
.eyebrow { font: 600 12px/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent-text); margin: 0 0 12px; }
.doc h1 { font-size: clamp(30px, 4.5vw, 42px); line-height: 1.15; letter-spacing: -.025em; margin: 0 0 14px; font-weight: 800; }
.doc .lede { font-size: 19px; line-height: 1.6; color: var(--text-muted); margin: 0 0 24px; }
.doc h2 { font-size: 26px; line-height: 1.25; letter-spacing: -.015em; margin: 56px 0 14px; padding-top: 8px; font-weight: 750; }
.doc h3 { font-size: 19px; line-height: 1.35; margin: 34px 0 10px; font-weight: 700; }
.doc h4 { font-size: 16px; margin: 24px 0 8px; }
.doc h2 .anchor, .doc h3 .anchor { opacity: 0; margin-left: 8px; color: var(--text-faint); text-decoration: none; font-weight: 400; }
.doc h2:hover .anchor, .doc h3:hover .anchor { opacity: 1; }
.doc p, .doc ul, .doc ol { margin: 0 0 16px; }
.doc li { margin: 4px 0; }
.doc li > ul, .doc li > ol { margin: 4px 0; }
.doc strong { font-weight: 650; }
.doc :not(pre) > code {
  font-size: .86em; padding: .12em .38em; border-radius: 5px;
  background: var(--bg-sunk); border: 1px solid var(--border); color: var(--text); white-space: nowrap;
}
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 40px 0; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 28px; }
.pill { font-size: 12.5px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); background: var(--bg-elev); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--border); border-radius: var(--radius); }
.doc table { border-collapse: collapse; width: 100%; font-size: 14.5px; line-height: 1.5; }
.doc th, .doc td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc th { background: var(--bg-sunk); font-weight: 650; font-size: 13px; }
.doc tr:last-child td { border-bottom: 0; }

/* ---------- Code blocks ---------- */
.codeblock { margin: 0 0 20px; border: 1px solid var(--code-border); border-radius: var(--radius); background: var(--code-bg); overflow: hidden; }
.codeblock-head {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px 7px 14px; border-bottom: 1px solid var(--code-border);
  font: 12px/1.4 var(--font-mono); color: var(--text-muted);
}
.codeblock-head .lang { margin-left: auto; text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; color: var(--text-faint); }
.copy-btn {
  font: 500 11.5px/1 var(--font-sans); padding: 5px 9px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--code-border); background: var(--bg-elev); color: var(--text-muted);
}
.copy-btn:hover { color: var(--text); }
pre.code { margin: 0; padding: 14px 16px; overflow-x: auto; font-size: 13.5px; line-height: 1.6; color: var(--code-text); tab-size: 4; }
pre.code code { font-family: inherit; }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-keyword { color: var(--tok-keyword); font-weight: 500; }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-func { color: var(--tok-func); }
.tok-key { color: var(--tok-key); }
.tok-flag { color: var(--tok-flag); }
.tok-jinja { color: var(--tok-jinja); background: var(--tok-jinja-bg); border-radius: 3px; }
.tok-jinja .tok-keyword { color: var(--tok-jinja); font-weight: 700; }
.tok-jinja .tok-string { color: var(--tok-string); }
.tok-jinja .tok-func { color: var(--tok-func); }
.tok-jinja-comment { color: var(--tok-comment); font-style: italic; }
.tok-prompt { color: var(--text-faint); user-select: none; }

/* Jinja → compiled side-by-side */
.compare { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin: 0 0 20px; }
.compare .codeblock { margin: 0; }
.doc .compare-label, .compare-label { margin: 0 0 6px; font: 600 11px/1 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Callouts ---------- */
.callout { margin: 0 0 20px; padding: 14px 16px 14px 16px; border-radius: var(--radius); border: 1px solid; border-left-width: 4px; }
.callout > :last-child { margin-bottom: 0; }
.doc .callout-title, .callout-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin: 0 0 6px; }
.callout-title svg { width: 16px; height: 16px; flex: none; }
.callout.tip { background: var(--tip-bg); border-color: color-mix(in srgb, var(--tip) 35%, transparent); border-left-color: var(--tip); }
.callout.tip .callout-title { color: var(--tip); }
.callout.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); border-left-color: var(--warn); }
.callout.warn .callout-title { color: var(--warn); }
.callout.danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 35%, transparent); border-left-color: var(--danger); }
.callout.danger .callout-title { color: var(--danger); }
.callout.deep { background: var(--deep-bg); border-color: color-mix(in srgb, var(--deep) 35%, transparent); border-left-color: var(--deep); }
.callout.deep .callout-title { color: var(--deep); }
.callout.lab { background: var(--bg-elev); border-color: var(--border); border-left-color: var(--text-muted); }
.callout.lab .callout-title { color: var(--text); }

/* ---------- Figures / diagrams ---------- */
figure.diagram { margin: 8px 0 28px; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); }
figure.diagram svg { display: block; width: 100%; height: auto; }
figure.diagram figcaption { margin-top: 12px; font-size: 13.5px; color: var(--text-muted); text-align: center; }
.d-box { fill: var(--bg-sunk); stroke: var(--border-strong); }
.d-box-accent { fill: var(--accent-soft); stroke: var(--accent); }
.d-box-deep { fill: var(--deep-bg); stroke: var(--deep); }
.d-box-warn { fill: var(--warn-bg); stroke: var(--warn); }
.d-text { fill: var(--text); font: 600 13px var(--font-sans); }
.d-sub { fill: var(--text-muted); font: 400 11.5px var(--font-sans); }
.d-mono { fill: var(--text-muted); font: 400 11px var(--font-mono); }
.d-line { stroke: var(--text-faint); stroke-width: 1.5; fill: none; }
.d-line-accent { stroke: var(--accent); stroke-width: 1.8; fill: none; }
.d-head { fill: var(--text-faint); }
.d-head-accent { fill: var(--accent); }
.d-label { fill: var(--text-faint); font: 600 10.5px var(--font-mono); letter-spacing: .06em; }
/* Circuits and waveforms (Power Electronics track) */
.c-wire { stroke: var(--text); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: var(--text); }
.c-acc { stroke: var(--accent); stroke-width: 2.2; fill: none; stroke-linejoin: round; }
.c-acc-fill { fill: var(--accent); }
.c-warn { stroke: var(--warn); stroke-width: 2.2; fill: none; stroke-linejoin: round; }
.c-deep { stroke: var(--deep); stroke-width: 2.2; fill: none; stroke-linejoin: round; }
.c-shade { fill: var(--danger); opacity: .22; }
.c-grid { stroke: var(--border); stroke-width: 1; }
.c-axis { stroke: var(--text-faint); stroke-width: 1.2; fill: none; }
.c-dash { stroke: var(--text-faint); stroke-width: 1.2; stroke-dasharray: 4 4; fill: none; }

/* Numbered step list */
ol.steps { list-style: none; counter-reset: step; padding: 0; margin: 0 0 24px; }
ol.steps > li { counter-increment: step; position: relative; padding: 0 0 18px 48px; margin: 0; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 1px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); font: 700 13px/1 var(--font-mono);
}
ol.steps > li:not(:last-child)::after { content: ""; position: absolute; left: 14.5px; top: 36px; bottom: 4px; width: 1px; background: var(--border); }
ol.steps > li > strong:first-child { display: block; margin-bottom: 2px; }
ol.steps .where { display: block; font: 12px/1.5 var(--font-mono); color: var(--text-faint); margin-top: 4px; }

/* Key takeaways / exercises */
.takeaways { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); padding: 18px 22px; margin: 0 0 24px; }
.takeaways h3 { margin-top: 0; }
.takeaways ul { margin-bottom: 0; }
details.exercise { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); margin: 0 0 12px; }
details.exercise > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; list-style: none; display: flex; gap: 10px; }
details.exercise > summary::-webkit-details-marker { display: none; }
details.exercise > summary::before { content: "▸"; color: var(--accent); transition: transform .15s; }
details.exercise[open] > summary::before { transform: rotate(90deg); }
details.exercise .q { padding: 0 16px 4px 38px; }
details.exercise .answer { margin: 0 16px 14px 38px; padding: 12px 14px; border-radius: 8px; background: var(--bg-sunk); }
details.exercise .answer > :last-child { margin-bottom: 0; }
details.exercise .answer-label { font: 600 11px/1 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--accent-text); margin-bottom: 8px; display: block; }

/* Prev / next */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--border); }
.pager a { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); background: var(--bg-elev); }
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--text-faint); font-size: 12px; margin-bottom: 2px; }
.pager .next { text-align: right; grid-column: 2; }
.pager .disabled { visibility: hidden; }

/* ---------- Landing & overview pages ---------- */
.page-wide { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.hero { padding: clamp(56px, 10vw, 110px) 0 48px; }
.hero .eyebrow { margin-bottom: 18px; font-size: 12px; color: var(--accent-text); }
.card-foot[data-progress] { display: block; }
.hero h1 { font-size: clamp(38px, 7vw, 68px); line-height: 1.04; letter-spacing: -.035em; margin: 0 0 20px; font-weight: 800; max-width: 14ch; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { font-size: clamp(17px, 2vw, 20px); color: var(--text-muted); max-width: 60ch; margin: 0 0 28px; }
.btn { display: inline-flex; align-items: center; gap: 8px; height: 42px; padding: 0 18px; border-radius: 9px; font-weight: 600; font-size: 15px; text-decoration: none; border: 1px solid var(--border); color: var(--text); background: var(--bg-elev); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); font-weight: 600; margin: 0 0 16px; }
.track { border-top: 1px solid var(--border); padding: 40px 0; }
.track-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.track-head h2 { font-size: 28px; letter-spacing: -.02em; margin: 0; }
.track-head p { margin: 4px 0 0; color: var(--text-muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; padding: 22px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg-elev); text-decoration: none; color: var(--text); transition: border-color .15s, transform .15s;
}
a.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .tag { font: 600 11px/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent-text); margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 20px; letter-spacing: -.01em; line-height: 1.3; }
.card p { margin: 0 0 16px; color: var(--text-muted); font-size: 15px; line-height: 1.6; }
.card .card-foot { margin-top: auto; display: flex; gap: 14px; font-size: 13px; color: var(--text-faint); }
.card.muted { border-style: dashed; background: transparent; }
.progress { height: 6px; border-radius: 3px; background: var(--bg-sunk); overflow: hidden; margin: 0 0 12px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.chapter-list { list-style: none; padding: 0; margin: 0 0 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); }
.chapter-list li { border-bottom: 1px solid var(--border); margin: 0; }
.chapter-list li:last-child { border-bottom: 0; }
.chapter-list a, .chapter-list .item { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; padding: 14px 18px; text-decoration: none; color: var(--text); align-items: baseline; }
.chapter-list a:hover { background: var(--bg-sunk); }
.chapter-list .num { font: 500 13px/1 var(--font-mono); color: var(--text-faint); }
.chapter-list .t { font-weight: 600; }
.chapter-list .d { display: block; font-weight: 400; color: var(--text-muted); font-size: 14px; margin-top: 2px; line-height: 1.5; }
.chapter-list .status { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.chapter-list .status.ready { color: var(--accent-text); }
.chapter-list .part { padding: 10px 18px; background: var(--bg-sunk); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); font-weight: 600; }
.site-footer { border-top: 1px solid var(--border); padding: 28px 20px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------- Statistics track: chart kit (statviz.js) ---------- */
:root {
  --viz-surface: #fcfcfb; --viz-ink: #0b0b0b; --viz-ink-2: #52514e; --viz-muted: #898781;
  --viz-grid: #e1e0d9; --viz-axis: #c3c2b7;
  --viz-s1: #2a78d6; --viz-s2: #eb6834; --viz-s3: #1baf7a; --viz-s4: #eda100;
  --viz-band: rgba(42,120,214,.12); --viz-neutral: #f0efec; --viz-red: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --viz-surface: #1a1a19; --viz-ink: #f0efec; --viz-ink-2: #c3c2b7; --viz-muted: #898781;
    --viz-grid: #2c2c2a; --viz-axis: #383835;
    --viz-s1: #3987e5; --viz-s2: #d95926; --viz-s3: #199e70; --viz-s4: #c98500;
    --viz-band: rgba(57,135,229,.18); --viz-neutral: #383835; --viz-red: #e66767;
  }
}
:root[data-theme="dark"] {
  --viz-surface: #1a1a19; --viz-ink: #f0efec; --viz-ink-2: #c3c2b7; --viz-muted: #898781;
  --viz-grid: #2c2c2a; --viz-axis: #383835;
  --viz-s1: #3987e5; --viz-s2: #d95926; --viz-s3: #199e70; --viz-s4: #c98500;
  --viz-band: rgba(57,135,229,.18); --viz-neutral: #383835; --viz-red: #e66767;
}
figure.chart { margin: 8px 0 28px; padding: 16px 16px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--viz-surface); }
figure.chart > .chart-title { margin: 0 0 2px; font-weight: 650; font-size: 15px; color: var(--viz-ink); }
figure.chart > .chart-sub { margin: 0 0 10px; font-size: 13px; color: var(--viz-ink-2); }
figure.chart figcaption { margin-top: 8px; font-size: 12.5px; color: var(--text-muted); }
.viz { position: relative; }
.viz-plot { position: relative; width: 100%; }
.viz-svg { display: block; overflow: visible; font-family: var(--font-sans); }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.viz-axis { stroke: var(--viz-axis); stroke-width: 1; shape-rendering: crispEdges; }
.viz-tick { fill: var(--viz-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-label { fill: var(--viz-ink-2); font-size: 11.5px; font-weight: 500; }
.viz-value { fill: var(--viz-ink-2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.viz-annot { fill: var(--viz-ink-2); font-size: 11.5px; font-weight: 500; paint-order: stroke; stroke: var(--viz-surface); stroke-width: 3px; stroke-linejoin: round; }
.viz-inbar { fill: #fff; font-size: 11px; font-weight: 600; pointer-events: none; }
.viz-inbar.on-light { fill: #0b0b0b; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-line.thin { stroke-width: 1.25; }
.viz-area { opacity: .1; stroke: none; }
.viz-bar { stroke: none; }
.viz-bar:focus, .viz-box:focus { outline: none; filter: brightness(1.12); }
.viz-dot { stroke: var(--viz-surface); stroke-width: 2; }
.viz-dot.faint { opacity: .55; stroke-width: 1; }
.viz-hover-ring { fill: none; stroke: var(--viz-ink); stroke-width: 1.5; pointer-events: none; }
.viz-fill-s1 { fill: var(--viz-s1); } .viz-fill-s2 { fill: var(--viz-s2); } .viz-fill-s3 { fill: var(--viz-s3); } .viz-fill-s4 { fill: var(--viz-s4); }
.viz-stroke-s1 { stroke: var(--viz-s1); } .viz-stroke-s2 { stroke: var(--viz-s2); } .viz-stroke-s3 { stroke: var(--viz-s3); } .viz-stroke-s4 { stroke: var(--viz-s4); }
.viz-box { opacity: .85; }
.viz-whisker { stroke: var(--viz-ink-2); stroke-width: 1.25; }
.viz-median { stroke: var(--viz-surface); stroke-width: 2.5; }
.viz-mean-dot { fill: var(--viz-ink); stroke: var(--viz-surface); stroke-width: 2; }
.viz-outlier { fill: var(--viz-surface); stroke-width: 1.5; }
.viz-shade { opacity: .35; }
.viz-ref { stroke: var(--viz-ink-2); stroke-width: 1; opacity: .7; }
.viz-ref.strong { stroke-width: 2; opacity: 1; }
.viz-band { fill: var(--viz-neutral); opacity: .8; }
.viz-band-fill { fill: var(--viz-band); }
.viz-cross { stroke: var(--viz-axis); stroke-width: 1; visibility: hidden; pointer-events: none; }
.viz-hit { fill: transparent; cursor: crosshair; }
.viz-hit:focus { outline: none; }
.viz-tip {
  position: absolute; z-index: 5; pointer-events: none; opacity: 0; transition: opacity .1s;
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 12.5px; line-height: 1.45; max-width: 260px; font-variant-numeric: tabular-nums;
}
.viz-tip.on { opacity: 1; }
.viz-key, .viz-swatch { display: inline-block; vertical-align: middle; background: var(--sw); }
.viz-key { width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 8px; font-size: 12.5px; color: var(--viz-ink-2); }
.viz-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.viz-swatch.box { width: 11px; height: 11px; border-radius: 3px; }
.viz-swatch.line { width: 16px; height: 3px; border-radius: 2px; }
.viz-note { font-size: 13px; color: var(--text-muted); margin: 6px 0 0; }
details.viz-table { margin-top: 8px; font-size: 12.5px; }
details.viz-table > summary { cursor: pointer; color: var(--text-muted); width: max-content; }
.viz-table-wrap { max-height: 280px; overflow: auto; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; }
.viz-table-wrap table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.viz-table-wrap th, .viz-table-wrap td { padding: 5px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.viz-table-wrap th:first-child, .viz-table-wrap td:first-child { text-align: left; }
.viz-table-wrap th { position: sticky; top: 0; background: var(--bg-sunk); font-weight: 600; }

.heat td.cell { text-align: center; font-variant-numeric: tabular-nums; }
.heat td.cell small { display: block; color: var(--text-muted); font-size: 11.5px; }

/* Stat tiles */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 0 0 24px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); padding: 14px 16px; }
.stat .label { font-size: 12.5px; color: var(--text-muted); margin: 0 0 4px; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -.01em; line-height: 1.15; }
.stat .sub { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* Formula cards */
.formula { border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); background: var(--bg-elev); padding: 12px 16px; margin: 0 0 18px; }
.formula .f-name { font: 600 11px/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent-text); margin: 0 0 8px; }
.formula .f-body { font-size: 16px; line-height: 1.6; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.texd { display: block; overflow-x: auto; overflow-y: hidden; }
.texd .katex-display { margin: 4px 0; text-align: left; }
.texd .katex-display > .katex { text-align: left; }
.tex:not([data-tex-done]), .texd:not([data-tex-done]) { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }
.katex { font-size: 1.12em; }
@media (max-width: 600px) { .texd .katex { font-size: 0.98em; } .formula { padding: 12px 12px; } }
.formula .f-note { font-size: 13.5px; color: var(--text-muted); margin: 6px 0 0; white-space: normal; }
.formula-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 18px; }
.formula-grid .formula { margin: 0; }

/* Interactive widgets */
.widget { border: 1px solid var(--border); border-radius: var(--radius); background: var(--viz-surface); padding: 16px; margin: 8px 0 28px; }
.widget-title { font-weight: 650; margin: 0 0 4px; }
.widget-sub { font-size: 13px; color: var(--text-muted); margin: 0 0 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: end; margin: 0 0 12px; font-size: 13.5px; }
.controls label { display: flex; flex-direction: column; gap: 4px; color: var(--text-muted); }
.controls label b { color: var(--text); font-variant-numeric: tabular-nums; }
.controls input[type=range] { width: 180px; accent-color: var(--accent); }
.controls select, .controls input[type=number] { font: inherit; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); }
.btn-sm { font: 600 13px var(--font-sans); padding: 7px 12px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); cursor: pointer; }
.btn-sm.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn-sm:hover { border-color: var(--accent); }
.readout { font-size: 14px; background: var(--bg-sunk); border-radius: 8px; padding: 10px 12px; margin: 10px 0 0; font-variant-numeric: tabular-nums; }
.readout b { font-weight: 650; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.split > figure.chart { margin: 0; }
.in60 { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin: 0 0 28px; background: linear-gradient(135deg, var(--accent-soft), transparent 70%); }
.in60 h2 { margin: 0 0 8px !important; font-size: 15px !important; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-text); padding: 0 !important; }
.in60 ul { margin: 0; }
.data-badge { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--bg-sunk); border: 1px solid var(--border); color: var(--text-muted); }
@media (max-width: 760px) { .split { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Architecture track: wide pages and full-size diagrams ---------- */
:root {
  --a-snow: #1A8FC4; --a-snow-soft: #E3F3FB;
  --a-dbt: #D9532F;  --a-dbt-soft: #FCEAE4;
  --a-flow: #128473; --a-flow-soft: #E1F3EF;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --a-snow: #5CC3EE; --a-snow-soft: #12303F; --a-dbt: #F07A57; --a-dbt-soft: #3A2019; --a-flow: #4CC7B2; --a-flow-soft: #123330;
  }
}
:root[data-theme="dark"] {
  --a-snow: #5CC3EE; --a-snow-soft: #12303F; --a-dbt: #F07A57; --a-dbt-soft: #3A2019; --a-flow: #4CC7B2; --a-flow-soft: #123330;
}
body.wide .layout { grid-template-columns: 280px minmax(0, 1fr); }
body.wide .toc { display: none; }
body.wide .doc { max-width: 1180px; }
body.wide .doc > p, body.wide .doc > ul, body.wide .doc > ol, body.wide .doc > h1, body.wide .doc > .lede,
body.wide .doc > .callout, body.wide .doc > .in60, body.wide .doc > details { max-width: 860px; }

figure.arch { margin: 8px 0 30px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); }
figure.arch .arch-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
figure.arch .arch-bar .legend-item { display: inline-flex; align-items: center; gap: 6px; }
figure.arch .arch-bar .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
figure.arch .arch-bar .fs-btn { margin-left: auto; }
figure.arch .arch-scroll { overflow-x: auto; padding: 10px; }
figure.arch svg { display: block; width: 100%; min-width: 900px; height: auto; }
figure.arch figcaption { padding: 0 14px 12px; font-size: 13px; color: var(--text-muted); }
figure.arch:fullscreen { background: var(--bg); display: flex; flex-direction: column; border: 0; border-radius: 0; }
figure.arch:fullscreen .arch-scroll { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; }
figure.arch:fullscreen svg { max-height: calc(100vh - 110px); width: auto; max-width: 100%; min-width: 0; }
/* full-size design diagrams shown as images (Snowflake track): scroll sideways at normal size, fit in full screen */
figure.arch img.big { display: block; width: 100%; min-width: 1100px; height: auto; background: #FFFFFF; border-radius: 6px; }
figure.arch:fullscreen img.big { width: auto; min-width: 0; max-width: 100%; max-height: calc(100vh - 110px); }
figure.arch .arch-bar .dl { font-size: 13px; font-weight: 600; }
/* text sitting on a hard-coded light box (class added by site.js) */
svg text.d-on-light { fill: #1d2127; }
svg text.d-on-light.d-sub, svg text.d-on-light.d-label { fill: #4b5563; }
/* diagram zoom controls (added by site.js) */
.zoom-ctl { display: inline-flex; gap: 4px; }
.zoom-ctl .btn-sm { min-width: 34px; padding: 5px 9px; }
.zoom-ctl .zoom-pct { min-width: 58px; font-family: var(--font-mono); font-size: 12px; }
.zoom-ctl .btn-sm:disabled { opacity: .4; cursor: default; }
figure.arch .arch-bar .zoom-ctl { margin-left: auto; }
figure.arch .arch-bar .zoom-ctl + .fs-btn { margin-left: 0; }
figure.diagram .zoom-bar { display: flex; justify-content: flex-end; margin: -6px -6px 8px; }
.zoom-scroll { overflow: auto; }
.zoomable.zoomed { overflow: auto; cursor: grab; max-height: 80vh; }
figure.arch:fullscreen .zoomable.zoomed { max-height: none; display: block; }
.zoomable.panning { cursor: grabbing; user-select: none; }
/* real screenshots from SSMS, Snowsight and Airflow */
figure.shot { margin: 8px 0 28px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); overflow: hidden; }
figure.shot .shot-bar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--bg-sunk); font: 600 11.5px/1.4 var(--font-mono); color: var(--text-muted); }
figure.shot .shot-bar i { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); display: inline-block; }
figure.shot img { display: block; width: 100%; height: auto; }
figure.shot img.portrait, .doc figure.shot img.portrait { width: auto; max-width: min(100%, 600px); margin: 12px auto; }
figure.shot figcaption { padding: 10px 14px 12px; font-size: 13px; color: var(--text-muted); }
figure.shot .pending { padding: 48px 20px; text-align: center; color: var(--text-faint); font-size: 14px; background: repeating-linear-gradient(45deg, var(--bg-sunk), var(--bg-sunk) 10px, var(--bg-elev) 10px, var(--bg-elev) 20px); }

.arch svg text { font-family: var(--font-sans); fill: var(--text); }
.arch svg .t-title { font-weight: 700; font-size: 14px; }
.arch svg .t-big { font-weight: 800; font-size: 18px; }
.arch svg .t-sub { font-size: 11.5px; fill: var(--text-muted); }
.arch svg .t-mono { font-family: var(--font-mono); font-size: 11px; fill: var(--text-muted); }
.arch svg .t-band { font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; fill: var(--text-faint); }
.arch svg .box { fill: var(--bg-elev); stroke: var(--border-strong); stroke-width: 1.2; }
.arch svg .box-snow { fill: var(--a-snow-soft); stroke: var(--a-snow); stroke-width: 1.6; }
.arch svg .layer { fill: var(--bg-elev); stroke: var(--a-snow); stroke-width: 1.2; }
.arch svg .box-dbt { fill: var(--a-dbt-soft); stroke: var(--a-dbt); stroke-width: 1.6; }
.arch svg .box-flow { fill: var(--a-flow-soft); stroke: var(--a-flow); stroke-width: 1.6; }
.arch svg .wh { fill: var(--bg-elev); stroke: var(--a-snow); stroke-width: 1; }
.arch svg .edge { stroke: var(--text-muted); stroke-width: 1.6; fill: none; }
.arch svg .edge-flow { stroke: var(--a-flow); stroke-width: 1.6; fill: none; stroke-dasharray: 5 4; }
.arch svg .edge-dbt { stroke: var(--a-dbt); stroke-width: 1.6; fill: none; stroke-dasharray: 5 4; }
.arch svg .edge-snow { stroke: var(--a-snow); stroke-width: 1.6; fill: none; }
.arch svg .head { fill: var(--text-muted); }
.arch svg .head-flow { fill: var(--a-flow); }
.arch svg .head-dbt { fill: var(--a-dbt); }
.arch svg .head-snow { fill: var(--a-snow); }
.arch svg .step { fill: var(--text); }
.arch svg .step-t { fill: var(--bg); font-family: var(--font-mono); font-size: 11px; font-weight: 600; }
.arch svg .divider { stroke: var(--border-strong); stroke-dasharray: 3 4; }
.arch svg .c-snow { fill: var(--a-snow); }
.arch svg .c-flow { fill: var(--a-flow); }
.arch svg .c-dbt { fill: var(--a-dbt); }
.arch svg .zone { fill: none; stroke: var(--border-strong); stroke-width: 1.2; stroke-dasharray: 6 4; }

.badge { display: inline-block; font-family: var(--font-mono); font-size: 11px; padding: 1px 7px; border-radius: 4px; margin-right: 6px; vertical-align: 1px; }
.badge.snow { background: var(--a-snow-soft); color: var(--a-snow); }
.badge.dbt { background: var(--a-dbt-soft); color: var(--a-dbt); }
.badge.flow { background: var(--a-flow-soft); color: var(--a-flow); }
.badge.ext { background: var(--bg-sunk); color: var(--text-muted); }
.flowline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; margin: 0 0 24px; }
.flowline .s { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; padding: 7px 11px; }
.flowline .a { color: var(--text-faint); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; margin: 0 0 20px; }
.cols > div { min-width: 0; }
.cols h3 { margin-top: 0 !important; }
@media (max-width: 900px) { body.wide .layout { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: grid; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; height: auto; width: min(320px, 86vw); z-index: 40;
    background: var(--bg); transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.35); z-index: 30; }
  .compare { grid-template-columns: minmax(0, 1fr); }
  .brand-name small { display: none; }
}
@media (max-width: 600px) {
  .topbar { gap: 8px; padding: 0 12px; }
  .search { width: auto; flex: 1; }
  .brand-name { display: none; }
  main.content { padding: 24px 16px 64px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .doc :not(pre) > code { white-space: normal; word-break: break-word; }
}

@media print {
  .topbar, .sidebar, .toc, .pager, .copy-btn { display: none !important; }
  .layout { display: block; }
  body { background: #fff; color: #000; }
  details.exercise { break-inside: avoid; }
}

/* ---------- Data Warehousing track: lab infrastructure strip ---------- */
.lab-strip { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin: 0 0 22px; padding: 10px 14px; border: 1px solid var(--border); border-left: 4px solid var(--a-snow); border-radius: var(--radius); background: var(--bg-elev); font-size: 13.5px; color: var(--text-muted); max-width: 860px; }
.lab-strip strong { color: var(--text); }
.lab-strip .chip { font: 600 11.5px/1.7 var(--font-mono); padding: 0 8px; border-radius: 999px; background: var(--a-snow-soft); color: var(--a-snow); white-space: nowrap; }
.lab-strip .plus { color: var(--text-faint); }
.lab-strip .note { flex-basis: 100%; margin-top: 2px; }
/* Screenshots inside articles (BI track) */
.doc figure.shot { margin: 22px 0; }
.doc figure.shot img { display: block; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.doc figure.shot figcaption { margin-top: 8px; font-size: 13px; color: var(--text-muted); }
