/* Fonts are registered by the loader in index.html (FontFace API), one file at a time. */
:root {
  --bg: #05070b;
  --panel: rgba(12, 17, 26, 0.62);
  --panel-solid: #0c111a;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e9eef4;
  --muted: #8f9cae;
  --faint: #5f6b7c;
  --o2: #ff5a4d;
  --co2: #4aa8ff;
  --tissue: #ffb0a4;
  --good: #7ee0c2;
  --warn: #ffc46b;
  --low: #ff6f61;
  --sans: "Plex", "Plex Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument", "Naskh", "Times New Roman", serif;
  --mono: "Plex Mono", "Plex Arabic", ui-monospace, monospace;
  --pad: 20px;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; line-height: 1.45; overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--tissue); outline-offset: 3px; border-radius: 8px; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[dir="rtl"] .fact__next svg, [dir="rtl"] .begin svg { transform: scaleX(-1); }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
body::after { content: ""; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(130% 100% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55) 100%); }
#ui { position: fixed; inset: 0; pointer-events: none; transition: opacity 0.9s ease; }
#ui.is-hidden { opacity: 0; }
#ui > * { pointer-events: auto; }
#ui > #labels { pointer-events: none; }

/* ------------------------------------------------------------ top bar */
.topbar { position: absolute; inset-block-start: 0; inset-inline: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px var(--pad); pointer-events: none !important; z-index: 6; }
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.brand__mark { font-family: var(--serif); font-size: 34px; line-height: 1; letter-spacing: 0.01em; }
[dir="rtl"] .brand__mark { font-size: 32px; line-height: 1.25; }
.brand__tag { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: 6px; padding: 5px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2); }
.tool { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border-radius: 999px; color: var(--muted); font-size: 13px; transition: background 0.2s, color 0.2s; white-space: nowrap; }
.tool:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.tool[aria-pressed="true"], .tool[aria-expanded="true"] { color: var(--text); background: rgba(255, 255, 255, 0.09); }
.tool .mute { display: none; }
.tool[aria-pressed="false"] .wave { display: none; }
.tool[aria-pressed="false"] .mute { display: inline; }
.tool--lang { color: var(--text); font-weight: 500; border: 1px solid var(--line-strong); min-width: 64px; justify-content: center; }
.tool-group { position: relative; }
.popover { position: absolute; inset-block-start: calc(100% + 12px); inset-inline-end: 0; min-width: 170px; padding: 8px; border-radius: 14px; background: rgba(12, 17, 26, 0.92); border: 1px solid var(--line); backdrop-filter: blur(16px); display: grid; gap: 2px; z-index: 5; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.check:hover { background: rgba(255, 255, 255, 0.06); }
.check input { appearance: none; width: 30px; height: 18px; border-radius: 99px; background: rgba(255, 255, 255, 0.14); position: relative; transition: background 0.2s; cursor: pointer; margin: 0; flex: none; }
.check input::after { content: ""; position: absolute; inset-block-start: 2px; inset-inline-start: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.check input:checked { background: var(--tissue); }
.check input:checked::after { transform: translateX(12px); }
[dir="rtl"] .check input:checked::after { transform: translateX(-12px); }

/* ------------------------------------------------------------ panels */
.panel { position: absolute; inset-block-start: 78px; width: 292px; max-height: calc(100vh - 78px - 150px); overflow: auto; overscroll-behavior: contain; padding: 18px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(18px) saturate(1.25); -webkit-backdrop-filter: blur(18px) saturate(1.25); scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent; }
.panel--vitals { inset-inline-start: var(--pad); }
.panel--controls { inset-inline-end: var(--pad); width: 300px; }
.panel h2 { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
[dir="rtl"] .panel h2 { letter-spacing: 0; font-size: 13px; }
.panel__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.phase { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 500; padding: 4px 11px; border-radius: 99px; border: 1px solid var(--line); color: var(--text); min-width: 82px; }
.phase__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--co2); box-shadow: 0 0 10px currentColor; transform: scale(var(--s, 1)); transition: background 0.4s; }
.phase.is-in .phase__dot { background: var(--tissue); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.stat { background: rgba(10, 14, 22, 0.88); padding: 12px 12px 11px; min-width: 0; }
.stat__label { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat__value { display: flex; align-items: baseline; gap: 6px; margin-top: 3px; }
.stat__value b { font-family: var(--mono); font-weight: 400; font-size: 29px; line-height: 1.1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat__value span { font-size: 11px; color: var(--faint); white-space: nowrap; }
.stat--spo2 .stat__value b { color: var(--good); transition: color 0.6s; }
.stat--spo2.is-warn .stat__value b { color: var(--warn); }
.stat--spo2.is-low .stat__value b { color: var(--low); }
.meter { width: 100%; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin-top: 7px; direction: ltr; }
.meter i { display: block; height: 100%; width: 90%; border-radius: 99px; background: linear-gradient(90deg, var(--low), var(--warn) 55%, var(--good) 80%); background-size: 110px 100%; transition: width 0.4s; }

.graph { margin-top: 14px; }
.graph__head { display: flex; justify-content: space-between; align-items: baseline; font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.graph__now b { font-family: var(--mono); font-weight: 500; color: var(--text); font-size: 13px; }
.graph canvas { display: block; width: 100%; height: 96px; border-radius: 10px; background: rgba(10, 14, 22, 0.7); border: 1px solid var(--line); }
.minis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.minis > div { display: grid; gap: 2px; min-width: 0; }
.minis span { font-size: 10.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.minis b { font-weight: 400; font-size: 12px; color: var(--muted); white-space: nowrap; }
.minis i { font-style: normal; font-family: var(--mono); font-size: 14px; color: var(--text); }
.minis small { font-size: 10px; color: var(--faint); }

/* ------------------------------------------------------------ scenarios + sliders */
.scenarios { display: grid; gap: 3px; margin-top: 10px; }
.scn { display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid transparent; color: var(--muted); text-align: start; transition: background 0.2s, color 0.2s, border-color 0.2s; }
.scn i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); opacity: 0.55; transition: opacity 0.2s, box-shadow 0.2s; flex: none; }
.scn:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.scn.is-active { background: rgba(255, 255, 255, 0.08); border-color: var(--line-strong); color: var(--text); font-weight: 500; }
.scn.is-active i { opacity: 1; box-shadow: 0 0 12px var(--c); }
.scn-desc { margin-top: 10px; font-size: 12.5px; color: var(--muted); min-height: 5.6em; line-height: 1.5; }
.sliders { display: grid; gap: 14px; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.slider { display: grid; gap: 9px; }
.slider__top { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; color: var(--muted); }
.slider output { font-family: var(--mono); color: var(--text); font-size: 13px; direction: ltr; }
input[type="range"] { appearance: none; -webkit-appearance: none; width: 100%; height: 22px; margin: 0; background: transparent; cursor: pointer; --p: 30%; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 99px; background: linear-gradient(to right, var(--tissue) var(--p), rgba(255, 255, 255, 0.14) var(--p)); }
[dir="rtl"] input[type="range"]::-webkit-slider-runnable-track { background: linear-gradient(to left, var(--tissue) var(--p), rgba(255, 255, 255, 0.14) var(--p)); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.14); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 99px; background: var(--tissue); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(255, 176, 164, 0.18), 0 2px 6px rgba(0, 0, 0, 0.5); transition: box-shadow 0.2s; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(255, 176, 164, 0.18); }
input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 0 7px rgba(255, 176, 164, 0.2), 0 2px 6px rgba(0, 0, 0, 0.5); }

.fact { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.fact__head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
[dir="rtl"] .fact__head { letter-spacing: 0; font-size: 13px; }
.fact__next { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); color: var(--muted); }
.fact__next:hover { color: var(--text); border-color: var(--line-strong); }
.fact__num { font-family: var(--serif); font-size: 32px; line-height: 1.15; margin-top: 6px; color: var(--tissue); direction: ltr; text-align: start; }
[dir="rtl"] .fact__num { direction: rtl; font-size: 30px; line-height: 1.4; }
.fact__text { font-size: 12.5px; color: var(--muted); margin-top: 4px; min-height: 4.4em; }
.fact__num, .fact__text { transition: opacity 0.35s; }
.fact.is-swapping .fact__num, .fact.is-swapping .fact__text { opacity: 0; }
.fact__dots { display: flex; gap: 4px; margin-top: 8px; }
.fact__dots i { width: 100%; height: 2px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); }
.fact__dots i.on { background: var(--tissue); }

/* ------------------------------------------------------------ bottom: caption + level stepper */
.bottom { position: absolute; inset-block-end: 22px; inset-inline: 0; display: grid; justify-items: center; gap: 12px; pointer-events: none !important; padding: 0 12px; }
.bottom > * { pointer-events: auto; }
.caption { display: grid; justify-items: center; gap: 7px; text-align: center; max-width: min(680px, 92vw); padding: 10px 20px 11px; border-radius: 16px; background: radial-gradient(closest-side, rgba(5, 7, 11, 0.72), rgba(5, 7, 11, 0.45) 70%, transparent); }
.caption p { font-size: 13.5px; color: var(--text); text-shadow: 0 1px 12px #000, 0 0 3px #000; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.legend button, .legend span { display: inline-flex; align-items: center; gap: 7px; text-shadow: 0 1px 8px #000; }
.legend button:hover { color: var(--text); }
.legend i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 9px var(--c); flex: none; }
.legend i.grad { width: 26px; border-radius: 99px; background: linear-gradient(90deg, #5a0d18, #ff2a1c); box-shadow: none; }
[dir="rtl"] .legend i.grad { background: linear-gradient(270deg, #5a0d18, #ff2a1c); }
.levels { display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(18px) saturate(1.25); -webkit-backdrop-filter: blur(18px) saturate(1.25); }
.lvl { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: start; padding: 7px 18px 7px 8px; border-radius: 999px; color: var(--muted); transition: background 0.25s, color 0.25s; }
[dir="rtl"] .lvl { padding: 7px 8px 7px 18px; }
.lvl b { grid-row: 1 / 3; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-strong); font-family: var(--mono); font-weight: 400; font-size: 13px; transition: background 0.25s, color 0.25s, border-color 0.25s; }
.lvl span { font-size: 13.5px; font-weight: 500; line-height: 1.15; }
.lvl small { font-size: 10.5px; color: var(--faint); font-family: var(--mono); line-height: 1.2; }
.lvl:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.lvl.is-active { color: var(--text); background: rgba(255, 255, 255, 0.09); }
.lvl.is-active b { background: var(--tissue); border-color: var(--tissue); color: #1a0d0b; font-weight: 500; }
.lvl__line { width: 18px; height: 1px; background: var(--line-strong); }
.levels.is-flying .lvl { pointer-events: none; }
.levels.is-flying .lvl.is-active b { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(255, 176, 164, 0.16); } }

/* ------------------------------------------------------------ 3D labels + info card */
#labels { position: absolute; inset: 0; overflow: hidden; }
.tag { position: absolute; inset-block-start: 0; inset-inline-start: 0; left: 0; right: auto; display: flex; align-items: center; gap: 0; pointer-events: auto; cursor: pointer; will-change: transform, opacity; transition: opacity 0.35s; direction: ltr; }
.tag__dot { width: 7px; height: 7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.16), 0 0 12px rgba(255, 255, 255, 0.6); flex: none; margin: -3.5px 0 -3.5px -3.5px; }
.tag__line { width: 30px; height: 1px; background: linear-gradient(90deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.25)); flex: none; }
.tag__text { padding: 4px 10px; border-radius: 99px; background: rgba(9, 13, 20, 0.72); border: 1px solid var(--line); font-size: 12px; white-space: nowrap; color: var(--text); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: border-color 0.2s, background 0.2s; }
[dir="rtl"] .tag__text { direction: rtl; }
.tag:hover .tag__text { border-color: var(--tissue); background: rgba(20, 14, 16, 0.9); }
.tag.is-left { flex-direction: row-reverse; }
.tag.is-left .tag__dot { margin: -3.5px -3.5px -3.5px 0; }
.tag.is-left .tag__line { background: linear-gradient(270deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.25)); }

.info { position: absolute; left: 0; top: 0; width: min(310px, 86vw); padding: 15px 16px 16px; border-radius: 14px; background: rgba(10, 14, 21, 0.9); border: 1px solid var(--line-strong); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55); will-change: transform; animation: pop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2); z-index: 4; }
@keyframes pop { from { opacity: 0; scale: 0.94; } }
.info h3 { font-family: var(--serif); font-weight: 400; font-size: 23px; line-height: 1.2; padding-inline-end: 22px; }
[dir="rtl"] .info h3 { font-size: 21px; line-height: 1.5; }
.info__alt { font-size: 12px; color: var(--tissue); margin: 0 26px 3px; }
.info p { font-size: 13px; color: #b9c3d0; margin-top: 7px; line-height: 1.55; }
.info__close { position: absolute; inset-block-start: 8px; inset-inline-end: 9px; width: 26px; height: 26px; border-radius: 50%; color: var(--muted); font-size: 18px; line-height: 1; }
.info__close:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.info-pin { position: absolute; left: 0; top: 0; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 4px rgba(255, 176, 164, 0.3), 0 0 16px var(--tissue); pointer-events: none !important; will-change: transform; }

/* ------------------------------------------------------------ intro */
.intro { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: radial-gradient(120% 90% at 50% 40%, rgba(5, 7, 11, 0.55), rgba(5, 7, 11, 0.94) 70%); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: opacity 1.1s ease, visibility 1.1s; z-index: 10; }
.intro.is-gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro__inner { max-width: 560px; text-align: center; display: grid; justify-items: center; transition: opacity 0.6s; }
.fonts-pending .intro__inner { opacity: 0; }
.intro__eyebrow { font-size: 11.5px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.intro h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(72px, 13vw, 132px); line-height: 1; margin-top: 14px; letter-spacing: -0.01em; background: linear-gradient(180deg, #fff 30%, var(--tissue)); -webkit-background-clip: text; background-clip: text; color: transparent; padding-bottom: 0.08em; }
[dir="rtl"] .intro h1 { line-height: 1.5; font-size: clamp(64px, 11vw, 112px); padding-bottom: 0; margin-top: 0; }
.intro__tag { font-size: 17px; color: var(--text); margin-top: 6px; }
.intro__text { font-size: 14.5px; color: var(--muted); margin-top: 18px; line-height: 1.65; max-width: 50ch; }
.intro__load { margin-top: 34px; display: grid; justify-items: center; gap: 12px; font-size: 12.5px; color: var(--muted); height: 52px; }
.bar { width: 220px; height: 2px; background: rgba(255, 255, 255, 0.12); border-radius: 2px; overflow: hidden; direction: ltr; }
.bar i { display: block; height: 100%; width: 0%; background: var(--tissue); transition: width 0.3s; }
.intro__go { margin-top: 34px; display: flex; gap: 10px; align-items: center; height: 52px; }
.begin { display: inline-flex; align-items: center; gap: 12px; height: 52px; padding: 0 30px; border-radius: 999px; background: var(--tissue); color: #1a0d0b; font-size: 16px; font-weight: 600; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 0 0 0 rgba(255, 176, 164, 0.4); animation: breathe 4.2s ease-in-out infinite; }
.begin:hover { transform: translateY(-1px); }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 176, 164, 0.28); } 40% { box-shadow: 0 0 0 14px rgba(255, 176, 164, 0); } }
.ghost { height: 52px; padding: 0 22px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--text); font-weight: 500; }
.ghost:hover { background: rgba(255, 255, 255, 0.06); }
.intro__hint { margin-top: 26px; font-size: 12px; color: var(--faint); }
.fatal { position: fixed; inset: auto 16px 16px 16px; padding: 14px 16px; border-radius: 12px; background: #2a1213; border: 1px solid #6b2b2b; color: #ffd0cc; font-family: var(--mono); font-size: 12px; z-index: 20; white-space: pre-wrap; }

/* ------------------------------------------------------------ smaller screens */
/* wide windows: the side panels can run down past the centred caption and level stepper */
@media (min-width: 1200px) { .panel { max-height: calc(100vh - 78px - 22px); } .caption { max-width: min(680px, calc(100vw - 700px)); } }
@media (min-width: 821px) and (max-height: 740px) { .fact__text { min-height: 0; } .scn-desc { min-height: 0; } .panel { padding: 16px; } .scn { height: 32px; } .fact__num { font-size: 28px; } .sliders { gap: 12px; } }
@media (min-width: 821px) and (max-height: 660px) { .fact { display: none; } }
@media (max-width: 1080px) {
  .brand__tag { display: none; }
  .panel { width: 250px; padding: 14px; }
  .panel--controls { width: 262px; }
  .stat__value b { font-size: 24px; }
  .tool span { display: none; }
  .tool--lang span { display: inline; }
  .tool { padding: 0 10px; }
}
@media (max-width: 820px) {
  .panel { inset-block-start: 68px; }
  .panel--vitals { inset-inline: 10px; width: auto; padding: 8px; max-height: none; }
  .panel--vitals .panel__head, .panel--vitals .graph, .panel--vitals .minis, .panel--vitals .meter { display: none; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stat { padding: 7px 8px; }
    .stat__value b { font-size: 19px; }
  .stat__value span { display: none; }
  .stat__label { font-size: 10px; }
  .panel--controls { inset-block-start: auto; inset-block-end: 132px; inset-inline: 10px; width: auto; max-height: 34vh; }
  .scenarios { grid-template-columns: repeat(2, 1fr); }
  .scn-desc, .fact { display: none; }
  .lvl small { display: none; }
  .lvl { padding-inline-end: 12px; }
  .caption p { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { .begin, .levels.is-flying .lvl.is-active b { animation: none; } }
