/* Desktop uses the viewport; narrow screens keep natural document flow. */
:root {
  font:13px/1.4 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  color-scheme:light;
  --bg:#eff4f5; --paper:#fff; --ink:#172d37; --muted:#586d77;
  --line:#d8e2e6; --accent:#007c78; --soft:#e9f5f3;
  --portal:#7953ad; --hepatic:#b65c21; --arterial:#bc4052; --venous:#3979af;
  --baseline:#84929c; --grid:#e8eef0; --cursor:#d34b14;
}
* { box-sizing:border-box; }
body { margin:0; background:var(--bg); color:var(--ink); }
[hidden] { display:none!important; }
button,input,select { font:inherit; }
button,select { border:1px solid var(--line); border-radius:6px; background:var(--paper); color:var(--ink); padding:5px 8px; }
button { cursor:pointer; font-size:12px; font-weight:600; white-space:nowrap; }
button:hover { border-color:var(--accent); background:var(--soft); }
button[aria-pressed=true] { background:var(--accent); color:var(--paper); border-color:var(--accent); }
:focus-visible { outline:3px solid var(--accent); outline-offset:2px; }
h1,h2,h3,p { margin:0; }
h1 { font-size:17px; font-weight:680; letter-spacing:-.025em; }
h2 { font-size:13px; font-weight:650; }
h3 { font-size:12px; font-weight:550; color:var(--muted); }
#app { width:100%; height:100dvh; min-height:560px; display:flex; flex-direction:column; padding:8px; gap:8px; }
#app:fullscreen { background:var(--bg); }
.app-header { display:flex; align-items:center; gap:22px; flex-wrap:wrap; flex-shrink:0; }
.brand { display:flex; align-items:baseline; gap:10px; }
.eyebrow { font-size:10px; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--accent); }
.header-tools { margin-left:auto; display:flex; align-items:center; gap:8px; }
.header-tools label { font-size:11px; color:var(--muted); }
.mode-switch { display:inline-flex; gap:3px; padding:3px; border:1px solid var(--line); border-radius:8px; background:var(--paper); }
.mode-switch button { border-color:transparent; }
.compact button { font-size:10px; padding:3px 5px; }
#workspace { display:grid; grid-template-columns:225px minmax(280px,1fr) minmax(330px,.95fr); grid-template-rows:72px minmax(0,1fr); gap:8px; min-height:0; flex:1; }
.panel { background:var(--paper); border:1px solid var(--line); border-radius:9px; padding:10px; min-width:0; min-height:0; }
.controls { grid-column:1; grid-row:1/3; overflow-y:auto; scrollbar-width:thin; }
.controls>section { padding:0; margin:0; border:0; }
.section-heading { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.section-heading .eyebrow { display:block; }
.section-heading button { font-size:10px; padding:3px 7px; }
#control-method { margin:7px 0; display:block; }
.presets { display:flex; flex-wrap:wrap; gap:4px; margin:8px 0 10px; }
.presets button { font-size:10px; padding:4px 6px; font-weight:500; }
.control-grid { display:grid; gap:8px; }
.control { display:block; min-width:0; }
.control>span { display:flex; justify-content:space-between; gap:6px; font-size:12px; font-weight:550; }
.control output { color:var(--accent); font-weight:650; white-space:nowrap; font-variant-numeric:tabular-nums; }
input[type=range] { display:block; width:100%; height:24px; margin:3px 0 0; accent-color:var(--accent); cursor:pointer; }
.method,.insight { color:var(--muted); font-size:11px; line-height:1.5; }
.method { margin-top:7px; }
.insight { margin:6px 0; }
.controls section+section,.controls details { border-top:1px solid var(--line); padding-top:9px; margin-top:9px; }
.controls .section-heading .eyebrow { display:none; }
.controls .section-heading>div { display:flex; flex-direction:column; }
.controls .section-heading h2 { order:-1; }
#control-method { font-size:9px; white-space:nowrap; margin:3px 0 0; }
summary { cursor:pointer; font-size:11px; font-weight:600; }
details[open]>summary { margin-bottom:10px; }
.heart-knobs { margin:8px 0; }
.case-label { display:block; font-size:11px; }
.case-label select { display:block; width:100%; font-size:11px; margin-top:4px; }
#solver-status { font-size:10px; overflow-wrap:anywhere; }
.display-controls .control { margin-top:10px; }
.metrics { grid-column:2/4; display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:8px; }
.metrics article { padding:7px 10px; background:var(--paper); border:1px solid var(--line); border-radius:9px; min-width:0; }
.metrics h3 { font-size:11px; }
.metrics p { white-space:nowrap; }
.metrics strong { font-size:23px; letter-spacing:-.04em; font-weight:650; font-variant-numeric:tabular-nums; }
.metrics span,.metrics small { font-size:10px; color:var(--muted); }
.metrics small { display:block; font-variant-numeric:tabular-nums; }
.body-panel { grid-column:2; grid-row:2; display:flex; flex-direction:column; gap:5px; overflow:hidden; }
#circulation-schematic { flex:1; min-height:0; }
.core-diagram { display:block; width:100%; height:100%; color:var(--ink); }
.core-diagram text { font-family:inherit; fill:var(--ink); font-size:15px; }
.core-diagram .cd-sub { fill:var(--muted); font-size:12px; }
.cv-body { opacity:.8; }
.cv-leader { stroke:var(--line); stroke-width:1; fill:none; }
.cv-compartment rect { fill:var(--paper); stroke:var(--line); stroke-width:1.2; }
.cv-node-title { font-weight:600; font-size:13px!important; }
.cv-node-value { font-size:16px!important; font-variant-numeric:tabular-nums; }
.cv-edge-track { fill:none; stroke:var(--line); stroke-width:1; stroke-dasharray:3 4; }
.cv-edge { fill:none; stroke:var(--cv-color); stroke-linejoin:round; stroke-linecap:round; }
.cv-arterial { --cv-color:var(--arterial); }
.cv-venous,.cv-pulmonary { --cv-color:var(--venous); }
.cv-portal { --cv-color:var(--portal); }
.cv-hepatic { --cv-color:var(--hepatic); }
.cv-arrow { fill:var(--cv-color); stroke:none; }
.cv-flow-value { font-variant-numeric:tabular-nums; }
.cv-label { font-size:13px!important; font-weight:600; }
.cv-width-legend line { stroke:var(--muted); stroke-linecap:round; }
.cv-width-legend text { font-size:11px; fill:var(--muted); }
.body-legend,.legend { display:flex; justify-content:center; align-items:center; flex-wrap:wrap; gap:6px 12px; font-size:10px; color:var(--muted); }
.body-legend span:before,.legend span:before { content:""; display:inline-block; width:13px; height:3px; vertical-align:middle; margin-right:4px; background:var(--accent); }
.body-legend span:last-child:before,.cursor-key:before { display:none!important; }
.arterial-key:before { background:var(--arterial)!important; }
.venous-key:before { background:var(--venous)!important; }
.portal-key:before { background:var(--portal)!important; }
.hepatic-key:before { background:var(--hepatic)!important; }
.baseline-key:before { background:repeating-linear-gradient(to right,var(--baseline) 0 4px,transparent 4px 6px)!important; }
.cursor-key { color:var(--cursor); }
.attribution { font-size:9px; text-align:center; color:var(--muted); }
a { color:var(--accent); }
.playback { display:flex; align-items:center; gap:10px; padding:7px; background:var(--bg); border-radius:6px; }
.playback button { min-width:48px; }
.timeline { display:grid; grid-template-columns:1fr auto; gap:0 8px; font-size:10px; color:var(--muted); flex:1; min-width:0; }
.timeline input { grid-row:2; grid-column:1/3; }
.timeline output { grid-row:1; grid-column:2; font-size:12px; font-variant-numeric:tabular-nums; color:var(--cursor); font-weight:700; }
.speed-label { font-size:10px; }
.speed-label select { display:block; padding:3px; font-size:11px; }
.results { grid-column:3; grid-row:2; display:flex; flex-direction:column; overflow:hidden; }
.results>.panel { flex:1; display:flex; flex-direction:column; border:0; padding:0; }
.plot-toolbar { display:flex; align-items:center; justify-content:space-between; gap:6px; flex-wrap:wrap; }
.chart-grid { flex:1; min-height:0; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); grid-template-rows:repeat(2,minmax(0,1fr)); gap:12px 8px; margin:8px 0; }
.chart-grid article { display:flex; flex-direction:column; min-height:0; min-width:0; }
.chart-grid h3 { font-size:11px; color:var(--ink); }
.chart { width:100%; min-height:0; flex:1; position:relative; }
.chart svg { display:block; width:100%; height:100%; overflow:visible; touch-action:none; }
.chart text { font-family:inherit; fill:var(--muted); font-size:10px; }
.chart .axis-label { font-size:10px; }
.chart .grid { stroke:var(--grid); stroke-width:1; }
.chart .curve { fill:none; stroke-width:1.8; stroke-linejoin:round; stroke-linecap:round; }
.chart .inspection-band { fill:var(--cursor); opacity:.09; }
.chart .inspection-line { stroke:var(--cursor); stroke-width:1.7; }
.chart .inspection-halo { fill:var(--cursor); opacity:.2; }
.chart .inspection-point { fill:var(--cursor); stroke:var(--paper); stroke-width:2.5; }
.chart .inspection-label { fill:var(--cursor); font-size:11px; font-weight:700; paint-order:stroke; stroke:var(--paper); stroke-width:4; stroke-linejoin:round; }
.chart .inspection-hit { fill:transparent; cursor:crosshair; }
.table-scroll { overflow:auto; max-height:300px; }
table { font-size:10px; border-collapse:collapse; width:100%; white-space:nowrap; }
td,th { padding:5px; text-align:right; border-bottom:1px solid var(--line); }
td:first-child,th:first-child { text-align:left; }
.notice { padding:12px; background:var(--paper); border:1px solid var(--line); border-radius:8px; }
@media(min-width:1650px) {
  #workspace { grid-template-columns:250px minmax(400px,1.1fr) minmax(500px,1fr); }
  .chart-grid h3 { font-size:13px; }
  .metrics strong { font-size:25px; }
}
@media(max-width:1100px) {
  #workspace { grid-template-columns:205px minmax(270px,1fr) minmax(290px,1fr); }
  .brand .eyebrow { display:none; }
  .app-header { gap:10px; }
  h1 { font-size:15px; }
  .chart-grid { grid-template-columns:1fr; grid-template-rows:repeat(4,minmax(115px,1fr)); overflow-y:auto; }
  .chart-grid article { min-height:115px; }
  .header-tools { gap:5px; }
  .header-tools label { font-size:0; }
  .header-tools select { font-size:12px; }
}
@media(max-width:850px) {
  #app { height:auto; min-height:100dvh; padding:8px; }
  .app-header { gap:8px; }
  .brand { flex:1; }
  .header-tools { margin-left:0; }
  .header-tools label { font-size:11px; }
  #workspace { grid-template-columns:190px minmax(0,1fr); grid-template-rows:76px 620px auto; }
  .controls { grid-row:2/4; }
  .metrics { grid-column:1/3; }
  .body-panel { grid-column:2; grid-row:2; }
  #circulation-schematic { overflow:auto; scrollbar-width:thin; }
  .core-diagram { min-width:560px; }
  .body-legend:after { content:"Pan the body to read all labels"; font-size:9px; }
  .results { grid-column:2; grid-row:3; min-height:650px; }
  .chart-grid { grid-template-columns:repeat(2,minmax(0,1fr)); grid-template-rows:repeat(2,240px); overflow:visible; }
  #pressure-results { min-height:390px; }
}
@media(max-width:560px) {
  .brand { width:100%; flex:auto; }
  .brand .eyebrow { display:block; }
  h1 { font-size:16px; }
  .header-tools { margin-left:auto; }
  .header-tools label { font-size:0; }
  #fullscreen { display:none; }
  #workspace { display:flex; flex-direction:column; }
  .metrics { order:0; grid-template-columns:repeat(2,minmax(0,1fr)); }
  .controls { order:1; overflow:visible; }
  .body-panel { order:2; height:630px; flex:none; }
  .results { order:3; min-height:670px; }
  .chart-grid { grid-template-rows:repeat(2,230px); }
  .control-grid { grid-template-columns:1fr 1fr; gap:8px 18px; }
  .presets { margin:8px 0; }
  .controls details,.controls section+section { margin-top:9px; padding-top:9px; }
  .metrics article { padding:7px 10px; }
  .metrics strong { font-size:22px; }
}
:root[data-theme=dark] {
  color-scheme:dark; --bg:#111c23; --paper:#192730; --ink:#e0ebef; --muted:#a5b7c1;
  --line:#34454e; --accent:#65cbc1; --soft:#203d3d; --portal:#bc9be8;
  --hepatic:#eda768; --arterial:#fa7b89; --venous:#7ab5e6; --baseline:#7f929f;
  --grid:#2a3b45; --cursor:#ffb55e;
}
:root[data-theme=dark] .cv-body { opacity:.85; }
@media(prefers-reduced-motion:reduce) { * { scroll-behavior:auto!important; } }
