:root {
  --bg: #10131a;
  --panel: #1a1f2b;
  --line: #2b3242;
  --ink: #eef1f7;
  --muted: #9aa4b8;
  --accent: #d4a24c;
  --accent-ink: #221a09;
}

* { box-sizing: border-box; }

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

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- top bar ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 13px; letter-spacing: .5px;
}
.brand-text { font-weight: 600; letter-spacing: .2px; }
.status {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; white-space: nowrap;
}
.status.ok { color: #a6e3a1; border-color: #2f4a33; }
.status.warn { color: #f2cd6b; border-color: #4a412a; }
.status.err { color: #f38ba8; border-color: #4a2a33; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #06080c;
  overflow: hidden;
}

/* Camera mode FILLS the stage (object-fit: cover) so the view reads like a mirror with the
   face large. With `contain`, a 16:9 camera feed inside a wide, short stage rendered as a
   small strip with big black bars either side - which is what made the camera look "barely
   visible behind the main page" even once the intro overlay was correctly hidden.
   Photo mode keeps `contain` so an uploaded picture is never cropped.
   CRITICAL: the canvas must use the SAME fit as the video/photo, or the drawn frame drifts
   out of alignment with the face. That is why the fit is applied to all three together. */
.stage.fit-cover   #video, .stage.fit-cover   #photo, .stage.fit-cover   #overlay { object-fit: cover; }
.stage.fit-contain #video, .stage.fit-contain #photo, .stage.fit-contain #overlay { object-fit: contain; }
#video, #photo, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
/* Selfie view: mirror both the video AND the overlay so the drawn frame stays glued
   to the face. The landmark coordinates are in un-mirrored video space, and mirroring
   the canvas container in CSS applies the same flip to everything drawn on it. */
#video, #overlay { transform: scaleX(-1); }
#photo { display: none; }
#overlay { pointer-events: none; }

/* 3D frame layer. #mirror carries the selfie flip for camera mode and is switched off in
   photo mode (an uploaded photo is shown un-mirrored, so the frame must be too). */
#mirror { position: absolute; inset: 0; }
#mirror.mirrored { transform: scaleX(-1); }
#frame3d {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  pointer-events: none;
  /* transform-origin is set per frame from the frame's own optical centre, which is the
     point that must land on the wearer's pupils */
  will-change: transform;
}

/* ---------- intro / permission gate ---------- */
.intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(6, 8, 12, .82);
  backdrop-filter: blur(3px);
}
.intro h1 { margin: 0; font-size: 22px; }
.intro p { margin: 0; color: var(--muted); max-width: 42ch; }
.intro-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 6px; }

/* `hidden` ALONE DOES NOT HIDE THIS ELEMENT. The author rule `display: grid` above wins
   over the UA stylesheet's [hidden] { display: none }, so setting intro.hidden = true in
   JS left the overlay sitting on top of the live camera - the video was "barely visible
   behind the main page" and the page looked broken even though the camera had started.
   Any element that is both styled with `display` and toggled via `hidden` needs this. */
.intro[hidden] { display: none; }
.error { color: #f38ba8; font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- bottom controls ---------- */
.controls {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.frames {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.frame-chip {
  flex: 0 0 auto;
  width: 92px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 4px;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.frame-chip img { display: block; width: 100%; height: 46px; object-fit: contain; }
.frame-chip figcaption {
  font-size: 10px; color: #444; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.frame-chip[aria-selected="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
}
.actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Debug HUD - the element only exists when the page is loaded with ?debug=1, so this
   styling is inert for customers. Green monospace, low opacity, never intercepts taps. */
#debug {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 99;
  margin: 0;
  padding: 6px 9px;
  max-width: 94vw;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #a9f5bd;
  background: rgba(0, 0, 0, .7);
  border: 1px solid rgba(169, 245, 189, .28);
  border-radius: 6px;
  white-space: pre-wrap;
  pointer-events: none;
}

@media (min-width: 720px) {
  .frame-chip { width: 110px; }
  .frame-chip img { height: 56px; }
}
