/* ------------------------------------------------------------------ *
   Ferrite — no framework, no CDN, no webfont.
   The project links libc and nothing else; the site does the same.
 * ------------------------------------------------------------------ */

:root {
  /* Warm charcoals, so the crimson reads as intentional rather than
     fighting a blue-black. */
  --bg:         #0c0b0c;
  --surface:    #161517;
  --surface-2:  #1c1b1e;
  --border:     #2b2829;
  --text:       #ebe8e9;
  --muted:      #a29ea1;

  /* Harvard Crimson is too dark for text on black (2.4:1), so it backs
     solid fills that carry white text, and a lightened crimson does the
     text and link work (4.7:1). */
  --crimson:    #a51c30;
  --accent:     #e3495d;
  --accent-dim: #6e1420;
  --ok:         #57a07a;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;

  --maxw: 1080px;
  --gutter: 16px;
  --nav-h: 56px;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 16px);
  -webkit-text-size-adjust: 100%;
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* The default light scrollbar on the code blocks, tables and the diagram
   is glaring against a dark page. */
* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: #443f41; background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.skip {
  position: absolute; left: -9999px;
  background: var(--crimson); color: #fff;
  padding: 10px 16px; z-index: 100;
}
.skip:focus { left: 8px; top: 8px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

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

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(12, 11, 12, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  height: var(--nav-h);
  display: flex; align-items: center; gap: 16px;
}

.brand {
  display: inline-flex; align-items: center; gap: 9px;
  color: var(--text); font-family: var(--mono);
  font-weight: 600; letter-spacing: .02em;
  text-decoration: none; flex: none;
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 20px; height: 20px; color: var(--accent); }

.nav {
  margin-left: auto;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}
.nav a {
  color: var(--muted);
  font-size: 13.5px;
  padding: 6px 9px;
  border-radius: 5px;
  white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--accent); }
.nav-gh { color: var(--text) !important; border: 1px solid var(--border); margin-left: 6px; }

.nav-toggle {
  margin-left: auto;
  display: none;
  width: 38px; height: 34px;
  flex-direction: column; justify-content: center; gap: 4px;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; padding: 0 8px;
}
.nav-toggle span { display: block; height: 1.5px; background: var(--text); transition: .2s; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

@media (max-width: 900px) {
  .nav-toggle { display: flex; }
  .nav {
    position: absolute; top: var(--nav-h); left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--bg); border-bottom: 1px solid var(--border);
    padding: 8px var(--gutter) 16px;
    display: none;
  }
  .nav.open { display: flex; }
  .nav a { padding: 11px 6px; font-size: 15px; border-radius: 0; }
  .nav-gh { margin: 8px 0 0; text-align: center; padding: 11px !important; border-radius: 6px; }
}

/* ------------------------------ hero ------------------------------ */

.hero {
  padding: clamp(56px, 11vw, 112px) 0 clamp(40px, 7vw, 72px);
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(ellipse 70% 100% at 50% -10%, rgba(190, 35, 58, .22), transparent 70%),
    var(--bg);
}

.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 12px;
}

h1 {
  font-family: var(--mono);
  font-size: clamp(44px, 10vw, 84px);
  line-height: 1;
  letter-spacing: -.03em;
  margin: 0 0 20px;
  font-weight: 600;
}

.lede {
  font-size: clamp(19px, 3vw, 25px);
  line-height: 1.45;
  margin: 0 0 18px;
  max-width: 34ch;
}
.lede strong { color: var(--accent); font-weight: 600; }

.sub { color: var(--muted); max-width: 62ch; margin: 0 0 28px; }
.nothing {
  display: block; margin-top: 10px;
  font-family: var(--mono); font-size: 14px;
  color: var(--text);
}

.cta { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 48px; }
.btn {
  display: inline-block;
  padding: 11px 20px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 15px; font-weight: 500;
}
.btn:hover { border-color: var(--accent-dim); background: var(--surface); text-decoration: none; }
.btn-primary {
  background: var(--crimson); border-color: var(--crimson); color: #fff;
}
.btn-primary:hover { background: #bd2239; border-color: #bd2239; }

.stats {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 1px;
  grid-template-columns: repeat(4, 1fr);
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.stats li {
  background: var(--surface);
  padding: 18px 16px;
  display: flex; flex-direction: column; gap: 3px;
}
.stat-n {
  font-family: var(--mono);
  font-size: clamp(20px, 3.4vw, 27px);
  color: var(--accent);
  line-height: 1.1;
}
.stat-l { font-size: 12.5px; color: var(--muted); }

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------------------------- sections ---------------------------- */

.section { padding: clamp(52px, 8vw, 88px) 0; border-bottom: 1px solid var(--border); }
.section.alt { background: #100e10; }

h2 {
  font-size: clamp(26px, 4.6vw, 37px);
  line-height: 1.18;
  letter-spacing: -.02em;
  margin: 0 0 16px;
  font-weight: 600;
}
h3 {
  font-size: 18px;
  margin: 40px 0 12px;
  font-weight: 600;
  letter-spacing: -.01em;
}
p { margin: 0 0 16px; max-width: 68ch; }
.section-lede { font-size: 18px; color: var(--muted); max-width: 62ch; margin-bottom: 28px; }
.note {
  color: var(--muted); font-size: 15px;
  border-left: 2px solid var(--accent-dim);
  padding-left: 16px; margin-top: 24px;
}
.caption { color: var(--muted); font-size: 15px; margin-top: 16px; }
.caption strong { color: var(--text); }

/* ----------------------------- tables ----------------------------- */

.table-wrap { overflow-x: auto; margin: 4px 0 8px; -webkit-overflow-scrolling: touch; }

table {
  width: 100%; min-width: 480px;
  border-collapse: collapse;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--mono); font-size: 12.5px;
  letter-spacing: .05em; text-transform: uppercase;
  text-align: left; font-weight: 500;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
tbody th {
  text-align: left; font-weight: 500; color: var(--muted);
  padding: 12px 16px; vertical-align: top;
  width: 1%; white-space: nowrap;
}
td { padding: 12px 16px; vertical-align: top; }
tbody tr + tr th, tbody tr + tr td { border-top: 1px solid var(--border); }

.cmp .col-us { background: rgba(227, 73, 93, .07); }
.cmp thead .col-us { color: var(--accent); }
.cmp b, .bench b { color: var(--text); font-weight: 600; }
.bench .ratio { font-family: var(--mono); color: var(--ok); font-weight: 600; }
.layers tbody th { white-space: nowrap; }
.layers tbody th code { color: var(--accent); background: none; padding: 0; border: 0; }

/* ------------------------------ code ------------------------------ */

code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}

pre {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 16px 18px;
  margin: 0 0 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
pre code {
  background: none; border: 0; padding: 0;
  font-size: 13.5px; line-height: 1.6;
  display: block; white-space: pre;
  color: #d2cdcf;
}

/* mini highlighter output */
.tk-cmt { color: #736e72; font-style: italic; }
.tk-str { color: #a7c489; }
.tk-num { color: #cfa15f; }
.tk-kw  { color: #c08ad0; }
.tk-typ { color: #62a8c4; }
.tk-fn  { color: #e0c07a; }
.tk-flg { color: #62a8c4; }
.tk-cmd { color: var(--accent); }

.copy-btn {
  position: absolute; top: 8px; right: 8px;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 9px;
  cursor: pointer;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
pre:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--accent-dim); }
.copy-btn.done { color: var(--ok); border-color: var(--ok); opacity: 1; }
@media (hover: none) { .copy-btn { opacity: 1; } }

/* ---------------------------- terminal ---------------------------- */

.terminal {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  margin-bottom: 4px;
}
.terminal-bar {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.terminal-bar span {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border); flex: none;
}
.terminal-bar em {
  font-family: var(--mono); font-size: 12px;
  color: var(--muted); font-style: normal; margin-left: 6px;
}
.terminal pre { border: 0; border-radius: 0; margin: 0; background: none; }
.terminal pre code { font-size: 12px; line-height: 1.35; }

pre.plain code { color: var(--muted); }
.punch { color: var(--accent); font-weight: 600; }

/* ---------------------------- pipeline ---------------------------- */

.pipeline {
  list-style: none; margin: 0 0 40px; padding: 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-family: var(--mono);
}
.pipeline li { display: flex; align-items: center; gap: 8px; }
.pipeline li:not(:last-child)::after {
  content: "\2192"; color: var(--accent); font-size: 15px;
}
.pstage {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
}
.pstage b {
  color: var(--accent); font-size: 11px;
  border: 1px solid var(--accent-dim); border-radius: 3px;
  width: 17px; height: 17px;
  display: inline-flex; align-items: center; justify-content: center;
}
.pin {
  font-size: 13px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 7px;
  padding: 9px 12px;
}

/* ----------------------------- cards ------------------------------ */

.cards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-bottom: 8px;
}
.cards.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.card h3 {
  margin: 0 0 8px; font-size: 16px;
  display: flex; align-items: center; gap: 9px;
}
.card p { margin: 0; font-size: 14.5px; color: var(--muted); max-width: none; }
.card p code { font-size: .92em; }
.card .num {
  color: var(--accent); font-family: var(--mono); font-size: 11px;
  border: 1px solid var(--accent-dim); border-radius: 3px;
  width: 18px; height: 18px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.card.accent { border-color: var(--accent-dim); background: rgba(227, 73, 93, .06); }
.card pre { margin: 14px 0 0; background: var(--surface-2); font-size: 12px; }
.card pre code { font-size: 12.5px; }

/* ---------------------------- figures ----------------------------- */

.figure {
  margin: 24px 0 8px;
  /* Below ~560px the diagram's labels would scale into illegibility,
     so it scrolls inside its own box instead — same as the tables. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.figure svg {
  width: 100%; height: auto; display: block;
  min-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 0;
}
.svg-ax  { fill: var(--muted); font-family: var(--mono); font-size: 12px; }
.svg-lbl { fill: #f1e9ea; font-family: var(--mono); font-size: 13px; }
.svg-hw  { fill: var(--accent); font-family: var(--mono); font-size: 12px; }
.svg-blk { fill: #3c3940; stroke: #565059; stroke-width: 1; }
.svg-blk.reuse { fill: #6e1a28; stroke: var(--accent); }
.figure figcaption {
  color: var(--muted); font-size: 14px; margin-top: 12px;
}

/* ----------------------------- split ------------------------------ */

.split {
  display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.split p { font-size: 15px; color: var(--muted); }
.split p strong { color: var(--text); }

/* --------------------------- blockquote --------------------------- */

.pull {
  margin: 32px 0 0;
  padding: 20px 24px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 9px 9px 0;
  font-size: 17px;
  color: var(--text);
  max-width: 68ch;
}
.pull cite {
  display: block; margin-top: 10px;
  font-family: var(--mono); font-size: 12px;
  color: var(--muted); font-style: normal;
}

/* ---------------------------- callout ----------------------------- */

.callout {
  margin-top: 28px;
  padding: 20px 24px;
  border: 1px solid var(--accent-dim);
  background: rgba(227, 73, 93, .07);
  border-radius: 10px;
}
.callout h3 { margin: 0 0 8px; font-size: 16px; color: var(--accent); }
.callout p { margin: 0; color: var(--muted); }
.callout b { color: var(--text); }

.win-note {
  margin-top: 28px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14.5px; color: var(--muted);
}
.win-note b { color: var(--text); }

/* ---------------------------- limits ------------------------------ */

.limits { list-style: none; margin: 0; padding: 0; max-width: 72ch; }
.limits li {
  position: relative;
  padding: 14px 0 14px 26px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 15px;
}
.limits li:last-child { border-bottom: 1px solid var(--border); }
.limits li::before {
  content: "\2014"; position: absolute; left: 0; color: var(--accent);
}
.limits b { color: var(--text); font-weight: 600; }

/* ---------------------------- linkcards --------------------------- */

.links { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.linkcard {
  display: block;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}
.linkcard:hover { border-color: var(--accent-dim); text-decoration: none; }
.linkcard b { display: block; font-family: var(--mono); font-size: 14px; color: var(--accent); margin-bottom: 5px; }
.linkcard span { font-size: 14px; color: var(--muted); }

/* ----------------------------- footer ----------------------------- */

.footer { padding: 44px 0; }
.footer-inner {
  display: flex; flex-wrap: wrap; gap: 20px;
  align-items: flex-end; justify-content: space-between;
}
.footer-brand {
  font-family: var(--mono); font-size: 17px; font-weight: 600;
  margin: 0 0 4px;
}
.footer-tag { color: var(--muted); font-size: 14px; margin: 0; max-width: 46ch; }
.footer-meta { color: var(--muted); font-size: 13px; margin: 0; font-family: var(--mono); }

/* ----------------------------- reveal ----------------------------- */

.reveal { opacity: 0; transform: translateY(14px); transition: opacity .5s ease, transform .5s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}
