/* ==========================================================================
   Face + Gesture Unlock: dark "scanner" UI
   ========================================================================== */

:root {
  --bg: #05080d;
  --bg-2: #0a111a;
  --panel: rgba(8, 16, 26, 0.78);
  --line: rgba(120, 220, 255, 0.16);
  --text: #d8f3ff;
  --muted: #7d98a8;
  --accent: #3ee8ff;      /* scanning / idle */
  --ok: #34f5a0;          /* match / unlocked */
  --bad: #ff4d6d;         /* errors / no match */
  --hand: #b48cff;        /* hand step */
  --state: var(--accent); /* current state colour, set per stage state below */
  --radius: 18px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(62, 232, 255, 0.10), transparent 70%),
    linear-gradient(rgba(120, 220, 255, 0.035) 1px, transparent 1px) 0 0 / 100% 28px,
    var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

main { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Header + step indicator ---------- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 600 15px/1 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand-icon {
  width: 26px; height: 26px;
  fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round;
  filter: drop-shadow(0 0 6px rgba(62, 232, 255, 0.6));
}

.steps {
  display: flex;
  gap: 6px;
  margin: 0; padding: 0;
  list-style: none;
  font: 500 12px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.step {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px 7px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  transition: color .3s, border-color .3s, background .3s;
}

/* Little arrow between steps */
.step + .step::before {
  content: "";
  width: 10px; height: 1px;
  margin-left: -13px; margin-right: 2px;
  background: var(--line);
}

.step .dot {
  display: grid; place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1px solid currentColor;
  font-size: 11px;
}

.step.active { color: var(--accent); border-color: rgba(62, 232, 255, 0.5); background: rgba(62, 232, 255, 0.07); }
.step.done   { color: var(--ok); border-color: rgba(52, 245, 160, 0.4); }
.step.done .dot { background: var(--ok); color: var(--bg); border-color: var(--ok); }

/* ---------- Stage: video + overlay ---------- */

.stage {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 20px 60px rgba(0, 0, 0, 0.5);
  isolation: isolate;
  /* Hand tracking draws over the video, so no text selection / touch scroll quirks */
  user-select: none;
  -webkit-user-select: none;
}

/* State colours used by the frame, scan line and status */
.stage[data-state="face"],
.stage[data-state="enroll"],
.stage[data-state="enrolling"] { --state: var(--accent); }
.stage[data-state="match"]     { --state: var(--ok); }
.stage[data-state="hand"]      { --state: var(--hand); }
.stage[data-state="unlocked"]  { --state: var(--ok); }

#video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Selfie view: mirror the video. The overlay canvas is NOT mirrored; app.js
   mirrors the X coordinates itself so drawings line up with the video. */
#video {
  object-fit: cover;
  transform: scaleX(-1);
  background: #000;
}

/* Above the slider and the success panel, so the hand cursor is always visible */
#overlay { z-index: 4; pointer-events: none; }

/* Corner brackets + scan line */
.frame {
  position: absolute;
  inset: 7%;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s;
}

.stage:not([data-state="landing"]):not([data-state="loading"]) .frame { opacity: 1; }

.corner {
  position: absolute;
  width: 34px; height: 34px;
  border: 0 solid var(--state);
  filter: drop-shadow(0 0 6px var(--state));
  transition: border-color .3s;
}
.corner.tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 10px; }
.corner.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 10px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 10px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 10px; }

.scanline {
  position: absolute;
  left: 2%; right: 2%;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--state), transparent);
  box-shadow: 0 0 14px 2px var(--state);
  opacity: .85;
  animation: scan 2.6s ease-in-out infinite alternate;
}

/* The scan line only sweeps while the face step is running */
.stage[data-state="hand"] .scanline,
.stage[data-state="unlocked"] .scanline { display: none; }

@keyframes scan {
  from { top: 0; }
  to   { top: calc(100% - 2px); }
}

/* ---------- Panels over the stage (landing, success) ---------- */

.panel {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px;
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.panel[hidden] { display: none; }

.landing h1 {
  margin: 0;
  font: 700 clamp(20px, 4.6vw, 30px)/1.15 var(--mono);
  letter-spacing: 0.02em;
}

.consent {
  max-width: 460px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(13px, 2.8vw, 15px);
}

.error {
  max-width: 460px;
  margin: 0;
  padding: 10px 14px;
  border: 1px solid rgba(255, 77, 109, 0.45);
  border-radius: 12px;
  background: rgba(255, 77, 109, 0.1);
  color: #ffc2cd;
  font-size: 14px;
}

.success { background: rgba(4, 18, 14, 0.72); }
.success h2 {
  margin: 0;
  font: 700 clamp(26px, 6vw, 40px)/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ok);
  text-shadow: 0 0 22px rgba(52, 245, 160, 0.6);
  animation: rise .5s .25s both cubic-bezier(.2, .9, .3, 1.3);
}
.success .hint { margin: 0; color: var(--muted); font-size: 14px; max-width: 360px; animation: rise .5s .4s both; }
.success .row  { animation: rise .5s .5s both; }

/* Unlock animation: shackle pops up, then the check mark draws itself */
.lock-anim svg {
  width: clamp(70px, 16vw, 104px);
  fill: none;
  stroke: var(--ok);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 12px rgba(52, 245, 160, 0.7));
  overflow: visible;
}
.lock-anim .shackle { transform-origin: 44px 28px; animation: shackle .6s both cubic-bezier(.3, 1.6, .5, 1); }
.lock-anim .check   { stroke-dasharray: 30; stroke-dashoffset: 30; animation: draw .45s .35s forwards ease-out; }
.lock-anim::after {
  /* expanding ring */
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 10px; height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  border: 2px solid var(--ok);
  animation: ripple 1.1s .1s ease-out both;
  pointer-events: none;
}
.lock-anim { position: relative; }

@keyframes shackle { from { transform: translateY(0) rotate(0); } to { transform: translateY(-7px) rotate(28deg); } }
@keyframes draw    { to { stroke-dashoffset: 0; } }
@keyframes rise    { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes ripple  { from { transform: scale(1); opacity: .9; } to { transform: scale(26); opacity: 0; } }

/* ---------- Slide to unlock ---------- */

.slider {
  position: absolute;
  left: 8%; right: 8%;
  bottom: 7%;
  z-index: 2; /* under the overlay canvas (z 4), so the hand cursor draws on top */
}
.slider[hidden] { display: none; }

.track {
  --pad: 6px;
  --knob: clamp(44px, 9vw, 58px);
  position: relative;
  height: calc(var(--knob) + var(--pad) * 2);
  border-radius: 999px;
  background: rgba(10, 16, 28, 0.62);
  border: 1px solid rgba(180, 140, 255, 0.45);
  box-shadow: inset 0 0 18px rgba(180, 140, 255, 0.18), 0 0 18px rgba(180, 140, 255, 0.15);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  overflow: hidden;
}

.fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  background: linear-gradient(90deg, rgba(180, 140, 255, 0.05), rgba(180, 140, 255, 0.35));
}

.track-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-left: var(--knob);
  font: 600 clamp(11px, 2.4vw, 14px)/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(216, 243, 255, 0.75);
  /* shimmering text, like a phone's slide-to-unlock */
  background: linear-gradient(90deg, rgba(216,243,255,.35) 0%, #fff 50%, rgba(216,243,255,.35) 100%) 0 0 / 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2.4s linear infinite;
}

@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.handle {
  position: absolute;
  top: var(--pad);
  left: var(--pad);
  width: var(--knob);
  height: var(--knob);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e3d6ff, var(--hand) 60%, #6a42c9);
  box-shadow: 0 0 0 0 rgba(180, 140, 255, 0.6), 0 6px 16px rgba(0, 0, 0, 0.45);
  will-change: transform;
  transition: box-shadow .2s, scale .2s;
}
.handle svg { width: 50%; fill: none; stroke: #1b0f33; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

/* Cursor is over the handle */
.handle.hover    { box-shadow: 0 0 0 6px rgba(180, 140, 255, 0.28), 0 6px 16px rgba(0, 0, 0, 0.45); }
/* Handle is held by a pinch */
.handle.grabbed  { scale: 0.92; box-shadow: 0 0 0 10px rgba(180, 140, 255, 0.35), 0 0 28px rgba(180, 140, 255, 0.9); }
/* Released early: spring back to the start */
.handle.spring   { transition: transform .45s cubic-bezier(.3, 1.5, .5, 1), box-shadow .2s, scale .2s; }
.fill.spring     { transition: width .45s cubic-bezier(.3, 1.5, .5, 1); }

/* ---------- Status + meters ---------- */

.status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-2);
  font-family: var(--mono);
}

.status-text { margin: 0; font-size: 14px; min-height: 1.5em; }
.status-text::before { content: "> "; color: var(--accent); }

.meter[hidden], .progress[hidden] { display: none; }

.meter-bar, .progress-bar {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.meter-bar span, .progress-bar span {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  border-radius: inherit;
  background: var(--bad);
  transition: width .25s, background .25s;
}
.meter-bar span.ok { background: var(--ok); }
.progress-bar span { background: var(--accent); }

/* Marker for the 0.5 threshold. Bar width maps distance 0..1 → 0..100 %,
   and the bar is drawn "closeness", so the marker sits at 50 %. */
.meter-threshold {
  position: absolute;
  top: -2px; bottom: -2px;
  left: 50%;
  width: 2px;
  background: rgba(255, 255, 255, 0.6);
}

.meter-label { margin: 0; font-size: 12px; }
.muted { color: var(--muted); }

/* ---------- Buttons ---------- */

.controls { display: flex; flex-wrap: wrap; gap: 10px; }
.controls .btn { flex: 1 1 200px; }

.btn {
  appearance: none;
  min-height: 46px;
  padding: 0 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: 600 14px/1 var(--mono);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background .2s, border-color .2s, box-shadow .2s, opacity .2s;
}
.btn:hover:not(:disabled) { border-color: rgba(62, 232, 255, 0.5); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, rgba(62, 232, 255, 0.22), rgba(62, 232, 255, 0.08));
  border-color: rgba(62, 232, 255, 0.55);
  box-shadow: 0 0 18px rgba(62, 232, 255, 0.15);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 0 24px rgba(62, 232, 255, 0.35); }

.btn.danger { border-color: rgba(255, 77, 109, 0.4); color: #ffc2cd; }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); background: rgba(255, 77, 109, 0.08); }

/* ---------- Legend + disclaimer ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin: 0; padding: 0;
  list-style: none;
  font: 13px/1 var(--mono);
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 8px; }
.legend b { color: var(--text); font-weight: 600; }

/* Tiny icons that match the cursor states drawn on the canvas */
.g { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.g-move  { border: 2px solid var(--accent); box-shadow: 0 0 8px var(--accent); }
.g-pinch { width: 10px; height: 10px; background: var(--hand); box-shadow: 0 0 8px var(--hand); }
.g-fist  { border-radius: 4px; background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.disclaimer {
  margin: 0;
  padding: 10px 14px;
  border-left: 3px solid #ffb547;
  border-radius: 8px;
  background: rgba(255, 181, 71, 0.07);
  color: #f4dcb6;
  font-size: 13px;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 16px;
  color: var(--muted);
  font-size: 12px;
}
.foot a { color: var(--accent); text-decoration: none; }
.foot a:hover { text-decoration: underline; }

/* ---------- Small screens ---------- */

@media (max-width: 520px) {
  .steps { width: 100%; justify-content: space-between; }
  .step { padding: 6px 9px 6px 6px; font-size: 11px; }
  .step + .step::before { display: none; }
  .frame { inset: 5%; }
  .slider { left: 5%; right: 5%; bottom: 5%; }
}

@media (prefers-reduced-motion: reduce) {
  .scanline, .track-label { animation: none; }
  .lock-anim .shackle, .lock-anim .check, .success h2, .success .hint, .success .row { animation-duration: .01s; animation-delay: 0s; }
}

/* ==========================================================================
   Security lab: liveness prompt, lockout, red/blue team cards, X-ray, log
   ========================================================================== */

:root {
  /* Chart colours (validated for colour-blind separation and contrast on --bg-2) */
  --viz-neg: #3987e5;   /* diverging: negative */
  --viz-pos: #e66767;   /* diverging: positive */
  --viz-mid: #383835;   /* diverging: neutral midpoint */
  /* Status colours: always shown with an icon + label, never colour alone */
  --st-good: #0ca30c;
  --st-warn: #fab219;
  --st-crit: #d03b3b;
}

.step[hidden] { display: none; }

.stage[data-state="liveness"] { --state: var(--accent); }
.stage[data-state="lockout"]  { --state: var(--bad); }
.stage[data-state="liveness"] .scanline,
.stage[data-state="lockout"] .scanline { display: none; }

/* ---------- Liveness challenge prompt (top of the stage) ---------- */

.challenge {
  position: absolute;
  top: 5%;
  left: 50%;
  z-index: 3;
  translate: -50% 0;
  width: min(86%, 380px);
  padding: 10px 14px 12px;
  border: 1px solid rgba(62, 232, 255, 0.5);
  border-radius: 14px;
  background: rgba(5, 12, 20, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 0 24px rgba(62, 232, 255, 0.2);
  text-align: center;
  animation: rise .35s both;
}
.challenge[hidden] { display: none; }

.challenge-step {
  margin: 0 0 6px;
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.challenge-body { display: flex; align-items: center; justify-content: center; gap: 10px; }
.challenge-icon svg {
  display: block;
  width: 30px; height: 30px;
  fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 6px rgba(62, 232, 255, 0.7));
}
.challenge-text { margin: 0; font: 700 clamp(16px, 3.6vw, 21px)/1.2 var(--mono); }
.challenge-timer {
  height: 4px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.challenge-timer span { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: inherit; }

/* ---------- Lockout panel ---------- */

.lockout { background: rgba(26, 4, 9, 0.8); }
.lockout-title {
  margin: 0;
  font: 700 clamp(18px, 4vw, 24px)/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--bad);
}
.lockout-count {
  margin: 0;
  font: 700 clamp(48px, 12vw, 80px)/1 var(--mono);
  color: #ffd6de;
  text-shadow: 0 0 24px rgba(255, 77, 109, 0.6);
}
.lockout-count small { font-size: 0.4em; margin-left: 4px; color: var(--muted); }
.lockout .hint { margin: 0; max-width: 380px; color: #e6b8c1; font-size: 14px; }

/* ---------- Lab layout ---------- */

.lab { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.lab-head h2 { margin: 0 0 4px; font: 700 20px/1.2 var(--mono); letter-spacing: 0.02em; }
.lab-head p { margin: 0; color: var(--muted); font-size: 14px; }

.lab-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 14px; }

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-2);
}
.card[hidden] { display: none; }
.card h3 { margin: 0 0 10px; font: 700 15px/1.3 var(--mono); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }
.card-head .row { display: flex; gap: 8px; }

.team.red  { border-color: rgba(255, 77, 109, 0.3); }
.team.blue { border-color: rgba(57, 135, 229, 0.35); }

.tag {
  padding: 3px 8px;
  border-radius: 6px;
  font: 700 11px/1.2 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.tag-red  { background: rgba(255, 77, 109, 0.15); color: #ffc2cd; border: 1px solid rgba(255, 77, 109, 0.45); }
.tag-blue { background: rgba(57, 135, 229, 0.15); color: #c4dcfb; border: 1px solid rgba(57, 135, 229, 0.5); }

.attacks, .defences { margin: 0 0 12px; padding-left: 20px; font-size: 14px; color: #c4d9e4; }
.attacks li, .defences li { margin-bottom: 6px; }
.attacks b, .defences b { color: var(--text); }
.fails { margin: 0; font: 13px var(--mono); color: var(--muted); }
.fails b { color: var(--text); font-size: 15px; }

.small { font-size: 12.5px; }

/* ---------- Switch (checkbox styled as a toggle) ---------- */

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui {
  position: relative;
  flex: none;
  width: 44px; height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  transition: background .2s, border-color .2s;
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: translate .2s, background .2s;
}
.switch input:checked + .switch-ui { background: rgba(62, 232, 255, 0.25); border-color: rgba(62, 232, 255, 0.6); }
.switch input:checked + .switch-ui::after { translate: 20px 0; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }
.team.red .switch input:not(:checked) + .switch-ui { border-color: rgba(255, 77, 109, 0.6); background: rgba(255, 77, 109, 0.15); }

/* ---------- X-ray ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat {
  display: flex; flex-direction: column; gap: 4px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
.stat span { font-size: 11.5px; color: var(--muted); }
.stat b { font: 600 16px/1.1 var(--mono); }

.viz { margin: 0 0 16px; }
.viz figcaption { margin-bottom: 8px; font-size: 13.5px; color: #c4d9e4; }
.viz figcaption b { color: var(--text); }

.embed { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: stretch; }
.embed-labels {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  font: 11px/1 var(--mono);
  color: var(--muted);
}
.embed-labels span { display: flex; align-items: center; justify-content: flex-end; }
.plot { position: relative; }
.embed-canvas { display: block; width: 100%; height: 66px; cursor: crosshair; touch-action: pan-y; }
.dist-canvas  { display: block; width: 100%; height: 170px; cursor: crosshair; touch-action: pan-y; }

.tip {
  position: absolute;
  bottom: calc(100% + 6px);
  z-index: 5;
  min-width: 120px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1924;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  font: 12px/1.45 var(--mono);
  pointer-events: none;
  white-space: nowrap;
}
.tip[hidden] { display: none; }
.tip .tip-title { color: var(--muted); margin-bottom: 2px; }
.tip b { color: var(--text); margin-right: 8px; }
.tip span { color: var(--muted); }

.scales { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 8px 0 4px; font: 11px var(--mono); color: var(--muted); }
.scale { display: inline-flex; align-items: center; gap: 6px; }
.ramp { display: inline-block; width: 90px; height: 8px; border-radius: 4px; }
.ramp-div { background: linear-gradient(90deg, var(--viz-neg), var(--viz-mid), var(--viz-pos)); }
.ramp-seq { background: linear-gradient(90deg, var(--viz-mid), var(--accent)); }

.threshold label { display: block; margin-bottom: 6px; font: 13px var(--mono); }
.threshold label b { color: var(--accent); }
.threshold input[type="range"] { width: 100%; accent-color: var(--accent); }
.threshold p { margin: 6px 0 0; }

/* ---------- Event log ---------- */

.empty { margin: 10px 0 0; color: var(--muted); font: 13px var(--mono); }
.empty[hidden] { display: none; }

.log-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  font: 12.5px/1.4 var(--mono);
}
.ev {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 2px 10px;
  align-items: baseline;
  padding: 8px 2px;
  border-bottom: 1px solid rgba(120, 220, 255, 0.07);
}
.ev time { color: var(--muted); }
.ev-action { color: var(--text); font-weight: 600; }
.ev-msg { grid-column: 2 / -1; color: #b5cbd6; }

.ev-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
}
.ev-badge i {
  display: grid; place-items: center;
  width: 15px; height: 15px;
  border-radius: 50%;
  font-style: normal;
  font-size: 10px;
  color: #071018;
  background: var(--muted);
}
.ev-success .ev-badge i { background: var(--st-good); }
.ev-warn .ev-badge i    { background: var(--st-warn); }
.ev-alert .ev-badge i   { background: var(--st-crit); color: #fff; border-radius: 3px; }
.ev-alert { background: rgba(208, 59, 59, 0.1); }

/* ---------- Threat model ---------- */

.threats summary { cursor: pointer; list-style: none; }
.threats summary::-webkit-details-marker { display: none; }
.threats summary h3 { margin: 0; flex-wrap: nowrap; }
.threats summary h3::before { content: "+"; color: var(--accent); width: 14px; }
.threats[open] summary h3::before { content: "−"; }
.threats[open] summary { margin-bottom: 12px; }
.table-wrap { overflow-x: auto; }
.threats table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 13px; }
.threats th, .threats td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.threats th { font: 600 11.5px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.threats td:first-child { color: var(--text); font-weight: 600; }
.threats td { color: #b5cbd6; }
.threats p { margin: 10px 0 0; }

.btn.small { min-height: 34px; padding: 0 12px; font-size: 12px; border-radius: 9px; }

@media (max-width: 520px) {
  .ev { grid-template-columns: auto 1fr; }
  .ev-action { grid-column: 1 / -1; }
  .ev-msg { grid-column: 1 / -1; }
  .card { padding: 14px; }
}

/* ==========================================================================
   Vault + gesture PIN pad
   ========================================================================== */

.tag-vault { background: rgba(62, 232, 255, 0.12); color: #c9f6ff; border: 1px solid rgba(62, 232, 255, 0.5); }

.vault { border-color: rgba(62, 232, 255, 0.3); }
.vault-status { margin: 0 0 12px; font: 13.5px/1.5 var(--mono); }
.vault-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.vault-row:empty, .vault-row:has(> [hidden]:only-child) { display: none; }
.vault p.small { margin: 6px 0 0; }

.vault input[type="password"], .vault textarea {
  flex: 1 1 220px;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: 14px var(--mono);
}
.vault textarea { display: block; width: 100%; margin-bottom: 8px; resize: vertical; line-height: 1.5; }
.vault input:focus-visible, .vault textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.attacker { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.attacker summary { cursor: pointer; font: 600 13px var(--mono); color: #ffc2cd; }
.attacker pre {
  margin: 10px 0;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  font: 11.5px/1.45 var(--mono);
  color: #9fb6c2;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Gesture PIN pad over the stage */
.pinpad { background: rgba(4, 12, 20, 0.8); }
.pinpad[hidden] { display: none; }
.pin-count {
  --p: 0;
  display: grid;
  place-items: center;
  width: clamp(96px, 22vw, 130px);
  aspect-ratio: 1;
  margin: 0;
  border-radius: 50%;
  /* the ring fills while the same finger count is held */
  background:
    radial-gradient(closest-side, rgba(4, 12, 20, 0.95) 84%, transparent 85%),
    conic-gradient(var(--accent) calc(var(--p) * 360deg), rgba(255, 255, 255, 0.1) 0);
  font: 700 clamp(44px, 10vw, 64px)/1 var(--mono);
  color: var(--text);
  text-shadow: 0 0 18px rgba(62, 232, 255, 0.6);
}
.pin-count.waiting { color: var(--muted); text-shadow: none; }
.pin-dots { display: flex; gap: 10px; }
.pin-dots i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent); }
.pin-dots i.on { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.pin-hint { margin: 0; max-width: 340px; color: var(--muted); font-size: 14px; }

/* Step numbers follow the visible steps (the Live step can be hidden) */
.steps { counter-reset: step; }
.step:not([hidden]) { counter-increment: step; }
.step:not([data-step="unlocked"]) .dot::before { content: counter(step); }
