/* Patient viewer — designed for a headset browser first, a phone or laptop
   second. Everything is oversized: text read through a Quest's lenses at arm's
   length loses a lot of effective resolution, and targets are hit with a
   controller ray, not a fingertip.

   Palette is deliberately cool and dim. This screen is the last thing a patient
   sees before an exposure they are anxious about; bright white panels and red
   accents are the wrong choice clinically. */

:root {
  --bg: #0a0f1c;
  --bg-panel: #111a2e;
  --line: #24314f;
  --ink: #e8eefc;
  --ink-dim: #93a3c4;
  --accent: #6366f1;
  --accent-soft: #4f46e5;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 400 18px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* A calm radial wash rather than a flat fill — flat dark panels read as "screen
   off" through headset optics. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, #16224180 0%, #0a0f1c 70%);
  pointer-events: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4vh 4vw;
}
.screen[hidden] { display: none; }
.screen-bare { padding: 0; }

.panel {
  width: min(560px, 92vw);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 40px 36px;
  text-align: center;
  box-shadow: 0 24px 70px #0008;
}

.brand {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}
.greeting { margin: 0 0 10px; font-size: 34px; font-weight: 700; }
.lede { margin: 0 0 26px; font-size: 20px; color: var(--ink-dim); }

/* ---- PIN entry ---- */
.entry {
  display: flex;
  justify-content: center;
  gap: 12px;
  min-height: 62px;
  margin-bottom: 8px;
}
.entry i {
  display: block;
  width: 42px;
  height: 58px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #0c142a;
  font: 700 30px/54px ui-monospace, monospace;
  font-style: normal;
  text-align: center;
  color: var(--ink);
}
.entry i.filled { border-color: var(--accent); }

.error {
  min-height: 28px;
  margin: 0 0 12px;
  font-size: 17px;
  color: var(--err);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.key {
  appearance: none;
  padding: 26px 0;
  font: 600 30px/1 system-ui, sans-serif;
  color: var(--ink);
  background: #17223c;
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  /* Touch/ray targets need real area; 26px padding puts every key well past
     the 44px minimum even before the grid gap. */
  min-height: 82px;
  transition: background 120ms ease, transform 80ms ease;
}
.key:hover { background: #1e2b4a; }
.key:active { transform: scale(0.97); }
.key-muted { color: var(--ink-dim); font-size: 26px; }
.key-go { background: var(--accent-soft); border-color: var(--accent); }
.key-go:hover { background: var(--accent); }
.key:disabled { opacity: 0.4; cursor: default; }

.link {
  appearance: none;
  margin-top: 22px;
  padding: 12px 20px;
  font: 500 17px/1 system-ui, sans-serif;
  color: var(--ink-dim);
  background: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.link:hover { color: var(--ink); }

/* ---- Lobby ---- */
.waiting {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 10px 0 30px;
}
.waiting span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.waiting span:nth-child(2) { animation-delay: 0.2s; }
.waiting span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50%      { opacity: 1;    transform: scale(1.15); }
}

.facts {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
  text-align: left;
}
.facts > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: #0e1730;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.facts dt { margin: 0; color: var(--ink-dim); font-size: 16px; }
.facts dd { margin: 0; font-weight: 600; font-size: 17px; text-align: right; }
.facts dd.ok { color: var(--ok); }
.facts dd.warn { color: var(--warn); }
.facts dd.err { color: var(--err); }

.hint { margin: 6px 0 0; font-size: 16px; color: var(--warn); min-height: 24px; }

/* ---- Running scene ---- */
#scene-frame {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 20px;
  grid-auto-flow: row;
  background: #060a14ee;
  font-size: 20px;
  color: var(--ink-dim);
}
.overlay[hidden] { display: none; }

.spinner {
  width: 54px;
  height: 54px;
  border: 5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.badge {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 22px;
  background: #0b122abb;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 16px;
  color: var(--ink-dim);
}
.badge[hidden] { display: none; }

/* Respect a patient's reduced-motion preference. Vestibular sensitivity and
   phobia treatment overlap more than you would like. */
@media (prefers-reduced-motion: reduce) {
  .waiting span, .spinner { animation: none; }
  .key { transition: none; }
}

/* ── Emergency stop ──────────────────────────────────────────────────────────
   The patient's single control during an exposure. Deliberately the largest,
   highest-contrast target on the screen and pinned to a corner that no scene
   content occupies. Sized for a controller ray in a headset, not a mouse. */
#shell-emergency-stop {
  position: fixed;
  top: 3vh;
  right: 3vw;
  z-index: 2147483647;
  padding: 22px 40px;
  font: 700 26px/1 system-ui, -apple-system, sans-serif;
  color: #fff;
  background: #dc2626;
  border: 3px solid #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.66);
  cursor: pointer;
}
#shell-emergency-stop:hover { background: #b91c1c; }
#shell-emergency-stop:active { transform: scale(0.97); }
#shell-emergency-stop:focus-visible { outline: 4px solid #fca5a5; outline-offset: 3px; }
/* No visibility rule needed: the button lives inside #screen-session, and
   `.screen[hidden] { display: none }` above takes its descendants with it. */
