:root {
  --accent: #d94f70;
  --bg: #05070a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

#stage {
  position: relative;
  width: 100vw;
  /* 100vh on mobile includes space behind the browser's collapsible address
     bar, which pushes bottom-anchored content (the capture/switch-camera
     controls) below the actually-visible viewport. 100dvh accounts for the
     real visible area; vh stays as a fallback for browsers without dvh. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

video#cameraFeed {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
video#cameraFeed.mirrored { transform: scaleX(-1); }

canvas#overlayCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  /* Not CSS-mirrored: mirroring is baked into the landmark-to-pixel mapping
     in ar-tryon.js so translation and rotation stay consistent together. */
}

/* Doubles as the offscreen compositing buffer for capturePhoto() AND, when
   un-hidden briefly after a capture, the frozen "still" preview shown on
   top of the live feed before returning to the live filter view. */
canvas#captureCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 6;
}

.capture-flash {
  position: absolute; inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 15;
}
.capture-flash.flash {
  animation: capture-flash-anim 350ms ease-out;
}
@keyframes capture-flash-anim {
  0% { opacity: 0.85; }
  100% { opacity: 0; }
}

.hud {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between;
  /* calc() guarantees a minimum 16px even where env() resolves to 0 (any
     non-notch device) — env()'s own fallback only kicks in when the
     safe-area feature is entirely unsupported, not when it's just 0. */
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-right: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding-left: 16px;
  z-index: 10;
}

.hud-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: auto;
}
.suit-info {
  background: rgba(0,0,0,0.45); backdrop-filter: blur(6px);
  border-radius: 12px; padding: 10px 14px; max-width: 70%;
}
.suit-info .name { font-weight: 700; font-size: 15px; }
.suit-info .meta { font-size: 12px; color: #cfd3da; margin-top: 2px; }

.status-pill {
  background: rgba(0,0,0,0.5); border-radius: 999px; padding: 6px 12px;
  font-size: 12px; display: flex; align-items: center; gap: 6px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #f5a623; }
.status-dot.tracking { background: #2ecc71; }
.status-dot.lost { background: #e74c3c; }

/* Snapchat-style vertical rail of secondary controls on the right edge,
   independent of the top/bottom flex flow (positioned absolutely within
   .hud, vertically centered). */
.side-rail {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right, 0px));
  top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 14px;
  pointer-events: auto;
}

.hud-bottom {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: auto;
  max-height: 40vh;
  max-height: 40dvh;
}

.adjust-panel {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.35); border-radius: 14px; padding: 8px;
}

.capture-row { display: flex; justify-content: center; }
.capture-btn {
  width: 72px; height: 72px; border-radius: 50%;
  background: transparent;
  border: 4px solid #fff;
  padding: 4px;
  cursor: pointer;
  position: relative;
}
.capture-btn::after {
  content: '';
  position: absolute; inset: 4px;
  border-radius: 50%;
  background: #fff;
  transition: transform 120ms ease, background 120ms ease;
}
.capture-btn:active::after {
  transform: scale(0.82);
  background: var(--accent);
}

.view-switch {
  display: flex; gap: 6px; background: rgba(0,0,0,0.45); padding: 5px; border-radius: 999px;
}
.view-switch button {
  border: none; background: transparent; color: #cfd3da;
  padding: 7px 14px; border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.view-switch button.active { background: var(--accent); color: #fff; }

.size-adjust-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.45); border-radius: 999px; padding: 4px 6px 4px 14px;
}
.size-adjust-label { font-size: 12px; color: #cfd3da; }
.icon-btn.small { width: 36px; height: 36px; font-size: 16px; }

.icon-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.2);
  color: #fff; font-size: 20px; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

#permissionScreen, #loadingScreen, #errorScreen, .qr-scan-intro {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px; background: var(--bg);
}
#permissionScreen h1, #errorScreen h1, .qr-scan-intro h1 { font-size: 20px; margin-bottom: 8px; }
#permissionScreen p, #errorScreen p, .qr-scan-intro p { color: #a9adb5; font-size: 14px; max-width: 320px; line-height: 1.5; }
.btn-cta {
  margin-top: 20px; background: var(--accent); color: #fff; border: none;
  padding: 14px 28px; border-radius: 999px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-cta.secondary { background: rgba(255,255,255,0.12); }

.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.2); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#qrScanScreen { position: absolute; inset: 0; z-index: 20; }

.qr-viewfinder-wrap {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px;
  pointer-events: none;
}
.qr-viewfinder { position: relative; width: 240px; height: 240px; }
.qr-corner { position: absolute; width: 36px; height: 36px; border: 4px solid var(--accent); }
.qr-corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; border-radius: 12px 0 0 0; }
.qr-corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; border-radius: 0 12px 0 0; }
.qr-corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; border-radius: 0 0 0 12px; }
.qr-corner.br { bottom: 0; right: 0; border-left: none; border-top: none; border-radius: 0 0 12px 0; }
.qr-scan-status {
  background: rgba(0,0,0,0.55); padding: 8px 16px; border-radius: 999px;
  font-size: 14px; text-align: center; margin: 0;
}
.qr-scan-error { color: #e74c3c; font-size: 13px; max-width: 320px; }

.hidden { display: none !important; }
