/* =========================================================
   measure.css — Face Analysis / FaceMesh page
   GHOSTFRAME Design System
   ========================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gf-lime:        #D4FF00;
  --gf-cyan:        #00DCFF;
  --gf-amber:       #FFA000;
  --gf-violet:      #A855F7;
  --gf-black:       #000000;
  --gf-white:       #FFFFFF;
  --gf-bg:          #0A0A0A;
  --gf-surface:     rgba(255,255,255,0.05);
  --gf-border:      rgba(255,255,255,0.10);
  --gf-text-muted:  rgba(255,255,255,0.45);
  --gf-font:        'Inter', 'Helvetica Neue', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--gf-bg);
  color: var(--gf-white);
  font-family: var(--gf-font);
  overflow: hidden;
}

/* ── Utility ──────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Top bar ──────────────────────────────────────────── */
.gf-top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--gf-border);
}

.gf-top-bar__back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--gf-text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  transition: color 0.2s;
  min-height: 44px;
}
.gf-top-bar__back:hover { color: var(--gf-white); }

.gf-top-bar__title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gf-white);
}

.gf-top-bar__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* FPS badge */
.fps-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  color: var(--gf-text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
}

/* Detection dot */
.detection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  transition: background 0.3s;
  flex-shrink: 0;
}
.detection-dot.detected {
  background: var(--gf-lime);
  box-shadow: 0 0 8px rgba(212,255,0,0.55);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ── Camera viewport ───────────────────────────────────── */
.camera-wrap {
  position: fixed;
  inset: 52px 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

/* Video is only the camera source — not displayed.
   Mirroring and rendering both happen on canvas via context.scale(-1,1). */
#videoEl { display: none; }

/* Canvas fills the viewport area.
   object-fit: contain scales the bitmap to fit without cropping,
   keeping landmark coordinates aligned with the displayed image. */
#canvasEl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ── Face guide oval ──────────────────────────────────── */
.face-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -56%);
  width: 180px;
  height: 240px;
  border: 2px solid rgba(212,255,0,0.35);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s;
}
.face-guide.visible { opacity: 1; }

/* ── Overlays (start / init / error) ─────────────────── */
.overlay-start,
.overlay-init,
.overlay-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 80;
  text-align: center;
  padding: 2rem;
}

/* Start overlay */
.overlay-start {
  background: rgba(0,0,0,0.90);
  transition: opacity 0.4s;
}
.overlay-start.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Init (loading) overlay */
.overlay-init {
  background: rgba(0,0,0,0.96);
  display: none;
}
.overlay-init.visible { display: flex; }

/* Error overlay */
.overlay-error {
  background: rgba(0,0,0,0.96);
  display: none;
  z-index: 90;
}
.overlay-error.visible { display: flex; }

/* Shared overlay children */
.start-icon {
  width: 72px;
  height: 72px;
  border: 2px solid var(--gf-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gf-text-muted);
}

.start-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.start-sub {
  font-size: 12px;
  color: var(--gf-text-muted);
  letter-spacing: 0.05em;
  max-width: 260px;
  line-height: 1.7;
}

.init-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gf-border);
  border-top-color: var(--gf-lime);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.init-text {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gf-text-muted);
}

.error-icon  { font-size: 2rem; opacity: 0.5; }
.error-title { font-size: 14px; font-weight: 700; letter-spacing: 0.06em; }
.error-msg   { font-size: 12px; color: var(--gf-text-muted); max-width: 300px; line-height: 1.7; }

/* ── Phase panel ──────────────────────────────────────── */
.phase-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(8,8,8,0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--gf-border);
  padding: 18px 20px 28px;
  /* Safe area for devices with home bar */
  padding-bottom: max(28px, env(safe-area-inset-bottom, 28px));
}

/* Individual phase — animated in/out */
.phase {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Phase header row */
.phase-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.phase-badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  background: var(--gf-surface);
  border: 1px solid var(--gf-border);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gf-text-muted);
  white-space: nowrap;
}
.phase-badge.ok {
  background: rgba(212,255,0,0.12);
  border-color: rgba(212,255,0,0.35);
  color: var(--gf-lime);
}
.phase-badge.error {
  background: rgba(255,80,80,0.12);
  border-color: rgba(255,80,80,0.35);
  color: #ff6060;
}

.phase-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}

.phase-body {}

.phase-instruction {
  font-size: 12px;
  color: var(--gf-text-muted);
  line-height: 1.65;
  letter-spacing: 0.03em;
}
.phase-instruction strong {
  color: var(--gf-white);
  font-weight: 700;
}

.phase-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Calibration status ────────────────────────────────── */
.calib-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.calib-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.calib-dot.ok {
  background: var(--gf-lime);
  box-shadow: 0 0 6px rgba(212,255,0,0.5);
}

.calib-status span:last-child {
  font-size: 11px;
  color: var(--gf-text-muted);
  letter-spacing: 0.04em;
}

.calib-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--gf-text-muted);
  letter-spacing: 0.04em;
}
.calib-info svg { flex-shrink: 0; color: var(--gf-lime); }

/* ── Live measurement cards ────────────────────────────── */
.live-measurements {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.meas-card {
  background: var(--gf-surface);
  border: 1px solid var(--gf-border);
  border-radius: 8px;
  padding: 10px 12px 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.meas-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gf-text-muted);
}

/* Colour dots */
.meas-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.meas-dot.cyan   { background: var(--gf-cyan); }
.meas-dot.lime   { background: var(--gf-lime); }
.meas-dot.amber  { background: var(--gf-amber); }
.meas-dot.violet { background: var(--gf-violet); }

.meas-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--gf-white);
}

.meas-unit {
  font-size: 10px;
  color: var(--gf-text-muted);
  letter-spacing: 0.06em;
}

/* ── Stability bar ─────────────────────────────────────── */
.stability-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stability-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--gf-text-muted);
  white-space: nowrap;
  width: 56px;
}

.stability-bar {
  flex: 1;
  height: 4px;
  background: var(--gf-border);
  border-radius: 2px;
  overflow: hidden;
}

.stability-fill {
  height: 100%;
  width: 0%;
  background: var(--gf-lime);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.stability-pct {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gf-lime);
  width: 34px;
  text-align: right;
}

/* ── Results grid ──────────────────────────────────────── */
.results-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.res-size-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.res-size-id {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--gf-lime);
}

.res-size-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--gf-white);
}

.res-size-desc {
  font-size: 11px;
  color: var(--gf-text-muted);
  letter-spacing: 0.04em;
}

.res-format {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--gf-white);
}

.res-format-labels {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 10px;
  color: var(--gf-text-muted);
  letter-spacing: 0.06em;
}

.res-measurements {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--gf-border);
  padding-top: 10px;
}

.res-meas-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.res-meas-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--gf-text-muted);
  letter-spacing: 0.06em;
}

.res-meas-val {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gf-white);
  letter-spacing: 0.04em;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn-primary-action {
  width: 100%;
  height: 46px;
  background: var(--gf-lime);
  border: none;
  border-radius: 4px;
  color: var(--gf-black);
  font-family: var(--gf-font);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary-action:hover:not(:disabled) { opacity: 0.88; }
.btn-primary-action:active:not(:disabled) { transform: scale(0.98); }
.btn-primary-action:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-secondary-action {
  height: 42px;
  padding: 0 22px;
  background: transparent;
  border: 1px solid var(--gf-border);
  border-radius: 4px;
  color: var(--gf-white);
  font-family: var(--gf-font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.btn-secondary-action:hover {
  border-color: rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.05);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--gf-text-muted);
  font-family: var(--gf-font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: color 0.2s;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: transparent;
}
.btn-link:hover {
  color: var(--gf-white);
  text-decoration-color: rgba(255,255,255,0.35);
}

/* Constrain button width inside overlays (prevents full-screen-wide button on desktop) */
.overlay-start .btn-primary-action,
.overlay-error .btn-secondary-action,
.overlay-error .btn-primary-action {
  max-width: 280px;
}

.btn-primary-action,
.btn-secondary-action {
  text-align: center;
}

/* ── Color analysis results ────────────────────────────── */
.color-section {
  border-top: 1px solid var(--gf-border);
  padding-top: 12px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.season-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.season-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--gf-white);
}

.season-tagline {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gf-text-muted);
}

.season-desc {
  font-size: 11px;
  color: var(--gf-text-muted);
  letter-spacing: 0.03em;
  line-height: 1.5;
}

/* Skin tone swatch */
.skin-swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.skin-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}

.skin-swatch-label {
  font-size: 10px;
  color: var(--gf-text-muted);
  letter-spacing: 0.06em;
}

/* Palette swatches */
.palette-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.palette-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.10);
  flex-shrink: 0;
  transition: transform 0.15s;
}
.palette-swatch:hover { transform: scale(1.15); }

.palette-label {
  font-size: 9px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--gf-text-muted);
  margin-left: 2px;
}

/* Frame recommendations chips */
.frame-recs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.frame-chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  background: var(--gf-surface);
  border: 1px solid var(--gf-border);
  border-radius: 11px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  color: var(--gf-white);
  white-space: nowrap;
}

.avoid-note {
  font-size: 10px;
  color: var(--gf-text-muted);
  letter-spacing: 0.03em;
}
.avoid-note strong { color: rgba(255,255,255,0.4); font-weight: 600; }

/* ── STL Export button ─────────────────────────────────── */
.btn-stl-download {
  width: 100%;
  height: 42px;
  margin-top: 4px;
  background: transparent;
  border: 1px solid var(--gf-border);
  border-radius: 4px;
  color: var(--gf-text-muted);
  font-family: var(--gf-font);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-stl-download:hover {
  border-color: var(--gf-lime);
  color: var(--gf-lime);
  background: rgba(212,255,0,0.05);
}
.btn-stl-download svg { flex-shrink: 0; }

/* Color unavailable fallback */
.color-unavailable {
  font-size: 11px;
  color: var(--gf-text-muted);
  letter-spacing: 0.04em;
  padding: 8px 0;
  text-align: center;
}

/* ── Mobile ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .phase-panel { padding: 14px 16px max(24px, env(safe-area-inset-bottom, 24px)); }
  .meas-value  { font-size: 18px; }
  .res-size-id { font-size: 28px; }
  .res-format  { font-size: 16px; }
  .live-measurements { gap: 6px; }
  .meas-card   { padding: 8px 10px 9px; }
  .season-name { font-size: 17px; }
}
