:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dddcd7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --blood: #c0392b;
  --blood-2: #e57368;
  --wall: #e9b8a8;
  --wall-stroke: #b9705c;
  --filtrate: #e0a400;
  --capsule: #6c8bb5;
  --g1: #0ca30c; --g2: #7aa81c; --g3a: #d69a00; --g3b: #e2733f; --g4: #d03b3b; --g5: #8e1f2a;
  --band-g1: #e6f4e3; --band-g2: #eef3dc; --band-g3a: #fbf1d6; --band-g3b: #fbe5da; --band-g4: #f8dcdc; --band-g5: #f0d3d6;
  --risk-low: #cfe8c8; --risk-mod: #fbe7a1; --risk-high: #f6c29b; --risk-vhigh: #ee9a9a;
  
  --model-bg: #e6eef9; --model-ink: #1c5cab;
  --cf: #8a8984;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #383835;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e88;
    --accent: #3987e5; --blood: #e0574a; --blood-2: #ef8a80; --wall: #6b3a30; --wall-stroke: #c9806c;
    --filtrate: #f2bc2f; --capsule: #8aa9d6;
    --g1: #2bbf2b; --g2: #9cc63a; --g3a: #e6ae1a; --g3b: #ee8a59; --g4: #e66767; --g5: #c2475a;
    --band-g1: #1d2a1c; --band-g2: #232a19; --band-g3a: #2d2716; --band-g3b: #2f2119; --band-g4: #2f1c1c; --band-g5: #2b1a1e;
    --risk-low: #2b4a27; --risk-mod: #5a4c17; --risk-high: #6a3c1f; --risk-vhigh: #6e2a2a;
    --model-bg: #1d2a3d; --model-ink: #86b6ef; --cf: #8f8e88;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.4; font-size: 15px; }
h1 { font-size: 1.55rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; margin: 0 0 .7rem; }
h3 { font-size: .9rem; margin: 1rem 0 .4rem; color: var(--text-2); }
.sub { margin: 0; color: var(--text-2); font-size: .9rem; max-width: 70ch; }
.top { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-end; flex-wrap: wrap; padding: 1.1rem 1.4rem .6rem; }
.top-right { display: flex; flex-direction: column; align-items: flex-end; gap: .45rem; }
.lang { display: inline-flex; gap: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang .btn { border: 0; border-radius: 0; margin: 0; padding: .3rem .7rem; font-weight: 600; background: var(--surface); }
.lang .btn[aria-pressed="true"] { background: var(--text); color: var(--surface); }
.legend-tags { font-size: .78rem; color: var(--text-2); display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.tag { display: inline-block; font-size: .68rem; font-weight: 600; padding: 1px 6px; border-radius: 999px; vertical-align: 1px; white-space: nowrap; }
.tag-model { background: var(--model-bg); color: var(--model-ink); }
.hint { font-size: .78rem; color: var(--muted); margin: .25rem 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.layout {
  display: grid; gap: 14px; padding: 0 1.4rem 1rem;
  grid-template-columns: 320px minmax(0, 1fr) 340px;
  grid-template-areas:
    "controls schematic explain"
    "controls stats explain"
    "charts charts charts"
    "normals normals normals";
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.controls { grid-area: controls; }
.schematic { grid-area: schematic; }
.explain { grid-area: explain; }
.stats { grid-area: stats; padding: 10px; }
.charts { grid-area: charts; }
.normals { grid-area: normals; }
@media (max-width: 1150px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr);
    grid-template-areas: "controls schematic" "controls stats" "explain explain" "charts charts" "normals normals"; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 .7rem 1rem;
    grid-template-areas: "schematic" "stats" "controls" "explain" "charts" "normals"; }
  .top { padding: .9rem .8rem .5rem; }
}

/* controls */
.btn { font: inherit; font-size: .88rem; padding: .45rem .8rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.btn:hover { border-color: var(--text-2); }
.btn:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; min-width: 8.5rem; }
.btn.small { font-size: .78rem; padding: .3rem .6rem; margin-top: .4rem; }
.btn.preset[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.transport { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; }
.clock { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-2); }
fieldset { border: 0; padding: 0; margin: 0 0 .8rem; }
legend { font-weight: 600; font-size: .85rem; margin-bottom: .35rem; padding: 0; }
.preset-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.preset-row .btn { font-size: .8rem; padding: .35rem .6rem; }
.slider { margin: 0 0 .75rem; }
.slider label { display: flex; justify-content: space-between; gap: .4rem; font-size: .84rem; align-items: baseline; flex-wrap: wrap; }
.slider output { font-variant-numeric: tabular-nums; font-weight: 600; margin-left: auto; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: .25rem 0 0; }
.toggles .switch { display: grid; grid-template-columns: auto 1fr; gap: .5rem; align-items: start; font-size: .88rem; margin: .35rem 0; cursor: pointer; }
.toggles .switch input { margin-top: .1rem; }
.toggles .switch small { color: var(--muted); display: block; }
.toggles .switch.subtle { font-size: .8rem; color: var(--text-2); }
.toggles input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
details.advanced summary { cursor: pointer; font-size: .85rem; font-weight: 600; margin-bottom: .5rem; }

/* schematic */
.glom-host svg { width: 100%; height: auto; display: block; }
.glom-host text { font-size: 13px; fill: var(--text); }
.glom-host .lbl-2 { fill: var(--text-2); font-size: 11.5px; }
.glom-host .lbl-big { font-size: 16px; font-weight: 700; }
.glom-host .lbl-chip { fill: var(--surface); stroke: var(--border); }
.starling { border-top: 1px solid var(--border); margin-top: .4rem; padding-top: .6rem; }
.starling-head { font-size: .84rem; font-weight: 600; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.starling-head code { font-weight: 400; font-size: .8rem; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.starling-bars { margin-top: .4rem; display: grid; gap: 4px; }
.sb-row { display: grid; grid-template-columns: 4.6rem 1fr 5.6rem; gap: .5rem; align-items: center; font-size: .78rem; color: var(--text-2); }
.sb-row > span:last-child { font-variant-numeric: tabular-nums; color: var(--text); text-align: right; }
.sb-track { height: 12px; background: var(--surface-2); border-radius: 4px; display: flex; overflow: hidden; }
.sb { height: 100%; transition: width .15s linear; }
.sb.pgc { background: var(--blood); }
.sb.pbs { background: var(--capsule); border-right: 2px solid var(--surface); }
.sb.pi { background: #9a8fd0; }
.sb.net { background: var(--filtrate); }

/* explain */
.cycle { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.cycle li { position: relative; padding: .45rem .55rem .45rem 2.2rem; margin-bottom: 6px; border-radius: 9px; border: 1px solid var(--border); font-size: .85rem; color: var(--muted); transition: background .2s, color .2s; }
.cycle li::before { counter-increment: step; content: counter(step); position: absolute; left: .55rem; top: .45rem; width: 1.2rem; height: 1.2rem; border-radius: 50%; background: var(--surface-2); color: var(--text-2); font-size: .72rem; font-weight: 700; display: grid; place-items: center; }
.cycle li b { color: var(--text-2); }
.cycle li.on { color: var(--text); background: var(--surface-2); border-color: var(--text-2); }
.cycle li.on b { color: var(--text); }
.cycle li.on::before { background: var(--blood); color: #fff; }
.cycle li.loop { border-style: dashed; }
.cycle li.loop.on { border-color: var(--blood); }
.treat-note { font-size: .83rem; padding: .55rem .65rem; border-radius: 9px; background: var(--model-bg); margin-top: .5rem; }
.treat-note p { margin: .2rem 0; }
.log { list-style: none; margin: 0; padding: 0; font-size: .78rem; max-height: 210px; overflow: auto; }
.log li { padding: .25rem 0; border-bottom: 1px solid var(--border); color: var(--text-2); }
.log li b { color: var(--text); font-variant-numeric: tabular-nums; }
.log li.warn { color: var(--text); border-left: 3px solid var(--g4); padding-left: .4rem; }
.log li.tx { color: var(--text); border-left: 3px solid var(--accent); padding-left: .4rem; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 9px; padding: .45rem .6rem; }
.tile .k { font-size: .72rem; color: var(--text-2); }
.tile .v { font-size: 1.28rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: .72rem; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.tile .d { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stage-chip { display: inline-block; padding: 0 .4rem; border-radius: 6px; color: #fff; }

/* charts */
.chart-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; }
@media (max-width: 1000px) { .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .chart-grid { grid-template-columns: minmax(0, 1fr); } }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: 2px; }
.chart-title { font-size: .84rem; font-weight: 600; }
.chart-value { font-size: .84rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .tick { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .axis-name { fill: var(--text-2); }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .grid line.baseline { stroke: var(--muted); }
.chart line.ref { stroke: var(--text-2); stroke-dasharray: 4 3; }
.chart line.ref.thr { stroke: var(--g4); }
.chart .ref-label { font-size: 9.5px; fill: var(--text-2); }
.chart .ref-label.thr { fill: var(--g4); font-weight: 600; }
.chart .band-label { font-size: 9.5px; fill: var(--text-2); font-weight: 600; }
.chart .line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.dashed { stroke-dasharray: 5 4; stroke-width: 1.6; }
.chart .end-dot { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; }
.chart .hover-dot { stroke: var(--surface); stroke-width: 2; }
.chart .hover-label { font-size: 10.5px; fill: var(--text); font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.line.s-main { stroke: var(--accent); } .end-dot.s-main, .hover-dot.s-main { fill: var(--accent); }
.line.s-cf { stroke: var(--cf); } .hover-dot.cf { fill: var(--cf); }
.line.st-G1 { stroke: var(--g1); } .end-dot.st-G1, .hover-dot.st-G1 { fill: var(--g1); }
.line.st-G2 { stroke: var(--g2); } .end-dot.st-G2, .hover-dot.st-G2 { fill: var(--g2); }
.line.st-G3a { stroke: var(--g3a); } .end-dot.st-G3a, .hover-dot.st-G3a { fill: var(--g3a); }
.line.st-G3b { stroke: var(--g3b); } .end-dot.st-G3b, .hover-dot.st-G3b { fill: var(--g3b); }
.line.st-G4 { stroke: var(--g4); } .end-dot.st-G4, .hover-dot.st-G4 { fill: var(--g4); }
.line.st-G5 { stroke: var(--g5); } .end-dot.st-G5, .hover-dot.st-G5 { fill: var(--g5); }
.band.b-G1 { fill: var(--band-g1); } .band.b-G2 { fill: var(--band-g2); } .band.b-G3a { fill: var(--band-g3a); }
.band.b-G3b { fill: var(--band-g3b); } .band.b-G4 { fill: var(--band-g4); } .band.b-G5 { fill: var(--band-g5); }
.band.b-A1 { fill: var(--band-g1); } .band.b-A2 { fill: var(--band-g3a); } .band.b-A3 { fill: var(--band-g4); }
.band.b-hf { fill: var(--band-g4); }
.chart-legend { font-size: .74rem; color: var(--text-2); margin-top: 2px; display: flex; gap: .8rem; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--accent); vertical-align: middle; margin-right: 4px; }
.chart-legend i.cf { border-top: 2px dashed var(--cf); }

/* kdigo */
.kdigo { border-collapse: separate; border-spacing: 3px; width: 100%; font-size: .78rem; }
.kdigo th { font-weight: 600; text-align: center; padding: 2px; }
.kdigo th small { display: block; font-weight: 400; color: var(--muted); font-size: .66rem; }
.kdigo small.nm { font-size: .62rem; line-height: 1.15; color: var(--text-2); }
.kdigo tbody th small.nm { display: block; margin-left: 0; white-space: normal; max-width: 9.5rem; }
.kdigo tbody th { text-align: left; white-space: nowrap; }
.kdigo tbody th small { display: inline; margin-left: 4px; }
.kdigo td { height: 26px; min-width: 2.6rem; border-radius: 5px; text-align: center; font-size: 1rem; color: var(--text); }
.kdigo td.current { outline: 3px solid var(--text); outline-offset: -1px; font-weight: 700; }
.risk-low { background: var(--risk-low); } .risk-mod { background: var(--risk-mod); }
.risk-high { background: var(--risk-high); } .risk-vhigh { background: var(--risk-vhigh); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-left: 4px; }
.table-view { margin-top: .8rem; font-size: .82rem; }
.table-view summary { cursor: pointer; font-weight: 600; }
.table-view table { border-collapse: collapse; margin-top: .5rem; font-variant-numeric: tabular-nums; width: 100%; }
.table-view th, .table-view td { padding: 3px 8px; border-bottom: 1px solid var(--border); text-align: right; }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-wrap { max-height: 260px; overflow: auto; }

.normals ul { margin: 0; padding-left: 1.1rem; font-size: .88rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .2rem 1.5rem; }
.foot { text-align: center; font-size: .8rem; color: var(--text-2); padding: .4rem 1rem 1.6rem; }

@media (prefers-reduced-motion: reduce) { .sb, .cycle li { transition: none; } }

[hidden] { display: none !important; }

/* ---- Simulario theme: colours and logo only ---- */
:root { --sim-accent: #4B3FE0; --bg: #F5F6FB; --surface: #FFFFFF; --surface-2: #EEF0F7; --border: #E1E3EE; --text: #12142B; --text-2: #5A5F7A; --muted: #7A7F99; --accent: #4B3FE0; --accent-ink: #FFFFFF; --model-bg: #ECEAFE; --model-ink: #3127B8; }
@media (prefers-color-scheme: dark) {
  :root { --sim-accent: #6A60F5; --bg: #0E1024; --surface: #181B33; --surface-2: #20243F; --border: #2A2E4A; --text: #F2F3FA; --text-2: #A9ADC8; --muted: #8A8FAD; --accent: #6A60F5; --accent-ink: #FFFFFF; --model-bg: #231E58; --model-ink: #A59EFF; }
}
.lang .btn[aria-pressed="true"] { background: var(--sim-accent); color: #fff; }
.btn.preset[aria-pressed="true"] { background: var(--sim-accent); color: #fff; border-color: var(--sim-accent); }
.sim-brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; margin: 0 0 6px; }
.sim-brand svg { display: block; flex: none; }
.sim-brand b { font: 700 18px/1 "Space Grotesk", "Segoe UI", system-ui, sans-serif; letter-spacing: -.03em; }
h1 { font-family: "Space Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif; letter-spacing: -.02em; }
