/* sim.css: the shared skeleton of the Physiology Simulator pages (/sim-lung, /sim-vad, ...). Load after tokens.css and
   site.css and before the page's own <style>, so a page can still override a rule of equal weight.
   Layout only; every value comes from tokens.css. One order on every simulator: mode (if any), the main drawing and
   the tiles, Play, the scenario picker, the main sliders, "More controls", then the other drawings. */

/* ---------- Two columns on wide screens: controls, then the drawings ---------- */
.sim { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); align-items: start; }
@media (min-width: 980px) { .sim { grid-template-columns: minmax(0, 320px) minmax(0, 1fr); } }

/* ---------- Controls ---------- */
.ctl { display: grid; gap: var(--space-4); min-width: 0; }
.ctl label { display: grid; gap: 4px; font-size: var(--fs-md); }
.ctl .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ctl .row i { color: var(--muted); font-style: normal; font-size: var(--fs-xs); }
.ctl output { font-family: var(--font-num); font-variant-numeric: var(--num-figures); color: var(--ink); }
.ctl input[type=range] { width: 100%; accent-color: var(--link); min-height: 32px; }
.ctl select { width: 100%; }
.ctl fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.ctl .grp { display: grid; gap: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--line-subtle); }
.ctl .grp > h3 { margin: 0; font-size: var(--fs-sm); color: var(--section-ink); }
.runbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.runbar label { display: inline-grid; }
.runbar select { width: auto; }
.got { font-family: var(--font-num); font-variant-numeric: var(--num-figures); color: var(--muted); font-size: var(--fs-xs); margin: 0; }

/* "More controls": the sliders past the main three or four, closed until asked for. The summary keeps the browser's own
   disclosure marker, so it stays a list item (no flex). */
.ctl details.more { min-width: 0; border-top: 1px solid var(--line-subtle); }
.ctl details.more > summary { cursor: pointer; padding: 7px 0; font-size: var(--fs-md); color: var(--ink); }
.ctl details.more > summary i { color: var(--muted); font-style: normal; font-size: var(--fs-xs); }
.ctl details.more > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.ctl details.more > .morebody { display: grid; gap: var(--space-4); padding-top: var(--space-2); }

/* ---------- Drawings and readouts ---------- */
.simview { display: grid; gap: var(--space-4); min-width: 0; }
.pin { display: grid; gap: var(--space-4); min-width: 0; }
.status { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: var(--fs-xs); color: var(--muted); margin: 0; }
.status span { font-family: var(--font-num); font-variant-numeric: var(--num-figures); }
.screens { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
@media (min-width: 1180px) { .screens.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.screen { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3); min-width: 0; }
.screen figcaption { font-size: var(--fs-sm); color: var(--muted); margin: 0 0 6px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.screen figcaption b { color: var(--ink); font-weight: 600; }
.screen canvas { display: block; width: 100%; border-radius: var(--radius-sm); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 0; padding: 0; list-style: none; font-size: var(--fs-xs); color: var(--muted); }
.heroes { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); margin: 0; }
.hero2 { background: var(--surface); border: 1px solid var(--line); border-top: var(--panel-rule-w, 2px) solid var(--panel-rule); border-radius: var(--radius); padding: var(--space-3) var(--space-4); min-width: 0; }
.hero2 .lab { font-size: var(--fs-sm); color: var(--muted); display: flex; gap: 4px; align-items: center; }
.hero2 .v { font-family: var(--font-num); font-size: var(--fs-hero); font-weight: 500; color: var(--hero-ink); line-height: 1.1; font-variant-numeric: var(--num-figures); display: block; }
.hero2 .v small { font-size: 0.45em; color: var(--muted); }
.hero2 .note { font-size: var(--fs-xs); color: var(--muted); margin: 6px 0 0; }
.kv2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 16px; margin: 0; }
.kv2 div { display: grid; min-width: 0; }
.kv2 dt { font-size: var(--fs-xs); color: var(--muted); }
.kv2 dd { margin: 0; font-family: var(--font-num); font-variant-numeric: var(--num-figures); color: var(--ink); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Phones and narrow screens: one column in the shared order ----------
   Order only; nothing is hidden, and the DOM order and the wide layout are unchanged. The column is a flex box, not a
   grid, because a pinned block can only travel inside its own grid row. Notices come after the controls, so one that
   appears at a threshold never pushes the slider out from under the finger. */
@media screen and (max-width: 979px) {
  .sim { display: flex; flex-direction: column; align-items: stretch; gap: var(--space-4); }
  .ctl, .simview { display: contents; }
  .ctl > * { order: 5; }
  .ctl > .hc-prefill { order: 0; }
  .ctl > .modebox { order: 1; }
  .simview > .pin { order: 2; }
  .ctl > .runbar { order: 3; }
  .ctl > .scen { order: 4; }
  .ctl > details.more { order: 6; }
  .simview > .notice { order: 7; }
  .simview > * { order: 8; }
  .simview > .screens { order: 9; }
}

/* ---------- The main drawing and the tiles stay in view while the controls scroll ----------
   Only where the screen is tall enough to leave room for the controls under it: not on a phone held sideways. */
@media screen and (max-width: 640px) and (min-height: 540px), screen and (min-width: 641px) and (max-width: 979px) and (min-height: 800px) {
  .sim { --pin-clear: 520px; }
  /* Edge to edge, so a slider end or a focus ring passing under it never shows beside it. */
  .pin { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bg); margin-inline: calc(-1 * var(--gutter)); padding: var(--space-2) var(--gutter); border-bottom: 1px solid var(--line-subtle); }
  body:has(#hc-offline) .pin { top: calc(env(safe-area-inset-top, 0px) + 40px); }
  /* A control reached by keyboard scrolls clear of the pinned block: the form's, and any under the other drawings. */
  .ctl :is(input, select, button, summary), .simview > :not(.pin) :is(a, input, select, button, summary) { scroll-margin-top: var(--pin-clear); }
}
@media screen and (max-width: 640px) {
  .sim { --pin-clear: 370px; }
  .pin { gap: var(--space-2); }
  .pin .screen { padding: var(--space-2); }
  .pin .screen figcaption { margin-bottom: 4px; }
  .pin .legend { gap: 2px 10px; margin-top: 4px; }
  .pin .heroes { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
  .pin .hero2 { padding: var(--space-2); overflow-wrap: anywhere; }
  /* A narrow tile's label runs as text, so a unit, a tag or an info button wraps with it instead of leaving the tile. */
  .pin .hero2 .lab { display: block; font-size: var(--fs-xs); }
  .pin .hero2 .v { font-size: var(--fs-2xl); }
  .pin .hero2 .note { margin-top: 2px; }
}

/* ---------- Touch: sliders and the "More controls" bar reach 40px ---------- */
@media (max-width: 640px), (pointer: coarse) {
  .ctl input[type=range] { min-height: 40px; }
  .ctl details.more > summary { padding: 11px 0; }
}
