:root {
  --bg: #0b0e16;
  --glass: rgba(18, 24, 40, 0.62);
  --glass-2: rgba(28, 36, 58, 0.55);
  --stroke: rgba(120, 150, 200, 0.18);
  --stroke-2: rgba(140, 175, 230, 0.32);
  --ink: #e8eef7;
  --ink-dim: #93a4bd;
  --accent: #36d0e0;
  --accent-2: #7aa0ff;
  --warn: #ffce4a;
  --crit: #ff5b5b;
  --ok: #34d39a;
  --radius: 14px;
  --blur: blur(14px) saturate(1.2);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* enforce the hidden attribute over element display rules */
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }

/* ── Loading ── */
#loading {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 18px;
  background: radial-gradient(60% 60% at 50% 45%, #11192b 0%, var(--bg) 100%); z-index: 50;
  transition: opacity 0.6s ease; color: var(--ink-dim);
}
#loading.done { opacity: 0; pointer-events: none; }
#loading .heartbeat { font-size: 56px; color: #c0303a; animation: beat 1s ease-in-out infinite; }
#loading p { font-size: 14px; letter-spacing: 0.04em; }
@keyframes beat { 0%, 60%, 100% { transform: scale(1); } 12% { transform: scale(1.18); } 30% { transform: scale(1.05); } }

/* ── Fatal fallback ── */
#fatal { position: fixed; inset: 0; display: grid; place-content: center; padding: 24px; z-index: 60; background: var(--bg); }
.fatal-card { max-width: 560px; background: var(--glass); border: 1px solid var(--stroke); border-radius: var(--radius); padding: 26px; backdrop-filter: var(--blur); }
.fatal-card h1 { font-size: 22px; margin-bottom: 10px; }
#fatal-panels { margin-top: 18px; }

/* ── UI overlay ── */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#ui > * { pointer-events: auto; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: linear-gradient(180deg, rgba(8, 11, 20, 0.85), rgba(8, 11, 20, 0));
  pointer-events: none;
}
#topbar .brand { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
#topbar .brand-mark { font-size: 22px; color: #d23a42; filter: drop-shadow(0 0 8px rgba(210, 58, 66, 0.6)); }
#topbar h1 { font-size: 19px; }
#topbar .tagline { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-dim); max-width: 60ch; }
.icon-btn {
  pointer-events: auto; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--stroke-2);
  background: var(--glass); color: var(--ink); font-style: italic; font-weight: 700; backdrop-filter: var(--blur);
}

/* ── Side panels ── */
aside {
  position: fixed; top: 64px; bottom: 78px; width: 290px; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 12px; padding: 4px; scrollbar-width: thin;
}
#panel-left { left: 14px; }
#panel-right { right: 14px; }
aside::-webkit-scrollbar { width: 7px; }
aside::-webkit-scrollbar-thumb { background: rgba(120, 150, 200, 0.25); border-radius: 4px; }

.section, .panel {
  background: var(--glass); border: 1px solid var(--stroke); border-radius: var(--radius);
  padding: 14px 15px; backdrop-filter: var(--blur); box-shadow: var(--shadow);
}
.section h2, .panel-h { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-dim); margin-bottom: 10px; }
.panel-h .unit, .panel-h .sub { text-transform: none; letter-spacing: 0; color: var(--accent); font-weight: 500; }
.panel-h .sub { display: block; font-size: 11px; color: var(--ink-dim); margin-top: 2px; }

/* scenarios */
.scenarios { display: flex; flex-direction: column; gap: 7px; }
.scenario-btn {
  text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--stroke);
  background: var(--glass-2); color: var(--ink); font-size: 13.5px; transition: all 0.18s ease;
}
.scenario-btn:hover { border-color: var(--stroke-2); transform: translateX(2px); }
.scenario-btn.active { border-color: var(--accent); background: rgba(54, 208, 224, 0.14); color: #fff; box-shadow: inset 0 0 0 1px rgba(54, 208, 224, 0.4); }

/* controls */
.ctl-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 2px; font-size: 13px; color: var(--ink); }
.ctl-select { background: var(--glass-2); color: var(--ink); border: 1px solid var(--stroke); border-radius: 8px; padding: 4px 8px; font-size: 12.5px; }
.ctl-toggle { appearance: none; width: 38px; height: 21px; border-radius: 11px; background: rgba(120, 140, 170, 0.3); position: relative; transition: background 0.2s; cursor: pointer; flex: none; }
.ctl-toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.ctl-toggle:checked { background: var(--accent); }
.ctl-toggle:checked::after { transform: translateX(17px); }

/* spectrum */
.spectrum-bar { position: relative; height: 16px; border-radius: 8px; margin: 4px 0 2px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); }
.spectrum-cursor { position: absolute; top: -3px; width: 3px; height: 22px; background: #fff; border-radius: 2px; box-shadow: 0 0 8px #fff; transform: translateX(-1.5px); }
.spectrum-ticks { position: relative; height: 26px; margin-top: 2px; }
.spectrum-ticks .tick { position: absolute; transform: translateX(-50%); text-align: center; }
.spectrum-ticks .tick i { display: block; width: 1px; height: 5px; background: var(--ink-dim); margin: 0 auto 2px; }
.spectrum-ticks .tick b { font-size: 10.5px; color: var(--ink-dim); font-weight: 500; }
.spectrum-note { font-size: 11.5px; color: var(--ink-dim); margin: 6px 0 0; line-height: 1.45; }

/* shear gap */
.gap-panel { border-color: rgba(255, 206, 74, 0.25); }
.gap-chart { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.gap-row { display: grid; grid-template-columns: 92px 1fr 42px; align-items: center; gap: 8px; font-size: 11.5px; }
.gap-label { color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gap-track { height: 9px; background: rgba(120, 140, 170, 0.14); border-radius: 5px; overflow: hidden; }
.gap-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, #2b6, #6c9); transition: width 0.9s cubic-bezier(.2,.7,.2,1); }
.gap-row.physiological .gap-fill { background: linear-gradient(90deg, #ffce4a, #ff5b5b, #c000c8); }
.gap-row.physiological .gap-label { color: var(--ink); font-weight: 600; }
.gap-val { font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; }
.gap-take { font-size: 11.5px; line-height: 1.5; color: var(--ink-dim); margin: 4px 0 0; border-top: 1px solid var(--stroke); padding-top: 8px; }

/* readout */
.readout-wss { margin: 2px 0 6px; }
.readout-num { font-size: 20px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.readout-regime { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 20px; background: rgba(120,150,200,0.16); color: var(--ink-dim); margin-bottom: 6px; }
.regime-extreme { background: rgba(10,20,120,0.4); color: #9bb8ff; }
.regime-low { background: rgba(0,180,220,0.16); color: #7fe3f0; }
.regime-moderate { background: rgba(220,220,0,0.14); color: #e7e07a; }
.regime-high { background: rgba(255,80,0,0.16); color: #ffb27a; }
.regime-low_oscillatory { background: rgba(255,206,74,0.16); color: var(--warn); }
.readout-note { font-size: 12px; color: var(--ink-dim); line-height: 1.5; margin: 4px 0 0; }

/* tooltip */
.tooltip { position: fixed; z-index: 40; max-width: 260px; padding: 9px 12px; background: rgba(10, 14, 24, 0.92); border: 1px solid var(--stroke-2); border-radius: 10px; backdrop-filter: var(--blur); font-size: 12px; pointer-events: none; box-shadow: var(--shadow); }
.tooltip b { display: block; color: #fff; font-size: 13px; margin-bottom: 3px; }
.tip-wss { display: block; color: var(--accent); font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.tip-note { display: block; color: var(--ink-dim); line-height: 1.4; }

/* bottom bar + journey button */
#bottombar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: center; gap: 16px; padding: 14px; background: linear-gradient(0deg, rgba(8,11,20,0.85), rgba(8,11,20,0)); pointer-events: none; }
#bottombar > * { pointer-events: auto; }
.primary-btn { padding: 11px 20px; border-radius: 24px; border: 1px solid var(--stroke-2); background: linear-gradient(180deg, rgba(54,208,224,0.22), rgba(54,208,224,0.08)); color: #fff; font-size: 14px; font-weight: 600; backdrop-filter: var(--blur); box-shadow: var(--shadow); transition: transform 0.15s, box-shadow 0.2s; }
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 16px 44px rgba(54,208,224,0.3); }
.controls-hint { font-size: 11.5px; color: var(--ink-dim); margin: 0; }
body.journey-active #bottombar, body.journey-active aside { opacity: 0.0; pointer-events: none; transition: opacity 0.3s; }

/* journey stage */
#journey-stage { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(440px, 92vw); z-index: 30; }
.jcard { background: var(--glass); border: 1px solid var(--stroke-2); border-radius: 16px; padding: 16px 18px; backdrop-filter: var(--blur); box-shadow: var(--shadow); animation: jrise 0.35s ease; }
.jcard.climax { border-color: var(--crit); box-shadow: 0 0 0 1px var(--crit), 0 16px 48px rgba(255,91,91,0.3); }
@keyframes jrise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.jhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.jstep { font-size: 11px; color: var(--ink-dim); letter-spacing: 0.08em; }
.jevent { font-size: 11px; padding: 2px 10px; border-radius: 20px; background: rgba(54,208,224,0.16); color: var(--accent); font-weight: 600; }
.jevent.rupture { background: rgba(255,91,91,0.18); color: var(--crit); }
.jcard h3 { font-size: 17px; margin: 2px 0 10px; }
.jshear { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.jshear-bar { position: relative; flex: 1; height: 10px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1); }
.jshear-mark { position: absolute; top: -3px; width: 3px; height: 16px; background: #fff; border-radius: 2px; box-shadow: 0 0 8px #fff; transform: translateX(-1.5px); }
.jshear-val { font-size: 13px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.jshear-val .unit { font-size: 10px; color: var(--ink-dim); font-weight: 400; }
.jcopy { font-size: 13px; line-height: 1.55; color: var(--ink); margin: 0 0 8px; }
.jnote { font-size: 11px; color: var(--ink-dim); margin: 0 0 8px; font-style: italic; }
.jgauge { display: flex; align-items: center; gap: 9px; margin: 10px 0; }
.jgauge-label { font-size: 11px; color: var(--ink-dim); white-space: nowrap; }
.jgauge-track { flex: 1; height: 10px; background: rgba(120,140,170,0.18); border-radius: 6px; overflow: hidden; }
.jgauge-fill { height: 100%; border-radius: 6px; transition: width 0.6s cubic-bezier(.2,.7,.2,1), background 0.4s; }
.jgauge-fill.ok { background: linear-gradient(90deg, #2b8, var(--ok)); }
.jgauge-fill.warn { background: linear-gradient(90deg, #d9a23a, var(--warn)); }
.jgauge-fill.crit { background: linear-gradient(90deg, #b33, var(--crit)); }
.jgauge-pct { font-size: 12.5px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; width: 38px; text-align: right; }
.jctrls { display: flex; gap: 8px; margin-top: 10px; }
.jbtn { flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--stroke-2); background: var(--glass-2); color: var(--ink); font-size: 12.5px; font-weight: 600; transition: all 0.15s; }
.jbtn:hover:not(:disabled) { border-color: var(--accent); color: #fff; }
.jbtn:disabled { opacity: 0.4; cursor: default; }
.jbtn.jexit { flex: 0 0 auto; padding: 9px 12px; color: var(--ink-dim); }
.jcard.resolution { border-color: var(--crit); }

/* modal */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-content: center; padding: 22px; background: rgba(6,9,16,0.6); backdrop-filter: blur(3px); }
.modal-card { position: relative; max-width: 540px; background: var(--glass); border: 1px solid var(--stroke-2); border-radius: var(--radius); padding: 26px 28px; backdrop-filter: var(--blur); box-shadow: var(--shadow); }
.modal-card h2 { font-size: 20px; margin-bottom: 12px; }
.modal-card p { font-size: 14px; line-height: 1.6; color: var(--ink); margin: 0 0 12px; }
.modal-foot { font-size: 12px; color: var(--ink-dim); }
.modal-close { position: absolute; top: 12px; right: 14px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--stroke); background: var(--glass-2); color: var(--ink); font-size: 18px; }

/* skip intro */
#skip-intro { position: fixed; bottom: 22px; right: 22px; z-index: 45; padding: 8px 16px; border-radius: 20px; border: 1px solid var(--stroke-2); background: var(--glass); color: var(--ink); font-size: 13px; backdrop-filter: var(--blur); }
body.intro-running aside, body.intro-running #bottombar { opacity: 0; transition: opacity 0.5s; }

/* flow disclaimer (persistent, main view) */
#flow-disclaimer { position: fixed; left: 14px; bottom: 8px; z-index: 25; font-size: 10.5px; color: var(--ink-dim); background: rgba(10,14,24,0.55); border: 1px solid var(--stroke); border-radius: 8px; padding: 4px 9px; backdrop-filter: var(--blur); pointer-events: none; max-width: 280px; }
body.journey-active #flow-disclaimer, body.simlab-active #flow-disclaimer, body.intro-running #flow-disclaimer { opacity: 0; }

/* tumor + sim-lab chips */
.h2-hint, .sl-blurb { text-transform: none; letter-spacing: 0; }
.h2-hint { color: var(--accent); font-size: 10px; font-weight: 500; margin-left: 6px; }
.sl-blurb { font-size: 11.5px; color: var(--ink-dim); margin: 0 0 9px; line-height: 1.45; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 11px; border-radius: 18px; border: 1px solid var(--stroke); background: var(--glass-2); color: var(--ink); font-size: 12px; transition: all 0.15s; }
.chip:hover { border-color: var(--stroke-2); }
.chip.on { border-color: #c050d8; background: rgba(192,80,216,0.18); color: #fff; box-shadow: inset 0 0 0 1px rgba(192,80,216,0.4); }
.chip.sl-target:hover { border-color: var(--accent); color: #fff; }

/* simulation lab overlay */
#simlab-stage { position: fixed; right: 18px; bottom: 18px; z-index: 30; width: 280px; }
.sl-card { background: var(--glass); border: 1px solid var(--stroke-2); border-radius: 16px; padding: 14px 16px; backdrop-filter: var(--blur); box-shadow: var(--shadow); animation: jrise 0.35s ease; }
.sl-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sl-title { font-size: 15px; font-weight: 650; color: #fff; }
.sl-exit { padding: 6px 12px; border-radius: 9px; border: 1px solid var(--stroke-2); background: var(--glass-2); color: var(--ink-dim); font-size: 12px; }
.sl-exit:hover { color: #fff; border-color: var(--accent); }
.sl-canvas { display: block; width: 240px; height: 240px; margin: 0 auto; background: rgba(8,11,20,0.5); border-radius: 12px; }
.sl-readout { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 4px; }
.sl-wss { font-size: 15px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.sl-regime { font-size: 11px; padding: 2px 9px; border-radius: 20px; background: rgba(120,150,200,0.16); color: var(--ink-dim); }
.sl-caption { font-size: 10.5px; color: var(--ink-dim); line-height: 1.45; margin: 6px 0 0; border-top: 1px solid var(--stroke); padding-top: 7px; }
body.simlab-active aside, body.simlab-active #bottombar { opacity: 0; pointer-events: none; transition: opacity 0.3s; }

/* ── Responsive / touch ── */
@media (max-width: 820px) {
  #topbar .tagline { display: none; }
  #topbar h1 { font-size: 16px; }
  aside { position: fixed; top: auto; bottom: 0; width: auto; left: 0; right: 0; max-height: 44vh; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; gap: 10px; padding: 10px; background: linear-gradient(0deg, rgba(8,11,20,0.92), rgba(8,11,20,0.4)); }
  #panel-left, #panel-right { bottom: 0; }
  #panel-right { display: none; } /* readout shown via left on small screens to save room */
  .section, .panel { min-width: 220px; }
  #bottombar { bottom: 46vh; }
  #bottombar .controls-hint { display: none; }
  .primary-btn { white-space: nowrap; }
  #journey-stage { bottom: 12px; width: 94vw; }
}
@media (max-width: 820px) and (orientation: landscape) {
  aside { max-height: 90vh; flex-direction: column; width: 240px; }
  #panel-left { left: 8px; bottom: 8px; top: 56px; } #panel-right { display: flex; right: 8px; bottom: 8px; top: 56px; }
  #bottombar { bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; transition-duration: 0.08s !important; }
  #loading .heartbeat { animation: none; }
}
