/* hotkernels documentation: layout, typography and the furniture of a page.
   Shared pieces of the interactive figures are in widgets.css. */

:root {
  --bg: #faf7f1;
  --bg-raised: #ffffff;
  --panel: #f2ede3;
  --ink: #1e1b17;
  --ink-soft: #3d3831;
  --muted: #6f685d;
  --rule: #e3dccd;
  --rule-strong: #c9c0ad;
  --hot: #d9480f;          /* hotkernels: the kernel, the thing being shown */
  --hot-soft: #fbe3d6;
  --np: #3f6fa8;           /* NumPy */
  --np-soft: #dfe9f5;
  --cc: #6d7f78;           /* naive C compiled by clang */
  --cc-soft: #e3e9e6;
  --good: #2c7a4b;
  --good-soft: #dcefe2;
  --bad: #b3261e;
  --bad-soft: #f8dedb;
  --code-bg: #f4efe6;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .06);

  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Inter, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;

  --measure: 44rem;        /* width of a column of text */
  --wide: 60rem;           /* width a figure may grow to */
  --topbar: 3.5rem;
}

:root { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14120f;
  --bg-raised: #1c1915;
  --panel: #211e19;
  --ink: #ece6d9;
  --ink-soft: #d2cabb;
  --muted: #a0988a;
  --rule: #2f2b24;
  --rule-strong: #4a4439;
  --hot: #ff8a4c;
  --hot-soft: #40210f;
  --np: #86aee4;
  --np-soft: #1b2a3f;
  --cc: #9db0a8;
  --cc-soft: #232b28;
  --good: #6cc58c;
  --good-soft: #17301f;
  --bad: #f08a80;
  --bad-soft: #3d1a17;
  --code-bg: #1d1a16;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--topbar) + 1rem); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.68;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration-color: var(--hot); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a:hover { color: var(--hot); }
:focus-visible { outline: 2px solid var(--hot); outline-offset: 2px; border-radius: 3px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--bg); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: 0; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar);
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 clamp(1rem, 3vw, 2rem);
  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(--rule);
  font-family: var(--sans);
}
.wordmark {
  display: inline-flex; align-items: center; gap: .55rem;
  font-family: var(--mono); font-weight: 700; font-size: 1rem; letter-spacing: -.02em;
  text-decoration: none; color: var(--ink);
}
.wordmark-dot { width: .7rem; height: .7rem; border-radius: 3px; background: var(--hot); display: inline-block; }
.topnav { display: flex; gap: clamp(.75rem, 2vw, 1.5rem); margin-left: auto; font-size: .92rem; }
.topnav a { text-decoration: none; color: var(--muted); padding: .25rem 0; border-bottom: 2px solid transparent; white-space: nowrap; }
.topnav a:hover { color: var(--ink); }
.topnav a[aria-current] { color: var(--ink); border-bottom-color: var(--hot); }
.theme-toggle {
  display: grid; place-items: center; width: 2.1rem; height: 2.1rem; flex: none;
  border: 1px solid var(--rule); border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--rule-strong); }
:root[data-theme="light"] .theme-toggle .sun, :root[data-theme="dark"] .theme-toggle .moon { display: none; }

/* -------------------------------------------------------------------- shell */

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0 3rem;
  max-width: 92rem; margin: 0 auto;
  padding: 0 clamp(1rem, 3vw, 2rem);
}
.article { min-width: 0; padding: 3rem 0 4rem; }
.article-head, .prose > *, .pager { max-width: var(--measure); margin-left: auto; margin-right: auto; }

.chapters, .toc { font-family: var(--sans); font-size: .88rem; }
.chapters { padding-top: 1.25rem; border-bottom: 1px solid var(--rule); }
.chapters summary { cursor: pointer; font-weight: 600; padding: .25rem 0 1rem; color: var(--muted); }
.chapters ol { list-style: none; margin: 0 0 1rem; padding: 0; }
.chapters a {
  display: flex; gap: .7rem; align-items: baseline;
  padding: .38rem .6rem; border-radius: 7px; text-decoration: none; color: var(--muted); line-height: 1.35;
}
.chapters a:hover { color: var(--ink); background: var(--panel); }
.chapters a[aria-current] { color: var(--ink); background: var(--panel); font-weight: 600; }
.chapters .num { font-family: var(--mono); font-size: .76rem; color: var(--hot); min-width: .8rem; }
.toc { display: none; }

@media (min-width: 62rem) {
  .shell.has-chapters { grid-template-columns: 14rem minmax(0, 1fr); }
  .chapters {
    position: sticky; top: var(--topbar); align-self: start;
    height: calc(100vh - var(--topbar)); overflow-y: auto;
    padding: 3.2rem 0 2rem; border-bottom: 0;
  }
  .chapters summary { list-style: none; pointer-events: none; text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; padding-left: .6rem; }
  .chapters summary::-webkit-details-marker { display: none; }
}
@media (min-width: 84rem) {
  .shell { grid-template-columns: minmax(0, 1fr) 13rem; }
  .shell.has-chapters { grid-template-columns: 14rem minmax(0, 1fr) 13rem; }
  .toc {
    display: block; position: sticky; top: var(--topbar); align-self: start;
    max-height: calc(100vh - var(--topbar)); overflow-y: auto; padding: 3.2rem 0 2rem;
  }
  .toc p { margin: 0 0 .6rem; text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; font-weight: 600; color: var(--muted); }
  .toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
  .toc a { display: block; padding: .28rem 0 .28rem .9rem; margin-left: -1px; border-left: 2px solid transparent; text-decoration: none; color: var(--muted); line-height: 1.35; }
  .toc a:hover { color: var(--ink); }
  .toc a.active { color: var(--ink); border-left-color: var(--hot); }
}

/* ------------------------------------------------------------- article head */

.kicker {
  display: flex; gap: 1rem; align-items: baseline; margin: 0 0 .9rem;
  font-family: var(--sans); font-size: .78rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--hot);
}
.kicker .minutes { color: var(--muted); font-weight: 500; letter-spacing: .04em; }
.article-head h1 {
  font-family: var(--sans); font-weight: 750; letter-spacing: -.03em; line-height: 1.06;
  font-size: clamp(2.1rem, 5vw, 3.3rem); margin: 0 0 1.1rem; text-wrap: balance;
}
.standfirst { font-size: 1.3rem; line-height: 1.5; color: var(--ink-soft); margin: 0 0 2.5rem; text-wrap: pretty; }
.article-head { border-bottom: 1px solid var(--rule); margin-bottom: 2.5rem; }

/* -------------------------------------------------------------------- prose */

.prose h2, .prose h3, .prose h4 { font-family: var(--sans); letter-spacing: -.02em; line-height: 1.2; text-wrap: balance; }
.prose h2 { font-size: 1.7rem; font-weight: 720; margin-top: 3.4rem; margin-bottom: .9rem; }
.prose h3 { font-size: 1.22rem; font-weight: 680; margin-top: 2.4rem; margin-bottom: .6rem; }
.prose h4 { font-size: 1rem; font-weight: 680; margin-top: 1.8rem; margin-bottom: .4rem; }
.prose p, .prose ul, .prose ol { margin-top: 0; margin-bottom: 1.15rem; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin-bottom: .4rem; }
.prose li::marker { color: var(--hot); }
.prose strong { font-weight: 700; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 3rem auto; }
.prose blockquote { margin-top: 1.5rem; margin-bottom: 1.5rem; padding: .1rem 0 .1rem 1.2rem; border-left: 3px solid var(--hot); color: var(--ink-soft); font-style: italic; }
.prose > .lede { font-size: 1.24rem; line-height: 1.55; }

code, kbd { font-family: var(--mono); font-size: .84em; }
:not(pre) > code { background: var(--code-bg); border: 1px solid var(--rule); border-radius: 5px; padding: .08em .32em; white-space: nowrap; }
a > code { color: inherit; }

pre.code {
  position: relative;
  background: var(--code-bg); border: 1px solid var(--rule); border-radius: 10px;
  padding: 1rem 1.15rem; overflow-x: auto; margin-top: 1.4rem; margin-bottom: 1.6rem;
  font-size: .84rem; line-height: 1.6; tab-size: 4;
}
pre.code code { font-size: inherit; }
pre.code .copy {
  position: absolute; top: .5rem; right: .5rem;
  font-family: var(--sans); font-size: .72rem; padding: .2rem .55rem;
  border: 1px solid var(--rule-strong); border-radius: 6px; background: var(--bg-raised); color: var(--muted); cursor: pointer; opacity: 0;
  transition: opacity .15s;
}
pre.code:hover .copy, pre.code .copy:focus-visible { opacity: 1; }
pre.code .copy:hover { color: var(--ink); }

/* Pygments token classes, mapped onto the site's own colours. */
.code .k, .code .kn, .code .kd, .code .kr, .code .kc, .code .ow { color: var(--hot); }
.code .kt, .code .nb, .code .nc { color: var(--np); }
.code .s, .code .s1, .code .s2, .code .sd, .code .se { color: var(--good); }
.code .c, .code .c1, .code .cm, .code .ch, .code .cp { color: var(--muted); font-style: italic; }
.code .m, .code .mi, .code .mf, .code .mh { color: var(--np); }
.code .nf, .code .fm { font-weight: 600; }
.code .go { color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; margin-top: 1.6rem; margin-bottom: 1.9rem; }
.prose > .table-wrap { max-width: var(--wide); }
table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .88rem; line-height: 1.45; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .55rem .8rem .55rem 0; vertical-align: top; border-bottom: 1px solid var(--rule); }
th { font-weight: 650; font-size: .76rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); border-bottom: 1.5px solid var(--rule-strong); white-space: nowrap; }
td code { white-space: nowrap; }
tbody tr:hover td { background: color-mix(in srgb, var(--panel) 60%, transparent); }
td.num, th.num { text-align: right; }

/* callouts */
.callout {
  margin-top: 1.8rem; margin-bottom: 1.8rem; padding: 1rem 1.25rem .15rem;
  background: var(--panel); border-radius: 10px; border-left: 3px solid var(--rule-strong);
  font-size: 1rem; line-height: 1.6;
}
.callout-title { font-family: var(--sans); font-weight: 700; font-size: .8rem; letter-spacing: .07em; text-transform: uppercase; margin-bottom: .5rem !important; color: var(--muted); }
.callout.takeaway { border-left-color: var(--hot); background: var(--hot-soft); }
.callout.takeaway .callout-title { color: var(--hot); }
.callout.warning { border-left-color: var(--bad); background: var(--bad-soft); }
.callout.warning .callout-title { color: var(--bad); }
.callout.aside { background: transparent; border: 1px solid var(--rule); border-left: 3px solid var(--np); }
.callout.aside .callout-title { color: var(--np); }

/* figures: diagrams and interactive widgets */
.prose { counter-reset: figure; }
.prose > figure { margin-top: 2.4rem; margin-bottom: 2.6rem; max-width: var(--wide); counter-increment: figure; }
figure.narrow { max-width: var(--measure) !important; }
figcaption { font-family: var(--sans); font-size: .86rem; line-height: 1.5; color: var(--muted); margin-top: .9rem; max-width: var(--measure); margin-left: auto; margin-right: auto; }
figcaption::before { content: "Figure " counter(figure) ". "; font-weight: 700; color: var(--ink); }
/* a screenshot: a framed image with its caption */
.prose > figure > img { display: block; max-width: 100%; height: auto; border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow); }
figure.diagram { background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 12px; padding: 1.5rem 1rem 1.2rem; box-shadow: var(--shadow); }
figure.diagram pre.mermaid { margin: 0; text-align: center; overflow-x: auto; font-family: var(--sans); font-size: .8rem; color: var(--muted); line-height: 1.4; }
figure.diagram pre.mermaid:not([data-processed]) { white-space: pre; text-align: left; opacity: .5; }
figure.diagram svg { max-width: 100%; height: auto; }
figure.diagram figcaption { padding: 0 .5rem; }
/* Node classes a diagram can use without defining colours of its own. */
.mermaid .node.hot rect, .mermaid .node.hot polygon, .mermaid .node.hot path, .mermaid .node.hot circle { fill: var(--hot-soft) !important; stroke: var(--hot) !important; }
.mermaid .node.np rect, .mermaid .node.np polygon, .mermaid .node.np path, .mermaid .node.np circle { fill: var(--np-soft) !important; stroke: var(--np) !important; }
.mermaid .node.good rect, .mermaid .node.good polygon, .mermaid .node.good path, .mermaid .node.good circle { fill: var(--good-soft) !important; stroke: var(--good) !important; }
.mermaid .node.bad rect, .mermaid .node.bad polygon, .mermaid .node.bad path, .mermaid .node.bad circle { fill: var(--bad-soft) !important; stroke: var(--bad) !important; }

/* hand-drawn diagrams */
svg.dg { display: block; width: 100%; height: auto; min-width: 30rem; font-family: var(--sans); font-size: 13px; }
figure.diagram:has(svg.dg) { overflow-x: auto; }
.dg text { fill: var(--ink); }
.dg .dg-label { fill: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; }
.dg .dg-box { fill: var(--panel); stroke: var(--rule-strong); }
.dg .dg-hotbox { fill: var(--hot-soft); stroke: var(--hot); }
.dg .dg-arrow { fill: none; stroke: var(--muted); stroke-width: 1.3; }
.dg .dg-arrow.dg-hot { stroke: var(--hot); stroke-width: 2; }
.dg .dg-headfill { fill: var(--muted); }
.dg .dg-headfill-hot { fill: var(--hot); }
.dg .dg-hottext { fill: var(--hot); }

/* maths */
.math.block { overflow-x: auto; margin-top: 1.4rem; margin-bottom: 1.4rem; text-align: center; }
.katex { font-size: 1.04em; }

/* footnotes */
.footnotes { font-size: .92rem; color: var(--ink-soft); margin-top: 3rem; }
.footnotes-sep { margin-bottom: 1.5rem; }
.footnote-ref a { text-decoration: none; color: var(--hot); font-family: var(--sans); font-size: .78em; }

/* pager */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 4rem; font-family: var(--sans); }
.pager a { display: block; padding: 1rem 1.2rem; border: 1px solid var(--rule); border-radius: 12px; text-decoration: none; font-weight: 650; line-height: 1.3; background: var(--bg-raised); }
.pager a:hover { border-color: var(--hot); color: var(--ink); }
.pager a span { display: block; font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: .3rem; }
.pager-next { text-align: right; grid-column: 2; }

/* chapter cards on the report's overview */
.chapter-cards { list-style: none; padding: 0 !important; display: grid; gap: .8rem; counter-reset: none; }
.chapter-cards li { margin: 0; }
.chapter-cards a {
  display: grid; grid-template-columns: 2.4rem 1fr; gap: .2rem 1rem; align-items: baseline;
  padding: 1rem 1.2rem; border: 1px solid var(--rule); border-radius: 12px; background: var(--bg-raised); text-decoration: none;
}
.chapter-cards a:hover { border-color: var(--hot); color: inherit; box-shadow: var(--shadow); }
.chapter-cards .num { font-family: var(--mono); color: var(--hot); font-size: 1.3rem; font-weight: 700; grid-row: span 2; }
.chapter-cards b { font-family: var(--sans); font-size: 1.05rem; letter-spacing: -.01em; }
.chapter-cards span.what { font-size: .95rem; color: var(--ink-soft); line-height: 1.5; }

/* footer */
.footer { border-top: 1px solid var(--rule); margin-top: 2rem; padding: 2rem clamp(1rem, 3vw, 2rem) 3rem; font-family: var(--sans); font-size: .84rem; color: var(--muted); }
.footer p { max-width: var(--measure); margin: 0 auto; }

/* --------------------------------------------------------------------- home */

.home { padding: 0 clamp(1rem, 3vw, 2rem) 2rem; }
.home > * { max-width: var(--wide); margin-left: auto; margin-right: auto; }
.hero { padding: clamp(3rem, 8vw, 6.5rem) 0 2.5rem; }
.hero .eyebrow { font-family: var(--sans); font-size: .8rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--hot); margin: 0 0 1.2rem; }
.hero h1 { font-family: var(--sans); font-weight: 780; letter-spacing: -.04em; line-height: 1; font-size: clamp(2.6rem, 7.5vw, 5.2rem); margin: 0 0 1.5rem; text-wrap: balance; }
.hero h1 em { font-style: normal; color: var(--hot); }
.hero .lede { font-size: clamp(1.15rem, 2.2vw, 1.4rem); line-height: 1.5; color: var(--ink-soft); max-width: 40rem; margin: 0 0 2rem; }
.hero-grid { display: grid; gap: 2rem; align-items: end; }
@media (min-width: 56rem) { .hero-grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 3rem; } }
.hero pre.code { margin: 0; font-size: .95rem; box-shadow: var(--shadow); background: var(--bg-raised); }
.cta { display: flex; flex-wrap: wrap; gap: .8rem; font-family: var(--sans); }
.btn { display: inline-block; padding: .7rem 1.2rem; border-radius: 10px; font-weight: 650; font-size: .95rem; text-decoration: none; border: 1.5px solid var(--ink); }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary:hover { background: var(--hot); border-color: var(--hot); color: #fff; }
.btn:hover { border-color: var(--hot); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 14px; overflow: hidden; margin-top: 1rem; margin-bottom: 3.5rem; }
.stats div { background: var(--bg-raised); padding: 1.3rem 1.4rem; }
.stats b { display: block; font-family: var(--sans); font-size: 2.3rem; font-weight: 760; letter-spacing: -.04em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats span { font-family: var(--sans); font-size: .86rem; color: var(--muted); line-height: 1.4; display: block; margin-top: .3rem; }

.home h2 { font-family: var(--sans); font-size: clamp(1.6rem, 3.5vw, 2.2rem); font-weight: 740; letter-spacing: -.03em; line-height: 1.15; margin-top: 4rem; margin-bottom: .8rem; text-wrap: balance; }
.home p, .home ul { max-width: var(--measure); }
.home > p, .home > ul, .home > h2 { margin-left: auto; margin-right: auto; max-width: var(--wide); }
.home > p, .home > ul { padding-right: calc(var(--wide) - var(--measure)); }
@media (max-width: 62rem) { .home > p, .home > ul { padding-right: 0; } }
.home figure { margin: 2rem auto 2.5rem; }
.home li::marker { color: var(--hot); }
.home li { margin-bottom: .5rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin-top: 1.5rem; margin-bottom: 3rem; }
.card { display: block; padding: 1.4rem 1.5rem; border: 1px solid var(--rule); border-radius: 14px; background: var(--bg-raised); text-decoration: none; }
a.card:hover { border-color: var(--hot); color: inherit; box-shadow: var(--shadow); }
.card h3 { font-family: var(--sans); font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; margin: 0 0 .4rem; }
.card p { margin: 0; font-size: .98rem; line-height: 1.55; color: var(--ink-soft); }
.card .more { display: inline-block; margin-top: .9rem; font-family: var(--sans); font-size: .86rem; font-weight: 650; color: var(--hot); }

@media (max-width: 40rem) {
  body { font-size: 1.04rem; }
  .topbar { gap: .75rem; padding: 0 .9rem; }
  .topnav { gap: .8rem; font-size: .84rem; min-width: 0; }
  .topnav a.external, .topnav a:nth-child(3) { display: none; }
  .wordmark { font-size: .92rem; }
  .standfirst { font-size: 1.15rem; }
  .pager { grid-template-columns: 1fr; }
  .pager-next { grid-column: 1; }
}

@media print {
  .topbar, .chapters, .toc, .pager, .footer { display: none; }
  body { background: #fff; }
}
