/* Interactive pieces: shared look for demos, drawers, buttons, matrix tables, code editors and the Python runtime.
   Loaded on interactive posts and on any post with front matter `ia: true`; the body sits in <div class="content ia">.
   Prose (paragraphs, headings, links, lists, tables, blockquotes, inline code) is the blog's own (static/style.css).
   Inside components (.demo, details.panel, .todo, the workshop's #app) the series keeps its compact Nunito/mono look.
   Those rules start with `article .content:where(.ia) :where(…)`: specificity (0,1,1) plus the element, so they tie
   the blog's `article .content p|code|li` rules and win by loading later, yet lose to any piece class like `.ia .small`. */
:root {
  --bg: #f2f0ee;
  --fg: #22272a;
  --muted: #6b6b6b;
  --red: #cc2a41;
  --teal: #567c77;
  --teal-soft: rgba(86, 124, 119, 0.4);
  --card: #f8f7f5;
  --line: #d8d2cc;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

/* ---------- inside components: the series' compact type, not the article's ---------- */
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) {
  color: var(--fg);
  font-family: Nunito, sans-serif;
  font-size: 17px;
  line-height: 1.725;
}
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) p { hyphens: auto; -webkit-hyphens: auto; margin: 1em 0; font-size: inherit; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) a {
  color: var(--fg); text-decoration: none;
  background-image: linear-gradient(transparent, transparent 5px, #aaa 5px, #aaa);
  background-position: bottom; background-size: 100% 6px; background-repeat: repeat-x;
}
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) a:hover { background-image: linear-gradient(transparent, transparent 4px, rgba(204, 42, 65, 0.6) 4px, rgba(204, 42, 65, 0.6)); }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) strong { font-weight: 700; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) code { border: 0; font-family: var(--mono); font-size: 0.84em; background: rgba(34, 39, 42, 0.06); padding: 0.1em 0.35em; border-radius: 4px; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) pre { font-family: var(--mono); font-size: 13.5px; line-height: 1.6; background: #fbfaf8; border: 1px solid var(--line); border-radius: 8px; padding: 0.9rem 1rem; overflow-x: auto; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) pre code { background: none; padding: 0; font-size: inherit; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) ul, article .content:where(.ia) :where(.demo, details.panel, .todo, #app) ol { padding-left: 1.4rem; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) li { margin: 0.2rem 0; font-size: inherit; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) table { line-height: inherit; width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 1rem 0; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) tr > th { text-align: left; color: var(--red); border-bottom: 1px dashed #666; padding: 6px 8px; font-family: Georgia, serif; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) tr > th, article .content:where(.ia) :where(.demo, details.panel, .todo, #app) tr > td { font-size: inherit; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) table code { font-size: 0.84em; white-space: normal; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) tr > td { padding: 6px 8px; vertical-align: top; border-bottom: 1px solid rgba(0,0,0,0.05); }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) tr > td:first-child { font-weight: 700; white-space: nowrap; }

/* the blog's own high-specificity article rules, undone inside components */
article .content.ia pre.hl { background: #fbfaf8; }
article .content.ia pre.pyout { background: #22272a; border: 0; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) tbody tr:hover { background: none; }
article .content:where(.ia) :where(.demo, details.panel, .todo, #app) thead th:not(:last-child), article .content:where(.ia) :where(.demo, details.panel, .todo, #app) tbody td:not(:last-child) { border-right: 0; }

/* ---------- components ---------- */
.ia pre .c { color: #8a8a8a; }
.ia pre .k { color: var(--red); }
.ia .hook { font-style: italic; }
.ia .eq {
  font-family: var(--mono); font-size: 15px; text-align: center; padding: 0.7rem 1rem; margin: 1.2rem 0;
  background: #fbfaf8; border-left: 3px solid var(--red); border-radius: 0 6px 6px 0; overflow-x: auto; white-space: nowrap;
}
.ia .eq .hl { color: var(--red); font-weight: 600; }
.ia .red { color: var(--red); font-weight: 700; }
.ia .teal { color: var(--teal); font-weight: 700; }
.ia .small { font-size: 0.85em; color: var(--muted); }
.ia .tablewrap { overflow-x: auto; }

/* ---------- demos ---------- */
.ia .demo {
  margin: 1.8rem 0; padding: 1rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 18px rgba(0,0,0,0.04);
}
.ia .wide { width: min(60rem, calc(100vw - 32px)); position: relative; left: 50%; transform: translateX(-50%); }
.ia .demo figcaption { font-size: 0.84rem; color: var(--muted); margin-top: 0.8rem; line-height: 1.55; }
.ia .demo-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--red); margin-bottom: 0.6rem; }
.ia .grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.ia .grid-plane { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
@media (max-width: 680px) { .ia .grid2, .ia .grid-plane { grid-template-columns: minmax(0, 1fr); } }
.ia canvas { display: block; width: 100%; height: auto; border-radius: 6px; touch-action: none; }
.ia canvas.plane { max-width: 360px; cursor: crosshair; box-shadow: inset 0 0 0 1px var(--line); }
.ia .controls { font-size: 0.9rem; }
.ia .sl { display: grid; grid-template-columns: 6.2rem minmax(0, 1fr) 3.4rem; align-items: center; gap: 0.5rem; margin: 0.15rem 0; font-family: var(--mono); font-size: 13px; }
.ia .sl output { text-align: right; font-variant-numeric: tabular-nums; }
.ia input[type=range] { width: 100%; accent-color: var(--red); }
.ia .btns { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0; align-items: center; }
.ia .btns > span { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.ia .btns .lbl { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-right: 0.2rem; }
.ia .chk { font-family: var(--mono); font-size: 12px; margin-left: 0.5rem; display: inline-flex; gap: 0.3rem; align-items: center; cursor: pointer; }
.ia .chk input { accent-color: var(--red); }
.ia button {
  font-family: var(--mono); font-size: 12.5px; color: var(--fg); background: transparent;
  border: 1px solid var(--fg); border-radius: 6px; padding: 3px 10px; cursor: pointer; line-height: 1.6;
}
.ia button:hover { background: rgba(34,39,42,0.06); }
.ia button.on { background: var(--fg); color: var(--bg); }
.ia button.primary { border-color: var(--red); color: var(--red); font-weight: 600; }
.ia button.primary.on, .ia button.primary:active { background: var(--red); color: #fff; }
.ia button:disabled { opacity: 0.4; cursor: default; }
.ia button.chip { padding: 1px 8px; font-size: 12px; }
.ia .readout { font-family: var(--mono); font-size: 13px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 0.55rem 0.7rem; margin-top: 0.6rem; line-height: 1.65; overflow-x: auto; }
.ia .readout.small { font-size: 12px; color: var(--fg); }
.ia .readout .big { font-size: 15px; font-weight: 600; }
.ia .stats { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; font-family: var(--mono); font-size: 13px; margin-top: 0.5rem; }
.ia .stats b { color: var(--red); font-weight: 600; }
.ia .meter { height: 8px; background: #e6e1dc; border-radius: 4px; overflow: hidden; margin: 0.25rem 0 0.1rem; }
.ia .meter > div { height: 100%; background: var(--red); width: 50%; transition: width 0.12s; }
.ia .legend { display: flex; gap: 1rem; font-size: 12px; font-family: var(--mono); color: var(--muted); margin-top: 0.4rem; flex-wrap: wrap; }
.ia .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* spam demo */
.ia .nrow { border-top: 1px dashed var(--line); margin-top: 0.6rem; padding-top: 0.4rem; }
.ia .nrow .nname { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.ia .verdict { font-family: var(--mono); font-size: 13px; margin: 0.35rem 0; }
.ia #spam-svg svg, .ia #bp-graph svg { width: 100%; height: auto; display: block; }

/* network view */
.ia .netview { position: relative; width: 100%; }
.ia .netview svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ia .netview canvas.node { position: absolute; border-radius: 4px; box-shadow: 0 0 0 1px rgba(34,39,42,0.35); background: #fff; }
.ia .netview canvas.node.click { cursor: pointer; }
.ia .netview canvas.node.sel { box-shadow: 0 0 0 2.5px var(--red); }
.ia .netview canvas.node.off { opacity: 0.25; }
.ia .netview .nlabel { position: absolute; transform: translateX(-50%); font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; pointer-events: none; }
.ia .netview .lhead { position: absolute; transform: translateX(-50%); font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); top: 0; white-space: nowrap; }

.ia .explain { min-height: 5.5em; }
.ia .todo { background: #fff; border: 1px dashed var(--line); border-radius: 8px; padding: 0.6rem 1rem 0.6rem 2.2rem; }
.ia .bigpic svg { width: 100%; height: auto; display: block; }
.ia .colophon { margin-top: 4rem; font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* math & python drawers */
.ia details.panel { margin-top: 0.8rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.ia details.panel > summary {
  cursor: pointer; list-style: none; padding: 0.45rem 0.8rem; font-family: var(--mono); font-size: 13px; font-weight: 600; user-select: none;
}
.ia details.panel > summary::-webkit-details-marker { display: none; }
.ia details.panel > summary::before { content: "▸"; display: inline-block; width: 1em; color: var(--red); transition: transform 0.15s; }
.ia details.panel[open] > summary::before { transform: rotate(90deg); }
.ia details.panel[open] > summary { border-bottom: 1px dashed var(--line); }
.ia details.panel > :not(summary) { margin-left: 0.9rem; margin-right: 0.9rem; }
.ia details.panel > p { font-size: 0.95rem; }
/* display math: shrink-to-fit (fitMath), else a thin scrollbar below the formula, never over it */
.ia .katex-display { overflow-x: auto; overflow-y: hidden; margin: 0.6em 0; padding: 0.3em 0 0.5em; scrollbar-width: thin; scrollbar-color: rgba(34, 39, 42, 0.25) transparent; }
.ia .katex-display.scrolls { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
.ia .katex-display.scrolls.at-end, .ia .katex-display.scrolls:hover { -webkit-mask-image: none; mask-image: none; }
.ia .ksplit > .ksplit-parts { display: none; }
.ia .ksplit.split > .katex-display { display: none; }
.ia .ksplit.split > .ksplit-parts { display: block; }
.ia .ksplit-parts .katex-display { margin: 0.2em 0; }
.ia .katex-display::-webkit-scrollbar { height: 6px; }
.ia .katex-display::-webkit-scrollbar-thumb { background: rgba(34, 39, 42, 0.25); border-radius: 3px; }
.ia .katex-display::-webkit-scrollbar-track { background: transparent; }
.ia .texlive { background: #fbfaf8; border-radius: 6px; padding: 0.2rem 0.5rem; overflow-x: auto; }
/* editor = colored <pre> underneath a transparent <textarea>; both share exact metrics */
.ia .editor { position: relative; margin-top: 0.7rem; }
.ia textarea.code, .ia pre.hl {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; tab-size: 4; white-space: pre;
  border: 1px solid var(--line); border-radius: 6px; padding: 0.6rem 0.7rem; margin: 0; letter-spacing: normal;
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
}
.ia textarea.code {
  position: relative; z-index: 1; display: block; width: 100%; min-height: 10rem; resize: vertical; overflow: auto;
  color: transparent; caret-color: var(--fg); background: transparent; -webkit-text-fill-color: transparent;
}
.ia textarea.code::selection { background: rgba(86, 124, 119, 0.25); }
.ia textarea.code:focus { outline: 2px solid var(--teal-soft); }
.ia pre.hl { position: absolute; inset: 0; overflow: hidden; background: #fbfaf8; color: var(--fg); pointer-events: none; }
.ia pre.hl code { background: none; padding: 0; font-size: inherit; display: block; }
.ia pre.hl.static { position: static; pointer-events: auto; overflow-x: auto; font-size: 13.5px; line-height: 1.6; padding: 0.9rem 1rem; border-radius: 8px; margin: 1rem 0; }
.ia .hl .t-c { color: #8a8f93; font-style: italic; }
.ia .hl .t-s { color: #2e7d4f; }
.ia .hl .t-n { color: #b0591a; }
.ia .hl .t-k { color: var(--red); font-weight: 600; }
.ia .hl .t-b { color: var(--teal); font-weight: 600; }
.ia .hl .t-f { color: #3355a0; }
.ia .hl .t-o { color: #7a7a7a; }
.ia pre.pyout { margin: 0 0.9rem 0.9rem; min-height: 0; max-height: 22rem; overflow: auto; background: #22272a; color: #e8e4df; border: 0; font-size: 12.5px; }
.ia pre.pyout:empty { display: none; }
.ia pre.pyout .err { color: #ff8a9b; }
.ia .pystatus { margin-left: 0.4rem; }
.ia .pyinfo {
  width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 1px solid var(--muted); color: var(--muted);
  font-family: Georgia, serif; font-style: italic; font-weight: 700; font-size: 12px; line-height: 16px; text-align: center;
}
.ia .pyinfo:hover, .ia .pyinfo[aria-expanded="true"] { border-color: var(--teal); color: #fff; background: var(--teal); }
.ia .pyhelp { font-size: 0.86rem; line-height: 1.55; background: #fbfaf8; border: 1px dashed var(--line); border-radius: 6px; padding: 0.2rem 0.8rem; margin-bottom: 0.8rem; }
.ia .pyhelp p { margin: 0.5rem 0; }

/* "press this next" pulse, and inline hints */
@keyframes nudge { 0%, 100% { box-shadow: 0 0 0 0 rgba(204, 42, 65, 0); } 50% { box-shadow: 0 0 0 5px rgba(204, 42, 65, 0.28); } }
.ia button.nudge { animation: nudge 0.9s ease-in-out 3; }
@media (prefers-reduced-motion: reduce) { .ia button.nudge { animation: none; outline: 2px solid rgba(204, 42, 65, 0.5); outline-offset: 2px; } }
.ia .hint { color: var(--muted); }
.ia .hint b { color: var(--fg); }

/* ▦ Numbers drawers: live matrix tables */
.ia .mats { padding: 0.3rem 0 0.7rem; }
.ia .meq { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.55rem; margin: 0.5rem 0; }
.ia .meq > .mop { font-family: var(--mono, "JetBrains Mono", monospace); color: var(--muted); font-size: 0.9rem; padding-top: 1.1rem; white-space: nowrap; }
.ia .mlayer { font-family: "JetBrains Mono", monospace; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; padding-top: 1.1rem; min-width: 4.5rem; }
.ia .mt { max-width: 100%; overflow-x: auto; }
.ia .mt-h { font-family: "JetBrains Mono", monospace; font-size: 0.78rem; font-weight: 600; margin-bottom: 0.15rem; white-space: nowrap; }
.ia .mt-s { color: var(--muted); font-weight: 400; font-size: 0.7rem; margin-left: 0.4rem; }
.ia .mt-n { font-size: 0.72rem; color: var(--muted); }
.ia .mt-t { border-collapse: separate; border-spacing: 0; font-family: "JetBrains Mono", monospace; font-size: 0.74rem; border-left: 2px solid var(--fg); border-right: 2px solid var(--fg); border-radius: 4px; }
.ia .mt-t td { padding: 0.12rem 0.4rem; text-align: right; min-width: 2.8em; font-variant-numeric: tabular-nums; }
.ia .mt-t th { font-weight: 400; color: #a29a92; font-size: 0.66rem; padding: 0 0.35rem; text-align: right; white-space: nowrap; }
.ia .mt-t tr.gaprow td, .ia .mt-t tr.gaprow th { color: var(--muted); text-align: center; background: none; line-height: 1; }
.ia .mscalar { font-family: "JetBrains Mono", monospace; font-size: 0.74rem; padding: 0.12rem 0.5rem; border-left: 2px solid var(--fg); border-right: 2px solid var(--fg); border-radius: 4px; }
.ia .mt-t th, .ia .mt-t td { border: 0; font-family: "JetBrains Mono", monospace; background-clip: padding-box; }
.ia .mt-t { margin: 0; width: auto; }
/* show() tables under a Python drawer's output */
.ia .pyvals { margin: -0.3rem 0.9rem 0.9rem; }
.ia .pyvals:empty { display: none; }
.ia .pyvals .meq { align-items: flex-start; gap: 0.6rem 1rem; }
.ia .pyvals-h { color: var(--muted); }
.ia .mt-t td.gap { color: var(--muted); text-align: center; min-width: 1em; background: none; }
.ia .sw { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 2px; vertical-align: -0.05em; margin-left: 0.3em; }
.ia .sw.pos { background: rgba(204,42,65,0.42); }
.ia .sw.neg { background: rgba(86,124,119,0.42); }
