/* =========================================================
   Tokens
   ========================================================= */
:root {
  --font: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --page: #f7f7f8;
  --surface: #ffffff;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --line: #e4e4e7;
  --line-soft: #f0f0f2;
  --hover: #f4f4f5;

  --ok: #16a34a;
  --err: #dc2626;
  --warn: #d97706;

  --toast-bg: #18181b;
  --toast-ink: #fafafa;
  --toast-muted: #a1a1aa;

  --radius: 12px;

  /* Spacing — tightened on short screens (see bottom of file) */
  --pad: 32px;          /* card padding */
  --gap: 24px;          /* space between main sections */
  --step-pad: 10px;     /* vertical padding of each instruction step */
  --title: 24px;        /* headline size */
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #09090b;
    --surface: #111113;
    --ink: #fafafa;
    --ink-2: #d4d4d8;
    --muted: #a1a1aa;
    --faint: #71717a;
    --line: #27272a;
    --line-soft: #1c1c1f;
    --hover: #1c1c1f;

    --ok: #22c55e;
    --err: #f87171;
    --warn: #fbbf24;

    --toast-bg: #fafafa;
    --toast-ink: #18181b;
    --toast-muted: #52525b;
  }
}

/* =========================================================
   Base
   ========================================================= */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--hover);
  border: 1px solid var(--line);
}

strong { font-weight: 500; color: var(--ink); }

[hidden] { display: none !important; }

/* =========================================================
   Card
   ========================================================= */
.card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: var(--pad);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 8px 24px -12px rgba(0, 0, 0, 0.08);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: calc(var(--gap) - 4px);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.eyebrow svg { width: 15px; height: 15px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 24px;
  padding: 0 10px 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
}

.card[data-state="ok"]    .dot { background: var(--ok); }
.card[data-state="error"] .dot { background: var(--err); }
.card[data-state="warn"]  .dot { background: var(--warn); }
.card[data-state="checking"] .dot { animation: blink 1.2s ease-in-out infinite; }

.card[data-state="ok"]    .pill { color: var(--ok); }
.card[data-state="error"] .pill { color: var(--err); }
.card[data-state="warn"]  .pill { color: var(--warn); }

/* =========================================================
   Status (the page headline)
   ========================================================= */
.status { margin-bottom: var(--gap); }

.status h1 {
  margin: 0;
  font-size: var(--title);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.card[data-state="error"] .status h1 { color: var(--err); }

.status p {
  margin: 6px 0 0;
  color: var(--muted);
  text-wrap: pretty;
}

/* =========================================================
   Camera preview
   ========================================================= */
.preview {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 40vh;   /* shrinks on short screens so the page never needs to scroll */
  max-height: 40dvh;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0a0a0a;
  margin-bottom: var(--gap);
  animation: enter 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
/* hairline ring that sits on top of the video */
.preview::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.preview video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, like looking in a mirror */
}

.live-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ef4444;
  animation: blink 1.6s ease-in-out infinite;
}

/* =========================================================
   Help / instructions
   ========================================================= */
.help {
  border-top: 1px solid var(--line);
  padding-top: calc(var(--gap) - 4px);
  margin-bottom: var(--gap);
  font-size: 14.5px;
  animation: enter 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.section-label {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.os-help { margin-top: calc(var(--gap) - 4px); }

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: step;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding: var(--step-pad) 0 var(--step-pad) 28px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-2);
  line-height: 1.5;
}
.steps li:last-child { border-bottom: 0; padding-bottom: 0; }

.steps li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: var(--step-pad);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 21.75px; /* = 14.5px × 1.5, so it sits on the first text line */
  color: var(--faint);
}

/* Secondary hints inside steps, e.g. "(iOS 17 or earlier: …)" */
.steps .muted { color: var(--faint); }
.steps .muted strong { color: inherit; font-weight: 500; }

/* "Don't see that icon? …" fallback line under a step list */
.step-tip {
  margin: 8px 0 0;
  padding-left: 28px;
  font-size: 13px;
  color: var(--muted);
}

/* "Open camera settings" deep link (macOS / Windows only) */
.settings-link {
  margin-top: 12px;
  padding-left: 28px;
}
.settings-link .btn {
  width: auto;
  height: 34px;
  padding: 0 12px;
  font-size: 13.5px;
  text-decoration: none;
}
.settings-link .btn svg { width: 14px; height: 14px; }
.settings-hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--faint);
}

/* =========================================================
   Buttons
   ========================================================= */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
/* Camera on: "Check again" on its own row, the two secondary actions below.
   Camera off: "Check again" and "Share details" side by side (saves a row). */
.actions:has(#stop-btn:not([hidden])) .primary { grid-column: 1 / -1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--ink);
  color: var(--surface);
}
.btn.primary:hover:not(:disabled) { opacity: 0.88; }

.btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
.btn.secondary:hover { background: var(--hover); }

.btn:disabled { opacity: 0.6; cursor: default; }
.btn:disabled svg { animation: spin 0.9s linear infinite; }

/* =========================================================
   Footer
   ========================================================= */
.privacy {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: calc(var(--gap) - 4px);
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 13px;
  line-height: 1.5;
}
.privacy svg { width: 14px; height: 14px; margin-top: 2px; }

/* =========================================================
   Wide screens with instructions: two columns
   (status + actions on the left, steps on the right)
   ========================================================= */
@media (min-width: 860px) {
  .card.has-help {
    max-width: 920px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "top     help"
      "status  help"
      "actions help"
      "footer  help";
    column-gap: 40px;
  }
  .card.has-help .topbar  { grid-area: top; }
  .card.has-help .status  { grid-area: status; }
  .card.has-help .actions { grid-area: actions; align-self: start; }
  .card.has-help .privacy { grid-area: footer; align-self: end; }
  .card.has-help .help {
    grid-area: help;
    margin: 0;
    padding: 0 0 0 40px;
    border-top: 0;
    border-left: 1px solid var(--line);
  }
  .card.has-help .status h1 { font-size: 26px; }
}

/* =========================================================
   Phones: drop the card chrome and use the whole screen
   ========================================================= */
@media (max-width: 520px) {
  :root {
    --pad: 4px;
    --gap: 20px;
    --title: 22px;
  }
  body {
    align-items: flex-start;
    background: var(--surface);
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  }
  .card { border: 0; box-shadow: none; border-radius: 0; }
  .help { font-size: 14px; }
  .steps li::before { line-height: 21px; }
}

/* =========================================================
   Short screens: tighten spacing so nothing needs scrolling
   ========================================================= */
@media (max-height: 760px) {
  :root {
    --gap: 18px;
    --step-pad: 7px;
  }
  body { padding-top: 16px; padding-bottom: 16px; }
}
@media (max-height: 760px) and (min-width: 521px) {
  :root { --pad: 26px; --title: 22px; }
}
@media (max-height: 640px) {
  :root {
    --gap: 14px;
    --step-pad: 5px;
    --title: 20px;
  }
  .settings-hint { display: none; }
}

/* =========================================================
   Toast (top-right)
   ========================================================= */
.toast {
  position: fixed;
  top: max(20px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  z-index: 100;
  width: 360px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.is-visible {
  opacity: 1;
  transform: none;
}

/* On narrow screens, span the top edge instead */
@media (max-width: 520px) {
  .toast {
    left: 12px;
    right: 12px;
    top: max(12px, env(safe-area-inset-top));
    width: auto;
    transform: translateY(-12px);
  }
}

.toast-icon {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  color: #fff;
}
.toast-icon svg { width: 12px; height: 12px; stroke-width: 3; display: none; }
.toast[data-state="ok"] .toast-icon { background: var(--ok); }
.toast[data-state="error"] .toast-icon { background: var(--err); }
.toast[data-state="ok"] .i-ok,
.toast[data-state="error"] .i-alert { display: block; }

.toast-body strong {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--toast-ink);
}
.toast-body p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--toast-muted);
}

/* =========================================================
   Animations
   ========================================================= */
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes enter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
