/* =============================================================================
   Capture Page — Mobile-first responsive styles for AI-guided capture flow.

   12-state flow: INIT, INSTRUCTIONS, TUTORIAL_FRONT, POSE_FRONT,
   COUNTDOWN_FRONT, PREVIEW_FRONT, TUTORIAL_SIDE, POSE_SIDE,
   COUNTDOWN_SIDE, PREVIEW_SIDE, PROCESSING, SUCCESS (+ ERROR, DESKTOP).

   Dark theme, full-screen, no scroll. Single persistent video element
   behind all overlay pages.
   ============================================================================= */

/* ── FittingMe design tokens (capture-local, no widget/marketing import) ─── */
/* Locked palette from the FittingMe design-system widget example. Copied
   into capture so the standalone app stays decoupled from widget CSS. */
:root {
  /* FM palette */
  --fm-porcelain: #FAFAFA;
  --fm-mist: #F6F4F5;
  --fm-aubergine: #2D0C1F;
  --fm-muted-aubergine: #7A4660;
  --fm-raspberry: #AE224C;
  --fm-raspberry-soft: #D03D63;
  --fm-sage: #4CAF50;
  --fm-platinum: #E0E0E0;
  --fm-gradient-ai: linear-gradient(135deg, #AE224C 0%, #D03D63 100%);

  /* Semantic aliases used throughout the capture page. Camera/overlay
     pages stay dark because the live video must remain legible behind
     translucent overlays, but instruction/processing/success pages use
     FM aubergine as the dark surface. */
  --color-primary: var(--fm-raspberry);
  --color-bg: var(--fm-aubergine);
  --color-text: var(--fm-porcelain);
  --color-overlay: rgba(45, 12, 31, 0.66);
  --color-success: var(--fm-sage);
  --color-error: #E5475A;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* The UA `[hidden] { display: none }` declaration loses specificity-and-
   source-order battles to any class rule that sets `display` (e.g. `.btn`
   sets `display: inline-flex`). Force the `hidden` attribute to win so
   dom-adapter's `setVisible(id, false)` (which toggles `el.hidden`) is
   visually correct regardless of which class the element happens to carry. */
[hidden] {
  display: none !important;
}

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--color-bg);
}

/* ── Body ───────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Persistent camera feed ─────────────────────────────────────────────── */
/* Single video element behind all pages. Stays alive from TUTORIAL_FRONT
   through PREVIEW_SIDE. Mirror transform for selfie camera. */
#camera-feed {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  /* Fill the phone viewport; camera.js requests a portrait-friendly stream so
     the preview stays upright without CSS rotation. */
  object-fit: cover;
  z-index: 1;
  transform: scaleX(-1);
}

/* ── Page states (visibility toggled by JS) ─────────────────────────────── */
/* Each state is a full-screen flex container layered above the video. */
.page {
  display: none;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
  padding: 24px;
  text-align: center;
}

.page.active {
  display: flex;
}

/* ── Page layer variants ────────────────────────────────────────────────── */
/* Tutorial overlays: semi-transparent over live camera feed */
.page-overlay {
  z-index: 10;
  background: var(--color-overlay);
}

/* Camera/pose pages: transparent so video shows through */
.page-camera {
  z-index: 5;
  background: transparent;
}

/* Countdown pages: above pose overlays */
.page-countdown {
  z-index: 20;
  background: transparent;
}

/* Preview pages: opaque background to show captured photo */
.page-preview {
  z-index: 10;
  background: var(--color-bg);
}

/* ── Instructions page ──────────────────────────────────────────────────── */
#page-instructions {
  background: var(--color-bg);
  justify-content: flex-start;
  gap: 12px;
  padding: 18px 20px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#page-instructions h1 {
  font-size: 21px;
  font-weight: 600;
  line-height: 1.2;
  margin: 6px 0 0;
}

.setup-illustration {
  width: min(100%, 336px);
  min-height: 166px;
  border: 1px solid rgba(250, 250, 250, 0.14);
  border-radius: 18px;
  background: rgba(250, 250, 250, 0.06);
  padding: 14px 16px 10px;
}

.setup-stage {
  position: relative;
  height: 108px;
}

.setup-person {
  position: absolute;
  top: 12px;
  left: 24px;
  width: 44px;
  height: 82px;
}

.setup-person-head,
.setup-person-body,
.setup-person-leg,
.setup-phone,
.setup-phone-lens {
  display: block;
}

.setup-person-head {
  width: 18px;
  height: 18px;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: var(--fm-porcelain);
}

.setup-person-body {
  width: 22px;
  height: 34px;
  margin: 0 auto;
  border-radius: 10px 10px 7px 7px;
  background: var(--fm-raspberry-soft);
}

.setup-person-leg {
  position: absolute;
  bottom: 0;
  width: 8px;
  height: 29px;
  border-radius: 999px;
  background: var(--fm-porcelain);
}

.setup-person-leg.left {
  left: 13px;
}

.setup-person-leg.right {
  right: 13px;
}

.setup-distance {
  position: absolute;
  left: 78px;
  right: 58px;
  bottom: 19px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.setup-distance-line {
  position: relative;
  width: 100%;
  height: 2px;
  background: rgba(250, 250, 250, 0.55);
}

.setup-distance-line::before,
.setup-distance-line::after {
  content: "";
  position: absolute;
  top: -4px;
  width: 2px;
  height: 10px;
  background: rgba(250, 250, 250, 0.55);
}

.setup-distance-line::before {
  left: 0;
}

.setup-distance-line::after {
  right: 0;
}

.setup-distance-label {
  font-size: 12px;
  font-weight: 600;
  color: rgba(250, 250, 250, 0.78);
}

.setup-phone {
  position: absolute;
  right: 16px;
  bottom: 13px;
  width: 31px;
  height: 48px;
  border: 2px solid var(--fm-porcelain);
  border-radius: 9px;
  transform: rotate(72deg);
  background: rgba(250, 250, 250, 0.10);
}

.setup-phone-lens {
  width: 6px;
  height: 6px;
  margin: 7px auto 0;
  border-radius: 50%;
  background: var(--fm-porcelain);
}

.setup-placeholder {
  font-size: 11px;
  color: rgba(250, 250, 250, 0.52);
}

.capture-sequence {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 32px;
}

.capture-sequence-step {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(250, 250, 250, 0.82);
}

.capture-sequence-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--fm-porcelain);
  color: var(--fm-aubergine);
  font-size: 12px;
}

.capture-sequence-line {
  width: 28px;
  height: 1px;
  background: rgba(250, 250, 250, 0.32);
}

.instructions-primary {
  max-width: 336px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
}

.instructions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(100%, 336px);
  list-style: none;
  text-align: left;
}

.instructions-list li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 14px;
  color: rgba(250, 250, 250, 0.78);
  line-height: 1.35;
}

.instructions-bullet {
  width: 7px;
  height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--fm-raspberry-soft);
  flex: 0 0 auto;
}

/* MVP-370 — sizing Photo Retention Notice on the Capture Instructions Screen.
   Replaces the retired consent row (.consent-row / .consent-note): capture is
   sizing-only, so the checkbox gate is gone and the privacy promise renders as
   a plain informational card instead. Reuses the same quiet-card visual
   language the consent row had. */
.privacy-note {
  margin-top: 2px;
  text-align: left;
  width: min(100%, 336px);
  padding: 11px 12px;
  border: 1px solid rgba(250, 250, 250, 0.13);
  border-radius: 14px;
  background: rgba(250, 250, 250, 0.05);
  font-size: 12.5px;
  line-height: 1.35;
  color: rgba(250, 250, 250, 0.82);
}

#page-instructions .btn-primary {
  margin-top: 0;
  width: min(100%, 336px);
  min-height: 50px;
}

/* ── Step indicator (tutorial pages) ────────────────────────────────────── */
.step-indicator {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 24px;
}

.step-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.step-dot.active {
  background: #fff;
  color: var(--color-bg);
}

.step-dot.inactive {
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  border-color: rgba(255, 255, 255, 0.4);
}

.step-line {
  width: 60px;
  height: 2px;
  background: rgba(255, 255, 255, 0.3);
}

.step-line.active {
  background: #fff;
}

/* ── Tutorial pages ─────────────────────────────────────────────────────── */
.page-overlay h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
}

.pose-reference {
  max-height: 55vh;
  margin: 0 auto 16px;
  display: block;
}

.tutorial-instruction {
  font-size: 16px;
  color: #ccc;
  margin-bottom: 24px;
  max-width: 300px;
}

/* ── Pose guide overlay (semi-transparent silhouette on camera feed) ────── */
.pose-guide {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scaleX(-1); /* mirror to match selfie camera */
  max-height: 80vh;
  max-width: 80vw;
  opacity: 0.25;
  z-index: 6; /* above camera (1), below feedback (10) */
  pointer-events: none;
}

/* ── Pose feedback overlay ──────────────────────────────────────────────── */
.pose-feedback {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-overlay);
  z-index: 10;
  padding: 20px;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
}

/* ── Countdown ring ─────────────────────────────────────────────────────── */
.page-countdown {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
}

.page-countdown.active {
  display: flex;
}

.countdown-ring {
  width: 200px;
  height: 200px;
}

.ring-bg {
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 8;
  fill: none;
}

.ring-fg {
  stroke: rgba(255, 255, 255, 0.5);
  stroke-width: 8;
  fill: none;
  /* circumference = 2 * pi * 54 = 339.292 */
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset 1s linear;
}

.countdown-number {
  position: absolute;
  font-size: 64px;
  font-weight: bold;
  line-height: 1;
}

/* ── Flash overlay ──────────────────────────────────────────────────────── */
.flash-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.15s ease-in;
}

.flash-overlay.flash {
  opacity: 1;
}

/* ── Preview pages ──────────────────────────────────────────────────────── */
.preview-img {
  max-height: 70vh;
  max-width: 100%;
  border-radius: 12px;
  object-fit: contain;
}

.preview-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.auto-advance-text {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 32px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
  min-width: 200px;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn:focus-visible {
  outline: 2px solid var(--fm-raspberry-soft);
  outline-offset: 3px;
}

/* Primary action: AI gradient on the FittingMe brand, porcelain text. */
.btn-primary {
  background: var(--fm-gradient-ai);
  color: var(--fm-porcelain);
  box-shadow: 0 6px 18px rgba(174, 34, 76, 0.28);
}

/* Secondary surface: mist over aubergine, used for low-emphasis actions. */
.btn-secondary {
  background: var(--fm-mist);
  color: var(--fm-aubergine);
  border: 1px solid var(--fm-platinum);
}

.btn-retake {
  background: var(--fm-mist);
  color: var(--fm-aubergine);
  border: 1px solid var(--fm-platinum);
  min-width: 120px;
  min-height: 48px;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s, background 0.2s;
}

.btn-retake:active {
  transform: scale(0.97);
  background: var(--fm-platinum);
}

.btn-retake:focus-visible {
  outline: 2px solid var(--fm-raspberry-soft);
  outline-offset: 3px;
}

.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* ── Processing / success / error ───────────────────────────────────────── */
#page-processing,
#page-success,
#page-error {
  background: var(--color-bg);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--fm-muted-aubergine);
  border-top-color: var(--fm-raspberry-soft);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.success-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 32px;
}

.success-return-btn {
  margin-top: 24px;
  min-width: min(280px, 100%);
  min-height: 50px;
}

.success-return-fallback {
  margin-top: 14px;
}

.error-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-error);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 32px;
}

.status-text {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.status-detail {
  font-size: 14px;
  color: #aaa;
  max-width: 300px;
}

/* ── Desktop gate ───────────────────────────────────────────────────────── */
#page-desktop {
  background: var(--color-bg);
}

.desktop-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 400px;
  padding: 24px;
}

.desktop-gate h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ── Flash effect keyframes (driven by JS class toggle) ─────────────────── */
@keyframes flash-effect {
  0%   { opacity: 0; }
  50%  { opacity: 1; }
  100% { opacity: 0; }
}
