:root {
  --paper: #f1f2ed;
  --paper-raised: #fbfbf8;
  --grid-line: #d7d9ce;
  --ink: #15181b;
  --ink-soft: #565b57;
  --ink-faint: #8a8f87;
  --rule: #c7cabd;
  --red: #a6392b;
  --red-bg: #f4e3df;
  --green: #1f6e4a;
  --green-bg: #deeae2;
  --navy: #24344b;
  --radius: 4px;
  --max: 1200px;
  --card-w: 800px;
  /* For text/borders sitting on the dark --ink background. */
  --paper-soft: #c7cbbf;
  --rule-dark: #4a5049;
}

* {
  box-sizing: border-box;
}

html {
  /* The design targets ~130% of the browser's default text size. A percentage
     (not a px value) so a visitor's own zoom/text-size settings still apply
     on top of this baseline. All rem/ch sizes scale from here. */
  font-size: 130%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 36px 36px;
  background-attachment: fixed;
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: "Spectral", serif;
  font-weight: 600;
  margin: 0;
}

.mono {
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.02em;
}

a {
  color: var(--navy);
}
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 3px;
}

.wrap {
  max-width: var(--max);
  margin: 0 auto;
}

/* ---------- Header ---------- */
header.site {
  padding: 25px 26px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
header.site .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.wordmark {
  font-family: "Spectral", serif;
  font-weight: 600;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.wordmark span {
  color: var(--ink-soft);
  font-weight: 500;
}

/* Stands in for the header on the mobile homepage hero — see the
   body.home media-query rule below, which hides header.site and reveals this. */
.hero-logo {
  display: none;
  font-family: "Spectral", serif;
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 24px;
}
.hero-logo span {
  color: var(--ink-soft);
  font-weight: 500;
}
nav.site-nav {
  display: flex;
  gap: 36px;
}
nav.site-nav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-family: "Spectral", serif;
  font-size: 1.2rem;
  font-weight: 600;
  border-bottom: 1px solid transparent;
  padding-top: 1px;
}
nav.site-nav a:hover {
  color: var(--ink);
  border-bottom-color: var(--ink-soft);
}

/* ---------- Hero ---------- */
.hero {
  padding: 65px 26px;
}
.eyebrow {
  display: inline-block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--red);
  background: var(--red-bg);
  padding: 4px 12px;
  border-radius: var(--radius);
  margin: 24px 0;
}
.hero h1 {
  font-size: clamp(2.1rem, 4.6vw, 3.2rem);
  line-height: 1.08;
  max-width: 15ch;
  letter-spacing: -0.01em;
}
.hero .sub {
  margin-top: 20px;
  max-width: 46ch;
  color: var(--ink-soft);
  font-size: 1.05rem;
}
.hero-cta {
  display: block;
  width: fit-content;
  margin-top: 28px;
  margin-bottom: 6px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.85rem;
  text-decoration: none;
  padding: 14px 26px;
  border-radius: var(--radius);
}
.hero-cta:hover {
  opacity: 0.88;
}

/* ---------- Question card (signature element) ---------- */
.question-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 var(--rule);
  max-width: var(--card-w);
}
.qc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 18px 26px;
  border-bottom: 1px solid var(--grid-line);
}
.qc-head-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.qc-head .qlabel {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.qc-head .qdifficulty {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  color: var(--ink-faint);
}
.qc-head .qdifficulty:empty {
  display: none;
}
.qc-head .qsource {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  color: var(--ink-faint);
}
.qc-body {
  padding: 28px 26px 26px;
}
.qc-body p {
  margin: 0 0 24px;
  font-size: 1rem;
}
.qc-body .stem-math {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.98rem;
}
.question-diagram {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 14px auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper-raised);
}

/* KaTeX doesn't line-wrap maths. A long display equation ($$…$$) would
   otherwise run off the card. renderMath wraps each display equation in a
   .math-scroll block whose width is capped at the card and which scrolls
   horizontally when the equation is wider. It must be display:block (not the
   default inline span) so max-width resolves against the card, not the
   equation's own content width. overflow-y stays visible so tall fractions
   aren't clipped; the small padding keeps the scrollbar off the equation. */
.math-scroll {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  /* Scroll affordance (macOS overlay scrollbars are invisible until you touch
     them, so the equation could look cut off with no hint it scrolls). Lea
     Verou's pure-CSS scroll shadows: a soft shadow at each edge that shows only
     when the equation overflows there and fades as you scroll to that end.
     How it works — two "cover" gradients (paper-coloured, background-attachment:
     local) scroll with the equation and sit on top; two "shadow" gradients
     (attachment: scroll) are pinned to the container's left/right edges beneath.
     At an end, the matching cover lines up with that edge and hides its shadow;
     scroll away and the cover moves off, revealing the shadow. If the equation
     fits, both covers sit at both edges and no shadow ever shows.
     Colours are hard-coded to --paper-raised (#fbfbf8) because a gradient stop
     needs that colour at zero alpha, which a CSS var can't express. */
  background:
    linear-gradient(to right, #fbfbf8 30%, rgba(251, 251, 248, 0)) left center,
    linear-gradient(to left, #fbfbf8 30%, rgba(251, 251, 248, 0)) right center,
    linear-gradient(to right, rgba(0, 0, 0, 0.16), rgba(0, 0, 0, 0)) left center,
    linear-gradient(to left, rgba(0, 0, 0, 0.16), rgba(0, 0, 0, 0)) right center;
  background-repeat: no-repeat;
  background-size: 34px 100%, 34px 100%, 16px 100%, 16px 100%;
  background-attachment: local, local, scroll, scroll;
}
/* KaTeX centres display maths and adds vertical margins; keep those but let
   the scroll container own the horizontal overflow. */
.math-scroll .katex-display {
  margin: 0.6em 0;
}

.options {
  display: grid;
  gap: 10px;
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}
.option {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 13px 18px;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
  transition:
    border-color 0.12s ease,
    background 0.12s ease;
}
.option:hover {
  border-color: var(--ink-soft);
}
.option .tag {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  color: var(--ink-faint);
  width: 1.2em;
}
.option[disabled] {
  cursor: default;
}
.option.correct {
  background: var(--green-bg);
  border-color: var(--green);
}
.option.correct .tag {
  color: var(--green);
}
.option.incorrect {
  background: var(--red-bg);
  border-color: var(--red);
}
.option.incorrect .tag {
  color: var(--red);
}
.option.dim {
  opacity: 0.55;
}

.feedback {
  display: none;
  border-top: 1px dashed var(--rule);
  padding-top: 18px;
  margin-top: 5px;
  font-size: 0.92rem;
  color: var(--ink-soft);
}
.feedback.show {
  display: block;
}
.feedback strong {
  color: var(--ink);
}
.feedback .working {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  display: block;
  margin-top: 10px;
}
.try-again {
  margin-top: 18px;
  background: none;
  border: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  color: var(--navy);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  display: none;
}
.try-again.show {
  display: inline-block;
}

/* ---------- Value strip ---------- */
.strip {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  background: var(--paper-raised);
  margin-bottom: 52px;
}
.strip .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
}
.strip-item {
  flex: 1 1 286px;
  padding: 24px 26px;
  border-right: 1px solid var(--grid-line);
}
.strip-item:last-child {
  border-right: none;
}
.strip-item .k {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 8px;
}
.strip-item .v {
  font-size: 0.92rem;
  color: var(--ink-soft);
}

/* ---------- Papers ---------- */
.section {
  padding: 0 26px 42px 26px;
}
.section-head {
  margin-bottom: 40px;
  max-width: 56ch;
}
.section-head .eyebrow-lite {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--ink-faint);
  display: block;
  margin-bottom: 10px;
}
.section-head h2 {
  font-size: 1.6rem;
}
.section-head p {
  color: var(--ink-soft);
  margin-top: 13px;
}

.paper-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}
.paper-card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 26px;
}
.paper-card .num {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--red);
  display: block;
  margin-bottom: 13px;
}
.paper-card h3 {
  font-size: 1.15rem;
  margin-bottom: 10px;
}
.paper-card p {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0;
}
.paper-card .status {
  display: inline-block;
  margin-top: 18px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--ink-faint);
  border: 1px solid var(--grid-line);
  padding: 3px 10px;
  border-radius: var(--radius);
}

/* ---------- Open source ---------- */
.oss {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 52px;
  display: flex;
  flex-wrap: wrap;
  gap: 32px;
  align-items: center;
  justify-content: space-between;
}
.oss h2 {
  color: var(--paper);
  font-size: 1.5rem;
  max-width: 22ch;
}
.oss p {
  color: var(--paper-soft);
  max-width: 40ch;
  margin-top: 13px;
  font-size: 0.92rem;
}
.oss-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.btn {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  text-decoration: none;
  padding: 13px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--rule-dark);
  color: var(--paper);
  white-space: nowrap;
}
.btn.primary {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}
.btn:hover {
  opacity: 0.85;
}

/* ---------- Footer ---------- */
footer.site {
  border-top: 1px solid var(--rule);
  padding: 32px 26px;
  background: var(--paper);
}
footer.site .wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 13px;
  font-size: 0.82rem;
  color: var(--ink-faint);
}
footer.site a {
  color: var(--ink-soft);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  * {
    transition: none !important;
  }
}

@media (max-width: 830px) {
  nav.site-nav {
    display: none;
  }
  /* On the homepage, drop the header bar entirely on mobile (nav links are
     already hidden, so it's just a thin bar) and show a large logo in the
     hero instead — the hero-cta button below it still covers navigation. */
  body.home header.site {
    display: none;
  }
  .hero {
    padding-top: 26px;
  }
  .hero-logo {
    display: block;
    font-size: 2.9em;
    margin: 0 0 6px 0;
  }
  .oss {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* The strip's 3-column row gets uncomfortably narrow (each item wrapping its
   text and leaving whitespace below) before the site's other 830px mobile
   breakpoint kicks in, so it switches to a stacked column earlier. */
@media (max-width: 910px) {
  .strip {
    margin-bottom: 36px;
  }
  .strip .wrap {
    flex-direction: column;
  }
  .strip-item {
    padding: 26px;
    border-right: none;
    border-bottom: 1px solid var(--grid-line);
    flex: 1 1 auto;
  }
  .strip-item:last-child {
    border-bottom: none;
  }
}
