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

:root {
  /* ── Core palette ── */
  --bg:          #F5F7FF;
  --surface:     #FFFFFF;
  --surface-2:   #EEF1FB;
  --border:      #D4DAF5;
  --border-strong: #B0BBEE;

  /* ── Brand — deep blue ── */
  --blue:        #2244D4;
  --blue-mid:    #3358E8;
  --blue-dim:    rgba(34,68,212,.10);
  --blue-glow:   rgba(34,68,212,.40);

  /* ── Oval guide ── */
  --oval-color:  #2244D4;
  --oval-glow:   rgba(34,68,212,.55);

  /* ── CTA — lemon (action only) ── */
  --accent:      #D4E000;
  --accent-fg:   #0A1040;
  --accent-glow: rgba(212,224,0,.45);

  /* ── States ── */
  --success:     #00A86B;
  --success-dim: rgba(0,168,107,.10);
  --error:       #E02040;
  --error-dim:   rgba(224,32,64,.08);

  /* ── Text ── */
  --text:        #0C1445;
  --text-sub:    #3C4A80;
  --text-muted:  #6676AA;

  /* ── Shape ── */
  --radius:      16px;
  --radius-sm:   10px;
  --radius-xs:   6px;
}

[data-theme="dark"] {
  --bg:           #0A1540;
  --surface:      #0F1E5A;
  --surface-2:    #172470;
  --border:       #2840AA;
  --border-strong:#3858CC;
  --text:         #EEF1FF;
  --text-sub:     #A8B8EE;
  --text-muted:   #7890CC;
  --blue-dim:     rgba(80,120,255,.15);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8px 12px 12px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── App header ──────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
}

.app-logo {
  width: 28px;
  height: 28px;
  background: var(--blue);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  flex: 1;
}

.attempt-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-dim);
  border: 1px solid rgba(34,68,212,.20);
  border-radius: 100px;
  padding: 2px 8px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* ── Camera box ──────────────────────────────────────── */
.camera-box {
  position: relative;
  aspect-ratio: 5/6;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0A0F2A;
  border: 1.5px solid var(--border);
  box-shadow: 0 2px 16px rgba(10,20,80,.10);
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

#overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.face-guide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.face-oval {
  width: 62%;
  aspect-ratio: 3/4;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.30);
  transition: border-color 0.25s, box-shadow 0.25s;
}

.face-oval.detected {
  border-color: var(--oval-color);
  box-shadow: 0 0 0 4px rgba(34,68,212,.18), 0 0 28px var(--oval-glow);
}

.face-oval.challenge {
  border-color: var(--oval-color);
  animation: pulse-oval 1.1s ease-in-out infinite;
}

.face-oval.success {
  border-color: var(--success);
  box-shadow: 0 0 0 5px rgba(0,168,107,.20), 0 0 32px rgba(0,168,107,.55);
}

@keyframes pulse-oval {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34,68,212,.16), 0 0 20px rgba(34,68,212,.45); }
  50%       { box-shadow: 0 0 0 6px rgba(34,68,212,.24), 0 0 38px rgba(34,68,212,.75); }
}

/* ── Status badge ────────────────────────────────────── */
.status-badge {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 11px;
  border-radius: 100px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-badge.idle {
  background: rgba(255,255,255,.88);
  color: var(--text-muted);
  border: 1px solid rgba(255,255,255,.5);
}
.status-badge.active {
  background: rgba(34,68,212,.18);
  color: #90AAFF;
  border: 1px solid rgba(34,68,212,.40);
}
.status-badge.success {
  background: rgba(0,168,107,.20);
  color: #00D488;
  border: 1px solid rgba(0,168,107,.45);
}
.status-badge.error {
  background: rgba(224,32,64,.20);
  color: #FF6080;
  border: 1px solid rgba(224,32,64,.45);
}

/* ── Step dots ───────────────────────────────────────── */
.steps-row { display: flex; gap: 5px; }

.step-dot {
  flex: 1;
  height: 3px;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.25s, box-shadow 0.25s;
}
.step-dot.done   { background: var(--success);  border-color: var(--success);  box-shadow: 0 0 6px rgba(0,168,107,.4); }
.step-dot.active { background: var(--blue);     border-color: var(--blue);     box-shadow: 0 0 8px var(--blue-glow); }

/* ── Cards shared ────────────────────────────────────── */
.instruction-card,
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 12px rgba(10,20,80,.07);
}

/* ── Instruction card ────────────────────────────────── */
.instruction-card {
  padding: 12px 14px 14px;
  text-align: center;
  border-top: 3px solid var(--blue);
}

.challenge-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 4px;
}

.instruction-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

/* ── Progress bar ────────────────────────────────────── */
.progress-track {
  height: 5px;
  background: var(--surface-2);
  border-radius: 100px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 100px;
  transition: width 0.18s ease;
  width: 0%;
}

.progress-fill.success {
  background: var(--success);
}

/* ── Result card ─────────────────────────────────────── */
.result-card {
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-icon  { font-size: 38px; text-align: center; }
.result-title { font-size: 19px; font-weight: 800; text-align: center; color: var(--text); letter-spacing: 0; }
.result-meta  { font-size: 13px; color: var(--text-muted); text-align: center; line-height: 1.45; }

/* ── Status rows ─────────────────────────────────────── */
.status-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.status-row-label { color: var(--text-muted); font-weight: 500; }
.status-row-value       { font-weight: 700; }
.status-row-value.ok    { color: var(--success); }
.status-row-value.fail  { color: var(--error); }
.status-row-value.muted { color: var(--text-muted); }

/* ── Confidence bar ──────────────────────────────────── */
.confidence-bar-wrap { display: flex; flex-direction: column; gap: 6px; }
.confidence-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ── Buttons ─────────────────────────────────────────── */
#btn-start, #btn-retry, #btn-close {
  width: 100%;
  min-height: 44px;
  padding: 11px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, opacity 0.15s;
}

#btn-start {
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: 0 4px 20px rgba(212,224,0,.35);
}
#btn-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(212,224,0,.50);
}

#btn-retry {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 4px 16px var(--blue-glow);
}
#btn-retry:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px var(--blue-glow);
}

#btn-close {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
#btn-close:hover { opacity: 0.80; }

#btn-start:active, #btn-retry:active, #btn-close:active {
  transform: scale(.98);
  box-shadow: none;
}

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