/* CardioVerse 3D. Tokens follow DESIGN.md: a dark clinical console,
   crimson for arterial / alerts, venous cyan for navigation and selection,
   sinus green for physiology. */
:root {
  --bg: #0b0f17; --s1: #121824; --s2: #1b2436; --s3: #243047; --s4: #2c3a56;
  --line: #1e293b; --line-2: #334155;
  --text: #f1f5f9; --text-2: #a7b4c8; --text-3: #6b7a93;
  --red: #e63946; --red-2: #ff6b6b; --red-bg: rgba(230,57,70,.12);
  --cyan: #00b4d8; --cyan-2: #4cd6fb; --cyan-bg: rgba(0,180,216,.12);
  --green: #10b981; --green-2: #34e39b; --green-bg: rgba(16,185,129,.12);
  --amber: #f5b942; --amber-bg: rgba(245,185,66,.12); --violet: #a78bfa;
  --r: 4px; --r-lg: 8px; --r-xl: 12px;
  --side: 248px; --top: 56px;
  --f-head: 'Space Grotesk', 'Noto Sans Hebrew', system-ui, sans-serif;
  --f-body: 'Noto Sans Hebrew', 'Noto Sans', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.55 var(--f-body); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
[hidden] { display: none !important; }
a { color: var(--cyan-2); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--f-head); margin: 0; line-height: 1.25; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--text-2); } .sm { font-size: 12px; }
.ms { font-family: 'Material Symbols Outlined'; font-weight: normal; font-style: normal; font-size: 20px; line-height: 1; letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; direction: ltr; -webkit-font-feature-settings: 'liga'; font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased; font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24; user-select: none; }
.skip { position: absolute; top: -40px; inset-inline-start: 8px; background: var(--cyan); color: #001; padding: 6px 10px; border-radius: var(--r); z-index: 100; }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--cyan-2); outline-offset: 2px; }
::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-thumb { background: var(--s3); border-radius: 8px; } ::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------ sidebar */
.sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--side); background: #0a0e16; border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; z-index: 60; padding: 14px 10px; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px; }
.brand-mark { width: 36px; height: 36px; border-radius: var(--r-lg); background: var(--s2); border: 1px solid rgba(230,57,70,.35); display: grid; place-items: center; color: var(--red-2); }
.brand-name { font: 700 15px var(--f-head); }
.brand-sub { font: 500 10px var(--f-mono); color: var(--cyan-2); letter-spacing: .08em; }
.brand .icon-btn { margin-inline-start: auto; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav-link-sm { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-lg); color: var(--text-2); font-size: 13.5px; border-inline-end: 2px solid transparent; transition: background .15s, color .15s; }
.nav a:hover, .nav-link-sm:hover { background: var(--s1); color: var(--text); }
.nav a.active, .nav-link-sm.active { background: var(--s2); color: var(--red-2); font-weight: 600; border-inline-end-color: var(--red); }
.nav a.active .ms { color: var(--cyan-2); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.progress-card { display: block; padding: 10px 12px; border-radius: var(--r-lg); background: var(--s1); border: 1px solid var(--line); color: var(--text-2); font-size: 12px; }
.progress-card .row { display: flex; justify-content: space-between; margin-bottom: 6px; }
.progress-card b { color: var(--cyan-2); }
.bar { height: 6px; background: var(--s3); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--cyan-2)); border-radius: 6px; transition: width .5s; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; }

/* ------------------------------------------------ top bar */
.topbar { position: fixed; top: 0; inset-inline-start: var(--side); inset-inline-end: 0; height: var(--top); display: flex; align-items: center; gap: 16px; padding: 0 18px; background: rgba(11,15,23,.88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); z-index: 50; }
.crumbs { font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.crumbs b { color: var(--red-2); } .crumbs .sep { opacity: .4; margin: 0 6px; }
.search { position: relative; flex: 1; max-width: 460px; display: flex; align-items: center; gap: 8px; padding: 0 10px; height: 36px; border-radius: var(--r-lg); background: var(--s1); border: 1px solid var(--line-2); transition: border-color .15s; }
.search:focus-within { border-color: var(--cyan); }
.search .ms { color: var(--text-3); font-size: 19px; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 13px; }
.search input::placeholder { color: var(--text-3); }
.search kbd { font: 11px var(--f-mono); color: var(--text-3); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 5px; }
.search-results { position: absolute; top: calc(100% + 6px); inset-inline: 0; background: var(--s2); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: 0 18px 40px rgba(0,0,0,.45); max-height: 60vh; overflow: auto; padding: 4px; z-index: 70; }
.search-results .res { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; padding: 8px 10px; border: 0; border-radius: var(--r); background: none; }
.search-results .res[aria-selected="true"], .search-results .res:hover { background: var(--s3); }
.search-results .res .k { font-size: 10px; color: var(--text-3); margin-inline-start: auto; font-family: var(--f-mono); }
.search-results .res small { color: var(--text-2); display: block; font-size: 11.5px; }
.search-results .empty { padding: 12px; color: var(--text-2); }
.top-actions { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r); background: var(--s1); border: 1px solid var(--line-2); color: var(--text-2); font: 500 11.5px var(--f-mono); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.chip.toggle[aria-pressed="true"] { color: var(--green-2); border-color: rgba(52,227,155,.4); }
.chip.toggle[aria-pressed="true"] .dot { background: var(--green-2); box-shadow: 0 0 8px var(--green-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--red-bg); color: var(--red-2); border: 1px solid rgba(230,57,70,.4); display: grid; place-items: center; }
.profile { position: relative; }
.profile-pop { inset-inline-end: 0; top: calc(100% + 8px); width: 260px; }
.profile-stats { font-size: 12px; color: var(--text-2); margin: 8px 0; }

/* ------------------------------------------------ layout */
main { margin-inline-start: var(--side); padding: calc(var(--top) + 16px) 18px 18px; min-height: 100vh; outline: none; }
.page-head { margin-bottom: 16px; }
.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head p { margin: 6px 0 0; color: var(--text-2); max-width: 760px; }
.card { background: rgba(18,24,36,.92); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }

/* ------------------------------------------------ controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r-lg); background: var(--s2); border: 1px solid var(--line-2); color: var(--text); font-weight: 600; font-size: 13px; transition: background .15s, border-color .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover { background: var(--s3); border-color: var(--cyan); }
.btn.primary { background: var(--red); border-color: var(--red-2); color: #fff; }
.btn.primary:hover { box-shadow: 0 0 16px rgba(230,57,70,.45); background: #ee4653; }
.btn.primary[aria-pressed="true"] { background: var(--s2); border-color: var(--red); color: var(--red-2); }
.btn.ghost { background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn .ms { font-size: 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: var(--r-lg); border: 1px solid transparent; background: none; color: var(--text-2); }
.icon-btn:hover { background: var(--s2); color: var(--text); }
.tool { display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 9px; border-radius: var(--r); background: rgba(27,36,54,.92); border: 1px solid var(--line-2); color: var(--text); font-size: 12.5px; }
.tool:hover { border-color: var(--cyan); }
.tool[aria-pressed="true"], .tool[aria-expanded="true"] { border-color: var(--cyan); color: var(--cyan-2); background: rgba(0,180,216,.14); }
.tool .ms { font-size: 18px; }
.seg { display: inline-flex; background: rgba(18,24,36,.9); border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; color: var(--text-2); padding: 5px 10px; border-radius: var(--r); font-size: 12.5px; white-space: nowrap; }
.seg button:hover { color: var(--text); background: var(--s2); }
.seg button.on { background: var(--s3); color: var(--cyan-2); font-weight: 600; }
.seg.sm button { padding: 3px 8px; font-size: 12px; }
select { height: 32px; background: var(--s1); border: 1px solid var(--line-2); border-radius: var(--r); padding: 0 8px; color: var(--text); min-width: 0; }
select:focus { border-color: var(--cyan); outline: none; }
input[type=range] { accent-color: var(--cyan-2); width: 100%; }
input[type=text], input:not([type]), input[type=search] { background: var(--s1); border: 1px solid var(--line-2); border-radius: var(--r); padding: 6px 8px; outline: none; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.field input { color: var(--text); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 2px; font-size: 13px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 34px; height: 20px; border-radius: 20px; background: var(--s3); position: relative; flex-shrink: 0; order: 2; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: inset-inline-start .15s, background .15s; }
.switch input:checked { background: rgba(0,180,216,.45); }
.switch input:checked::after { inset-inline-start: 17px; background: var(--cyan-2); }
.radio { display: flex; gap: 10px; padding: 7px 6px; border-radius: var(--r); cursor: pointer; align-items: flex-start; }
.radio:hover { background: var(--s3); }
.radio input { accent-color: var(--cyan-2); margin-top: 4px; }
.radio small { display: block; color: var(--text-2); font-size: 11.5px; }
.range-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; padding: 6px 2px; }
.range-row output { min-width: 56px; text-align: end; color: var(--cyan-2); font-size: 12px; }
.popover { position: absolute; z-index: 40; background: var(--s2); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: 0 18px 40px rgba(0,0,0,.5); padding: 10px; min-width: 250px; }
.pop-title { font: 600 12px var(--f-head); color: var(--text-2); margin-bottom: 6px; letter-spacing: .02em; }
.pop-wrap { position: relative; }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 20px; font-size: 11px; font-weight: 600; background: var(--s3); }
.badge.shock { background: var(--amber-bg); color: var(--amber); border: 1px solid rgba(245,185,66,.4); }
.badge.red { background: var(--red-bg); color: var(--red-2); } .badge.green { background: var(--green-bg); color: var(--green-2); } .badge.cyan { background: var(--cyan-bg); color: var(--cyan-2); }

/* ------------------------------------------------ 3D page */
/* The model gets the space: the info panel sits beside it, the monitor is
   one compact strip under both, and each can be put away (.no-info,
   .no-tele) from the toolbar. */
body.page-model main { padding: calc(var(--top) + 10px) 12px 10px; }
.model-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "viewer info" "tele tele"; gap: 10px; height: calc(100vh - var(--top) - 20px); min-height: 560px; }
.model-grid.no-info { grid-template-columns: minmax(0, 1fr); grid-template-areas: "viewer" "tele"; }
.model-grid.no-tele { grid-template-rows: minmax(0, 1fr); grid-template-areas: "viewer info"; }
.model-grid.no-info.no-tele { grid-template-areas: "viewer"; }
.model-grid.no-info .info-card, .model-grid.no-tele .telemetry-card { display: none; }
.viewer-card { grid-area: viewer; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.stage { position: relative; flex: 1; min-height: 300px; border-radius: var(--r-xl); overflow: hidden; border: 1px solid var(--line); background: radial-gradient(ellipse at 50% 38%, #1d2840 0%, #111827 45%, #0a0e16 80%); touch-action: none; }
.stage:fullscreen { border-radius: 0; }
.hv-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; outline: none; }
.hv-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.hv-labels { position: absolute; inset: 0; }
.hv-label { position: absolute; left: 0; top: 0; direction: ltr; pointer-events: auto; display: flex; align-items: center; gap: 0; padding: 0; border: 0; background: none; color: #fff; will-change: transform; cursor: pointer; }
.hv-num { display: inline-grid; place-items: center; min-width: 21px; height: 21px; padding: 0 4px; border-radius: 11px; background: #fbfbf8; color: #10131a; font: 700 11px var(--f-mono); box-shadow: 0 1px 5px rgba(0,0,0,.55); translate: -50% -50%; border: 1.5px solid #10131a; }
.hv-name { background: rgba(10,14,22,.86); border: 1px solid var(--line-2); padding: 1px 7px; border-radius: var(--r); font-size: 11.5px; font-weight: 600; white-space: nowrap; translate: -6px -50%; margin-inline-start: 0; direction: rtl; }
.hv-labels.numbers-only .hv-name { display: none; }
.hv-label.active .hv-num { background: var(--cyan-2); border-color: #002a35; }
.hv-label.active .hv-name { border-color: var(--cyan); color: var(--cyan-2); }
.hv-label.collide .hv-name { display: none; }
.hv-tooltip { position: absolute; left: 0; top: 0; background: rgba(36,48,71,.96); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 9px; font-size: 12px; box-shadow: 0 0 12px rgba(0,180,216,.25); white-space: nowrap; display: flex; flex-direction: column; }
.hv-tooltip span { color: var(--text-2); font-size: 11px; direction: ltr; text-align: start; }
.toolbar { position: absolute; top: 10px; inset-inline: 10px; display: flex; justify-content: space-between; gap: 8px; z-index: 5; flex-wrap: wrap; pointer-events: none; }
.toolbar > * { pointer-events: auto; }
.tool-group { display: flex; gap: 6px; flex-wrap: wrap; }
/* A menu hangs from its button toward the middle of the stage (the tools sit on its start side). */
.tool-group .popover { top: calc(100% + 6px); inset-inline-start: 0; overflow: auto; overscroll-behavior: contain; }
.cut-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 6px; }
.cut-list button { text-align: start; padding: 6px 8px; border-radius: var(--r); background: var(--s1); border: 1px solid var(--line-2); font-size: 12.5px; color: var(--text-2); }
.cut-list button.on { border-color: var(--cyan); color: var(--cyan-2); background: rgba(0,180,216,.12); }
.stage-hint { position: absolute; bottom: 10px; inset-inline-start: 10px; display: flex; gap: 6px; align-items: center; padding: 4px 9px; border-radius: var(--r); background: rgba(18,24,36,.85); border: 1px solid var(--line); font-size: 11.5px; color: var(--text-2); pointer-events: none; transition: opacity .6s; }
.stage-hint .ms { font-size: 15px; color: var(--cyan-2); }
.zoom-ctl { position: absolute; z-index: 5; bottom: 10px; inset-inline-end: 10px; display: flex; flex-direction: column; gap: 4px; }   /* above the canvas, which is mounted after it */
.beat-mini .ms { color: var(--red-2); }
.beat-mini[aria-pressed="true"] { background: var(--red); border-color: var(--red-2); }
.beat-mini[aria-pressed="true"] .ms { color: #fff; }
.phase-chip { position: absolute; top: 56px; inset-inline-start: 10px; padding: 4px 10px; border-radius: 20px; background: rgba(18,24,36,.88); border: 1px solid var(--line-2); font-size: 12px; color: var(--green-2); pointer-events: none; }
.stage-loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; z-index: 8; background: rgba(10,14,22,.65); text-align: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--s3); border-top-color: var(--red); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.legend-bar { display: flex; flex-direction: column; gap: 5px; padding: 4px 6px; font-size: 12px; color: var(--text-2); }
.legend-bar i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 5px; vertical-align: -1px; border: 1px solid rgba(255,255,255,.15); }

.info-card { grid-area: info; display: flex; flex-direction: column; min-height: 0; background: rgba(18,24,36,.95); border: 1px solid var(--line); border-radius: var(--r-xl); overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; flex-shrink: 0; }
.tabs button { flex: 1; padding: 11px 6px; border: 0; background: none; color: var(--text-2); font-size: 12.5px; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--cyan-2); border-bottom-color: var(--cyan); font-weight: 600; }
.tab-panel { padding: 14px; overflow: auto; flex: 1; min-height: 0; }
.s-head { padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.s-type { font: 600 11px var(--f-mono); color: var(--cyan-2); letter-spacing: .03em; }
.s-latin { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: var(--r); background: var(--red-bg); border: 1px solid rgba(230,57,70,.3); color: var(--red-2); font: 12px var(--f-mono); direction: ltr; }
.s-title { font-size: 19px; margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.s-title .num { display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 12px; background: #fbfbf8; color: #111; font: 700 12px var(--f-mono); }
.s-en { color: var(--text-2); font-size: 12.5px; direction: ltr; text-align: end; }
.s-section { margin: 12px 0; }
.s-section h3 { font: 600 12.5px var(--f-body); color: var(--text-2); display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.s-section h3 .ms { font-size: 16px; color: var(--cyan-2); }
.s-desc { font-size: 13px; line-height: 1.7; color: #dbe3ef; margin: 0; }
.facts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.fact { padding: 8px; border-radius: var(--r-lg); background: var(--bg); border: 1px solid var(--line); }
.fact span { display: block; font-size: 11px; color: var(--text-2); }
.fact b { font: 600 12.5px var(--f-mono); color: var(--text); display: block; unicode-bidi: plaintext; text-align: right; }   /* "4–5 cm" must not flip to "cm 5–4" */
.clinical { padding: 10px; border-radius: var(--r-lg); background: rgba(147,0,10,.16); border: 1px solid rgba(255,180,171,.22); }
.clinical h3 { color: #ffb4ab; } .clinical h3 .ms { color: #ffb4ab; }
.clinical p { margin: 0; font-size: 12.5px; line-height: 1.65; }
.s-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.s-empty { color: var(--text-2); text-align: center; padding: 30px 10px; }
.tree-group { margin-bottom: 12px; }
.tree-group h3 { font: 600 12px var(--f-body); color: var(--text-2); display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.tree-group h3 .ms { font-size: 16px; }
.tree-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border-radius: var(--r); background: none; border: 1px solid transparent; text-align: start; font-size: 13px; color: var(--text); }
.tree-item:hover { background: var(--s2); }
.tree-item.on { border-color: var(--cyan); background: rgba(0,180,216,.1); color: var(--cyan-2); }
.tree-item i { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(255,255,255,.2); }
.tree-item .abbr { margin-inline-start: auto; font: 11px var(--f-mono); color: var(--text-3); }
.tree-item .seen { color: var(--green-2); font-size: 15px; }
.legend-list { list-style: none; padding: 0; margin: 0; columns: 1; }
.legend-list li button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 5px 6px; border: 0; background: none; border-radius: var(--r); text-align: start; font-size: 13px; color: var(--text); }
.legend-list li button:hover { background: var(--s2); }
.legend-list li button.on { color: var(--cyan-2); background: rgba(0,180,216,.1); }
.legend-list .n { display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 12px; background: #fbfbf8; color: #111; font: 700 11px var(--f-mono); flex-shrink: 0; }
.legend-list small { color: var(--text-3); direction: ltr; margin-inline-start: auto; font-size: 11px; }

.telemetry-card { grid-area: tele; display: grid; grid-template-columns: minmax(220px, 1.25fr) minmax(200px, 0.75fr) minmax(330px, 1.2fr); gap: 8px; padding: 8px; border-radius: var(--r-xl); background: rgba(18,24,36,.95); border: 1px solid var(--line); }
.monitor { position: relative; min-height: 124px; border-radius: var(--r-lg); overflow: hidden; border: 1px solid #16324a; background: #0c1220; }
.monitor canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.monitor-head { position: absolute; top: 6px; inset-inline-start: 8px; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--green-2); }
.monitor-head .lead { background: rgba(52,227,155,.12); padding: 0 6px; border-radius: 3px; }
.monitor-hr { position: absolute; top: 6px; inset-inline-end: 10px; display: flex; align-items: baseline; gap: 4px; color: var(--green-2); }
.monitor-hr b { font-size: 28px; line-height: 1; }
.monitor-hr small { font: 10px var(--f-mono); opacity: .8; }
.monitor-hr .beat { font-size: 16px; color: var(--red-2); align-self: center; font-variation-settings: 'FILL' 1; transition: transform .08s; }
.monitor-hr .beat.pulse { transform: scale(1.35); }
.vitals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.vital { padding: 4px 8px; border-radius: var(--r-lg); background: var(--bg); border: 1px solid var(--line); min-width: 0; }
.v-lbl { display: block; font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vital b { display: block; font-size: 18px; line-height: 1.2; color: var(--text); }
.vital b.ok { color: var(--green-2); } .vital b.cyan { color: var(--cyan-2); } .vital b.warn { color: var(--amber); } .vital b.bad { color: var(--red-2); }
.vital small { font: 10px var(--f-mono); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
/* Three rows: start + rhythm + ischemia / rate + speed / view toggles. */
.controls { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); gap: 6px 8px; align-content: center; }
.controls .btn { height: 32px; padding: 0 10px; }
.ctl { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-2); min-width: 0; white-space: nowrap; }
.ctl select { flex: 1; min-width: 0; height: 30px; }
.ctl.bpm { grid-column: 1 / -1; }
.ctl.bpm input { flex: 1; min-width: 60px; }
.ctl.toggles { grid-column: 1 / -1; gap: 4px; }
.ctl.toggles .tool { height: 28px; }
.ctl.toggles .seg { flex-wrap: nowrap; }
.ctl.toggles .spacer { flex: 1; }

/* ------------------------------------------------ anatomy topics */
.topic-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.topic-nav { position: sticky; top: calc(var(--top) + 16px); display: flex; flex-direction: column; gap: 2px; background: var(--s1); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 8px; }
.topic-nav button { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 0; background: none; border-radius: var(--r); text-align: start; color: var(--text-2); font-size: 13px; }
.topic-nav button:hover { background: var(--s2); color: var(--text); }
.topic-nav button.on { background: var(--s2); color: var(--cyan-2); font-weight: 600; }
.topic-nav .ms { font-size: 18px; }
.topic-nav .done { margin-inline-start: auto; color: var(--green-2); font-size: 16px; }
.topic { background: rgba(18,24,36,.92); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 22px 24px; max-width: 900px; }
.topic h2 { font-size: 21px; display: flex; align-items: center; gap: 8px; }
.topic h2 .ms { color: var(--red-2); font-size: 24px; }
.topic .lead { color: var(--text-2); font-size: 14.5px; margin: 8px 0 16px; }
.topic h3 { font-size: 15px; margin: 18px 0 8px; color: var(--cyan-2); }
.topic p, .topic li { font-size: 14px; line-height: 1.75; color: #dbe3ef; }
.topic ul { padding-inline-start: 20px; margin: 6px 0; }
.topic table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.topic th, .topic td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: start; }
.topic th { color: var(--text-2); font-weight: 600; background: var(--s1); }
.keyfacts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin: 12px 0; }
.keyfacts div { padding: 10px; border-radius: var(--r-lg); background: var(--bg); border: 1px solid var(--line); }
.keyfacts span { display: block; font-size: 11.5px; color: var(--text-2); }
.keyfacts b { font: 600 14px var(--f-mono); color: var(--green-2); }
.callout { padding: 12px 14px; border-radius: var(--r-lg); background: var(--amber-bg); border: 1px solid rgba(245,185,66,.3); margin: 12px 0; font-size: 13.5px; }
.callout b { color: var(--amber); }
.topic-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ------------------------------------------------ circulation */
.circ-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.circ-grid > .card:last-child { grid-column: 1 / -1; }
.circ-svg-wrap { position: relative; }
.circ-svg-wrap svg { display: block; width: 100%; height: auto; }
.circ-svg-wrap .node { cursor: pointer; }
.circ-svg-wrap .node rect { transition: stroke .2s, fill .2s; }
.circ-svg-wrap .node.on rect { stroke: var(--cyan-2); stroke-width: 2.5; fill: #1d3150; }
.circ-svg-wrap .dim { opacity: .18; transition: opacity .3s; }
.stepper { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 10px; border-radius: var(--r-lg); background: var(--bg); border: 1px solid var(--line); }
.step-text { flex: 1; font-size: 13.5px; min-height: 42px; }
.step-text b { color: var(--cyan-2); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
#wiggers { width: 100%; height: 330px; display: block; background: var(--bg); border-radius: var(--r-lg); border: 1px solid var(--line); }
.wig-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font: 11px var(--f-mono); color: var(--text-2); margin-bottom: 6px; }
.wig-legend i { display: inline-block; width: 12px; height: 3px; margin-inline-end: 5px; vertical-align: 3px; border-radius: 2px; }
.phase-now { margin: 10px 0 6px; font-weight: 600; color: var(--green-2); min-height: 22px; }
.phase-list { margin: 0; padding-inline-start: 20px; font-size: 13px; color: var(--text-2); display: grid; gap: 4px; }
.phase-list li.on { color: var(--text); }
.phase-list li.on::marker { color: var(--green-2); }
.formula { font: 600 15px var(--f-head); color: var(--cyan-2); margin-bottom: 10px; }
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: center; margin-bottom: 12px; }
.calc .out { font: 700 26px var(--f-mono); color: var(--green-2); }
.facts { margin: 0; padding-inline-start: 20px; color: #dbe3ef; font-size: 13.5px; line-height: 1.8; }

/* ------------------------------------------------ pathologies */
.disclaimer { display: flex; gap: 8px; align-items: center; margin-top: 10px; padding: 8px 12px; border-radius: var(--r-lg); background: var(--amber-bg); border: 1px solid rgba(245,185,66,.3); font-size: 12.5px; color: #fde4b0; max-width: 760px; }
.disclaimer .ms { color: var(--amber); font-size: 18px; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.filters button { padding: 5px 12px; border-radius: 20px; background: var(--s1); border: 1px solid var(--line-2); color: var(--text-2); font-size: 12.5px; }
.filters button.on { border-color: var(--cyan); color: var(--cyan-2); background: rgba(0,180,216,.1); }
.patho-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; align-items: start; }
.patho { background: rgba(18,24,36,.92); border: 1px solid var(--line); border-radius: var(--r-xl); overflow: hidden; }
.patho > button.head { width: 100%; display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: none; border: 0; text-align: start; }
.patho .p-icon { width: 38px; height: 38px; border-radius: var(--r-lg); display: grid; place-items: center; background: var(--red-bg); color: var(--red-2); flex-shrink: 0; }
.patho .p-icon.rhythm { background: var(--green-bg); color: var(--green-2); } .patho .p-icon.structural { background: var(--amber-bg); color: var(--amber); } .patho .p-icon.vascular { background: var(--cyan-bg); color: var(--cyan-2); }
.patho h3 { font-size: 15.5px; }
.patho .p-en { font-size: 11.5px; color: var(--text-3); direction: ltr; text-align: end; }
.patho .p-sum { font-size: 13px; color: var(--text-2); margin-top: 4px; line-height: 1.6; }
.patho .p-tags { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.patho .chev { margin-inline-start: auto; color: var(--text-3); transition: transform .2s; }
.patho.open .chev { transform: rotate(180deg); }
.patho .body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.patho .body h4 { margin: 12px 0 4px; font: 600 12.5px var(--f-body); color: var(--cyan-2); display: flex; gap: 6px; align-items: center; }
.patho .body h4 .ms { font-size: 16px; }
.patho .body p, .patho .body li { font-size: 13px; line-height: 1.7; color: #dbe3ef; margin: 0; }
.patho .body ul { margin: 0; padding-inline-start: 18px; }
.patho .body .ecg-box { padding: 8px 10px; border-radius: var(--r); background: #0c1220; border: 1px solid #16324a; color: var(--green-2); font-size: 12.5px; }
.patho .seen-mark { color: var(--green-2); font-size: 16px; }

/* ------------------------------------------------ quiz */
.quiz-modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-bottom: 16px; }
.mode-card { text-align: start; padding: 16px; border-radius: var(--r-xl); background: rgba(18,24,36,.92); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s; }
.mode-card:hover { border-color: var(--cyan); transform: translateY(-2px); }
.mode-card .ms { font-size: 26px; color: var(--cyan-2); }
.mode-card b { font: 700 15px var(--f-head); }
.mode-card small { color: var(--text-2); font-size: 12.5px; line-height: 1.6; }
.cat-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.quiz-card { max-width: 920px; background: rgba(18,24,36,.95); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 18px; }
.quiz-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 12.5px; color: var(--text-2); }
.quiz-top .bar { flex: 1; }
.q-cat { font: 600 11px var(--f-mono); color: var(--cyan-2); }
.q-text { font-size: 17px; font-weight: 600; margin: 6px 0 14px; line-height: 1.55; }
.q-stage { position: relative; height: min(52vh, 440px); border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--line); margin-bottom: 12px; background: radial-gradient(ellipse at 50% 40%, #1d2840, #0a0e16 80%); touch-action: none; }
.answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px; }
.answer { display: flex; gap: 10px; align-items: flex-start; text-align: start; padding: 11px 12px; border-radius: var(--r-lg); background: var(--s1); border: 1px solid var(--line-2); font-size: 14px; line-height: 1.5; transition: border-color .15s, background .15s; }
.answer:hover:not(:disabled) { border-color: var(--cyan); }
.answer .letter { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--s3); font: 600 12px var(--f-mono); flex-shrink: 0; }
.answer.correct { border-color: var(--green); background: var(--green-bg); }
.answer.correct .letter { background: var(--green); color: #fff; }
.answer.wrong { border-color: var(--red); background: var(--red-bg); }
.answer.wrong .letter { background: var(--red); color: #fff; }
.answer:disabled { cursor: default; }
.explain { margin-top: 12px; padding: 12px; border-radius: var(--r-lg); background: var(--bg); border: 1px solid var(--line); font-size: 13.5px; line-height: 1.7; }
.explain b { color: var(--green-2); } .explain.bad b { color: var(--red-2); }
.quiz-nav { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }
.result-hero { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.ring { --p: 0; width: 120px; height: 120px; border-radius: 50%; background: conic-gradient(var(--c, var(--green-2)) calc(var(--p) * 1%), var(--s3) 0); display: grid; place-items: center; flex-shrink: 0; }
.ring::before { content: ''; position: absolute; }
.ring > div { width: 94px; height: 94px; border-radius: 50%; background: var(--s1); display: grid; place-items: center; text-align: center; }
.ring b { font: 700 24px var(--f-mono); display: block; }
.ring small { color: var(--text-2); font-size: 11px; }
.review { margin-top: 16px; display: grid; gap: 8px; }
.review .r { padding: 10px; border-radius: var(--r-lg); background: var(--bg); border: 1px solid var(--line); font-size: 13px; }
.review .r.ok { border-inline-start: 3px solid var(--green); } .review .r.no { border-inline-start: 3px solid var(--red); }

/* ------------------------------------------------ progress */
.prog-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.prog-hero { grid-column: 1 / -1; display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; flex: 1; }
.stat { padding: 12px; border-radius: var(--r-lg); background: var(--bg); border: 1px solid var(--line); }
.stat span { display: block; font-size: 12px; color: var(--text-2); }
.stat b { font: 700 22px var(--f-mono); }
.stat .bar { margin-top: 8px; }
.chips-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-list .badge { height: 24px; padding: 0 9px; font-weight: 500; cursor: pointer; border: 1px solid transparent; }
.chips-list .badge.todo { background: var(--s1); color: var(--text-3); border-color: var(--line-2); }
.hist-chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 8px 4px 0; border-bottom: 1px solid var(--line-2); direction: ltr; }
.hist-chart .col { flex: 1; max-width: 34px; background: linear-gradient(180deg, var(--cyan-2), var(--cyan)); border-radius: 4px 4px 0 0; position: relative; min-height: 3px; }
.hist-chart .col span { position: absolute; top: -18px; left: 50%; translate: -50% 0; font: 10px var(--f-mono); color: var(--text-2); }
.cat-bars { display: grid; gap: 8px; }
.cat-bars .row { display: grid; grid-template-columns: 130px 1fr 44px; gap: 8px; align-items: center; font-size: 12.5px; }
.cat-bars .row b { font: 600 12px var(--f-mono); text-align: end; }
table.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
table.hist td, table.hist th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: start; }
table.hist th { color: var(--text-2); font-weight: 500; }

/* ------------------------------------------------ settings */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.settings-grid .card h2 { font-size: 15px; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.settings-grid .card h2 .ms { color: var(--cyan-2); }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.set-row:last-child { border-bottom: 0; }
.set-row small { display: block; color: var(--text-3); font-size: 11.5px; }
.credits p { font-size: 12.5px; color: var(--text-2); line-height: 1.7; margin: 6px 0; }

.toast { position: fixed; bottom: 18px; left: 50%; translate: -50% 0; background: var(--s3); border: 1px solid var(--line-2); padding: 9px 16px; border-radius: var(--r-lg); font-size: 13px; z-index: 90; box-shadow: 0 12px 30px rgba(0,0,0,.4); }

.only-mobile { display: none !important; }

/* ------------------------------------------------ responsive */
@media (max-width: 1500px) { .toolbar .tool .lbl { display: none; } }
/* A narrow rail instead of the full menu, chosen from the menu itself. */
@media (min-width: 861px) {
  body.nav-rail { --side: 64px; }
  body.nav-rail .sidebar { padding: 14px 8px; }
  body.nav-rail .brand { flex-direction: column; gap: 8px; padding: 0; }
  body.nav-rail .brand > div:not(.brand-mark), body.nav-rail .nav a > span:not(.ms), body.nav-rail .nav-link-sm > span:not(.ms), body.nav-rail .progress-card .row > span { display: none; }
  body.nav-rail .brand .rail-btn { margin: 0; }
  body.nav-rail .nav a, body.nav-rail .nav-link-sm { justify-content: center; padding: 10px 0; }
  body.nav-rail .progress-card { padding: 8px 4px; text-align: center; }
  body.nav-rail .progress-card .row { justify-content: center; }
}
@media (max-width: 1280px) {
  .model-grid { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 1100px) {
  .model-grid, .model-grid.no-info, .model-grid.no-tele, .model-grid.no-info.no-tele { grid-template-columns: 1fr; grid-template-rows: auto; grid-template-areas: "viewer" "tele" "info"; height: auto; min-height: 0; }
  .stage { height: 72vh; min-height: 380px; flex: none; }
  .telemetry-card { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .monitor { grid-column: 1 / -1; }
  .info-card { max-height: none; }
  .tab-panel { max-height: none; }
  .circ-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  :root { --side: 0px; }
  .sidebar { width: 272px; transform: translateX(100%); transition: transform .25s; box-shadow: -18px 0 40px rgba(0,0,0,.5); }
  body.nav-open .sidebar { transform: none; }
  .only-mobile { display: inline-grid !important; }
  .only-desktop { display: none !important; }
  .topbar { padding: 0 8px; gap: 8px; }
  .crumbs { display: none; }
  main { padding: calc(var(--top) + 10px) 10px 14px; }
  .topic-layout { grid-template-columns: 1fr; }
  .topic-nav { position: static; flex-direction: row; overflow-x: auto; }
  .topic-nav button { white-space: nowrap; }
  .topic { padding: 16px; }
  .vitals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .seg { max-width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar .seg::-webkit-scrollbar { display: none; }
  .tool-group { justify-content: flex-start; }
  .tool-group .popover { inset-inline-end: auto; inset-inline-start: 0; max-width: calc(100vw - 40px); }
  .keyfacts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tool .lbl { display: none; }
  .stage { height: 68vh; }
  .stage-hint { display: none; }
  .page-head h1 { font-size: 20px; }
  .patho-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ------------------------------------------------ voice tour */
.toolbar .tool.tour-btn { border-color: rgba(230,57,70,.55); color: #fff; background: rgba(230,57,70,.22); }
.toolbar .tool.tour-btn .lbl { display: inline; }
.toolbar .tool.tour-btn[aria-pressed="true"] { background: var(--red); border-color: var(--red-2); }
.tour { position: absolute; z-index: 7; left: 50%; bottom: 12px; translate: -50% 0; width: min(780px, calc(100% - 130px)); padding: 12px 14px 10px; border-radius: var(--r-xl); background: rgba(14,19,30,.9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line-2); box-shadow: 0 18px 40px rgba(0,0,0,.45); }
.tour-head { display: flex; align-items: center; gap: 8px; }
.tour-chapter { font: 600 11px var(--f-mono); color: var(--cyan-2); background: var(--cyan-bg); padding: 2px 8px; border-radius: 20px; }
.tour-count { font-size: 11px; color: var(--text-3); }
.tour-close { margin-inline-start: auto; width: 28px; height: 28px; }
.tour-title { font-size: 17px; margin: 4px 0 4px; }
.tour-text { margin: 0; font-size: 15px; line-height: 1.75; color: var(--text-2); min-height: 52px; }
.tour-text span { transition: color .2s, background .2s; border-radius: 4px; }
.tour-text span.now { color: #fff; background: rgba(76,214,251,.14); box-shadow: 0 0 0 2px rgba(76,214,251,.14); }
.tour-end { display: flex; gap: 6px; margin-top: 8px; }
.tour-bar { height: 3px; background: var(--s3); border-radius: 3px; margin: 8px 0; overflow: hidden; }
.tour-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--red), var(--red-2)); transition: width .4s; }
.tour-ctl { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tour-ctl .tool.play { background: var(--red); border-color: var(--red-2); color: #fff; padding: 0 14px; }
.tour-ctl select { height: 30px; }
.tour-note { font-size: 11.5px; color: var(--amber); }
body.touring .stage-hint, body.touring .phase-chip { display: none; }
@media (max-width: 860px) {
  .toolbar .tool.tour-btn .lbl { display: none; }
  .tour { width: calc(100% - 16px); bottom: 8px; padding: 10px; }
  .tour-text { font-size: 13.5px; }
}

/* Phones: the monitor strip stacks, and nothing in it may push the page wider than the screen. */
.ctl.toggles { flex-wrap: wrap; }
@media (max-width: 860px) {
  .telemetry-card { grid-template-columns: minmax(0, 1fr); }
  .controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .controls > .btn { grid-column: 1 / -1; }
}
/* Phones: the tour card shows only the sentence being spoken, so the heart stays in view. */
@media (max-width: 860px) {
  .tour-text:has(span.now) span:not(.now) { display: none; }
  .tour-text { min-height: 0; }
  .tour-title { font-size: 15px; }
}

/* The spoken explanation of a part is the first thing offered, under its name. */
.s-speak { display: flex; width: 100%; margin-top: 10px; }

/* ------------------------------------------------ the selected structure */
/* Its number grows and pings when it is chosen, and its name stands beside
   it even when names are off: the eye goes straight to it. A label is laid
   out left to right so that its number, not its name, sits on the point. */
.hv-label.active { z-index: 2; }
.hv-label.active .hv-num { min-width: 28px; height: 28px; border-radius: 14px; font-size: 13px; border-width: 2px; box-shadow: 0 0 0 4px rgba(76,214,251,.3), 0 0 16px rgba(76,214,251,.75); animation: hv-ping 1.3s ease-out 3; }
.hv-labels.numbers-only .hv-label.active .hv-name, .hv-label.active.collide .hv-name { display: inline-block; }
.hv-label.active .hv-name { font-size: 14px; padding: 3px 10px; color: #fff; background: rgba(4,34,46,.93); border: 1px solid var(--cyan); box-shadow: 0 0 14px rgba(76,214,251,.35); translate: -9px -50%; }
@keyframes hv-ping { from { box-shadow: 0 0 0 0 rgba(76,214,251,.75), 0 0 16px rgba(76,214,251,.75); } to { box-shadow: 0 0 0 16px rgba(76,214,251,0), 0 0 16px rgba(76,214,251,.75); } }

/* ------------------------------------------------ room for the heart */
/* A wide screen is short for an upright heart: the monitor moves into the
   side column under the information panel, and the model gets the whole
   height. */
@media (min-width: 1101px) and (min-aspect-ratio: 7/5) {
  .model-grid { grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "viewer info" "viewer tele"; }
  .model-grid.no-info { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "viewer tele" "viewer ."; }
  .model-grid.no-tele { grid-template-rows: minmax(0, 1fr); grid-template-areas: "viewer info"; }
  .model-grid.no-info.no-tele { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "viewer"; }
  .telemetry-card { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 6px; }
  .monitor { min-height: 92px; }
  .vitals { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .vital { padding: 3px 6px; }
  .vital b { font-size: 15px; }
  .v-lbl { font-size: 10.5px; }
  .controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 5px 6px; }
  .controls > .btn { grid-column: 1 / -1; }
}

/* The voice tour is a lesson at the model: the panels and the tools step
   aside (the card has its own controls), the menu folds to a rail, and the
   card docks beside the heart on a wide stage. */
@media (min-width: 861px) {
  body.touring { --side: 64px; }
  body.touring .sidebar { padding: 14px 8px; }
  body.touring .brand { flex-direction: column; gap: 8px; padding: 0; }
  body.touring .brand > div:not(.brand-mark), body.touring .nav a > span:not(.ms), body.touring .nav-link-sm > span:not(.ms), body.touring .progress-card .row > span { display: none; }
  body.touring .brand .rail-btn { margin: 0; }
  body.touring .nav a, body.touring .nav-link-sm { justify-content: center; padding: 10px 0; }
  body.touring .progress-card { padding: 8px 4px; text-align: center; }
  body.touring .progress-card .row { justify-content: center; }
  body.touring .model-grid, body.touring .model-grid.no-info, body.touring .model-grid.no-tele { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "viewer"; }
  body.touring .model-grid .info-card, body.touring .model-grid .telemetry-card, body.touring .stage .toolbar, body.touring .stage .zoom-ctl { display: none; }
}
.tour.docked { left: 14px; top: 50%; bottom: auto; translate: 0 -50%; width: 360px; max-height: calc(100% - 28px); overflow: auto; padding: 16px 16px 12px; }
.tour.docked .tour-title { font-size: 20px; margin: 8px 0 6px; }
.tour.docked .tour-text { font-size: 16px; line-height: 1.8; }

/* ------------------------------------------------ search field */
/* The global field style must not draw a second box inside the search bar. */
.search input[type=search] { border: 0; padding: 0; background: none; border-radius: 0; }
.search input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ------------------------------------------------ phones */
/* A phone gets an app, not a shrunken desktop: the page name in the top bar,
   search behind its own button, the five study areas in a bottom tab bar,
   the heart sized to the screen between the two bars, and the model's tool
   menus as bottom sheets within thumb reach. Touch targets are at least
   38px, and fields use 16px text so iOS does not zoom into them. */
.tabbar, .sheet-scrim { display: none; }
@media (max-width: 860px) {
  :root { --top: calc(54px + env(safe-area-inset-top, 0px)); --tabbar: 60px; --safe-b: env(safe-area-inset-bottom, 0px); }
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; }

  /* top bar */
  .topbar { height: var(--top); padding: env(safe-area-inset-top, 0px) 6px 0; gap: 4px; }
  .crumbs { display: block; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font: 700 16px var(--f-head); color: var(--text); }
  .crumbs b, .crumbs .sep { display: none; }
  .search { display: none; }
  body.search-open .search { display: flex; position: absolute; inset-inline: 8px; top: calc(env(safe-area-inset-top, 0px) + 7px); height: 40px; max-width: none; z-index: 3; padding-inline-end: 2px; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
  .search input[type=search] { font-size: 16px; }
  .search .search-close { width: 34px; height: 34px; }
  .search-results { max-height: calc(100vh - var(--top) - var(--tabbar) - 30px); max-height: calc(100dvh - var(--top) - var(--tabbar) - var(--safe-b) - 30px); }
  .search-results .res { padding: 11px 10px; }
  #latin-toggle { display: none !important; }
  .top-actions { gap: 2px; }
  .icon-btn { width: 40px; height: 40px; }
  .avatar { width: 34px; height: 34px; margin-inline-start: 4px; }
  .profile-pop { position: fixed; inset-inline: 8px; top: calc(var(--top) + 6px); width: auto; }

  /* menu drawer */
  .sidebar { padding-top: calc(14px + env(safe-area-inset-top, 0px)); padding-bottom: calc(14px + var(--safe-b)); }
  .nav a, .nav-link-sm { padding: 12px; font-size: 15px; }

  /* bottom tab bar */
  .tabbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; inset-inline: 0; bottom: 0; z-index: 52; height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b); background: rgba(10,14,22,.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
  .tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; color: var(--text-3); font-size: 10.5px; font-weight: 600; white-space: nowrap; }
  .tabbar a > span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .tabbar a .ms { font-size: 23px; transition: color .15s, transform .15s; }
  .tabbar a:active .ms { transform: scale(.9); }
  .tabbar a.active { color: var(--text); }
  .tabbar a.active .ms { color: var(--red-2); font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24; }
  .tabbar a.active::before { content: ''; position: absolute; top: 0; width: 30px; height: 2px; border-radius: 0 0 2px 2px; background: var(--red); }
  main { padding-bottom: calc(var(--tabbar) + var(--safe-b) + 16px); }
  .toast { bottom: calc(var(--tabbar) + var(--safe-b) + 12px); max-width: calc(100vw - 24px); text-align: center; }

  /* touch targets */
  select, textarea, input[type=text], input:not([type]) { font-size: 16px; }
  select { height: 38px; }
  .btn { height: 40px; }
  .btn.sm { height: 34px; }
  .seg button { padding: 7px 12px; }
  .tabs button { padding: 13px 6px; font-size: 13px; }
  .set-row { padding: 11px 0; }
  .switch { padding: 9px 2px; }
  .switch input { width: 42px; height: 24px; }
  .switch input::after { width: 18px; height: 18px; }
  .switch input:checked::after { inset-inline-start: 21px; }
  .mode-card:hover { transform: none; }
  .filters { flex-wrap: nowrap; overflow-x: auto; margin-inline: -10px; padding: 0 10px 2px; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }
  .filters button { flex-shrink: 0; padding: 8px 14px; }

  /* 3D page: the heart fills the screen between the two bars */
  body.page-model main { padding: calc(var(--top) + 8px) 8px calc(var(--tabbar) + var(--safe-b) + 12px); }
  .model-grid { gap: 8px; }
  .stage { height: calc(100vh - var(--top) - var(--tabbar) - 20px); height: calc(100dvh - var(--top) - var(--tabbar) - var(--safe-b) - 20px); min-height: 380px; max-height: 820px; }
  .toolbar { top: 8px; inset-inline: 8px; gap: 6px; }
  .toolbar .seg button { padding: 7px 11px; }
  .tool-group { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -8px; padding-inline: 8px; }
  .tool-group::-webkit-scrollbar { display: none; }
  .toolbar .tool { height: 38px; min-width: 38px; justify-content: center; flex-shrink: 0; border-radius: var(--r-lg); }
  .toolbar .tool.tour-btn .lbl { display: inline; }
  #btn-panel, #btn-tele, #btn-focus { display: none; }
  .zoom-ctl .tool { width: 40px; height: 40px; justify-content: center; border-radius: var(--r-lg); }
  .phase-chip { top: auto; bottom: 12px; inset-inline-start: 50%; translate: 50% 0; }

  /* the tool menus as bottom sheets */
  .toolbar .tool-group .popover { position: fixed; inset-inline: 0; top: auto; bottom: 0; z-index: 80; min-width: 0; max-width: none; max-height: min(72vh, 560px); overflow: auto; overscroll-behavior: contain; border: 0; border-top: 1px solid var(--line-2); border-radius: 16px 16px 0 0; padding: 24px 16px calc(16px + var(--safe-b)); box-shadow: 0 -18px 40px rgba(0,0,0,.5); animation: sheet-up .22s ease-out; }
  .toolbar .tool-group .popover::before { content: ''; position: absolute; top: 9px; left: 50%; translate: -50% 0; width: 38px; height: 4px; border-radius: 2px; background: var(--line-2); }
  /* The toolbar is its own layer (z-index 5): lift it over the tab bar while a sheet is open. */
  body:has(.toolbar .popover:not([hidden])) .toolbar { z-index: 81; }
  body:has(.toolbar .popover:not([hidden])) .sheet-scrim { display: block; position: fixed; inset: 0; z-index: 79; background: rgba(0,0,0,.5); }
  .pop-title { font-size: 14px; margin-bottom: 8px; }
  .radio { padding: 10px 6px; }
  .cut-list button { padding: 11px 10px; font-size: 13.5px; }
  .range-row { padding: 10px 2px; }

  /* reading pages */
  .page-head h1 { font-size: 22px; }
  .page-head p { font-size: 13.5px; }
  .card { padding: 14px; }
  .topic-nav { position: sticky; top: var(--top); z-index: 10; margin-inline: -10px; padding: 6px 10px; border-radius: 0; border-inline: 0; background: rgba(11,15,23,.95); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); scrollbar-width: none; }
  .topic-nav::-webkit-scrollbar { display: none; }
  .topic-nav button { padding: 9px 12px; }
  .topic { padding: 16px 14px; }
  .topic table { display: block; overflow-x: auto; }
  .q-stage { height: 46vh; height: 46dvh; }
  .quiz-card { padding: 14px; }
  .quiz-nav .btn { flex: 1; }
  .answer { padding: 13px 12px; }
  .cat-bars .row { grid-template-columns: 96px minmax(0, 1fr) 40px; }
  .result-hero { justify-content: center; }
}
/* A short rise, never from off-screen: if a busy page stalls the animation, the sheet is still there to use. */
@keyframes sheet-up { from { transform: translateY(18px); } }
@media (max-width: 860px) and (hover: none) {
  .zoom-ctl [data-zoom] { display: none; }   /* pinch zooms */
}
/* A phone on its side is short: no tab bar (the menu is one tap away), and
   the heart takes the whole height under the top bar. */
@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  .tabbar { display: none; }
  main, body.page-model main { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .stage { height: calc(100vh - var(--top) - 18px); height: calc(100dvh - var(--top) - 18px); min-height: 260px; }
  .toast { bottom: 12px; }
  /* the view angles and the tools share one row, so the toolbar takes a single strip of the short stage */
  .toolbar { flex-direction: row; flex-wrap: nowrap; align-items: flex-start; }
  .toolbar .seg { flex: 0 1 auto; min-width: 0; }
  .tool-group { flex: 0 1 auto; min-width: 0; margin-inline: 0; padding-inline: 0; }
  .toolbar .tool.tour-btn .lbl { display: none; }
}
/* Wider landscape phones fall in the desktop range: fold the menu to a rail. */
@media (min-width: 861px) and (max-height: 500px) {
  body { --side: 64px; }
  .sidebar { padding: 10px 8px; gap: 10px; }
  .brand { flex-direction: column; gap: 8px; padding: 0; }
  .brand > div:not(.brand-mark), .nav a > span:not(.ms), .nav-link-sm > span:not(.ms), .progress-card, .rail-btn { display: none; }
  .nav a, .nav-link-sm { justify-content: center; padding: 9px 0; }
  .model-grid { min-height: 0; }
}

/* ------------------------------------------------ the chosen part, on a phone's stage */
.sel-peek { display: none; }
@media (max-width: 860px) {
  .sel-peek:not([hidden]) { position: absolute; z-index: 6; bottom: 10px; inset-inline: 10px; display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 6px; border-radius: var(--r-xl); background: rgba(14,19,30,.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--line-2); box-shadow: 0 10px 28px rgba(0,0,0,.45); animation: peek-in .2s ease-out; }
  .sel-peek .num { display: inline-grid; place-items: center; min-width: 28px; height: 28px; border-radius: 14px; background: var(--cyan-2); color: #002a35; font: 700 13px var(--f-mono); flex-shrink: 0; }
  .sel-peek .txt { flex: 1; min-width: 0; line-height: 1.3; }
  .sel-peek b { display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sel-peek small { display: block; font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sel-peek .tool { height: 38px; min-width: 38px; justify-content: center; border-radius: var(--r-lg); flex-shrink: 0; }
  .sel-peek .tool.more { padding: 0 8px 0 4px; gap: 2px; font-weight: 600; }
  .sel-peek .tool.close { border-color: transparent; background: none; min-width: 30px; width: 30px; color: var(--text-3); }
  .sel-peek #peek-speak[aria-pressed="true"] { background: var(--red); border-color: var(--red-2); color: #fff; }
  body.touring .sel-peek { display: none; }
  .stage:has(.sel-peek:not([hidden])) .zoom-ctl { bottom: 74px; }   /* the beat button steps up over the card */
  .info-card { scroll-margin-top: calc(var(--top) + 8px); }
}
@keyframes peek-in { from { transform: translateY(8px); } }   /* no fade: a stalled animation must not leave it invisible */
