:root {
  --bg: #0b0c10;
  --card: #111316;
  --card-soft: #0f1115;
  --fg: #e6edf3;
  --muted: #a9b1ba;
  --link: #79c0ff;
  --accent: #9bcdff;
  --border: #232a31;
  --green: #78d6a3;
  --amber: #f7c873;
  --rose: #f28b82;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --card: #f8fafc;
    --card-soft: #ffffff;
    --fg: #0f172a;
    --muted: #475569;
    --link: #0b84c6;
    --accent: #0369a1;
    --border: #d8e0ea;
    --green: #16824c;
    --amber: #9f6412;
    --rose: #b42318;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font: 16px/1.65 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.wrapper {
  max-width: 1040px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2.5rem);
}

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 2.5rem;
}

.brand-link {
  color: var(--fg);
  font-weight: 750;
  font-size: clamp(1.25rem, 1rem + 1vw, 1.8rem);
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  justify-content: flex-end;
}

.nav-link,
.pill-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0 .75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-soft);
}

.article-hero {
  display: grid;
  gap: 1.25rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  color: var(--green);
  font-size: .86rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin: 0 0 .35rem;
}

h1,
h2,
h3 {
  line-height: 1.15;
  margin: 0 0 .75rem;
}

h1 {
  max-width: 12ch;
  font-size: clamp(2.4rem, 1.6rem + 4vw, 5rem);
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.35rem, 1.15rem + 1vw, 2rem);
}

h3 {
  font-size: 1.1rem;
}

p,
li {
  max-width: 74ch;
}

.dek {
  max-width: 68ch;
  color: var(--muted);
  font-size: clamp(1.05rem, 1rem + .35vw, 1.25rem);
  margin: 0;
}

.meta {
  color: var(--muted);
  font-size: .92rem;
  margin: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.7rem;
  padding: 0 .55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: var(--card-soft);
  font-size: .85rem;
}

main {
  display: grid;
  gap: 2.4rem;
}

main > *,
section,
.article-hero {
  min-width: 0;
}

section {
  border-top: 1px solid var(--border);
  padding-top: 2rem;
}

.lede {
  font-size: 1.05rem;
}

.plain-note {
  max-width: 72ch;
  margin: .45rem 0 1rem;
  padding-left: .75rem;
  border-left: 2px solid var(--green);
  color: var(--muted);
  font-size: .94rem;
}

.plain-note strong {
  color: var(--green);
  font-weight: 700;
}

.theory-card .plain-note {
  margin: .55rem 0 .8rem;
  font-size: .9rem;
}

.theory-card .plain-note:last-child {
  margin-bottom: 0;
}

.visual-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  padding: clamp(1rem, 2vw, 1.35rem);
  overflow: hidden;
}

.visual-panel > svg {
  display: block;
  width: 100%;
  height: auto;
}

.source-figure {
  max-width: 860px;
  margin: 1.25rem 0 0;
}

.source-figure a {
  display: block;
}

.source-figure img {
  display: block;
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.bio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

@media (min-width: 900px) {
  .bio-layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr);
    align-items: start;
  }
}

.bio-circuit-panel svg text {
  font-family: inherit;
}

.bio-callouts {
  display: grid;
  gap: .75rem;
}

.bio-callout,
.bio-map-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-soft);
}

.bio-callout {
  position: relative;
  padding: .95rem;
}

.bio-callout h3 {
  margin-right: 2.1rem;
  font-size: .98rem;
}

.bio-callout p {
  margin: .45rem 0 0;
  color: var(--muted);
  font-size: .92rem;
}

.bio-step {
  position: absolute;
  top: .85rem;
  right: .85rem;
  display: inline-grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--green);
  font-size: .8rem;
  font-weight: 700;
}

.bio-map {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .75rem;
  margin: 1rem 0;
}

@media (min-width: 760px) {
  .bio-map {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.bio-map-card {
  display: grid;
  gap: .25rem;
  padding: .9rem;
}

.bio-map-card strong,
.bio-map-card b {
  color: var(--fg);
  font-size: .92rem;
}

.bio-map-card b {
  margin-top: .45rem;
}

.bio-map-card span {
  color: var(--muted);
  font-size: .88rem;
}

.stage-track {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(0, 1fr);
  gap: .9rem 1rem;
}

.dimension-formula {
  display: contents;
  font-size: .88rem;
}

.formula-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  gap: .4rem;
  min-width: 0;
  padding: .8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--card-soft);
}

.formula-cell:not(:last-child)::after {
  content: "↓";
  position: absolute;
  left: 50%;
  bottom: -.72rem;
  z-index: 1;
  color: var(--muted);
  transform: translate(-50%, 50%);
}

.formula-label {
  flex: 0 0 auto;
}

.math-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
  min-height: 2.1rem;
  padding: .12rem .45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  background: #0b0d11;
}

.dimension-formula mjx-container {
  margin: 0;
}

.flow-card mjx-container {
  color: var(--fg);
}

mjx-container svg {
  width: auto;
  max-height: none;
}

.flow-grid {
  display: contents;
}

.flow-card {
  display: grid;
  grid-template-columns: minmax(170px, 240px) minmax(0, 1fr);
  grid-template-areas:
    "title title"
    "visual text";
  gap: .75rem 1rem;
  align-items: start;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-soft);
  padding: .9rem;
}

.flow-card h3 {
  grid-area: title;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .55rem;
  font-size: .96rem;
}

.flow-card p {
  grid-area: text;
  margin: .6rem 0 0;
  color: var(--muted);
  font-size: .92rem;
}

.stage-number {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 1.55rem;
  height: 1.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--green);
  font-size: .8rem;
}

.mini-visual {
  grid-area: visual;
  min-height: 150px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #07080b;
  overflow: hidden;
}

.mini-visual svg {
  width: 100%;
  max-height: 180px;
}

.dimension-formula .formula-cell:nth-child(1),
.flow-grid .flow-card:nth-child(1) {
  grid-row: 1;
}

.dimension-formula .formula-cell:nth-child(2),
.flow-grid .flow-card:nth-child(2) {
  grid-row: 2;
}

.dimension-formula .formula-cell:nth-child(3),
.flow-grid .flow-card:nth-child(3) {
  grid-row: 3;
}

.dimension-formula .formula-cell:nth-child(4),
.flow-grid .flow-card:nth-child(4) {
  grid-row: 4;
}

.dimension-formula .formula-cell:nth-child(5),
.flow-grid .flow-card:nth-child(5) {
  grid-row: 5;
}

.dimension-formula .formula-cell:nth-child(6),
.flow-grid .flow-card:nth-child(6) {
  grid-row: 6;
}

.dimension-formula .formula-cell {
  grid-column: 1;
}

.flow-grid .flow-card {
  grid-column: 2;
}

@media (max-width: 760px) {
  .stage-track {
    grid-template-columns: minmax(0, 1fr);
  }

  .formula-cell {
    align-items: flex-start;
  }

  .formula-cell:not(:last-child)::after {
    display: none;
  }

  .dimension-formula .formula-cell,
  .flow-grid .flow-card {
    grid-column: 1;
  }

  .dimension-formula .formula-cell:nth-child(1) {
    grid-row: 1;
  }

  .flow-grid .flow-card:nth-child(1) {
    grid-row: 2;
  }

  .dimension-formula .formula-cell:nth-child(2) {
    grid-row: 3;
  }

  .flow-grid .flow-card:nth-child(2) {
    grid-row: 4;
  }

  .dimension-formula .formula-cell:nth-child(3) {
    grid-row: 5;
  }

  .flow-grid .flow-card:nth-child(3) {
    grid-row: 6;
  }

  .dimension-formula .formula-cell:nth-child(4) {
    grid-row: 7;
  }

  .flow-grid .flow-card:nth-child(4) {
    grid-row: 8;
  }

  .dimension-formula .formula-cell:nth-child(5) {
    grid-row: 9;
  }

  .flow-grid .flow-card:nth-child(5) {
    grid-row: 10;
  }

  .dimension-formula .formula-cell:nth-child(6) {
    grid-row: 11;
  }

  .flow-grid .flow-card:nth-child(6) {
    grid-row: 12;
  }

  .flow-card {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "title"
      "visual"
      "text";
  }
}

.caption {
  color: var(--muted);
  font-size: .9rem;
  margin: .8rem 0 0;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 780px) {
  .two-col {
    grid-template-columns: minmax(0, 1fr) minmax(280px, .7fr);
    align-items: start;
  }
}

.note-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-soft);
  padding: 1rem;
}

.note-box p {
  margin-top: 0;
}

.note-box p:last-child {
  margin-bottom: 0;
}

.theory-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .9rem;
  margin: 1.1rem 0;
}

@media (min-width: 860px) {
  .theory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.theory-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-soft);
  padding: 1rem;
}

.theory-card h3 {
  font-size: 1rem;
}

.theory-card p {
  margin: .6rem 0 0;
}

.math-block {
  max-width: 100%;
  overflow-x: auto;
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #07080b;
}

.math-block mjx-container {
  margin: 0;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.result-table {
  width: 100%;
  min-width: 640px;
  max-width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: .95rem;
  white-space: nowrap;
}

.result-table th,
.result-table td {
  border-bottom: 1px solid var(--border);
  padding: .55rem .45rem;
  text-align: right;
}

.result-table th:first-child,
.result-table td:first-child {
  text-align: left;
}

.result-table th {
  color: var(--muted);
  font-weight: 650;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #07080b;
  color: #edf4ff;
  padding: 1rem;
  line-height: 1.5;
  font-size: .88rem;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace;
}

:not(pre) > code {
  color: var(--fg);
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .05rem .25rem;
}

.post-list {
  display: grid;
  gap: 1rem;
  margin: 1.25rem 0 0;
}

.post-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  padding: 1rem;
}

.post-card h2 {
  font-size: 1.2rem;
}

.post-card p {
  margin-bottom: 0;
}

.refs {
  padding-left: 1.25rem;
}

.refs li {
  margin-bottom: .75rem;
}

footer {
  color: var(--muted);
  padding: 3rem 0 0;
  text-align: center;
}
