/* Theme matches arnesh.me: Newsreader + Inter + JetBrains Mono, deep red accent.
   Light by default; dark only when the reader toggles it (data-theme="dark"). */
:root {
  --bg: #fafaf9;
  --bg-2: #f1f1ef;
  --card: #ffffff;
  --ink: #16171a;
  --ink-2: #44464c;
  --ink-3: #7b7e85;
  --rule: #e2e2df;
  --red: #a4161a;
  --red-soft: #f7e6e6;
  --arc: #1b87b0;
  --arc-soft: #e2f1f7;
  --link: #a4161a;
  --good: #1f7a45;
  --figure-bg: #ffffff;
  --figure-filter: none;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #000000;
  --bg-2: #0e0e0e;
  --card: #0a0a0a;
  --ink: #ededed;
  --ink-2: #b4b4b4;
  --ink-3: #7c7c7c;
  --rule: #222222;
  --red: #e5484d;
  --red-soft: #2a1215;
  --arc: #7fdcff;
  --arc-soft: #0d2430;
  --link: #ff7a7e;
  --good: #4cc38a;
  --figure-bg: #f4f4f2;
  --figure-filter: brightness(.92);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16.5px/1.72 var(--sans); -webkit-font-smoothing: antialiased; overflow-x: hidden; transition: background .2s, color .2s; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
::selection { background: var(--red-soft); color: var(--ink); }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .wrap { padding: 0 28px; } }

/* ---------- top bar (same as arnesh.me) ---------- */
.bar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--rule); }
.bar .wrap { display: flex; align-items: center; gap: 16px; height: 56px; max-width: 880px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-family: var(--serif); font-size: 19px; font-weight: 500; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand svg { width: 26px; height: 26px; flex: none; }
.nav { display: flex; gap: 20px; margin-left: auto; font-size: 13.5px; }
.nav a { color: var(--ink-3); white-space: nowrap; }
.nav a:hover { color: var(--ink); text-decoration: none; }
.theme-btn { flex: none; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--rule); background: transparent; color: var(--ink-2); cursor: pointer; display: grid; place-items: center; padding: 0; }
.theme-btn:hover { color: var(--red); border-color: var(--red); }
.theme-btn svg { width: 15px; height: 15px; }
.theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: block; }
:root[data-theme="dark"] .theme-btn .moon { display: none; }
@media (max-width: 520px) { .nav { gap: 14px; } .nav .hide-sm { display: none; } }

.reactor .ring-outer { stroke: var(--red); }
.reactor .ring-arc { stroke: var(--arc); opacity: .7; }
.reactor .tri, .reactor .core { stroke: var(--arc); fill: none; }
.reactor .core-dot { fill: var(--arc); }
.reactor .spin { transform-origin: 50px 50px; animation: spin 40s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .reactor .spin, .kicker .dot { animation: none; } }

/* ---------- post header ---------- */
.post-header { padding: 52px 0 26px; }
.kicker { font: 500 12px/1.5 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); display: flex; align-items: flex-start; gap: 8px; }
.kicker .dot { flex: none; margin-top: 5px; }
.kicker .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--arc); box-shadow: 0 0 0 3px var(--arc-soft); animation: pulse 2.8s ease-in-out infinite; }
h1 { font: 500 clamp(34px, 6vw, 50px)/1.08 var(--serif); letter-spacing: -.015em; margin: 16px 0 14px; }
.lede { font: 400 clamp(19px, 2.4vw, 22px)/1.45 var(--serif); color: var(--ink-2); margin: 0 0 20px; }
.post-meta { font: 400 13px/1.5 var(--mono); color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 6px 18px; }
.post-meta a { color: var(--ink-3); }
.post-meta a:hover { color: var(--red); }

.hero { margin: 8px 0 8px; border-radius: 10px; overflow: hidden; background: #000; }
.hero img { display: block; width: 100%; height: auto; }
.hero-caption { font: 400 12px/1.5 var(--mono); color: var(--ink-3); margin: 0 0 30px; }

/* ---------- facts + stats ---------- */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 22px; margin: 0 0 26px; padding: 16px 18px; border: 1px solid var(--rule); border-radius: 10px; background: var(--card); font-size: 14.5px; }
.facts dt { font: 500 11.5px/2 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.facts dd { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 0 34px; }
.stat { border: 1px solid var(--rule); border-radius: 10px; padding: 16px 16px 14px; background: var(--card); }
.stat .value { font: 500 32px/1.05 var(--serif); color: var(--red); letter-spacing: -.01em; }
.stat .label { font-size: 13.5px; color: var(--ink-2); margin-top: 8px; line-height: 1.45; }

/* ---------- contents ---------- */
.toc { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 16px 0 10px; margin: 0 0 8px; }
.toc .label { font: 500 11.5px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 10px; }
.toc ol { columns: 2; column-gap: 28px; margin: 0; padding-left: 20px; font-size: 14.5px; color: var(--ink-3); }
.toc li { margin-bottom: 4px; break-inside: avoid; }
.toc a { color: var(--ink-2); }
.toc a:hover { color: var(--red); }

/* ---------- body text ---------- */
article h2 { font: 500 29px/1.2 var(--serif); letter-spacing: -.01em; margin: 58px 0 14px; }
article h2 .num { font: 500 13px/1 var(--mono); color: var(--red); letter-spacing: .04em; margin-right: 10px; vertical-align: 5px; }
article h3 { font: 500 21px/1.3 var(--serif); margin: 32px 0 8px; }
article p { margin: 0 0 16px; color: var(--ink); }
article ul, article ol { padding-left: 22px; margin: 0 0 16px; }
article li { margin-bottom: 6px; }
article li::marker { color: var(--ink-3); }
strong { font-weight: 600; }
code { font: 0.86em var(--mono); background: var(--bg-2); padding: 2px 5px; border-radius: 4px; }
.equation { overflow-x: auto; margin: 6px 0 20px; padding: 6px 0; }

/* ---------- figures ---------- */
figure { margin: 28px 0 32px; }
figure .frame { background: var(--figure-bg); border: 1px solid var(--rule); border-radius: 10px; padding: 12px; }
figure img { display: block; width: 100%; height: auto; filter: var(--figure-filter); }
figcaption { font-size: 14px; line-height: 1.55; color: var(--ink-2); margin-top: 10px; }
figcaption b { font: 600 12px/1 var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--red); margin-right: 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 8px 0 6px; border: 1px solid var(--rule); border-radius: 10px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--rule); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { text-align: left; }
thead th { font: 500 11.5px/1.4 var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); background: var(--bg-2); }
tr.mine td { font-weight: 600; }
tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--red); }
td.up { color: var(--good); font-weight: 600; }
.table-caption { font-size: 13.5px; color: var(--ink-3); margin: 8px 0 26px; }

/* ---------- ideas that did not work ---------- */
.ideas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0 22px; }
.idea { border: 1px solid var(--rule); border-radius: 10px; padding: 14px 16px; background: var(--card); }
.idea .result { font: 500 11px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--red); }
.idea h4 { font: 500 18px/1.3 var(--serif); margin: 8px 0 6px; }
.idea p { margin: 0; font-size: 14.5px; line-height: 1.6; color: var(--ink-2); }

/* ---------- code link ---------- */
.code-link { display: flex; align-items: center; gap: 14px; border: 1px solid var(--rule); border-radius: 10px; padding: 16px 18px; margin: 8px 0 20px; color: var(--ink); background: var(--card); }
.code-link:hover { border-color: var(--red); text-decoration: none; }
.code-link svg { flex: none; color: var(--ink); }
.code-link .repo { font: 500 15px var(--mono); color: var(--link); }
.code-link .desc { display: block; font-size: 14px; color: var(--ink-2); margin-top: 2px; }

.refs { font-size: 14.5px; color: var(--ink-2); }
.refs li { margin-bottom: 8px; }

footer { border-top: 1px solid var(--rule); margin-top: 64px; }
footer .wrap { padding-top: 22px; padding-bottom: 40px; font: 400 13px/1.6 var(--mono); color: var(--ink-3); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
footer a { color: var(--ink-3); }
footer a:hover { color: var(--red); }

mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .post-header { padding-top: 34px; }
  article h2 { font-size: 25px; }
  .stats, .ideas { grid-template-columns: 1fr; }
  .toc ol { columns: 1; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 8px; }
  figure .frame { padding: 6px; }
}
