:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --border: #e5e8f0;
  --brand: #2457e6;
  --brand-dark: #1b3fb8;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #b45309;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.wrap { max-width: 620px; margin: 0 auto; padding: 24px 16px 64px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 20px;
}
.brand { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.01em; }
.brand-tag {
  background: var(--brand); color: #fff; font-size: 0.65rem; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; vertical-align: middle;
}
.badge {
  background: #e8edfb; color: var(--brand-dark); font-size: 0.8rem;
  padding: 4px 10px; border-radius: 999px; font-weight: 600;
}

/* Stepper */
.stepper {
  display: flex; gap: 8px; margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.stepper::-webkit-scrollbar {
  display: none;
}
.step-d {
  flex: 1; flex-shrink: 0; display: flex; align-items: center; gap: 8px;
  background: #eef1f8; border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 10px; color: var(--muted);
  font-size: 0.82rem; font-weight: 600;
}
.step-d span {
  width: 22px; height: 22px; border-radius: 50%; background: #d5dbea;
  color: #5b6270; display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 800;
}
.step-d.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.step-d.active span { background: rgba(255,255,255,0.25); color: #fff; }

/* Cards */
main { position: relative; }
.card {
  display: none; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: 0 10px 30px rgba(20, 40, 90, 0.06);
}
.card.visible { display: block; }
.card h2 { margin: 0 0 6px; font-size: 1.35rem; letter-spacing: -0.01em; }
.card h2.ok-big { color: var(--ok); }
.card h2.bad-big { color: var(--bad); }
.muted { color: var(--muted); font-size: 0.92rem; }
.muted b { color: var(--ink); }
.foot { margin-top: 16px; text-align: center; }

button {
  font: inherit; font-weight: 700; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; padding: 11px 18px; font-size: 0.95rem;
  transition: background 0.15s, opacity 0.15s;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 18px; }
.primary { background: var(--brand); color: #fff; }
.primary:hover:not(:disabled) { background: var(--brand-dark); }
.ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.link-btn { background: none; padding: 0; color: var(--brand); border: 0; font-weight: 600; }

/* OTP */
.otp-row { display: flex; gap: 10px; margin-top: 14px; }
.otp-row input {
  flex: 1; font-size: 1.25rem; letter-spacing: 0.35em; text-align: center;
  padding: 10px; border: 1px solid var(--border); border-radius: 10px;
  outline: none; font-variant-numeric: tabular-nums;
  min-width: 0;
}
.otp-row input::placeholder {
  letter-spacing: normal;
  font-size: 0.9rem;
}
.otp-row button {
  flex-shrink: 0;
}
.otp-row input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(36, 87, 230, 0.12); }
.error { color: var(--bad); font-size: 0.9rem; margin-top: 10px; }
.resend-row { display: flex; align-items: center; gap: 6px; margin-top: 14px; }
.devnote {
  margin-top: 16px; padding: 8px 12px; border-radius: 8px;
  background: #fffbeb; border: 1px dashed var(--warn);
  color: var(--warn); font-size: 0.85rem; font-weight: 600;
  word-break: break-all; overflow-wrap: break-word;
}

/* Key/value */
.kv { display: grid; grid-template-columns: 180px minmax(0, 1fr); margin: 16px 0; gap: 0; }
.kv dt { color: var(--muted); padding: 8px 0; border-bottom: 1px solid #f1f3f9; }
.kv dd { margin: 0; padding: 8px 0; border-bottom: 1px solid #f1f3f9; font-weight: 500; word-break: break-word; overflow-wrap: anywhere; }
.kv input {
  width: 100%; font: inherit; color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  background: #fafbfe; outline: none;
}
.kv input:focus { border-color: var(--brand); background: #fff; }
code { background: #eef1f8; padding: 1px 5px; border-radius: 5px; font-size: 0.85em; }
pre {
  font: 0.8rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
#ref-file { margin: 6px 0 4px; color: var(--muted); }

/* Declarations */
.decls { list-style: none; margin: 14px 0; padding: 0; display: grid; gap: 10px; }
.decls li {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  background: #fafbfe; font-size: 0.92rem; line-height: 1.45;
}
.decls input { accent-color: var(--brand); width: 16px; height: 16px; margin-right: 8px; vertical-align: -2px; }

/* Consent */
.consent {
  margin: 16px 0; padding: 18px; border-radius: 12px;
  background: #f2f6ff; border: 1px solid #dbe4fb;
  color: #233a6e; font-size: 1.02rem; line-height: 1.6; font-style: italic;
}

/* Recording */
.video-wrap {
  position: relative; background: #000; border-radius: 14px; overflow: hidden;
  aspect-ratio: 4/3; margin-top: 14px;
}
video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
#live-overlay {
  position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.65);
  border-radius: 10px; padding: 8px 12px; font-size: 0.8rem; z-index: 5;
  display: flex; flex-direction: column; gap: 4px; min-width: 142px;
  backdrop-filter: blur(4px);
}
#live-overlay.live { opacity: 1; }
.ov-row { display: flex; justify-content: space-between; gap: 10px; }
.ov-label { color: #ccc; }
.ov-tag { font-weight: 700; font-variant-numeric: tabular-nums; }
.ov-ok { color: #4ade80; }
.ov-danger { color: #f87171; }
.ov-idle { color: #aaa; }
.audio-vis {
  margin-top: 12px; background: #0b0f14; border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
}
.audio-vis-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.78rem; color: var(--muted); margin-bottom: 6px;
}
.audio-vis-title { font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; }
.audio-badge { font-weight: 700; font-variant-numeric: tabular-nums; }
.audio-badge.idle { color: #aaa; }
.audio-badge.ok { color: #4ade80; }
.audio-badge.warn { color: #fbbf24; }
.audio-badge.danger { color: #f87171; }
#spectrogram {
  display: block; width: 100%; height: 88px; background: #000;
  border-radius: 6px; image-rendering: pixelated;
}
.audio-level {
  height: 4px; background: #1f2937; border-radius: 2px;
  margin-top: 8px; overflow: hidden;
}
#audio-level-fill {
  height: 100%; width: 0%; background: linear-gradient(90deg, #4ade80, #fbbf24, #f87171);
  transition: width 80ms linear;
}
.audio-vis-hint { margin: 8px 0 0; font-size: 0.72rem; color: var(--muted); line-height: 1.4; }
.statusline { display: flex; align-items: center; gap: 14px; margin: 16px 0; }
.timer {
  font-size: 2rem; min-width: 2.5ch; text-align: center;
  font-variant-numeric: tabular-nums; font-weight: 700;
}
#progress { flex: 1; background: #e7ebf4; height: 8px; border-radius: 4px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--brand); transition: width 0.5s linear; }
.prompt {
  background: #eef3ff; padding: 14px 16px; border-left: 4px solid var(--brand);
  font-size: 1.05rem; border-radius: 8px; line-height: 1.5; min-height: 3em;
}
.feed-pip {
  position: absolute; bottom: 10px; left: 10px; width: 120px; aspect-ratio: 4/3;
  border-radius: 8px; border: 2px solid rgba(255,255,255,0.5); z-index: 5;
  object-fit: cover; background: #000;
}

/* Processing */
.checks { list-style: none; margin: 20px 0 0; padding: 0; display: grid; gap: 8px; }
.checks li {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
  color: var(--muted); font-weight: 500;
}
.checks li .dot {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 800;
}
.checks li.pass { color: var(--ok); border-color: #cdeedd; background: #f4fbf6; }
.checks li.pass .dot { border-color: var(--ok); background: var(--ok); color: #fff; }
.checks li.fail { color: var(--bad); border-color: #f5cdcd; background: #fdf5f3; }
.checks li.fail .dot { border-color: var(--bad); background: var(--bad); color: #fff; }
.checks li.disabled { color: var(--muted); border-color: var(--border); background: #f8f9fc; }
.checks li.disabled .dot { border-color: var(--muted); background: #f0f1f5; color: var(--muted); }
.checks-table .disabled { color: var(--muted); }

.result-details {
  margin-top: 14px; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 0.82rem; color: var(--muted);
}
.result-details summary { cursor: pointer; font-weight: 600; }
.result-details div { margin-top: 6px; line-height: 1.5; }

/* Spinner */
.spinner {
  width: 42px; height: 42px; margin: 22px auto; border-radius: 50%;
  border: 4px solid #dbe4fb; border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result table */
.checks-table { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 0.92rem; }
.checks-table td { padding: 10px 12px; border-bottom: 1px solid #f1f3f9; }
.checks-table td:last-child { text-align: right; font-weight: 700; }
.checks-table .pass { color: var(--ok); }
.checks-table .fail { color: var(--bad); }

@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }
.loading-pulse { animation: pulse 1.5s infinite; color: var(--brand); font-weight: 600; }

@media (max-width: 500px) {
  .kv {
    grid-template-columns: minmax(0, 1fr);
  }
  .kv dt {
    padding-bottom: 2px;
    border-bottom: none;
  }
  .kv dd {
    padding-top: 2px;
    padding-bottom: 10px;
  }
}