/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3348;
  --text: #e8eaf0;
  --text-muted: #8b92a8;
  --primary: #5865f2;
  --primary-hover: #4752c4;
  --success: #2ecc71;
  --success-bg: #0d2b1e;
  --danger: #e74c3c;
  --danger-bg: #2b0d0d;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 48px;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 540px;
  position: relative;
}

header {
  text-align: center;
  margin-bottom: 28px;
}

header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.25s ease;
}

.card h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 18px;
}

.step-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--primary);
  margin-bottom: 8px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border: none;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-success   { background: var(--success); color: #000; }
.btn-success:hover:not(:disabled) { background: #27ae60; }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

/* ── Challenge display ────────────────────────────────────────────────────── */
.challenge-box {
  margin-top: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
}

.challenge-emoji {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 10px;
}

.challenge-instruction {
  font-size: 1.1rem;
  font-weight: 600;
}

.challenge-meta {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.challenge-meta code {
  font-family: monospace;
  word-break: break-all;
}

/* ── Camera ───────────────────────────────────────────────────────────────── */
.camera-wrapper {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 4/3;
  margin-bottom: 16px;
}

#video, #preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1); /* mirror for selfie */
}

#canvas { display: none; }

.camera-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ── Result ───────────────────────────────────────────────────────────────── */
.result-banner {
  border-radius: 10px;
  padding: 18px 20px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 18px;
}

.result-banner.pass {
  background: var(--success-bg);
  border: 1px solid var(--success);
  color: var(--success);
}

.result-banner.fail {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
}

.result-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.detail-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.detail-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 1rem;
  font-weight: 600;
}

.detail-value.pass { color: var(--success); }
.detail-value.fail { color: var(--danger); }

/* ── Loading overlay ──────────────────────────────────────────────────────── */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(15,17,23,0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading p { color: var(--text-muted); font-size: 0.9rem; }

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

@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Mobile tweaks ────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .result-details { grid-template-columns: 1fr; }
  .camera-buttons { flex-direction: column; }
  .btn { width: 100%; }
}
