/* Simulation monitor — the instrument face.
   Load order: basecoat.min.css -> tokens.css -> tool.css -> monitor.css
   Everything on this page is brand chrome and uses the tokens, EXCEPT the
   block below. Those are DATA colours: the four traces, the numerals that
   belong to them, and the black ground monitor.js fills the canvas with.
   They are clinical convention, not theme — never re-theme them. */
:root {
  --screen:#000000;   /* canvas ground; monitor.js fills this exact value */
  --flash: #ffffff;   /* defibrillation discharge flash */

  /* The traces sweep only the left region; the numbers keep their own
     reserved column on the right, so the two can never overlap. */
  --numw: clamp(120px, 27vw, 320px);
}

* { -webkit-tap-highlight-color: transparent; }

/* tokens.css insets the body for the notch and lets it scroll; the monitor is
   a fixed full-bleed instrument and does its own insetting, lane by lane. */
html, body {
  height: 100%; padding: 0; overflow: hidden;
  background: var(--screen); color: var(--foreground);
  font-variant-numeric: tabular-nums;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--screen); }

/* ------------------------------------------------------------- top bar */
#topbar {
  flex: none; position: relative; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 40px;
  padding-top: env(safe-area-inset-top);
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: var(--background); border-bottom: 1px solid var(--border);
}
#code-chip {
  display: flex; align-items: baseline; gap: 7px; white-space: nowrap;
  font-family: var(--font-data); font-size: 11px; letter-spacing: .1em;
  color: var(--muted-foreground);
}
#code-chip b { font-size: 20px; font-weight: 700; letter-spacing: .22em; color: var(--primary); }

.tools { display: flex; align-items: center; gap: 2px; min-width: 0; }
#peer {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-data); font-size: 11px; letter-spacing: .06em;
  color: var(--muted-foreground);
}
#peer.live { color: var(--success); }

/* Slim bar, full-size targets. The visual box stays 30px so the bar keeps its
   40px height; a transparent pseudo-element takes the hit area to 44px
   without adding a single pixel to the layout. */
#topbar .mon-btn {
  position: relative; height: 30px; min-height: 0; min-width: 44px; padding: 0 8px;
  font-family: var(--font-data); font-size: 11px; font-weight: 400; letter-spacing: .08em;
  color: var(--foreground); cursor: pointer;
}
/* asymmetric on purpose: the bar sits at y=0, so the target grows downward
   into the (non-interactive) lane area rather than off the top of the screen */
#topbar .mon-btn::after { content: ""; position: absolute; left: 0; right: 0; top: -7px; bottom: -11px; }
#topbar .mon-btn:active { background: var(--secondary); }
#topbar .mon-btn.off { color: var(--muted-foreground); text-decoration: line-through; opacity: .7; }

/* Narrow landscape: the pairing code and the four controls are the bar's job —
   the status word is the first thing to go so nothing clips. */
@media (max-width: 460px) {
  #topbar { gap: 6px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right)); }
  #peer { display: none; }
  #code-chip { flex: none; }
  #topbar .mon-btn { padding: 0 5px; }
}

/* ---------------------------------------------------------- alarm strip */
#alarm-strip { flex: 1; min-width: 0; display: flex; gap: 6px; overflow: hidden; justify-content: center; }
.alarm {
  padding: 2px 9px; border-radius: calc(var(--radius) - 4px);
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; white-space: nowrap;
}
.alarm.p3 { background: var(--destructive); color: var(--destructive-foreground); animation: blink .9s steps(1,end) infinite; }
.alarm.p2 { background: var(--primary); color: var(--primary-foreground); }
.alarm.p1 { background: var(--accent); color: var(--accent-foreground); }
@keyframes blink { 50% { opacity: .25; } }

/* ---------------------------------------------------------------- lanes */
#lanes {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--screen);
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
.lane { position: relative; flex: 1; min-height: 0; }
.lane canvas {
  position: absolute; left: 0; top: 0; display: block;
  /* canvas is a replaced element: width/height:auto would use the intrinsic
     (attribute) size, not the left/right stretch — size it explicitly */
  width: calc(100% - var(--numw)); height: 100%;
}
.lane .readout {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  width: var(--numw); padding-right: 2.2vmin;
  text-align: right; pointer-events: none; line-height: .95;
}
.lane .lbl {
  display: block; margin: 0 0 .15em;
  font-size: clamp(11px, 2.1vmin, 20px); font-weight: 700; letter-spacing: .06em; opacity: .92;
}
/* .val and .sub also exist in tool.css as readout classes — reset the margins
   they bring so the label stays welded to its number. */
.lane .val { display: block; margin: 0; font-size: clamp(38px, 10vmin, 130px); font-weight: 700; letter-spacing: -.02em; }
.lane .sub { display: block; margin: .1em 0 0; font-size: clamp(15px, 3.2vmin, 40px); font-weight: 700; }
.lane .val.wide { font-size: clamp(24px, 7vmin, 96px); }   /* "124/76" needs the room */

/* SimMon-style: label sits inline to the left of the number */
.lane .inline { display: flex; align-items: baseline; justify-content: flex-end; gap: .35em; }
.lane .inline .lbl { margin: 0; }

#lane-ecg   .val, #lane-ecg   .lbl { color: var(--ecg); }
#lane-pleth .val, #lane-pleth .lbl { color: var(--vital); }
#lane-art   .val, #lane-art   .lbl { color: var(--vital); }
#lane-art   .sub { color: var(--art); }
#lane-co2   .val, #lane-co2   .lbl, #lane-co2 .sub { color: var(--co2); }
.readout.alarming { animation: blink 1s steps(1,end) infinite; }

#nopulse {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  font-size: clamp(14px, 3vmin, 34px); font-weight: 700; letter-spacing: .2em;
  color: var(--destructive); animation: blink 1s steps(1,end) infinite;
}

/* --------------------------------------------------------------- footer */
#footer {
  flex: none; min-height: 26px; display: flex; align-items: center; gap: 12px;
  padding: 2px max(12px, env(safe-area-inset-right))
           calc(2px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--background); border-top: 1px solid var(--border);
  font-family: var(--font-data); font-size: 11px; letter-spacing: .04em;
  color: var(--muted-foreground); overflow: hidden; white-space: nowrap;
}
#footer b { color: var(--foreground); font-weight: 700; }
#sc-note { color: var(--primary); overflow: hidden; text-overflow: ellipsis; }

/* Basecoat also ships .badge; these are the monitor's status flags, so scope
   past it rather than fight it. */
#badges { margin-left: auto; display: flex; gap: 6px; }
#badges .badge {
  height: auto; border: 0; padding: 1px 8px; border-radius: calc(var(--radius) - 4px);
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
  background: var(--accent); color: var(--accent-foreground);
}
#badges .badge.cpr { background: var(--destructive); color: var(--destructive-foreground); animation: blink .6s steps(1,end) infinite; }
#badges .badge.paused { background: color-mix(in oklab, var(--primary) 22%, transparent); color: var(--primary); }
#badges .badge.frozen { background: var(--secondary); color: var(--muted-foreground); }

#flash { position: fixed; inset: 0; z-index: 50; background: var(--flash); opacity: 0; pointer-events: none; }
.hidden { display: none !important; }

/* --------------------------------------------------------------- splash */
#splash {
  position: fixed; inset: 0; z-index: 60; overflow-y: auto;
  background: var(--background);
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
.splash-inner { min-height: 100%; display: flex; flex-direction: column; }
.splash-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.splash-card { width: 100%; max-width: 540px; gap: 0; padding-block: 4px; }
#splash .site-footer { margin-top: 0; }

.pair { display: flex; flex-wrap: wrap; gap: 18px; }
.pair-alt { flex: 1 1 190px; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.pair-alt .acts { margin-top: 0; }
.pair-alt .hint { margin: 0; }

#mpin { display: flex; gap: 8px; margin-bottom: 10px; }
.pin-box {
  width: 46px; height: 54px; display: grid; place-items: center;
  background: var(--background); border: 1px solid var(--input);
  border-radius: calc(var(--radius) + 2px);
  font-family: var(--font-data); font-size: 26px; font-weight: 700; color: var(--primary);
}
.pin-box.on { border-color: var(--primary); box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--primary) 20%, transparent); }

#keypad { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; }
#keypad .btn { height: 48px; font-family: var(--font-data); font-size: 20px; font-weight: 700; }
#keypad .btn[data-k="del"], #keypad .btn[data-k="go"] { font-size: 12px; letter-spacing: .14em; }
#pair-msg { min-height: 18px; font-size: 13px; line-height: 1.5; color: var(--destructive); white-space: normal; }

/* Landscape phone: the splash is short on height, so the chrome gives way
   first and the keypad drops to its 44px floor. It may still scroll — a
   one-time pairing screen is allowed to. */
@media (max-height: 520px) {
  #splash .site-header { min-height: 40px; padding: 4px 12px; }
  .splash-body { padding: 8px 12px; }
  #splash .site-footer { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .splash-card { padding-block: 0; }
  #mpin { margin-bottom: 8px; }
  .pin-box { height: 44px; }
  #keypad { gap: 6px; }
  #keypad .btn { height: 44px; }
}

/* ----------------------------------------------- standalone scenario menu */
#scmenu {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 55; width: min(420px, 92vw);
  display: flex; flex-direction: column;
  background: var(--popover); border-left: 1px solid var(--border);
  padding-top: env(safe-area-inset-top); padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}
.scmenu-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 10px 6px 16px; border-bottom: 1px solid var(--border);
}
.scmenu-head b { font-size: 12px; font-weight: 700; letter-spacing: .08em; color: var(--muted-foreground); }
#scmenu-list { flex: 1; overflow-y: auto; padding: 10px 12px 30px; }
.scmenu-cat {
  margin: 16px 4px 6px; font-size: 11px; font-weight: 700; letter-spacing: .1em;
  color: var(--muted-foreground);
}
.scmenu-item {
  display: block; width: 100%; min-height: 44px; margin-bottom: 8px; padding: 10px 13px;
  text-align: left; font: inherit; cursor: pointer; color: var(--foreground);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.scmenu-item:hover { border-color: color-mix(in oklab, var(--primary) 55%, transparent); }
.scmenu-item:active { background: var(--accent); }
.scmenu-item b { display: block; font-size: 14px; font-weight: 700; }
.scmenu-item span { display: block; margin-top: 2px; font-size: 12px; line-height: 1.5; color: var(--muted-foreground); }

/* ------------------------------------------------- landscape-only on phones
   The traces need width; a portrait phone gives a 44px-tall lane that reads as
   noise. Gate the whole instrument instead of shipping a broken one. The
   remote never loads this file, so the remote never sees this. */
#rotate-gate { display: none; }
@media (orientation: portrait) and (max-width: 900px) {
  #rotate-gate {
    position: fixed; inset: 0; z-index: 90;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
    padding: 32px calc(16px + env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom))
             calc(16px + env(safe-area-inset-left));
    background: var(--background); text-align: center; overflow: hidden;
  }
  /* rotate() leaves the layout box unrotated, so the mark gets a box the size
     of its rotated footprint and overflows it symmetrically. */
  #rotate-gate .rot-mark {
    width: min(23vw, 100px); height: min(46vw, 200px);
    display: grid; place-items: center; color: var(--primary);
  }
  #rotate-gate svg {
    width: min(46vw, 200px); height: auto;
    transform: rotate(90deg); animation: rot-nudge 2.8s ease-in-out infinite;
  }
  #rotate-gate p { max-width: 17em; font-size: 15px; line-height: 1.6; color: var(--muted-foreground); }
  /* Traces hold still underneath rather than sweeping behind a closed door. */
  #lanes { visibility: hidden; }
}
@keyframes rot-nudge { 0%, 74%, 100% { transform: rotate(90deg); } 86% { transform: rotate(76deg); } }
@media (prefers-reduced-motion: reduce) { #rotate-gate svg { animation: none; } }
