:root {
  --bg: #0b0f14; --panel: #121923; --line: #223041; --text: #dfe8f1; --dim: #8ea0b4;
  --p: #e69f00; --f: #56b4e9; --v: #009e73; --warn: #d55e00; --ok: #3ddc97; --acc: #cc79a7;
  --ink-on-acc: #0b0f14;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
header { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); }
h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }
h2 { font-size: 16px; margin: 0 0 8px; } h3 { font-size: 14px; margin: 14px 0 6px; color: var(--dim); text-transform: uppercase; letter-spacing: .6px; }
nav { display: flex; gap: 4px; }
nav button { background: transparent; color: var(--dim); border: 1px solid transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; font: inherit; }
nav button[aria-selected="true"] { color: var(--text); border-color: var(--line); background: var(--panel); }
.units { margin-left: auto; display: flex; gap: 12px; color: var(--dim); }
select, input, button { font: inherit; color: var(--text); background: #0e141c; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
button { cursor: pointer; } button:hover:not(:disabled) { border-color: var(--f); } button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--f); outline-offset: 2px; }
.banner { background: #2a2110; color: #f0d58a; padding: 4px 16px; font-size: 12px; border-bottom: 1px solid #4a3a14; }
main { padding: 12px 16px 40px; }
.grid { display: grid; grid-template-columns: 290px minmax(0, 1fr) 330px; gap: 12px; align-items: start; }
@media (max-width: 1100px) { .grid { grid-template-columns: 270px minmax(0, 1fr); } #right { grid-column: 1 / -1; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; margin: 6px 0; }
.row label { color: var(--dim); } .row output { font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.row input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--f); padding: 0; }
.row select { grid-column: 1 / -1; width: 100%; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.btns button.primary { background: var(--f); color: var(--ink-on-acc); border-color: var(--f); font-weight: 600; }
.btns button.on { background: var(--acc); color: var(--ink-on-acc); }
.monitor { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; }
.tile { background: #000; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.tile .n { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.tile .v { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .s { font-size: 12px; color: var(--dim); }
.tile.hr .v { color: #3ddc97; } .tile.bp .v { color: #ff6b6b; } .tile.sp .v { color: #56b4e9; } .tile.rr .v { color: #f0d58a; } .tile.co .v { color: #fff; } .tile.tp .v { color: #cfd8e3; }
.tile.alarm { border-color: var(--warn); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { background: #3a1306; } }
@media (prefers-reduced-motion: reduce) { .tile.alarm { animation: none; background: #3a1306; } }
.alarms { min-height: 22px; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.alarms span { background: #3a1306; color: #ffb59a; border: 1px solid var(--warn); padding: 1px 8px; border-radius: 10px; font-size: 12px; }
.wavewrap { position: relative; background: #000; border: 1px solid var(--line); border-radius: 8px; }
#wave { width: 100%; height: 380px; display: block; }
.ffnote { position: absolute; inset: 0; display: grid; place-items: center; background: #000c; color: var(--dim); }
.legend { list-style: none; display: flex; gap: 14px; margin: 0; padding: 4px 10px; font-size: 12px; }
.legend li::before { content: ""; display: inline-block; width: 18px; height: 3px; margin-right: 6px; vertical-align: middle; }
.lp::before { background: var(--p); } .lf::before { background: var(--f); } .lv::before { background: var(--v); }
.loophead { display: flex; gap: 6px; margin-bottom: 6px; } .loophead select { flex: 1; }
#loop { width: 100%; height: 240px; background: #000; border: 1px solid var(--line); border-radius: 6px; display: block; }
.meas { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.meas td { padding: 2px 4px; border-bottom: 1px solid var(--line); } .meas td:last-child { text-align: right; font-weight: 600; }
.meas td small { color: var(--dim); font-weight: 400; }
.chk { display: flex; gap: 6px; align-items: center; margin-top: 10px; color: var(--dim); }
.phys { margin-top: 8px; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.phys .bar { height: 8px; background: var(--line); border-radius: 4px; margin: 2px 0 6px; overflow: hidden; } .phys .bar i { display: block; height: 100%; background: var(--f); }
.scbar { background: var(--panel); border: 1px solid var(--acc); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.scbar .goals { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; } .goal { padding: 2px 10px; border-radius: 12px; border: 1px solid var(--line); font-size: 12px; }
.goal.ok { border-color: var(--ok); color: var(--ok); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; cursor: pointer; text-align: left; color: inherit; }
.card:hover { border-color: var(--f); } .card h3 { margin: 0 0 4px; color: var(--text); text-transform: none; font-size: 15px; letter-spacing: 0; }
.stars { color: var(--p); letter-spacing: 2px; }
.detail { max-width: 860px; } .detail .panel { margin: 10px 0; }
.opt { display: block; width: 100%; text-align: left; margin: 4px 0; padding: 8px 10px; }
.opt.right { border-color: var(--ok); } .opt.wrong { border-color: var(--warn); }
.why { color: var(--dim); font-size: 13px; margin: 0 0 6px 10px; }
.prose { max-width: 820px; } .prose code { background: #0e141c; padding: 1px 4px; border-radius: 4px; } .prose table { border-collapse: collapse; } .prose td, .prose th { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; max-width: 760px; width: 94%; }
dialog::backdrop { background: #000a; }
table.abg { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; } table.abg th, table.abg td { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: right; } table.abg th:first-child, table.abg td:first-child { text-align: left; }
table.abg .lo { color: #7db8ff; } table.abg .hi { color: #ffb59a; }
.muted { color: var(--dim); }

/* ---- ventilator-screen layout ---- */
.screen { display: grid; grid-template-columns: 170px minmax(0, 1fr) 128px; gap: 6px; align-items: start; background: #05080c; border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.lcol { display: grid; gap: 4px; }
.num { display: grid; grid-template-columns: 34px 1fr; background: #000; border: 1px solid #2a3a4c; border-radius: 4px; min-height: 66px; }
.num .set { font-size: 12px; color: var(--dim); padding: 4px 2px 4px 6px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.num .big { text-align: right; padding: 0 8px 2px 0; } .num .big b { display: block; font-size: 40px; line-height: 1.05; font-weight: 600; font-variant-numeric: tabular-nums; }
.num .big span { font-size: 11px; color: var(--dim); }
.num.alarm { border-color: var(--warn); animation: blink 1s steps(2) infinite; }
.mid { position: relative; display: grid; gap: 6px; min-width: 0; }
.mid #wave { height: 300px; }
.lower { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.pane { background: linear-gradient(#143e5c, #0c2a42); border: 1px solid #2f6f9a; border-radius: 6px; padding: 4px; min-width: 0; }
.pane h4 { margin: 0 0 4px; font-size: 12px; font-weight: 600; color: #cfe8ff; display: flex; justify-content: space-between; align-items: center; }
.pane h4 button { font-size: 11px; padding: 0 6px; }
.pane canvas { width: 100%; height: 220px; background: #02070b; border-radius: 4px; display: block; }
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 4px; background: linear-gradient(#143e5c, #0c2a42); border: 1px solid #2f6f9a; border-radius: 6px; padding: 6px; }
.strip .s { text-align: center; } .strip .s b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; } .strip .s span { font-size: 11px; color: #9fcbea; }
.rcol { display: grid; gap: 6px; }
.rbtn { padding: 10px 6px; text-align: center; background: #101820; border: 1px solid #2a3a4c; } .rbtn small { display: block; color: var(--dim); font-size: 10px; }
.rbtn.hl { border-color: #d6c14a; }
.dials { display: grid; gap: 6px; justify-items: center; }
.dial { width: 84px; height: 84px; border-radius: 50%; border: 3px solid #e8eef5; background: #05080c; color: var(--text); display: grid; place-items: center; padding: 0; line-height: 1.05; }
.dial b { font-size: 24px; font-variant-numeric: tabular-nums; } .dial small { font-size: 10px; color: var(--dim); display: block; text-align: center; }
.qb { display: grid; gap: 4px; } .qb button { padding: 4px; font-size: 12px; } .qb .primary { background: var(--f); color: var(--ink-on-acc); border-color: var(--f); font-weight: 600; }
.bbar { display: flex; gap: 2px; margin: 6px 0; } .bbar button { flex: 1; padding: 8px; border-radius: 0; background: #0c1219; } .bbar button.on { background: #1d2c3d; border-color: var(--f); }
.drawer { position: absolute; left: 0; right: 0; top: 0; z-index: 5; max-height: 640px; overflow: auto; background: #0e151d; border: 1px solid var(--f); border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 30px #000a; }
.dhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.drawer .row { max-width: 520px; } .modebtn { display: block; width: 100%; text-align: left; margin: 4px 0; padding: 8px 10px; } .modebtn.on { border-color: var(--ok); }
.under { margin-top: 6px; } .two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; } @media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.toast { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 6px; z-index: 20; } .toast span { background: #10304a; border: 1px solid var(--f); color: #cfe8ff; padding: 6px 12px; border-radius: 8px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; } .gallery figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; } .gallery p { font-size: 13px; color: var(--dim); margin: 6px 0 0; }
.gcanvas { width: 100%; height: 190px; background: #000; border-radius: 4px; display: block; margin-top: 4px; }
.prose h3 { margin-top: 22px; color: var(--text); font-size: 16px; text-transform: none; letter-spacing: 0; } .prose a { color: var(--f); }
@media (max-width: 1000px) { .screen { grid-template-columns: 140px minmax(0, 1fr); } .rcol { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); } .lower { grid-template-columns: 1fr; } }

.legend .lt::before { width: 0; height: 0; background: none; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid var(--acc); }

.wavebar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 4px 8px; font-size: 12px; color: var(--dim); border-bottom: 1px solid var(--line); }
.wavebar button { padding: 1px 8px; } .wavebar input[type=range] { width: 90px; vertical-align: middle; padding: 0; }
.wavewrap:fullscreen { background: #000; display: flex; flex-direction: column; } .wavewrap:fullscreen #wave { height: auto; flex: 1; }
.ex { background: #0c1219; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 6px 0; } .ex h4 { margin: 0 0 4px; } .ex p { margin: 4px 0; font-size: 13px; color: var(--dim); }
body.learner [data-d=patient], body.learner [data-d=examples], body.learner #physics, body.learner .chk { display: none; }
body.hidep #meas, body.hidep .num.pk .big b { visibility: hidden; }

.hdrlink { color: var(--f); font-size: 13px; align-self: center; margin-left: 8px; }
.btnlink { display: inline-block; padding: 6px 14px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); text-decoration: none; background: #0e141c; } .btnlink.primary { background: var(--f); color: var(--ink-on-acc); border-color: var(--f); font-weight: 600; }
.cite { background: #0e141c; border: 1px solid var(--line); border-radius: 6px; padding: 8px; white-space: pre-wrap; word-break: break-word; font-size: 12px; margin: 4px 0; }

/* ---- fit-to-viewport layout (no page scroll on the simulator) ---- */
main { padding: 6px 12px 6px; }
#tab-sim:not([hidden]) { display: flex; flex-direction: column; }   /* height is set from JS (layout()) */
.screen { flex: 1; min-height: 0; align-items: stretch; }
.lcol { height: 100%; grid-template-rows: repeat(6, minmax(0, 1fr)); gap: 3px; min-height: 0; }
.num { min-height: 0; }
.num .big b { font-size: clamp(22px, 4.6vh, 40px); } .num .big span { font-size: clamp(9px, 1.3vh, 11px); }
.mid { display: flex; flex-direction: column; gap: 5px; min-width: 0; min-height: 0; height: 100%; }
.wavewrap { flex: 1.1; min-height: 120px; display: flex; flex-direction: column; }
.wavewrap #wave { flex: 1; min-height: 0; height: auto; }
.lower { flex: 1; min-height: 130px; grid-template-rows: minmax(0, 1fr); }
.pane { display: flex; flex-direction: column; min-height: 0; }
.pane canvas { flex: 1; min-height: 0; height: auto; }
.strip { padding: 3px 6px; } .strip .s b { font-size: clamp(15px, 2.6vh, 22px); }
.alarms { position: absolute; right: 8px; top: 30px; margin: 0; min-height: 0; z-index: 2; pointer-events: none; }
.rcol { align-content: stretch; grid-auto-rows: min-content; gap: 4px; }
.dial { width: clamp(58px, 11vh, 84px); height: clamp(58px, 11vh, 84px); } .dial b { font-size: clamp(16px, 3vh, 24px); }
.rbtn { padding: clamp(4px, 1.1vh, 10px) 6px; }
.drawer { max-height: 100%; }
.bbar { margin: 4px 0 0; } .bbar button { padding: 6px; }
.pbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 5px 10px; margin-bottom: 5px; background: #0f1a26; border: 1px solid #2f6f9a; border-radius: 8px; font-size: 13px; }
.pbar label { color: var(--dim); display: inline-flex; gap: 5px; align-items: center; } .pbar input[type=number] { width: 62px; } .pbar .grow { flex: 1; }
.pbar .pbw { color: #cfe8ff; font-variant-numeric: tabular-nums; }
.tip { display: flex; gap: 10px; align-items: center; padding: 5px 10px; margin-bottom: 5px; background: #10304a; border: 1px solid var(--f); border-radius: 8px; font-size: 12.5px; color: #cfe8ff; } .tip span { flex: 1; } .tip button { white-space: nowrap; }
.scbar { margin-bottom: 5px; padding: 5px 10px; font-size: 12.5px; max-height: 18vh; overflow: auto; }
#d-meas .meas td { padding: 1px 4px; }
body.learner #patientbar { display: none; }
/* setup dialog */
.lungcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin: 8px 0; }
.lungcard { text-align: left; padding: 10px; border-radius: 8px; border: 2px solid var(--line); background: #0c1219; color: var(--text); }
.lungcard b { display: block; margin-bottom: 2px; } .lungcard span { font-size: 12px; color: var(--dim); }
.lungcard[aria-checked="true"] { border-color: var(--f); background: #10304a; }
.setuprow { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 8px 0; } .setuprow label { display: grid; gap: 3px; color: var(--dim); font-size: 12px; } .setuprow input, .setuprow select { width: 100%; }
.small { font-size: 11px; }
@media (max-height: 640px) { .num .big b { font-size: 22px; } }

.quick { background: #10304a; border: 1px solid var(--f); border-radius: 8px; padding: 8px 14px; margin: 10px 0; } .quick ol { margin: 6px 0 2px 18px; padding: 0; }

/* size to the space actually available (--sh is set in layout()) */
.screen { grid-template-rows: minmax(0, 1fr); overflow: hidden; }
.rcol, .lcol { min-height: 0; overflow: hidden; }
.num .big b { font-size: clamp(20px, calc(var(--sh, 600px) * 0.07), 40px); }
.dial { width: clamp(44px, calc(var(--sh, 600px) * 0.135), 84px); height: clamp(44px, calc(var(--sh, 600px) * 0.135), 84px); }
.dial b { font-size: clamp(14px, calc(var(--sh, 600px) * 0.04), 24px); } .dial small { font-size: clamp(8px, calc(var(--sh, 600px) * 0.016), 10px); }
.rbtn { padding: clamp(3px, calc(var(--sh, 600px) * 0.012), 10px) 6px; font-size: clamp(11px, calc(var(--sh, 600px) * 0.024), 14px); }
.rcol .qb button { padding: clamp(2px, calc(var(--sh, 600px) * 0.008), 6px); }

/* guided tour */
.tour-mask { position: fixed; inset: 0; z-index: 60; }
.tour-hole { position: fixed; z-index: 61; border: 2px solid var(--f); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(3, 7, 12, 0.72); pointer-events: none; }
.tour-card { position: fixed; z-index: 62; background: #0e151d; border: 1px solid var(--f); border-radius: 10px; padding: 12px 14px; box-shadow: 0 10px 40px #000a; }
.tour-card h3 { margin: 2px 0 6px; font-size: 15px; color: var(--text); text-transform: none; letter-spacing: 0; } .tour-card p { margin: 0 0 10px; font-size: 13px; line-height: 1.45; color: #cfd8e3; }
.tour-n { font-size: 11px; color: var(--dim); } .tour-btns { display: flex; gap: 6px; align-items: center; } .tour-btns .grow { flex: 1; } .tour-skip { border-color: transparent; background: transparent; color: var(--dim); }
.tour-btns .primary { background: var(--f); color: var(--ink-on-acc); border-color: var(--f); font-weight: 600; }

/* Boba, the assistant dog */
.boba { position: fixed; right: 14px; bottom: 10px; z-index: 40; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none; }
.boba > * { pointer-events: auto; }
.boba-dog { position: relative; width: 150px; height: 150px; padding: 0; border: 0; background: transparent; cursor: pointer; border-radius: 50%; filter: drop-shadow(0 4px 6px #000a); transform-origin: 50% 90%; animation: boba-bob 3.2s ease-in-out infinite; }
.boba-dog img { width: 100%; height: 100%; image-rendering: pixelated; display: block; user-select: none; }
.boba-dog:hover { filter: drop-shadow(0 4px 8px #000) brightness(1.08); }
.boba-bubble { position: relative; max-width: 290px; background: #f6f9fc; color: #14202c; border-radius: 14px 14px 4px 14px; padding: 10px 12px 8px; font-size: 13px; line-height: 1.4; box-shadow: 0 6px 20px #000a; }
.boba-bubble::after { content: ""; position: absolute; right: 28px; bottom: -8px; border: 8px solid transparent; border-top-color: #f6f9fc; border-bottom: 0; }
.boba-text { padding-right: 14px; } .boba-x { position: absolute; top: 2px; right: 4px; border: 0; background: transparent; color: #5b6b7b; padding: 2px 6px; }
.boba-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.boba-btns button { font-size: 11.5px; padding: 2px 8px; background: #e3ebf3; color: #14202c; border-color: #c4d2e0; } .boba-btns .primary { background: var(--f); border-color: var(--f); font-weight: 600; }
.boba-zzz { position: absolute; top: -4px; right: -2px; font-size: 11px; color: #cfe8ff; opacity: 0; letter-spacing: 2px; }
.boba-dog.nap { animation: none; opacity: .8; transform: translateY(6px) scale(.95); } .boba-dog.nap .boba-zzz { opacity: 1; animation: boba-zzz 2s ease-in-out infinite; }
.boba-dog.wag { animation: boba-wag .9s ease-in-out; } .boba-dog.hop { animation: boba-hop .5s ease-out; } .boba-dog.zoom { animation: boba-zoom 1.4s ease-in-out; }
@keyframes boba-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes boba-wag { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-6deg); } 40% { transform: rotate(6deg); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(4deg); } }
@keyframes boba-hop { 0% { transform: translateY(0); } 40% { transform: translateY(-16px); } 100% { transform: translateY(0); } }
@keyframes boba-zoom { 0% { transform: translateX(0); } 30% { transform: translateX(-240px) scaleX(-1); } 60% { transform: translateX(-120px) scaleX(1); } 100% { transform: translateX(0); } }
@keyframes boba-zzz { 0%, 100% { transform: translateY(0); opacity: .9; } 50% { transform: translateY(-6px); opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .boba-dog, .boba-dog.wag, .boba-dog.hop, .boba-dog.zoom, .boba-dog.nap .boba-zzz { animation: none; } }
.bbar { margin-right: 108px; }
@media (max-width: 700px) { .boba-dog { width: 100px; height: 100px; } .boba-bubble { max-width: 230px; } }
.headshot { float: right; width: 140px; height: 140px; object-fit: cover; object-position: 50% 25%; border-radius: 50%; border: 2px solid var(--line); margin: 0 0 8px 16px; }
