/* Self-Healing Feeder study page. Hand-written; no build step. */
:root {
  color-scheme: light;
  --bg: #fbfaf7; --surface: #ffffff; --fg: #1c1c1a; --fg2: #45443f; --muted: #6f6d66;
  --rule: #dedbd2; --rule2: #ebe8e0; --soft: #f2f0ea; --accent: #1f4e9c; --accent2: #b4521f;
  --link: #1f4e9c; --mark: #fff3c4;
  --st-on: #3d8b5a; --st-tie: #2f6db5; --st-dark: #b9bcc0; --st-fault: #cc3b2b;
  --lamp-on: #2e9e55; --lamp-off: #d23a2c;
  --s1: #8a8a84; --s2: #d07a2a; --s3: #1f4e9c;
  --heat-lo: #f2f0ea; --heat-hi: #1f3f7a;
  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", "Source Sans Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141412; --surface: #1c1c1a; --fg: #ecebe6; --fg2: #c9c7bf; --muted: #9b998f;
    --rule: #34332f; --rule2: #2a2926; --soft: #22221f; --accent: #8fb3ee; --accent2: #e39a63;
    --link: #8fb3ee; --mark: #4a4220;
    --st-on: #4fa36d; --st-tie: #5b95dc; --st-dark: #4a4c50; --st-fault: #e2553f;
    --lamp-on: #4cc775; --lamp-off: #f05a48;
    --s1: #a3a39b; --s2: #e39a63; --s3: #8fb3ee;
    --heat-lo: #22221f; --heat-hi: #8fb3ee;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141412; --surface: #1c1c1a; --fg: #ecebe6; --fg2: #c9c7bf; --muted: #9b998f;
  --rule: #34332f; --rule2: #2a2926; --soft: #22221f; --accent: #8fb3ee; --accent2: #e39a63;
  --link: #8fb3ee; --mark: #4a4220;
  --st-on: #4fa36d; --st-tie: #5b95dc; --st-dark: #4a4c50; --st-fault: #e2553f;
  --lamp-on: #4cc775; --lamp-off: #f05a48;
  --s1: #a3a39b; --s2: #e39a63; --s3: #8fb3ee;
  --heat-lo: #22221f; --heat-hi: #8fb3ee;
}

/* one language at a time */
html[lang="vi"] [data-l="en"], html:not([lang="vi"]) [data-l="vi"] { display: none !important; }

* { box-sizing: border-box; }
html { scroll-padding-top: 64px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 18px/1.62 var(--serif);
  font-optical-sizing: auto; text-rendering: optimizeLegibility; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
code { font: .82em var(--mono); background: var(--soft); padding: 1px 4px; border-radius: 3px; word-break: break-word; }
b, strong { font-weight: 650; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; z-index: 50; background: var(--surface); padding: 6px 10px; }

/* top bar */
.bar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(6px); border-bottom: 1px solid var(--rule); font-family: var(--sans); }
.bar-in { max-width: 1240px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--fg); text-decoration: none; font-size: 15px; white-space: nowrap; }
.brand-sub { font-weight: 400; color: var(--muted); }
.bar-links { display: flex; gap: 14px; font-size: 14.5px; }
.bar-links a { text-decoration: none; } .bar-links a:hover { text-decoration: underline; }
.bar-ctrl { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.seg button { font: 600 13px var(--sans); border: 0; background: transparent; color: var(--fg2); padding: 4px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.tbtn { font: 600 13px var(--sans); border: 1px solid var(--rule); background: transparent; color: var(--fg2); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
/* on narrow screens the bar wraps to three rows; let it scroll away instead of covering the text */
@media (max-width: 700px) { .bar { position: static; } }

/* layout */
.layout { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: grid; grid-template-columns: minmax(0, 1fr); }
.toc { display: none; }
@media (min-width: 1100px) {
  .layout { grid-template-columns: 210px minmax(0, 1fr); gap: 40px; }
  .toc { display: block; position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 80px); overflow: auto;
    padding: 28px 0 20px; font: 14px/1.4 var(--sans); }
  .toc-h { margin: 0 0 8px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: 12px; }
  .toc ol { list-style: none; margin: 0; padding: 0; }
  .toc a { display: block; padding: 4px 0 4px 10px; color: var(--fg2); text-decoration: none; border-left: 2px solid var(--rule2); }
  .toc a:hover { color: var(--fg); }
  .toc a.on { color: var(--fg); border-left-color: var(--accent); font-weight: 600; }
}
.paper { min-width: 0; padding: 28px 0 80px; }
/* prose measure ~70 characters; figures and tables may run wider */
.paper > section > p, .paper > section > ul, .paper > section > ol, .paper > section > h2, .paper > section > h3,
.paper > section > .eq, .paper > section > details, .titleblock, .worked, .foot { max-width: 41rem; }
.paper > section > details { max-width: 52rem; }
.titleblock h1 { font-size: clamp(28px, 4.2vw, 40px); line-height: 1.15; margin: 4px 0 12px; font-weight: 650; letter-spacing: -.01em; }
.kicker { font: 700 12.5px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--accent2); margin: 0; }
.byline { font: 15px var(--sans); color: var(--fg2); margin: 0 0 16px; }
.notice { font: 15.5px/1.5 var(--sans); background: var(--soft); border-left: 3px solid var(--accent2); padding: 10px 14px; margin: 0 0 8px; }
section { padding-top: 18px; }
h2 { font-size: 27px; line-height: 1.2; margin: 36px 0 6px; font-weight: 650; display: flex; gap: 12px; align-items: baseline; }
h2 .sn { font: 600 18px var(--sans); color: var(--muted); min-width: 1.2em; }
h3 { font-size: 20.5px; margin: 28px 0 6px; font-weight: 650; }
p { margin: 0 0 14px; hyphens: auto; }
.abstract { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-top: 18px; padding-bottom: 6px; }
.abstract h2 { font: 700 13px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 16px; }
.abstract p { font-size: 17.5px; }
.howto { font: 14.5px/1.5 var(--sans) !important; color: var(--muted); }
.inshort { font: 16px/1.5 var(--sans); color: var(--fg2); border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; margin: 0 0 16px; }
.inshort b { color: var(--fg); }
.proc { padding-left: 1.4em; } .proc li { margin: 4px 0; }
.facts li { margin: 6px 0; }
.eq { font: 17px/1.6 var(--serif); background: var(--surface); border: 1px solid var(--rule2); border-radius: 4px;
  padding: 10px 14px; margin: 6px 0 16px; overflow-x: auto; }
.eq-l { white-space: normal; }
.cmds code { word-break: break-all; }
.files { font: 14px var(--sans); columns: 2 220px; }
.refs li { margin: 6px 0; font-size: 16px; }
.foot { border-top: 1px solid var(--rule); margin-top: 48px; padding-top: 12px; font: 14px var(--sans); color: var(--muted); }
.noscript { font: 15px var(--sans); text-align: center; }

/* defined terms */
.term { text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: 3px; cursor: help; }
.term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#tip { position: fixed; z-index: 40; max-width: min(320px, calc(100vw - 24px)); background: var(--fg); color: var(--bg);
  font: 14px/1.45 var(--sans); padding: 8px 10px; border-radius: 6px; pointer-events: none; box-shadow: 0 4px 18px rgba(0,0,0,.18); }
#tip b { color: inherit; }

/* figures and tables */
figure { margin: 22px 0 26px; padding: 14px 0 0; border-top: 1px solid var(--rule); }
figure.wide { max-width: 100%; }
figure:not(.wide) { max-width: 48rem; }
figcaption { font: 14.5px/1.5 var(--sans); color: var(--fg2); margin-top: 8px; max-width: 52rem; }
figcaption .fnum, caption .fnum { font-weight: 700; color: var(--fg); margin-right: .35em; }
.ctl { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; font: 14.5px var(--sans); margin-bottom: 8px; }
.ctl label { display: inline-flex; gap: 8px; align-items: center; }
.ctl select, .ctl input[type=range] { font: 14px var(--sans); }
.ctl select { background: var(--surface); color: var(--fg); border: 1px solid var(--rule); border-radius: 5px; padding: 3px 6px; }
.ctl input[type=range] { width: min(260px, 50vw); accent-color: var(--accent); }
.ctl output { font-weight: 700; min-width: 5.5em; }
.lnk { font: 600 13.5px var(--sans); border: 1px solid var(--rule); background: var(--surface); color: var(--fg2); border-radius: 5px; padding: 4px 10px; cursor: pointer; }
.lnk:hover { color: var(--fg); border-color: var(--muted); }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--sans); }
.chart text { fill: var(--fg2); font-size: 12px; }
.chart .ax line, .chart .ax path { stroke: var(--rule); }
.chart .grid line { stroke: var(--rule2); }
.chart .lbl { fill: var(--muted); font-size: 11.5px; }
.chart [data-tip] { cursor: pointer; }
.chart-tools { display: flex; justify-content: flex-end; margin-top: 4px; }
.chart-table { margin-top: 8px; }
.readout { font: 15px/1.5 var(--sans); margin: 6px 0 0; color: var(--fg2); min-height: 3em; }
.readout b { color: var(--fg); }
.twocol { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 820px) { .twocol { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.tablewrap { overflow-x: auto; margin: 10px 0 18px; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; font: 14.5px/1.4 var(--sans); min-width: 100%; }
table.narrow { min-width: 0; }
caption { caption-side: top; text-align: left; font: 14.5px/1.45 var(--sans); color: var(--fg2); padding-bottom: 6px; }
th, td { text-align: left; padding: 5px 10px 5px 0; border-bottom: 1px solid var(--rule2); vertical-align: top; }
thead th { border-bottom: 1.5px solid var(--fg2); font-weight: 700; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 10px; }
tbody th { font-weight: 650; white-space: nowrap; }
tr.hl td, tr.hl th { background: var(--mark); }
.qtable td { min-width: 12em; } .claims td { width: 50%; min-width: 14em; }
.sw { display: inline-block; width: .8em; height: .8em; border-radius: 2px; vertical-align: -1px; margin-right: 6px; }
.tag { font: 600 11.5px var(--sans); border-radius: 3px; padding: 0 5px; border: 1px solid currentColor; white-space: nowrap; }
.tag.ieee { color: var(--fg2); } .tag.added { color: var(--accent2); }

details { margin: 12px 0 18px; border: 1px solid var(--rule2); border-radius: 6px; background: var(--soft); padding: 0 14px; }
details > summary { font: 600 14.5px var(--sans); cursor: pointer; padding: 9px 0; color: var(--fg2); list-style-position: outside; }
details[open] > summary { border-bottom: 1px solid var(--rule2); margin-bottom: 10px; }
details p { font-size: 16.5px; }
details .tablewrap { background: var(--surface); padding: 6px 10px; border-radius: 4px; }

/* feeder views */
.view { position: relative; width: 100%; aspect-ratio: 16 / 10; max-height: 70vh; min-height: 280px;
  background: var(--surface); border: 1px solid var(--rule2); border-radius: 6px; overflow: hidden; touch-action: pan-y; }
@media (max-width: 600px) { .view { aspect-ratio: 4 / 5; } }
.view canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
.view .svgfb { position: absolute; inset: 0; width: 100%; height: 100%; }
.view.is3d .svgfb { display: none; }
.view:not(.is3d) canvas, .view:not(.is3d) .labels3d { display: none !important; }
.view .labels3d { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lab3 { position: absolute; transform: translate(-50%, -100%); font: 600 11.5px/1.2 var(--sans); white-space: nowrap;
  background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--fg); border: 1px solid var(--rule);
  border-left: 3px solid var(--c, var(--rule)); padding: 1px 5px; border-radius: 3px; }
.lab3.dev { font-weight: 600; font-size: 10.5px; color: var(--fg2); border-left-width: 1px; }
.lab3.dev.added { color: var(--accent2); border-color: var(--accent2); }
.lab3.off { display: none; }
.vnote { z-index: 2; position: absolute; left: 8px; bottom: 6px; font: 12px var(--sans); color: var(--muted); pointer-events: none; }
.svgfb text { font-family: var(--sans); }
.svgfb .zl { font: 600 12px var(--sans); fill: var(--fg); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.svgfb .dl { font: 600 10px var(--sans); fill: var(--fg2); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.svgfb .dl.added { fill: var(--accent2); }
.svgfb .hit { stroke: transparent; stroke-width: 26; cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font: 13.5px var(--sans); color: var(--fg2); margin: 8px 0 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; }
.legend i.lamp { width: 10px; height: 10px; border-radius: 50%; }
.legend i.ring { background: transparent !important; border: 2px solid var(--accent2); width: 10px; height: 10px; }
.zinfo, .stepinfo { font: 15px/1.5 var(--sans); margin-top: 10px; min-height: 3.2em; }
.zinfo table { min-width: 0; }
.zinfo .hint { color: var(--muted); }

/* stepper */
.stepbtns { display: inline-flex; gap: 6px; align-items: center; }
.stepbtns > button:not(.lnk) { font: 700 16px var(--sans); width: 32px; height: 30px; border: 1px solid var(--rule); background: var(--surface); color: var(--fg); border-radius: 5px; cursor: pointer; }
.stepbtns > button:disabled { opacity: .35; cursor: default; }
#step-count { font: 600 14px var(--sans); min-width: 4.5em; text-align: center; }
.steplist { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; padding: 0; margin: 0 0 10px; font: 13px var(--sans); counter-reset: st; }
.steplist button { font: 600 12.5px var(--sans); border: 1px solid var(--rule); background: var(--surface); color: var(--fg2); border-radius: 14px; padding: 3px 10px; cursor: pointer; }
.steplist button[aria-current="step"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.stepinfo h4 { font: 700 16px var(--sans); margin: 0 0 4px; }
.stepinfo p { margin: 0 0 8px; }
.vbar { display: grid; grid-template-columns: 4.5em minmax(0, 1fr); gap: 4px 10px; align-items: center; margin: 8px 0; max-width: 34rem; }
.vbar svg { width: 100%; height: 34px; display: block; }
.kv { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 4px 0; }
.kv span b { font-variant-numeric: tabular-nums; }
.ok { color: var(--lamp-on); font-weight: 700; } .bad { color: var(--lamp-off); font-weight: 700; }

/* worked example */
.worked { font: 15px/1.5 var(--sans); background: var(--surface); border: 1px solid var(--rule2); border-radius: 6px; padding: 10px 14px; margin: 8px 0 18px; max-width: 52rem; }
.worked h4 { margin: 0 0 6px; font-size: 15.5px; }
.worked table { font-size: 14px; }
.worked tfoot td, .worked tfoot th { border-top: 1.5px solid var(--fg2); font-weight: 700; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  h2 { font-size: 23px; } h3 { font-size: 19px; }
  .bar-in { gap: 8px 12px; } .bar-links { gap: 10px; font-size: 13.5px; }
  .eq { font-size: 15.5px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* print: paper-like, collapsibles open (done in JS), 3D replaced by the 2D drawing */
@media print {
  .bar, .toc, .vnote, .chart-tools, .ctl .lnk, [data-view-toggle], .stepbtns, .skip, #tip, #folds-reshuffle { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .layout { display: block; max-width: none; padding: 0; }
  .view { aspect-ratio: auto; height: 120mm; border-color: #bbb; }
  .view canvas, .view .labels3d { display: none !important; }
  .view .svgfb { display: block !important; }
  figure, table, .eq, .worked { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
  details { background: none; border: 0; padding: 0; }
  details > summary { list-style: none; }
  a { color: inherit; }
}
