/* FreeFM blog post: long-form layout (centred reading column, sticky contents in the left
   margin), self-hosted fonts, Bright/Dark themes. Dark is the default; the choice is shared
   with the rest of the site through localStorage key "display". */

@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 300; font-display: swap; src: url("/assets/fonts/blog/source-serif-4-latin-300-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/fonts/blog/source-serif-4-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: italic; font-weight: 400; font-display: swap; src: url("/assets/fonts/blog/source-serif-4-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 600; font-display: swap; src: url("/assets/fonts/blog/source-serif-4-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 700; font-display: swap; src: url("/assets/fonts/blog/source-serif-4-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/fonts/blog/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap; src: url("/assets/fonts/blog/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url("/assets/fonts/blog/inter-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap; src: url("/assets/fonts/blog/inter-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/fonts/blog/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }

/* ---------- theme tokens ---------- */
:root {
  --bg: #fcfcfc;
  --bg-2: #f3f4f6;
  --text: #2a2a2a;
  --heading: #111316;
  --subheading: #33373c;
  --muted: #6b7178;
  --faint: #9aa0a6;
  --accent: #1d7aa3;
  --accent-soft: rgba(29, 122, 163, 0.28);
  --border: #e2e4e7;
  --key-bg: #f2f5f9;
  --key-border: #8fa3b8;
  --warn-bg: #fdf8e6;
  --warn-border: #c79200;
  --warn-strong: #8a5a00;
  --code-bg: #eff1f4;
  --shadow: rgba(0, 0, 0, 0.08);
  --header-bg: rgba(252, 252, 252, 0.9);
  --toggle-on-bg: #7a8288;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #1b1d20;
  --bg-2: #25282c;
  --text: #d0d4d8;
  --heading: #eef0f2;
  --subheading: #c3c8cd;
  --muted: #9ba2a8;
  --faint: #6f767d;
  --accent: #6ec6e2;
  --accent-soft: rgba(110, 198, 226, 0.35);
  --border: #353a40;
  --key-bg: #23272b;
  --key-border: #55606b;
  --warn-bg: #2a2619;
  --warn-border: #b8860b;
  --warn-strong: #f0c040;
  --code-bg: #25282c;
  --shadow: rgba(0, 0, 0, 0.35);
  --header-bg: rgba(27, 29, 32, 0.92);
  --toggle-on-bg: #3a3f46;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s, color 0.25s;
}
a { color: var(--accent); }

/* ---------- sticky header ---------- */
.sticky-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.sticky-header-inner {
  display: flex; align-items: center; gap: 16px;
  max-width: 1180px; margin: 0 auto; padding: 8px 24px;
}
.home-link {
  font-family: var(--sans); font-size: 0.85rem; font-weight: 600;
  color: var(--subheading); text-decoration: none; white-space: nowrap;
}
.home-link:hover { color: var(--accent); }
.sticky-title {
  flex: 1 1 auto; min-width: 0;
  font-family: var(--serif); font-size: 0.95rem; font-weight: 600; color: var(--heading);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.display-toggle {
  display: inline-flex; flex-shrink: 0; padding: 2px;
  border: 1px solid var(--border); border-radius: 2em;
}
.display-toggle button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 26px; padding: 0; border: 0; border-radius: 2em;
  background: transparent; color: var(--muted); cursor: pointer;
}
.display-toggle button:hover { color: var(--heading); }
.display-toggle button[aria-pressed="true"] { background: var(--toggle-on-bg); color: #fff; cursor: default; }
.display-toggle button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.display-toggle svg { width: 15px; height: 15px; }

/* ---------- hero + authors ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 0 24px; }
.hero { padding: 92px 0 6px; }
.back-link {
  display: inline-block; margin-bottom: 14px;
  font-family: var(--sans); font-size: 0.82rem; color: var(--muted); text-decoration: none;
}
.back-link:hover { color: var(--accent); }
.blog-title {
  margin: 0 0 18px; font-family: var(--serif); font-size: 2.45rem; font-weight: 700;
  line-height: 1.22; letter-spacing: -0.02em; color: var(--heading);
}
.blog-subtitle { margin: 0; max-width: 640px; font-size: 1.14rem; font-weight: 300; line-height: 1.65; color: var(--muted); }
.blog-meta { margin: 20px 0 0; font-family: var(--sans); font-size: 0.83rem; line-height: 1.6; color: var(--muted); }
.blog-meta a { text-decoration: underline; text-underline-offset: 2px; }

.authors { border-bottom: 1px solid var(--border); padding: 22px 0 24px; }
.authors-grid { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 12px 28px; }
.col-label {
  margin: 0 0 6px; font-family: var(--sans); font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}
.col-body { margin: 0; font-family: var(--sans); font-size: 0.88rem; line-height: 1.65; color: var(--text); }
.col-body a { text-decoration: none; }
.col-body a:hover { text-decoration: underline; }
@media (max-width: 720px) { .authors-grid { grid-template-columns: 1fr; } }

/* ---------- body layout: contents in the left margin ---------- */
.layout { display: grid; grid-template-columns: 1fr minmax(0, 760px) 1fr; padding: 36px 24px 40px; }
.toc {
  grid-column: 1; justify-self: end; align-self: start;
  position: sticky; top: 64px; width: 200px; max-height: calc(100vh - 84px); overflow-y: auto;
  margin-right: 28px; padding: 14px 12px; border-right: 1px solid var(--border);
}
.toc h4 { margin: 0 0 10px; font-family: var(--sans); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: block; padding: 4px 8px; border-radius: 4px;
  font-family: var(--sans); font-size: 0.78rem; line-height: 1.4; color: var(--muted); text-decoration: none;
}
.toc a:hover { background: var(--bg-2); color: var(--heading); }
.toc a.active { background: var(--bg-2); color: var(--heading); font-weight: 600; }
.body { grid-column: 2; min-width: 0; }
.toc-inline { display: none; margin: 8px 0 28px; padding: 18px 26px; border: 1px solid var(--border); border-radius: 6px; }
.toc-inline h3 { margin: 0 0 6px !important; font-family: var(--sans) !important; font-size: 0.9rem !important; }
.toc-inline ol { margin: 0; padding-left: 20px; font-family: var(--sans); font-size: 0.9rem; line-height: 1.8; }
.toc-inline a { text-decoration: none; }
@media (max-width: 1140px) {
  .layout { grid-template-columns: minmax(0, 1fr); max-width: 808px; margin: 0 auto; }
  .toc { display: none; }
  .body { grid-column: 1; }
  .toc-inline { display: block; }
}

/* ---------- reading column ---------- */
.body { font-size: 1.06rem; line-height: 1.8; }
.body h2 {
  margin: 54px 0 14px; font-size: 1.62rem; font-weight: 700; line-height: 1.3;
  letter-spacing: -0.01em; color: var(--heading); scroll-margin-top: 72px;
}
.body h2 .num { margin-right: 6px; color: var(--muted); font-weight: 600; }
.body h3 {
  margin: 32px 0 10px; font-family: var(--sans); font-size: 1.08rem; font-weight: 600;
  color: var(--subheading); scroll-margin-top: 72px;
}
.body p { margin: 0 0 16px; }
.body a { text-decoration: underline; text-decoration-color: var(--accent-soft); text-underline-offset: 2px; }
.body a:hover { text-decoration-color: var(--accent); }
.body strong { color: var(--heading); font-weight: 600; }
.body ul, .body ol { margin: 0 0 16px; padding-left: 1.4em; }
.body li { margin-bottom: 6px; }
.body code {
  padding: 0.08em 0.35em; border-radius: 4px; background: var(--code-bg);
  font-family: var(--mono); font-size: 0.86em;
}
.body pre {
  margin: 22px 0; padding: 16px 18px; overflow-x: auto; border-radius: 6px;
  background: var(--code-bg); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.6;
}
.body pre code { padding: 0; background: none; font-size: inherit; }
.body .katex-display { margin: 20px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.body .katex { font-size: 1.06em; }

.key-idea, .warning {
  margin: 24px 0; padding: 16px 22px; border-radius: 0 6px 6px 0;
  font-size: 0.97rem; line-height: 1.7;
}
.key-idea { background: var(--key-bg); border-left: 3px solid var(--key-border); }
.warning { background: var(--warn-bg); border-left: 3px solid var(--warn-border); }
.warning strong { color: var(--warn-strong); }
.key-idea p:last-child, .warning p:last-child { margin-bottom: 0; }

/* figures, videos, tables */
figure { margin: 28px 0; }
figure img, figure video {
  display: block; width: 100%; height: auto; border-radius: 6px;
  box-shadow: 0 2px 14px var(--shadow);
}
figure.plain img { background: #fff; }
figcaption { margin-top: 10px; font-family: var(--sans); font-size: 0.82rem; line-height: 1.55; color: var(--muted); }
figcaption strong { color: var(--subheading); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.pair img { height: 260px; object-fit: contain; background: #fff; }
@media (max-width: 720px) { .pair { grid-template-columns: 1fr; } .pair img { height: auto; } }
video { cursor: pointer; }

.table-wrap { margin: 22px 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 0.84rem; line-height: 1.5; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--heading); font-weight: 600; border-bottom-width: 2px; }
td.num, th.num { text-align: right; white-space: nowrap; }
table .katex { font-size: 1em; }

details { margin: 14px 0 26px; border: 1px solid var(--border); border-radius: 6px; padding: 10px 16px; }
summary { cursor: pointer; font-family: var(--sans); font-size: 0.88rem; font-weight: 600; color: var(--subheading); }
details[open] summary { margin-bottom: 8px; }
details .grid3 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
details .grid3 img { width: 100%; height: auto; border-radius: 4px; background: #fff; }
@media (max-width: 720px) { details .grid3 { grid-template-columns: 1fr; } }

.algo { margin: 24px 0; padding: 16px 22px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-2); }
.algo .algo-title { margin: 0 0 8px; font-family: var(--sans); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.algo ol { margin: 0; }

/* informal statements of results: Proposition / Theorem (informal) */
.stmt { margin: 24px 0; padding: 14px 22px 16px; border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0; background: var(--bg-2); font-size: 0.97rem; line-height: 1.7; }
.stmt .stmt-title { margin: 0 0 6px; font-family: var(--sans); font-size: 0.84rem; font-weight: 600; color: var(--heading); }
.stmt .stmt-title span { font-weight: 400; color: var(--muted); }
.stmt p:last-child { margin-bottom: 0; }

/* references + citation + footer */
.refs { padding-left: 1.6em; font-family: var(--sans); font-size: 0.86rem; line-height: 1.6; }
.refs li { margin-bottom: 8px; }
.cite-ref { font-family: var(--sans); font-size: 0.8em; text-decoration: none !important; }
.site-footer { border-top: 1px solid var(--border); padding: 26px 24px 40px; text-align: center; font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }

@media (max-width: 720px) {
  .blog-title { font-size: 1.9rem; }
  .hero { padding-top: 78px; }
  .sticky-title { display: none; }
  .sticky-header-inner { justify-content: space-between; }
}
@media print {
  .sticky-header, .toc, .toc-inline, .display-toggle { display: none !important; }
  .hero { padding-top: 0; }
}

/* ---- In-page FreeFM forecaster (lab/freefm-app.js) ---- */
.ffm-app { margin: 22px 0 28px; padding: 18px 20px 20px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-2); font-family: var(--sans); font-size: 0.92rem; color: var(--text); }
.ffm-app [hidden] { display: none !important; }
.ffm-app p { margin: 0; }
.ffm-files { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ffm-drop { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1.5px dashed var(--border);
  border-radius: 6px; background: var(--bg); cursor: pointer; transition: border-color .15s, background .15s; }
.ffm-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.ffm-drop:hover, .ffm-drop.over { border-color: var(--accent); }
.ffm-drop.over { background: var(--accent-soft); }
.ffm-drop:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.ffm-drop.loaded { border-style: solid; border-color: var(--accent); }
.ffm-drop-name { font-family: var(--mono); font-size: 0.9rem; font-weight: 600; color: var(--heading); }
.ffm-drop-sub { font-size: 0.8rem; color: var(--muted); }
.ffm-drop-info { margin-top: 4px; font-size: 0.82rem; color: var(--subheading); }
.ffm-drop.loaded .ffm-drop-info { color: var(--accent); }
.ffm-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px !important; }
.ffm-btn { font: inherit; font-size: 0.86rem; line-height: 1.3; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer; }
.ffm-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--heading); }
.ffm-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ffm-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ffm-run { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; padding: 7px 16px; }
.ffm-run:hover:not(:disabled) { color: var(--bg); filter: brightness(1.08); }
.ffm-hint { font-size: 0.82rem; color: var(--muted); }
.ffm-label { font-size: 0.74rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.ffm-cols { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 14px; }
.ffm-colboxes { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.ffm-colboxes label { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 0.84rem; cursor: pointer; }
.ffm-app input[type="checkbox"], .ffm-app input[type="range"] { accent-color: var(--accent); }
.ffm-app details.ffm-adv { margin: 12px 0 0; padding: 8px 12px; background: var(--bg); }
.ffm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; }
.ffm-grid label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.84rem; color: var(--subheading); }
.ffm-grid input { width: 5.5em; font: inherit; font-size: 0.85rem; padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg-2); color: var(--text); }
.ffm-progress { margin-top: 14px; }
.ffm-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.ffm-bar span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 0.25s; }
.ffm-status { margin-top: 6px !important; font-size: 0.84rem; color: var(--muted); }
.ffm-error { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--warn-border); border-radius: 4px; background: var(--warn-bg); font-size: 0.86rem; }
.ffm-out { margin-top: 18px; }
.ffm-metrics { margin-bottom: 10px !important; font-size: 0.88rem; line-height: 1.55; }
.ffm-metrics strong { color: var(--heading); }
.ffm-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 6px; font-size: 0.8rem; color: var(--muted); }
.ffm-legend .sw { display: inline-block; width: 18px; margin-right: 6px; vertical-align: middle; border-top: 2px solid; }
.ffm-legend .sw-train { border-color: var(--faint); }
.ffm-legend .sw-truth { border-color: var(--heading); }
.ffm-legend .sw-mean { border-top: 2px dashed var(--accent); }
.ffm-legend .sw-band { height: 10px; border: 0; background: var(--accent-soft); }
.ffm-canvas { display: block; width: 100%; margin-bottom: 6px; border-radius: 4px; }
.ffm-controls { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.ffm-scrub { flex: 1; min-width: 0; }
.ffm-step { min-width: 10ch; font-family: var(--mono); font-size: 0.78rem; color: var(--muted); text-align: right; }
.ffm-downloads { margin-top: 14px !important; }
@media (max-width: 720px) {
  .ffm-app { padding: 14px; }
  .ffm-files, .ffm-grid { grid-template-columns: 1fr; }
}

/* ---- Explorer for the Hidden Biases post (hiddenbiasblog/lab/hb-app.js) ---- */
.hb-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 16px; }
.hb-controls label { display: flex; flex-direction: column; gap: 4px; }
.hb-controls select { font: inherit; font-size: 0.86rem; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); }
.hb-controls b { color: var(--heading); font-weight: 600; }
.hb-sym { text-transform: none; }
.hb-out { margin-top: 16px; }
.hb-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hb-panel { margin: 0; }
.hb-panel .hb-title { margin: 0 0 4px; font-family: var(--sans); font-size: 0.8rem; color: var(--subheading); text-align: left; }
.hb-canvas { display: block; width: 100%; border-radius: 4px; }
.hb-note { margin: 8px 0 0 !important; font-size: 0.84rem; color: var(--muted); }
.hb-energy { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; align-items: center; margin-top: 14px; }
.hb-chart { display: block; width: 100%; }
.hb-stats table { width: 100%; margin: 0; font-size: 0.82rem; }
.hb-stats th, .hb-stats td { padding: 4px 6px; }
.hb-stats .sw { display: inline-block; width: 16px; margin-right: 6px; vertical-align: middle; border-top: 2px solid var(--accent); }
.hb-stats .sw-b { border-top: 2px dashed #e8915a; }
.hb-stats .ffm-hint { margin-top: 6px !important; }
@media (max-width: 720px) {
  .hb-energy { grid-template-columns: 1fr; }
}
