/* ============================================================================
   aman.study — shared design system for HTML study modules
   ----------------------------------------------------------------------------
   Two contexts:
     1. Standalone: the module file is opened directly. <html class="study-standalone">
        gets the full token set below (same names and values as the site's globals.css).
     2. Embedded: the site injects <main class="study"> into its reading layout and the
        site's own :root/.dark tokens apply. Tokens here are scoped to
        html.study-standalone so nothing collides.
   Every component rule is scoped under .study. Class names and markup are a contract
   with the writer agents (.claude/study/references/components.md) — restyle values only.
   ========================================================================== */

/* ---------- 1. Tokens (standalone only; keep identical to app/globals.css) ---- */
html.study-standalone {
  color-scheme: light;
  --bg-primary: #f8f6f1; --bg-surface: #fdfcf9; --bg-surface-hover: #f1eee7;
  --bg-elevated: #fffefb; --bg-code: #f2f0ea; --bg-sidebar: #f8f6f1;
  --text-primary: #1f1d1a; --text-secondary: #5c5850; --text-tertiary: #8d887d; --text-inverse: #f8f6f1;
  --accent-blue: #2f5fa3; --accent-blue-hover: #234b85; --accent-blue-subtle: #e9eff8;
  --accent-cyan: #0e7183; --accent-cyan-subtle: #e6f3f5;
  --accent-orange: #b9511a; --accent-orange-subtle: #fbeee4;
  --accent-green: #2e7a45; --accent-green-subtle: #e9f4ec;
  --accent-amber: #a5640c; --accent-amber-subtle: #faf0dc;
  --accent-red: #b03a3a; --accent-red-subtle: #f9e9e9;
  --border-primary: #e4e0d6; --border-secondary: #cfc9bc; --border-subtle: #ece8df;
  --shadow-sm: 0 1px 2px rgb(40 30 10 / .05);
  --shadow-md: 0 4px 14px -4px rgb(40 30 10 / .12);
  --shadow-lg: 0 16px 40px -12px rgb(40 30 10 / .18);
  --diagram-bg: #f8f6f1; --diagram-block-primary: #3d6fb5; --diagram-block-secondary: #1a8a9c;
  --diagram-block-accent: #d9622a; --diagram-block-muted: #dcd7cc; --diagram-arrow: #0e7183;
  --diagram-arrow-active: #d9622a; --diagram-text: #1f1d1a; --diagram-text-light: #5c5850;
  --diagram-highlight: #c98a12; --diagram-tooltip-bg: #fffefb; --diagram-tooltip-border: #e4e0d6; --diagram-grid: #ebe7de;
  --callout-info-bg: #e9eff8; --callout-info-border: #2f5fa3; --callout-info-text: #2f5fa3;
  --callout-warning-bg: #faf0dc; --callout-warning-border: #a5640c; --callout-warning-text: #a5640c;
  --callout-tip-bg: #e9f4ec; --callout-tip-border: #2e7a45; --callout-tip-text: #2e7a45;
  --callout-critical-bg: #f9e9e9; --callout-critical-border: #b03a3a; --callout-critical-text: #b03a3a;
  --progress-bg: #e4e0d6; --progress-fill: #2f5fa3; --progress-complete: #2e7a45;
  --measure: 40rem; --wide: 56rem; --gutter: 2rem; --rail: 15rem; --topbar: 3rem;
  --body-size: 1.125rem; --body-lh: 1.6;
  --font-body: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-heading: "Source Serif 4", Georgia, serif;
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Code", monospace;
}
html.study-standalone.dark,
html.study-standalone.dark-auto {
  color-scheme: dark;
  --bg-primary: #131211; --bg-surface: #1a1918; --bg-surface-hover: #222120;
  --bg-elevated: #1e1d1b; --bg-code: #171615; --bg-sidebar: #131211;
  --text-primary: #ddd8cf; --text-secondary: #a39e94; --text-tertiary: #716c63; --text-inverse: #131211;
  --accent-blue: #8cb0e0; --accent-blue-hover: #aac5ea; --accent-blue-subtle: rgba(140,176,224,.12);
  --accent-cyan: #5cc4d3; --accent-cyan-subtle: rgba(92,196,211,.12);
  --accent-orange: #eb9a66; --accent-orange-subtle: rgba(235,154,102,.12);
  --accent-green: #86c692; --accent-green-subtle: rgba(134,198,146,.12);
  --accent-amber: #dfb264; --accent-amber-subtle: rgba(223,178,100,.12);
  --accent-red: #e78f8f; --accent-red-subtle: rgba(231,143,143,.12);
  --border-primary: #262421; --border-secondary: #37342f; --border-subtle: #1f1e1b;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-md: 0 6px 18px -6px rgb(0 0 0 / .55);
  --shadow-lg: 0 18px 48px -12px rgb(0 0 0 / .7);
  --diagram-bg: #131211; --diagram-block-primary: #2f5a94; --diagram-block-secondary: #15707f;
  --diagram-block-accent: #b9552a; --diagram-block-muted: #2b2926; --diagram-arrow: #5cc4d3;
  --diagram-arrow-active: #eb9a66; --diagram-text: #ddd8cf; --diagram-text-light: #a39e94;
  --diagram-highlight: #dfb264; --diagram-tooltip-bg: #1e1d1b; --diagram-tooltip-border: #262421; --diagram-grid: #1d1c1a;
  --callout-info-bg: rgba(140,176,224,.08); --callout-info-border: #8cb0e0; --callout-info-text: #aac5ea;
  --callout-warning-bg: rgba(223,178,100,.08); --callout-warning-border: #dfb264; --callout-warning-text: #e8c98e;
  --callout-tip-bg: rgba(134,198,146,.08); --callout-tip-border: #86c692; --callout-tip-text: #a6d6ae;
  --callout-critical-bg: rgba(231,143,143,.08); --callout-critical-border: #e78f8f; --callout-critical-text: #f0aaaa;
  --progress-bg: #262421; --progress-fill: #8cb0e0; --progress-complete: #86c692;
}

/* ---------- 2. Standalone page chrome ------------------------------------ */
html.study-standalone { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
html.study-standalone body {
  margin: 0; background: var(--bg-primary); color: var(--text-primary);
  font-family: var(--font-body); font-size: var(--body-size); line-height: var(--body-lh);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-kerning: normal;
}
html.study-standalone .study-shell { display: grid; grid-template-columns: minmax(0, 1fr); }
html.study-standalone .study-shell > main.study { container-type: inline-size; padding: 3rem var(--gutter) 6rem; min-width: 0; max-width: none; }
html.study-standalone .study-shell > main.study > * { max-width: var(--measure); margin-left: auto; margin-right: auto; }
@media (min-width: 80rem) {
  html.study-standalone .study-shell { grid-template-columns: minmax(0, 1fr) var(--rail); }
}
html.study-standalone .study-toc {
  position: sticky; top: 0; align-self: start; max-height: 100vh; overflow-y: auto;
  padding: 3rem 1.25rem 2rem 0; font-family: var(--font-ui); font-size: .78rem; line-height: 1.4; display: none;
  font-variant-numeric: lining-nums tabular-nums;
}
@media (min-width: 80rem) { html.study-standalone .study-toc { display: block; } }
.study-toc .toc-title { font-size: .6875rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-tertiary); margin: 0 0 .75rem; }
.study-toc ol { list-style: none; margin: 0; padding: 0; }
.study-toc li a { display: block; padding: .3rem 0 .3rem .85rem; color: var(--text-tertiary); text-decoration: none; border-left: 1.5px solid var(--border-primary); }
.study-toc li.l3 a { padding-left: 1.6rem; font-size: .72rem; }
.study-toc li a:hover { color: var(--text-primary); }
.study-toc li.is-past > a { color: var(--text-secondary); }
.study-toc li.is-active > a { color: var(--text-primary); border-left-color: var(--text-primary); }
.study-progress { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--accent-blue); z-index: 60; transition: width .1s linear; }
.study-theme-toggle {
  position: fixed; top: .75rem; right: .75rem; z-index: 50; width: 2.25rem; height: 2.25rem; border-radius: 999px;
  border: 1px solid var(--border-primary); background: var(--bg-surface); color: var(--text-secondary); cursor: pointer;
  display: grid; place-items: center; box-shadow: var(--shadow-sm); font-size: 1rem;
}
.study-theme-toggle:hover { color: var(--text-primary); background: var(--bg-surface-hover); }

/* ---------- 3. Typography -------------------------------------------------- */
.study { font-family: var(--font-body); font-size: var(--body-size); line-height: var(--body-lh); color: var(--text-primary); counter-reset: none; font-variant-numeric: oldstyle-nums proportional-nums; }
.study h1, .study h2, .study h3, .study h4 { font-family: var(--font-heading); color: var(--text-primary); scroll-margin-top: 4.5rem; font-variant-numeric: lining-nums; text-wrap: balance; }
.study h1 { font-size: 2.375rem; font-weight: 650; letter-spacing: -.022em; line-height: 1.12; margin: 0 0 1rem; }
.study h2 { font-size: 1.5rem; font-weight: 650; letter-spacing: -.014em; line-height: 1.25; margin: 3.25rem 0 1rem; padding: 0; border: 0; }
.study h3 { font-size: 1.1875rem; font-weight: 600; letter-spacing: -.008em; line-height: 1.3; margin: 2.25rem 0 .625rem; }
.study h4 { font-size: 1rem; font-weight: 600; letter-spacing: 0; line-height: 1.4; margin: 1.5rem 0 .5rem; }
@media (max-width: 40rem) { .study h1 { font-size: 1.875rem; } .study h2 { font-size: 1.375rem; margin-top: 2.5rem; } }
.study p { margin: 0 0 1.15em; text-wrap: pretty; hanging-punctuation: first; }
.study strong, .study b { font-weight: 650; }
.study a:not(.cite) { color: var(--accent-blue); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .18em; text-decoration-color: color-mix(in srgb, var(--accent-blue) 35%, transparent); transition: text-decoration-color .15s ease; }
.study a:not(.cite):hover { text-decoration-color: currentColor; }
.study ul, .study ol { margin: 0 0 1.15em; padding-left: 1.35em; }
.study ul { list-style: disc; } .study ol { list-style: decimal; }
.study li { margin-bottom: .3em; }
.study li::marker { color: var(--text-tertiary); }
.study li > ul, .study li > ol { margin-top: .3em; margin-bottom: .3em; }
.study blockquote { border-left: 2px solid var(--border-secondary); padding: .1rem 0 .1rem 1.25rem; color: var(--text-secondary); font-style: italic; margin: 1.5rem 0; }
.study hr { border: 0; height: 1px; background: var(--border-primary); margin: 3rem auto; width: 6rem; }
.study code, .study kbd, .study pre, .study samp { font-family: var(--font-code); font-variant-numeric: lining-nums tabular-nums; }
.study :not(pre) > code { font-size: .86em; padding: .1em .35em; border-radius: 4px; background: var(--bg-code); color: var(--text-primary); border: 1px solid var(--border-subtle); font-weight: 450; }
.study kbd { font-size: .7em; font-weight: 500; padding: .1em .4em; border-radius: 4px; background: var(--bg-surface); border: 1px solid var(--border-primary); border-bottom-width: 2px; color: var(--text-secondary); line-height: 1; white-space: nowrap; }
.study .lede { font-size: 1.16em; line-height: 1.5; color: var(--text-secondary); margin: 0 0 1.25rem; }
.study .muted { color: var(--text-tertiary); }
.study .small { font-size: .875em; }
.study .grid-2, .study .grid-3 { display: grid; gap: 1rem; margin: 1.25rem 0; }
.study .grid-2 { grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.study .grid-3 { grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.study ::selection { background: color-mix(in srgb, var(--accent-blue) 28%, transparent); }
.study *:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; border-radius: 4px; }
.study .katex-display { overflow-x: auto; overflow-y: hidden; padding: .25rem 0; margin: 1rem 0 1.5rem; }
.study .katex { font-size: 1.04em; }

/* ---------- 4. Module header --------------------------------------------- */
.study .study-header { margin: 0 0 2.5rem; padding: 0 0 2rem; border-bottom: 1px solid var(--border-primary); }
.study .kicker { font-family: var(--font-ui); font-size: .75rem; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--text-tertiary); margin: 0 0 1rem; font-variant-numeric: lining-nums; }
.study .meta { display: flex; flex-wrap: wrap; gap: .25rem .5rem; margin-top: 1.25rem; font-family: var(--font-ui); font-size: .8125rem; color: var(--text-tertiary); font-variant-numeric: lining-nums tabular-nums; }
.study .chip { display: inline-flex; align-items: center; gap: .3rem; font-size: inherit; font-weight: 400; padding: 0; border: 0; border-radius: 0; background: none; color: var(--text-tertiary); }
.study .chip + .chip::before { content: "·"; margin-right: .5rem; opacity: .6; }
.study .chip b { font-weight: 500; color: var(--text-secondary); }
.study .chip.chip-blue, .study .chip.chip-amber, .study .chip.chip-green { background: none; border: 0; color: var(--text-secondary); font-weight: 500; }

/* ---------- 5. Callouts (margin notes: a rule and a label, no box) --------- */
.study .callout { position: relative; margin: 1.75rem 0; padding: .75rem 1.15rem; border: 0; border-left: 2px solid var(--border-secondary); border-radius: 0; background: transparent; }
.study .callout > :last-child { margin-bottom: 0; }
.study .callout p { font-size: .96em; }
.study .callout .callout-title { display: block; font-family: var(--font-ui); font-size: .6875rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; margin-bottom: .35rem; }
.study .callout-insight { border-left-color: var(--accent-cyan); background: color-mix(in srgb, var(--accent-cyan) 6%, transparent); border-radius: 0 6px 6px 0; }
.study .callout-insight .callout-title { color: var(--accent-cyan); }
.study .callout-note { border-left-color: var(--callout-info-border); }
.study .callout-note .callout-title { color: var(--callout-info-text); }
.study .callout-tip { border-left-color: var(--callout-tip-border); }
.study .callout-tip .callout-title { color: var(--callout-tip-text); }
.study .callout-warning { border-left-color: var(--callout-warning-border); }
.study .callout-warning .callout-title { color: var(--callout-warning-text); }
.study .callout-critical { border-left-color: var(--callout-critical-border); background: color-mix(in srgb, var(--accent-red) 5%, transparent); border-radius: 0 6px 6px 0; }
.study .callout-critical .callout-title { color: var(--callout-critical-text); }

/* ---------- 6. Figures & SVG diagrams ------------------------------------ */
.study figure.fig { margin: 2.25rem 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.study figure.fig > svg { display: block; width: 100%; height: auto; max-height: 82vh; cursor: zoom-in; }
.study figure.fig.fig-plain { border: 0; background: transparent; box-shadow: none; padding: 0; }
.study figure.fig figcaption { max-width: var(--measure); margin: .875rem auto 0; font-family: var(--font-ui); font-size: .8125rem; line-height: 1.55; color: var(--text-secondary); font-variant-numeric: lining-nums tabular-nums; }
.study figure.fig figcaption b { color: var(--text-primary); font-weight: 600; }
.study figure.fig figcaption .cite { font-size: .7em; }
.study .fig-zoom { position: fixed; inset: 0; z-index: 100; background: color-mix(in srgb, var(--bg-primary) 92%, transparent); display: grid; place-items: center; padding: 2rem; cursor: zoom-out; backdrop-filter: blur(4px); }
.study .fig-zoom svg { width: min(96vw, 1600px); height: auto; max-height: 92vh; background: var(--bg-surface); border-radius: 12px; padding: 1.5rem; box-shadow: var(--shadow-lg); }
/* SVG palette — diagrams use these classes instead of hard-coded colours so both themes work */
.study svg { font-family: var(--font-ui); font-size: 13px; font-variant-numeric: lining-nums tabular-nums; }
.study svg text { fill: var(--diagram-text); }
.study svg .d-text { fill: var(--diagram-text); } .study svg .d-text-light { fill: var(--diagram-text-light); }
.study svg .d-text-inv { fill: #fff; }
.study svg .d-mono { font-family: var(--font-code); font-size: 12px; }
.study svg .d-small { font-size: 11px; } .study svg .d-bold { font-weight: 600; } .study svg .d-title { font-size: 14px; font-weight: 650; }
.study svg .d-block { fill: var(--diagram-block-primary); stroke: none; }
.study svg .d-block-2 { fill: var(--diagram-block-secondary); }
.study svg .d-block-accent { fill: var(--diagram-block-accent); }
.study svg .d-block-muted { fill: var(--diagram-block-muted); }
.study svg .d-surface { fill: var(--bg-surface); stroke: var(--border-primary); }
.study svg .d-panel { fill: var(--bg-code); stroke: var(--border-primary); }
.study svg .d-outline { fill: none; stroke: var(--border-secondary); stroke-width: 1.25; }
.study svg .d-dashed { stroke-dasharray: 4 3; }
.study svg .d-arrow { stroke: var(--diagram-arrow); stroke-width: 1.75; fill: none; }
.study svg .d-arrow-active { stroke: var(--diagram-arrow-active); stroke-width: 2.25; fill: none; }
.study svg .d-grid { stroke: var(--diagram-grid); stroke-width: 1; }
.study svg .d-axis { stroke: var(--border-secondary); stroke-width: 1.25; }
.study svg .d-hl { fill: var(--diagram-highlight); }
.study svg .d-fill-blue { fill: var(--accent-blue); } .study svg .d-fill-cyan { fill: var(--accent-cyan); }
.study svg .d-fill-orange { fill: var(--accent-orange); } .study svg .d-fill-green { fill: var(--accent-green); }
.study svg .d-fill-amber { fill: var(--accent-amber); } .study svg .d-fill-red { fill: var(--accent-red); }
.study svg .d-fill-blue-soft { fill: var(--accent-blue-subtle); } .study svg .d-fill-cyan-soft { fill: var(--accent-cyan-subtle); }
.study svg .d-fill-orange-soft { fill: var(--accent-orange-subtle); } .study svg .d-fill-green-soft { fill: var(--accent-green-subtle); }
.study svg .d-fill-amber-soft { fill: var(--accent-amber-subtle); } .study svg .d-fill-red-soft { fill: var(--accent-red-subtle); }
.study svg .d-stroke-blue { stroke: var(--accent-blue); } .study svg .d-stroke-cyan { stroke: var(--accent-cyan); }
.study svg .d-stroke-orange { stroke: var(--accent-orange); } .study svg .d-stroke-green { stroke: var(--accent-green); }
.study svg .d-stroke-amber { stroke: var(--accent-amber); } .study svg .d-stroke-red { stroke: var(--accent-red); }
.study svg .d-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.study svg .d-marker { fill: var(--diagram-arrow); } .study svg .d-marker-active { fill: var(--diagram-arrow-active); }
.study svg .d-dim { opacity: .35; }
.study svg .d-label-bg { fill: var(--bg-surface); stroke: var(--border-primary); }

/* ---------- 7. Code blocks ----------------------------------------------- */
.study pre.code { margin: 1.5rem 0; padding: .9rem 1.1rem; border: 1px solid var(--border-primary); border-radius: 8px; background: var(--bg-code); overflow-x: auto; font-size: .8125rem; line-height: 1.6; tab-size: 4; }
.study pre.code code { background: none; border: 0; padding: 0; color: var(--text-primary); font-size: inherit; font-weight: 400; }
.study .code-block { margin: 1.5rem 0; border: 1px solid var(--border-primary); border-radius: 8px; background: var(--bg-code); overflow: hidden; }
.study .code-block pre.code { margin: 0; border: 0; border-radius: 0; width: auto; }
.study .code-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .3rem .5rem .3rem .9rem; border-bottom: 1px solid var(--border-subtle); background: transparent; font-family: var(--font-ui); }
.study .code-head .code-title { font-size: .75rem; color: var(--text-secondary); font-family: var(--font-code); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.study .code-head .lang { font-size: .625rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; padding: 0; border-radius: 0; background: none; color: var(--text-tertiary); }
.study .code-head .copy { font: inherit; font-size: .6875rem; padding: .2rem .5rem; border-radius: 5px; border: 1px solid transparent; background: none; color: var(--text-tertiary); cursor: pointer; }
.study .code-head .copy:hover { color: var(--text-primary); border-color: var(--border-primary); }
.study .code-head .copy.is-done { color: var(--accent-green); border-color: var(--accent-green); }
.study pre.code .hl { display: block; background: var(--accent-amber-subtle); margin: 0 -1.1rem; padding: 0 1.1rem; border-left: 2px solid var(--accent-amber); }
/* highlight.js theme mapped to tokens */
.study .hljs-comment, .study .hljs-quote { color: var(--text-tertiary); font-style: italic; }
.study .hljs-keyword, .study .hljs-selector-tag, .study .hljs-literal, .study .hljs-meta .hljs-keyword { color: var(--accent-blue); font-weight: 500; }
.study .hljs-string, .study .hljs-regexp, .study .hljs-addition { color: var(--accent-green); }
.study .hljs-number, .study .hljs-symbol, .study .hljs-bullet { color: var(--accent-orange); }
.study .hljs-title, .study .hljs-title.function_, .study .hljs-title.class_, .study .hljs-section { color: var(--accent-cyan); font-weight: 500; }
.study .hljs-type, .study .hljs-built_in, .study .hljs-class .hljs-title { color: var(--accent-amber); }
.study .hljs-attr, .study .hljs-attribute, .study .hljs-variable, .study .hljs-template-variable, .study .hljs-property { color: var(--text-primary); }
.study .hljs-meta, .study .hljs-doctag { color: var(--accent-red); }
.study .hljs-deletion { color: var(--accent-red); }
.study .hljs-emphasis { font-style: italic; } .study .hljs-strong { font-weight: 600; }

/* ---------- 8. Tables (book style: rules above and below, hairlines between) ---- */
.study .tbl-wrap { overflow-x: auto; margin: 1.75rem 0; border: 0; border-radius: 0; background: transparent; }
.study table.tbl { width: 100%; border-collapse: collapse; margin: 0; font-family: var(--font-ui); font-size: .875rem; line-height: 1.45; border-top: 1.5px solid var(--text-primary); border-bottom: 1.5px solid var(--text-primary); font-variant-numeric: lining-nums tabular-nums; }
.study table.tbl caption { caption-side: top; text-align: left; padding: 0 0 .6rem; font-size: .8125rem; color: var(--text-secondary); line-height: 1.5; }
.study table.tbl caption b { color: var(--text-primary); }
.study table.tbl th { position: static; text-align: left; padding: .55rem .75rem; font-weight: 600; font-size: .75rem; color: var(--text-secondary); text-transform: none; letter-spacing: 0; background: transparent; border-bottom: 1px solid var(--border-secondary); white-space: nowrap; vertical-align: bottom; }
.study table.tbl td { padding: .5rem .75rem; border-bottom: 1px solid var(--border-subtle); vertical-align: top; }
.study table.tbl tr:last-child td { border-bottom: 0; }
.study table.tbl tbody tr:hover td { background: color-mix(in srgb, var(--bg-surface-hover) 70%, transparent); }
.study table.tbl th:first-child, .study table.tbl td:first-child { padding-left: .25rem; }
.study table.tbl th:last-child, .study table.tbl td:last-child { padding-right: .25rem; }
.study table.tbl td.num, .study table.tbl th.num { text-align: right; font-family: var(--font-code); font-size: .8125rem; white-space: nowrap; }
.study table.tbl td[data-best] { color: var(--accent-green); font-weight: 600; }
.study table.tbl td[data-worst] { color: var(--accent-red); }
.study table.tbl th.row, .study table.tbl td.row { font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.study table.tbl.tbl-compare td:first-child { font-weight: 600; white-space: nowrap; }
.study table.tbl.tbl-dense td, .study table.tbl.tbl-dense th { padding: .375rem .55rem; font-size: .8125rem; }
.study table.tbl .cite { font-size: .7em; }

/* ---------- 9. Spec grid & KPIs ----------------------------------------- */
.study dl.spec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .75rem; margin: 1.5rem 0; font-family: var(--font-ui); font-size: .875rem; font-variant-numeric: lining-nums tabular-nums; }
.study dl.spec-grid .spec { margin: 0; padding: .75rem .875rem; border: 1px solid var(--border-primary); border-radius: 6px; background: var(--bg-surface); }
.study dl.spec-grid dt { font-size: .6875rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-tertiary); margin: 0 0 .25rem; }
.study dl.spec-grid dd { margin: 0; font-weight: 600; color: var(--text-primary); }
.study dl.spec-grid dd small { display: block; font-weight: 400; color: var(--text-secondary); font-size: .8125rem; margin-top: .125rem; }
.study .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; margin: 1.5rem 0; font-variant-numeric: lining-nums tabular-nums; }
.study .kpi { padding: .75rem 0 .5rem; border: 0; border-top: 1.5px solid var(--border-secondary); border-radius: 0; background: transparent; }
.study .kpi b { display: block; font-family: var(--font-heading); font-size: 1.5rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; }
.study .kpi span { display: block; margin-top: .25rem; font-family: var(--font-ui); font-size: .78rem; color: var(--text-secondary); }
.study .kpi.kpi-cyan { border-top-color: var(--accent-cyan); } .study .kpi.kpi-orange { border-top-color: var(--accent-orange); }
.study .kpi.kpi-green { border-top-color: var(--accent-green); } .study .kpi.kpi-amber { border-top-color: var(--accent-amber); } .study .kpi.kpi-red { border-top-color: var(--accent-red); }

/* ---------- 10. Tabs ----------------------------------------------------- */
.study .tabs { margin: 1.5rem 0; border: 1px solid var(--border-primary); border-radius: 8px; background: var(--bg-surface); overflow: hidden; }
.study .tabs-nav { display: flex; flex-wrap: wrap; gap: .25rem; padding: .5rem .5rem 0; border-bottom: 1px solid var(--border-primary); background: color-mix(in srgb, var(--bg-code) 60%, transparent); font-family: var(--font-ui); }
.study .tabs-nav button { font: inherit; font-size: .8125rem; font-weight: 500; padding: .5rem .875rem; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-secondary); cursor: pointer; margin-bottom: -1px; }
.study .tabs-nav button:hover { color: var(--text-primary); }
.study .tabs-nav button.is-active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }
.study .tabs-panel { display: none; padding: 1rem 1.25rem; }
.study .tabs-panel.is-active { display: block; }
.study .tabs-panel > :last-child { margin-bottom: 0; }

/* ---------- 11. Stepper (step-through diagrams) -------------------------- */
.study .stepper { margin: 2rem 0; border: 1px solid var(--border-primary); border-radius: 8px; background: var(--bg-surface); padding: 1rem; }
.study .stepper figure.fig { margin: 0 0 .75rem; padding: .5rem; border: 0; box-shadow: none; background: transparent; }
.study .stepper svg [data-step] { transition: opacity .25s ease; }
.study .stepper svg [data-step].is-future { opacity: .12; }
.study .stepper svg [data-step].is-past { opacity: .55; }
.study .stepper svg [data-step].is-current { opacity: 1; }
.study .stepper-controls { display: flex; align-items: center; gap: .5rem; margin: .5rem 0 .75rem; font-family: var(--font-ui); }
.study .stepper-controls button { font: inherit; font-size: .8125rem; padding: .375rem .75rem; border-radius: 6px; border: 1px solid var(--border-primary); background: var(--bg-surface); color: var(--text-primary); cursor: pointer; }
.study .stepper-controls button:hover:not(:disabled) { background: var(--bg-surface-hover); }
.study .stepper-controls button:disabled { opacity: .4; cursor: default; }
.study .stepper-controls .stepper-pos { font-size: .75rem; color: var(--text-tertiary); margin-left: auto; font-variant-numeric: lining-nums tabular-nums; }
.study ol.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.study ol.steps li { counter-increment: step; position: relative; padding: .5rem .75rem .5rem 2.5rem; border-radius: 6px; color: var(--text-secondary); cursor: pointer; font-size: .95em; }
.study ol.steps li::before { content: counter(step); position: absolute; left: .75rem; top: .6rem; width: 1.25rem; height: 1.25rem; border-radius: 999px; display: grid; place-items: center; font-family: var(--font-ui); font-size: .6875rem; font-weight: 700; background: var(--bg-code); border: 1px solid var(--border-primary); color: var(--text-tertiary); font-variant-numeric: lining-nums; }
.study ol.steps li.is-current { background: var(--accent-blue-subtle); color: var(--text-primary); }
.study ol.steps li.is-current::before { background: var(--accent-blue); border-color: var(--accent-blue); color: #fff; }
.study ol.steps li.is-past { color: var(--text-tertiary); }

/* ---------- 12. Calculators ---------------------------------------------- */
.study .calc { margin: 1.5rem 0; padding: 1rem 1.25rem; border: 1px solid var(--border-primary); border-left: 3px solid var(--accent-cyan); border-radius: 8px; background: var(--bg-surface); font-family: var(--font-ui); font-variant-numeric: lining-nums tabular-nums; }
.study .calc .calc-title { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-cyan); margin: 0 0 .75rem; }
.study .calc .calc-row { display: grid; grid-template-columns: minmax(8rem, 14rem) 1fr auto; gap: .75rem; align-items: center; margin: .375rem 0; font-size: .875rem; }
.study .calc .calc-row label { color: var(--text-secondary); }
.study .calc .calc-row input[type=range] { width: 100%; accent-color: var(--accent-cyan); }
.study .calc .calc-row select, .study .calc .calc-row input[type=number] { font: inherit; font-size: .875rem; padding: .25rem .5rem; border-radius: 6px; border: 1px solid var(--border-primary); background: var(--bg-code); color: var(--text-primary); }
.study .calc .calc-row .calc-val { min-width: 5.5rem; text-align: right; font-family: var(--font-code); font-size: .8125rem; }
.study .calc .calc-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; margin-top: .875rem; padding-top: .875rem; border-top: 1px dashed var(--border-primary); }
.study .calc .calc-out div { font-size: .75rem; color: var(--text-tertiary); }
.study .calc .calc-out output { display: block; font-family: var(--font-heading); font-size: 1.25rem; font-weight: 600; color: var(--text-primary); }
.study .calc .calc-note { font-family: var(--font-body); font-size: .875rem; color: var(--text-secondary); margin: .75rem 0 0; }

/* ---------- 13. Timeline ------------------------------------------------- */
.study ol.timeline { list-style: none; margin: 1.5rem 0; padding: 0 0 0 1.25rem; border-left: 2px solid var(--border-primary); }
.study ol.timeline li { position: relative; padding: 0 0 1.25rem 1rem; }
.study ol.timeline li::before { content: ""; position: absolute; left: calc(-1.25rem - 6px); top: .45rem; width: 10px; height: 10px; border-radius: 999px; background: var(--accent-blue); border: 2px solid var(--bg-primary); }
.study ol.timeline li:last-child { padding-bottom: 0; }
.study ol.timeline time { display: block; font-family: var(--font-ui); font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: .125rem; font-variant-numeric: lining-nums tabular-nums; }
.study ol.timeline li > b { display: block; margin-bottom: .125rem; }
.study ol.timeline li > p { margin-bottom: 0; font-size: .95em; color: var(--text-secondary); }

/* ---------- 14. Where experts disagree ----------------------------------- */
.study section.disagree .positions { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin: 1.25rem 0; }
.study .position { padding: 1rem 1.125rem; border: 1px solid var(--border-primary); border-radius: 8px; background: var(--bg-surface); display: flex; flex-direction: column; font-size: .93em; }
.study .position > h4 { margin: 0 0 .5rem; font-size: 1rem; }
.study .position .who { font-family: var(--font-ui); font-size: .75rem; color: var(--text-tertiary); margin: -.25rem 0 .625rem; }
.study .position p { margin-bottom: .75rem; }
.study .position .pros, .study .position .cons { list-style: none; padding: 0; margin: 0 0 .5rem; font-size: .92em; }
.study .position .pros li::before { content: "+"; color: var(--accent-green); font-weight: 700; margin-right: .5rem; }
.study .position .cons li::before { content: "−"; color: var(--accent-red); font-weight: 700; margin-right: .5rem; }
.study .verdict { margin: 1rem 0; padding: 1rem 1.25rem; border-radius: 8px; border: 1px solid color-mix(in srgb, var(--accent-amber) 45%, transparent); background: color-mix(in srgb, var(--accent-amber) 7%, transparent); }
.study .verdict .verdict-title { display: block; font-family: var(--font-ui); font-size: .6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-amber); margin-bottom: .375rem; }
.study .verdict > :last-child { margin-bottom: 0; }

/* ---------- 15. Citations & references ----------------------------------- */
.study a.cite { color: var(--accent-blue); text-decoration: none; font-family: var(--font-ui); font-size: .68em; font-weight: 500; vertical-align: super; line-height: 0; padding: 0 .06em; letter-spacing: .02em; font-variant-numeric: lining-nums; }
.study a.cite::before { content: "["; } .study a.cite::after { content: "]"; }
.study a.cite:hover { color: var(--accent-blue-hover); }
.study .cite-pop { position: absolute; z-index: 80; max-width: 28rem; padding: .625rem .875rem; font-family: var(--font-ui); font-size: .8125rem; line-height: 1.5; color: var(--text-primary); background: var(--bg-elevated); border: 1px solid var(--border-primary); border-radius: 8px; box-shadow: var(--shadow-lg); font-variant-numeric: lining-nums; }
.study .cite-pop .ref-use { display: block; }
.study section#references ol.refs, .study ol.refs { padding-left: 1.75rem; font-family: var(--font-ui); font-size: .84rem; line-height: 1.55; font-variant-numeric: lining-nums; }
.study ol.refs li { margin-bottom: .55rem; color: var(--text-secondary); }
.study ol.refs li:target { background: var(--accent-amber-subtle); border-radius: 6px; padding: .25rem .5rem; margin-left: -.5rem; }
.study ol.refs li em { color: var(--text-primary); font-style: italic; }
.study ol.refs li a { word-break: break-all; }
.study ol.refs .ref-use { display: block; font-size: .8rem; color: var(--text-tertiary); margin-top: .125rem; }
.study ol.refs .ref-type { display: inline-block; font-size: .6rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: .0625rem .375rem; border-radius: 4px; background: var(--bg-code); border: 1px solid var(--border-subtle); color: var(--text-tertiary); margin-right: .375rem; vertical-align: middle; }
.study mark.unverified { background: color-mix(in srgb, var(--accent-amber) 14%, transparent); color: inherit; border-bottom: 2px dotted var(--accent-amber); padding: 0 .125rem; border-radius: 2px; cursor: help; }
.study mark.unverified::after { content: " ⚠"; font-size: .75em; color: var(--accent-amber); }

/* ---------- 16. Disclosure ----------------------------------------------- */
.study details.more { margin: 1.25rem 0; border: 1px solid var(--border-primary); border-radius: 8px; background: var(--bg-surface); }
.study details.more > summary { cursor: pointer; padding: .75rem 1rem; font-family: var(--font-ui); font-weight: 600; font-size: .9rem; list-style: none; display: flex; align-items: center; gap: .5rem; }
.study details.more > summary::-webkit-details-marker { display: none; }
.study details.more > summary::before { content: ""; width: .45rem; height: .45rem; border-right: 2px solid var(--text-tertiary); border-bottom: 2px solid var(--text-tertiary); transform: rotate(-45deg); margin: 0 .25rem 0 .125rem; transition: transform .15s ease; flex: none; }
.study details.more[open] > summary::before { transform: rotate(45deg); }
.study details.more[open] > summary { border-bottom: 1px solid var(--border-primary); }
.study details.more > *:not(summary) { padding: 0 1rem; }
.study details.more > *:not(summary):first-of-type { padding-top: .75rem; }
.study details.more > *:last-child { padding-bottom: .75rem; }
.study details.more > .code-block, .study details.more > pre.code, .study details.more > .tbl-wrap { margin-left: 1rem; margin-right: 1rem; padding: 0; }

/* ---------- 17. Misc blocks ---------------------------------------------- */
.study .aside-note { font-size: .875em; color: var(--text-secondary); padding: .625rem .875rem; border-left: 2px solid var(--border-secondary); margin: 1rem 0; }
.study .badge { display: inline-block; font-family: var(--font-ui); font-size: .625rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: .125rem .5rem; border-radius: 4px; background: var(--bg-code); border: 1px solid var(--border-primary); color: var(--text-secondary); vertical-align: middle; }
.study .badge-blue { background: var(--accent-blue-subtle); color: var(--accent-blue); border-color: transparent; }
.study .badge-green { background: var(--accent-green-subtle); color: var(--accent-green); border-color: transparent; }
.study .badge-amber { background: var(--accent-amber-subtle); color: var(--accent-amber); border-color: transparent; }
.study .badge-red { background: var(--accent-red-subtle); color: var(--accent-red); border-color: transparent; }
.study .asof { font-size: .8125em; color: var(--text-tertiary); font-style: italic; }

/* ---------- 18. Wide band: plates are centred and may grow to --wide -----------
   Last on purpose: component rules above set `margin: X 0`, and the plate's
   negative left margin must win.
   Figures, tables, steppers, KPI rows, spec grids, tabs, calculators and the
   "where experts disagree" grid measure against the nearest container
   (.reading-article on the site, main.study standalone). Code keeps the prose's
   left edge and grows to the right only as far as its longest line needs. */
.study > figure.fig, .study > .tbl-wrap, .study > .stepper, .study > .kpis, .study > dl.spec-grid, .study > .tabs, .study > .calc, .study > .grid-2, .study > .grid-3,
.study section > figure.fig, .study section > .tbl-wrap, .study section > .stepper, .study section > .kpis, .study section > dl.spec-grid, .study section > .tabs, .study section > .calc, .study section > .grid-2, .study section > .grid-3,
.study section.disagree > .positions {
  --bw: max(100%, min(100cqw - 2 * var(--gutter), var(--wide)));
  width: var(--bw);
  margin-left: calc((100% - var(--bw)) / 2);
  box-sizing: border-box;
}
.study > .code-block, .study > pre.code, .study section > .code-block, .study section > pre.code {
  width: fit-content; min-width: 100%;
  max-width: max(100%, calc(100% + (min(100cqw - 2 * var(--gutter), var(--wide)) - 100%) / 2));
  box-sizing: border-box;
}
/* Standalone: main.study is itself the container, so plates centre with auto margins. */
html.study-standalone .study-shell > main.study > figure.fig, html.study-standalone .study-shell > main.study > .tbl-wrap, html.study-standalone .study-shell > main.study > .stepper,
html.study-standalone .study-shell > main.study > .kpis, html.study-standalone .study-shell > main.study > dl.spec-grid, html.study-standalone .study-shell > main.study > .tabs,
html.study-standalone .study-shell > main.study > .calc, html.study-standalone .study-shell > main.study > .grid-2, html.study-standalone .study-shell > main.study > .grid-3 {
  width: auto; max-width: min(100%, var(--wide)); margin-left: auto; margin-right: auto;
}
html.study-standalone .study-shell > main.study > .code-block, html.study-standalone .study-shell > main.study > pre.code {
  min-width: min(100%, var(--measure)); max-width: min(100%, var(--wide)); width: fit-content; margin-left: max(0px, calc((100% - var(--measure)) / 2)); margin-right: 0;
}

/* ---------- 19. Print ---------------------------------------------------- */
@media print {
  .study-toc, .study-theme-toggle, .study-progress, .study .code-head .copy, .study .stepper-controls { display: none !important; }
  .study figure.fig, .study .callout, .study .tbl-wrap, .study .position, .study .code-block { break-inside: avoid; }
  .study a.cite { color: inherit; }
  .study details.more > summary { display: none; }
  .study details.more > *:not(summary) { display: block; }
}
