/* ==========================================================================
   Long-form post styles + charts. Loaded after style.css, on posts only.
   ========================================================================== */

:root {
  /* Categorical series colours. Validated for CVD separation and contrast
     against the light surface; see the note in writing.html. Do not swap one
     of these without re-checking the pair separation. */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s-base: #a0a8b3;
}

:root[data-theme="dark"] {
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s-base: #5e6979;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s-base: #5e6979;
  }
}

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

.post {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Reading column; figures and charts break out wider. */
.post > * {
  max-width: 40rem;
  margin-left: auto;
  margin-right: auto;
}

.post > .breakout {
  max-width: 62rem;
}

.post-head {
  padding: 3.25rem 0 0;
  margin-bottom: 2.5rem;
}

.kicker {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.9rem;
}

.post-head h1 {
  font-size: clamp(2rem, 5.5vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.022em;
  margin-bottom: 0.4em;
  text-wrap: balance;
}

.post-head .dek {
  font-size: 1.2rem;
  line-height: 1.55;
  color: var(--muted);
  margin-bottom: 1.2rem;
}

.post-meta {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--faint);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
}

.post h2 {
  font-size: 1.5rem;
  letter-spacing: -0.015em;
  margin-top: 3rem;
  margin-bottom: 0.7rem;
  text-wrap: balance;
}

.post h2:first-of-type { margin-top: 2rem; }

.post .lede {
  font-size: 1.1rem;
  color: var(--muted);
}

.post ul { padding-left: 1.25em; }

/* --- Stat row ----------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 2px solid var(--text);
  border-bottom: 1px solid var(--border);
  margin: 2rem auto;
  padding: 0;
  list-style: none;
}

.stats li {
  padding: 0.9rem 1rem 1rem 0;
  margin: 0;
}

.stats li + li {
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}

.stats .v {
  display: block;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.35rem;
}

.stats .v.hl { color: var(--accent); }

.stats .k {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--muted);
}

@media (max-width: 38rem) {
  .stats { grid-template-columns: 1fr; }
  .stats li + li {
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}

/* --- Pull quote --------------------------------------------------------- */

.pull {
  border-left: 3px solid var(--accent);
  padding: 0.3rem 0 0.3rem 1.1rem;
  margin: 2rem auto;
  font-size: 1.15rem;
  line-height: 1.5;
}

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

.vid {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.vid .frame {
  position: relative;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  line-height: 0;
}

.vid video {
  display: block;
  width: 100%;
  height: auto;
  background: #0b1220;
}

.vid figcaption {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--muted);
}

.vid figcaption b { color: var(--text); font-weight: 600; }

/* Corner label over a clip */
.tag {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1.4;
  color: #fff;
  background: rgba(12, 18, 27, 0.74);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  pointer-events: none;
  z-index: 1;
}

.tag.ok::before { content: "\2713 "; color: #7be0a8; }

/* Clip grids */
.grid2,
.grid3,
.grid4 {
  display: grid;
  gap: 1.1rem;
  margin: 2rem auto;
}

.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 56rem) {
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 34rem) {
  .grid2,
  .grid3,
  .grid4 { grid-template-columns: minmax(0, 1fr); }
}

/* --- Figures / charts --------------------------------------------------- */

.fig {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 0.9rem;
  margin: 2rem auto;
}

.fig-t {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.15rem;
}

.fig-s {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 0 0 0.8rem;
}

.chart {
  position: relative;
  width: 100%;
  min-height: 60px;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart text {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--faint);
}

.chart text.lbl {
  font-family: var(--font-sans);
  font-size: 12px;
  fill: var(--muted);
}

.chart text.val {
  font-family: var(--font-mono);
  font-size: 12px;
  fill: var(--text);
}

.chart .gridl { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--faint); stroke-width: 1; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.6rem;
}

.legend span { display: inline-flex; align-items: center; gap: 0.45rem; }

.legend i {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  padding: 0.35rem 0.55rem;
  border-radius: 5px;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  margin-top: -8px;
  z-index: 3;
}

.tip[hidden] { display: none !important; }

.fig details {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--faint);
  margin-top: 0.7rem;
}

.fig summary { cursor: pointer; width: max-content; }
.fig details .tw { overflow-x: auto; margin-top: 0.5rem; }

.fig table {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  width: auto;
}

.fig th,
.fig td {
  padding: 0.2rem 0.9rem 0.2rem 0;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.fig th { color: var(--faint); font-weight: 400; background: none; }

.cap {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--muted);
  margin: 0.6rem auto 0;
}

.cap b { color: var(--text); font-weight: 600; }

/* --- Algorithm block ---------------------------------------------------- */

.algo {
  margin: 2rem auto;
  padding: 0;
  border-top: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
}

.algo-t {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.algo-in {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 0;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.algo-body {
  list-style: none;
  counter-reset: algoline;
  margin: 0;
  padding: 0.6rem 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.75;
}

/* Line numbers sit in the gutter; wrapped text hangs at the text edge. */
.algo-body li {
  counter-increment: algoline;
  position: relative;
  margin: 0;
  padding-left: 2.5rem;
  padding-right: 2.2rem;
}

.algo-body li::before {
  content: counter(algoline);
  position: absolute;
  left: 0;
  width: 1.6rem;
  text-align: right;
  color: var(--faint);
}

.algo-body .i1 { padding-left: 4rem; }
.algo-body .i2 { padding-left: 5.5rem; }

.algo-body i { color: var(--text); font-style: italic; }

/* Keep superscript stars and subscripts from stretching the line box. */
.algo-body sub { line-height: 0; font-size: 0.8em; }

/* Branch tag, pinned to the right edge of the line */
.algo-br {
  position: absolute;
  right: 0;
  color: var(--accent);
}

@media (max-width: 34rem) {
  .algo-body { font-size: 0.75rem; }
  .algo-body li { padding-left: 2rem; padding-right: 1.9rem; }
  .algo-body .i1 { padding-left: 3rem; }
  .algo-body .i2 { padding-left: 4rem; }
}

/* --- Post index (writing.html) ------------------------------------------ */

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

.post-list li {
  padding: 1.4rem 0;
  border-bottom: 1px solid var(--border);
  margin: 0;
}

.post-list h2 {
  font-size: 1.25rem;
  margin: 0 0 0.3rem;
}

.post-list h2 a { color: var(--text); }
.post-list h2 a:hover { color: var(--accent); text-decoration: none; }

.post-list time {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--faint);
}

.post-list p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}
