/*
  Diagrams for math-heavy posts, in the site's language: no fills, no
  colour, dashed rules. Emphasis (.hi) is ink + weight against --ink-soft.
*/

.katex {
  font-size: 1.08em;
}

.math-block {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
  scrollbar-width: none;
}

.math-block::-webkit-scrollbar {
  display: none;
}

.math-block .katex-display {
  margin: 0;
}

.label {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: 13px;
  line-height: 1.2;
  color: var(--ink-soft);
}

.note {
  font-size: 14px;
  color: var(--ink-soft);
}

.small {
  font-size: 15px;
  line-height: 1.55;
}

.panel code,
.cells code,
.table code,
.box code,
.small code {
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.box {
  border: 1px dashed var(--rule-box);
  padding: var(--space-2) var(--space-3);
}

.center {
  align-items: center;
  text-align: center;
}

/* ── panels: a block between dashed rules ─────────────────────────────── */

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) 0;
  min-width: 0;
}

.panel.rule-top {
  padding-bottom: 0;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2) var(--space-6);
}

.big {
  font-size: 1.15em;
}

.grid-2,
.grid-3 {
  display: grid;
  gap: var(--space-4) var(--space-6);
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
}

/* ── cells: a dashed grid of numbered steps ───────────────────────────── */

.cells {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px dashed var(--rule-box);
  border-left: 1px dashed var(--rule-box);
}

.cells-3 {
  grid-template-columns: repeat(3, 1fr);
}

.cells-4 {
  grid-template-columns: repeat(4, 1fr);
}

.cells > li {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
  border-right: 1px dashed var(--rule-box);
  border-bottom: 1px dashed var(--rule-box);
  overflow-wrap: anywhere;
}

.cells .note {
  margin-top: auto;
}

@media (max-width: 560px) {
  .cells-3,
  .cells-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── rows: label/value lines separated by dashed rules ────────────────── */

.rows > div {
  display: grid;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  border-top: 1px dashed var(--rule-box);
  color: var(--ink-soft);
}

.rows > div:last-child {
  border-bottom: 1px dashed var(--rule-box);
}

.rows > div.hi {
  color: var(--ink);
  font-weight: 600;
}

.rows strong {
  font-weight: 500;
  color: var(--ink);
}

.embed-rows > div {
  grid-template-columns: 64px 36px minmax(0, 1fr);
}

.embed-rows > div.soft {
  font-size: 13px;
}

.embed-rows .math {
  overflow-x: auto;
}

.lookup-rows > div {
  grid-template-columns: 1fr auto 1fr;
}

.silu-rows > div {
  grid-template-columns: 1fr auto;
}

.prob-rows > div {
  grid-template-columns: 40px 40px minmax(0, 1fr) 48px;
}

.prob-rows > div > span:last-child {
  text-align: right;
}

.bar {
  height: 8px;
  border: 1px dashed var(--rule-box);
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--rule);
}

.hi .bar > span {
  background: var(--solid);
}

/* ── tokens (BPE merge) ───────────────────────────────────────────────── */

.merge {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: var(--space-4) var(--space-6);
  align-items: start;
}

.merge > div {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.tokens {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tokens code {
  min-width: 34px;
  padding: var(--space-2);
  border: 1px dashed var(--rule-box);
  text-align: center;
  color: var(--ink-soft);
}

.tokens code.hi {
  border: 1px solid var(--ink);
  color: var(--ink);
  font-weight: 600;
}

/* ── flows and equations ──────────────────────────────────────────────── */

.flow,
.equation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
}

.flow .math-block {
  width: auto;
}

.arrow,
.op {
  color: var(--ink-soft);
}

.matrix {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  max-width: 100%;
  font-size: 14px;
}

.matrix.hi {
  padding-left: var(--space-3);
  border-left: 2px solid var(--ink);
}

.matrix.hi .label,
.box.hi {
  color: var(--ink);
}

.box.hi {
  border: 1px solid var(--ink);
}

/* ── batch stack ──────────────────────────────────────────────────────── */

.batch {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-6) calc(var(--space-8) * 1.4);
}

.batch-stack {
  display: grid;
  padding: 24px 24px 0 0;
}

.batch-stack > div {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 190px;
  min-height: 92px;
  padding: var(--space-3);
  border: 1px dashed var(--rule-box);
  background: var(--bg);
  font-size: 14px;
}

.batch-stack > div:nth-child(1) { transform: translate(24px, -24px); }
.batch-stack > div:nth-child(2) { transform: translate(16px, -16px); }
.batch-stack > div:nth-child(3) { transform: translate(8px, -8px); }

.batch-stack > .front {
  border: 1px solid var(--ink);
}

.batch-stack > .front .label {
  color: var(--ink);
}

/* ── shape tables ─────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 15px;
}

.table th,
.table td {
  padding: var(--space-2) var(--space-3) var(--space-2) 0;
  border-bottom: 1px dashed var(--rule-box);
  text-align: left;
  vertical-align: middle;
}

.table thead th,
.table tbody th {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: 13px;
  color: var(--ink-soft);
}

.table thead th {
  border-top: 1px dashed var(--rule-box);
}

.shift {
  min-width: 420px;
}

.shift tr:first-child > * {
  border-top: 1px dashed var(--rule-box);
}

.shift td {
  text-align: center;
  color: var(--ink-soft);
}

.shift .hi td {
  color: var(--ink);
  font-weight: 600;
}

/* ── one-offs ─────────────────────────────────────────────────────────── */

.callout {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--space-4) var(--space-6);
}

.callout > .math {
  font-size: 18px;
}

.callout p {
  font-size: 15px;
}

.heads {
  gap: var(--space-4);
}

.head-slices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.head-slices > .box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 72px;
  font-size: 13px;
}

.head-slices > .box.soft {
  justify-content: center;
}

.factor {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rope,
.silu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  align-items: center;
  gap: var(--space-4) var(--space-6);
}

.rope svg,
.silu svg {
  display: block;
  width: 100%;
  max-width: 224px;
  height: auto;
}

.rotation .ring,
.rotation .arc {
  fill: none;
  stroke: var(--rule-box);
  stroke-width: 1.25;
}

.rotation .arc {
  stroke: var(--ink);
}

.rotation .axis,
.silu .axis {
  stroke: var(--rule);
  stroke-width: 1;
  stroke-dasharray: 6 5;
}

.rotation .before {
  stroke: var(--ink-soft);
  stroke-width: 2;
}

.rotation .after {
  stroke: var(--ink);
  stroke-width: 2.5;
}

.rotation .dot-before {
  fill: var(--ink-soft);
}

.rotation .dot-after {
  fill: var(--ink);
}

.rotation text {
  font-family: var(--font-body);
  font-size: 10.5px;
}

.rotation .theta,
.rotation .coord {
  font-size: 12px;
}

.rotation .text-before {
  fill: var(--ink-soft);
}

.rotation .theta,
.rotation .text-after {
  fill: var(--ink);
}

.silu .curve {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps > li {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  font-size: 16px;
}
