/* Cam 2 Cam — design system. Minimal, calm, camera-first. */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Roboto Mono", monospace;

  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --surface-3: #e6e5df;
  --line: rgba(28, 28, 30, 0.09);
  --line-strong: rgba(28, 28, 30, 0.16);
  --text: #1c1c1e;
  --text-2: #5c5c61;
  --text-3: #8e8e93;
  --ink: #1c1c1e;
  --on-ink: #f6f5f1;

  --green: #23824f;
  --green-bg: #dff3e7;
  --green-dot: #34c46b;
  --amber: #8a5a00;
  --amber-bg: #fff1d1;
  --amber-dot: #f2a516;
  --red: #d9363e;
  --red-bg: #fde9e9;
  --blue: #2f64c8;
  --blue-bg: #e5eefc;

  --radius-xl: 24px;
  --radius-l: 18px;
  --radius-m: 14px;
  --radius-s: 10px;
  --shadow-1: 0 1px 1px rgba(46, 38, 24, 0.04), 0 2px 6px rgba(46, 38, 24, 0.04), 0 10px 28px -6px rgba(46, 38, 24, 0.08);
  --shadow-2: 0 2px 4px rgba(46, 38, 24, 0.05), 0 14px 30px -8px rgba(46, 38, 24, 0.2), 0 30px 60px -20px rgba(46, 38, 24, 0.16);
  --ink-fill: linear-gradient(160deg, #2d3038 0%, #1c1e23 55%, #141518 100%);

  /* Page backdrop: soft daylight from the top, a hint of mint and warm sand. */
  --glow-top: rgba(255, 255, 255, 0.95);
  --glow-mint: rgba(134, 221, 170, 0.2);
  --glow-sand: rgba(226, 204, 166, 0.24);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --gutter: 20px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1c1c1f;
    --surface-2: #26262a;
    --surface-3: #2f2f34;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.16);
    --text: #f2f2f4;
    --text-2: #b4b4ba;
    --text-3: #85858c;
    --ink: #f2f1ec;
    --on-ink: #141416;
    --green: #7fd3a2;
    --green-bg: rgba(52, 196, 107, 0.16);
    --amber: #f5c769;
    --amber-bg: rgba(242, 165, 22, 0.16);
    --red: #ff7a7f;
    --red-bg: rgba(255, 92, 99, 0.15);
    --blue: #8db3ff;
    --blue-bg: rgba(90, 140, 255, 0.16);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -8px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 18px 40px rgba(0, 0, 0, 0.5);
    --ink-fill: linear-gradient(160deg, #fbfaf6 0%, #eceae3 100%);
    --glow-top: rgba(255, 255, 255, 0.045);
    --glow-mint: rgba(127, 211, 162, 0.085);
    --glow-sand: rgba(255, 214, 160, 0.035);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(95% 55% at 50% -14%, var(--glow-top), transparent 72%),
    radial-gradient(60% 42% at 104% 0%, var(--glow-mint), transparent 74%),
    radial-gradient(70% 46% at -6% 104%, var(--glow-sand), transparent 72%);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 70%, transparent); outline-offset: 2px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.muted { color: var(--text-2); }
.noscript { padding: 24px; text-align: center; }

/* ------------------------------------------------------------------ type */
.title-xl { font-size: 34px; line-height: 1.1; font-weight: 750; letter-spacing: -0.025em; margin: 0; }
.title-m { font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -0.012em; margin: 0; }
.subtitle { margin: 6px 0 0; color: var(--text-2); font-size: 17px; }
.fine { font-size: 13px; line-height: 1.5; color: var(--text-3); margin: 12px 0 0; }
.hint { font-size: 14px; color: var(--text-2); line-height: 1.55; margin: 14px 4px 0; }

/* --------------------------------------------------------------- screens */
.screen-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.page {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + var(--gutter)) 32px calc(var(--safe-l) + var(--gutter));
  flex: 1;
}
.page-reading { max-width: 720px; }

/* ------------------------------------------------------------------ home */
.page-home { display: flex; flex-direction: column; gap: 22px; padding-top: calc(var(--safe-t) + 36px); }
.home-head { display: flex; flex-direction: column; align-items: flex-start; }
.app-mark { width: 56px; height: 56px; margin-bottom: 18px; border-radius: 22.6%; box-shadow: 0 1px 2px rgba(20, 22, 28, 0.12), 0 12px 26px -8px rgba(20, 22, 28, 0.45); }
@media (prefers-color-scheme: dark) { .app-mark { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 12px 26px -8px rgba(0, 0, 0, 0.7); } }
.title-accent { color: var(--green); }
.status-pill {
  margin-top: 16px;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px 7px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13.5px; color: var(--text-2); min-height: 40px;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
.dot { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.status-pill[data-tone="ok"] .dot::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; opacity: 0; animation: ping 2.6s var(--ease-out) infinite; }
.status-pill[data-tone="ok"] { background: var(--green-bg); border-color: transparent; color: var(--green); }
.status-pill[data-tone="ok"] .dot { background: var(--green-dot); }
.status-pill[data-tone="warn"] { background: var(--amber-bg); border-color: transparent; color: var(--amber); }
.status-pill[data-tone="warn"] .dot { background: var(--amber-dot); }
.status-pill[data-tone="bad"] { background: var(--red-bg); border-color: transparent; color: var(--red); }
.status-pill[data-tone="bad"] .dot { background: var(--red); }

.hero-actions { display: grid; gap: 12px; }
.hero {
  position: relative; isolation: isolate; overflow: hidden;
  display: flex; align-items: center; gap: 16px;
  width: 100%; min-height: 104px; padding: 20px 18px 20px 20px;
  border-radius: var(--radius-xl); text-align: left;
  transition: transform 0.4s var(--ease-spring), box-shadow 0.3s ease;
}
.hero:active { transform: scale(0.975); transition-duration: 0.12s; }
.hero-ink { background: var(--ink-fill); color: var(--on-ink); box-shadow: var(--shadow-2), inset 0 1px 0 rgba(255, 255, 255, 0.08); }
.hero-paper { background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.hero-deco {
  position: absolute; z-index: -1; right: -96px; bottom: -96px; width: 230px; height: 230px;
  color: rgba(255, 255, 255, 0.07); pointer-events: none;
  transition: transform 0.7s var(--ease-out);
}
@media (prefers-color-scheme: dark) { .hero-deco { color: rgba(20, 20, 22, 0.065); } }
.hero-icon { width: 56px; height: 56px; border-radius: 17px; display: grid; place-items: center; flex: none; }
.hero-ink .hero-icon { background: rgba(255, 255, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06); }
.hero-paper .hero-icon { background: var(--green-bg); color: var(--green); }
@media (prefers-color-scheme: dark) { .hero-ink .hero-icon { background: rgba(0, 0, 0, 0.08); } }
.hero-icon .ico { width: 28px; height: 28px; }
.hero-text { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.hero-title { font-size: 19px; font-weight: 750; letter-spacing: 0.05em; text-transform: uppercase; }
.hero-sub { font-size: 14.5px; opacity: 0.72; }
.hero .chevron { opacity: 0.45; transition: transform 0.3s var(--ease-out), opacity 0.2s ease; }
@media (hover: hover) {
  .hero:hover { transform: translateY(-2px); }
  .hero-ink:hover { box-shadow: 0 4px 8px rgba(46, 38, 24, 0.08), 0 22px 44px -12px rgba(46, 38, 24, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.08); }
  .hero-paper:hover { box-shadow: var(--shadow-2); }
  .hero:hover .hero-deco { transform: translateX(-10px) rotate(-8deg); }
  .hero:hover .chevron { transform: translateX(3px); opacity: 0.8; }
}

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); overflow: hidden; box-shadow: var(--shadow-1); }
.list-row, .form-row {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 56px; padding: 10px 16px;
  text-decoration: none; text-align: left;
}
.list-row + .list-row, .form-row + .form-row, .list-row + .form-row, .form-row + .list-row { border-top: 1px solid var(--line); }
.list-row { transition: background-color 0.15s ease; }
.list-row:active { background: var(--surface-2); }
@media (hover: hover) {
  .list-row:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
  .list-row:hover .chevron { transform: translateX(2px); }
}
.row-icon { width: 32px; height: 32px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--text); }
.row-icon .ico { width: 19px; height: 19px; }
.row-icon[data-tint="green"] { background: var(--green-bg); color: var(--green); }
.row-icon[data-tint="amber"] { background: var(--amber-bg); color: var(--amber); }
.row-icon[data-tint="blue"] { background: var(--blue-bg); color: var(--blue); }
.row-label { flex: 1; font-size: 16px; display: inline-flex; align-items: center; gap: 8px; }
.row-label .ico { width: 18px; height: 18px; color: var(--text-2); }
.row-value { color: var(--text-3); font-size: 15px; text-align: right; }
.list .chevron { width: 18px; height: 18px; color: var(--text-3); transition: transform 0.25s var(--ease-out); }

.home-note { display: flex; gap: 10px; align-items: flex-start; margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.55; padding: 0 4px; }
.home-note .ico { width: 19px; height: 19px; margin-top: 1px; color: var(--green); }

.app-footer {
  display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: center;
  padding: 18px calc(var(--safe-r) + var(--gutter)) calc(var(--safe-b) + 18px) calc(var(--safe-l) + var(--gutter));
  font-size: 12.5px; color: var(--text-3); text-align: center;
}
.app-footer a { color: var(--text-2); }

/* ------------------------------------------------------------- nav / page */
.nav {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  margin: calc(-1 * (var(--safe-t) + 12px)) calc(-1 * (var(--safe-r) + var(--gutter))) 18px calc(-1 * (var(--safe-l) + var(--gutter)));
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 12px) 8px calc(var(--safe-l) + 12px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(18px); backdrop-filter: saturate(1.6) blur(18px);
  border-bottom: 1px solid var(--line);
}
.nav-back, .nav-spacer { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 12px; color: var(--text); }
.nav-back:active { background: var(--surface-2); }
.nav-title { flex: 1; text-align: center; font-size: 17px; font-weight: 650; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----------------------------------------------------------- components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xl); padding: 20px; box-shadow: var(--shadow-1); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 11px 18px; border-radius: var(--radius-m);
  font-size: 16px; font-weight: 650; text-decoration: none; text-align: center;
  transition: transform 0.25s var(--ease-spring), opacity 0.12s ease, background-color 0.15s ease;
  border: 1px solid transparent;
}
.btn:active:not(:disabled) { transform: scale(0.97); transition-duration: 0.1s; }
.btn .ico { width: 20px; height: 20px; }
.btn-ink { background: var(--ink); color: var(--on-ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1), 0 8px 18px -8px rgba(20, 22, 28, 0.45); }
@media (prefers-color-scheme: dark) { .btn-ink { box-shadow: none; } }
@media (hover: hover) {
  .btn-ink:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 86%, var(--bg)); }
  .btn-soft:hover:not(:disabled), .icon-btn:hover, .nav-back:hover { background: var(--surface-3); }
}
.btn-soft { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger-soft { background: var(--red-bg); color: var(--red); }
.btn-lg { min-height: 54px; font-size: 17px; border-radius: 16px; }
.btn-sm { min-height: 42px; padding: 8px 14px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row-center { justify-content: center; }
.btn-row-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.icon-btn .ico { width: 18px; height: 18px; }

.field { margin-top: 18px; }
.field-label { display: block; font-size: 13px; font-weight: 650; color: var(--text-2); letter-spacing: 0.02em; margin-bottom: 8px; text-transform: uppercase; }
.field-hint { display: block; font-size: 13px; color: var(--text-3); margin-top: 8px; line-height: 1.5; }
.field-error { color: var(--red); font-size: 14px; margin: 8px 0 0; }

input[type="text"], input[type="url"], input:not([type]), textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  font-size: 16px; /* 16px keeps iOS Safari from zooming on focus */
  background: var(--surface-2); border: 1px solid transparent; border-radius: var(--radius-m);
  outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { border-color: var(--line-strong); background: var(--surface); }
textarea { resize: vertical; line-height: 1.4; font-family: var(--mono); font-size: 16px; min-height: 84px; word-break: break-all; }
.code-input { font-size: 26px !important; text-align: center; letter-spacing: 0.12em; min-height: 62px !important; margin-bottom: 14px; text-transform: uppercase; }
.code-input::placeholder { color: var(--text-3); opacity: 0.6; }

.segmented { position: relative; isolation: isolate; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; padding: 3px; background: var(--surface-2); border-radius: 12px; }
/* The highlight slides to the chosen option; --i / --n / --on are set by segmented() in lib/dom.js. */
.segmented::before {
  content: ""; position: absolute; z-index: -1; top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px - (var(--n, 1) - 1) * 3px) / var(--n, 1));
  border-radius: 9px; background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  opacity: var(--on, 0);
  transform: translateX(calc(var(--i, 0) * (100% + 3px)));
  transition: transform 0.45s var(--ease-spring), opacity 0.2s ease;
}
@media (prefers-color-scheme: dark) { .segmented::before { background: var(--surface-3); } }
.segmented button { min-height: 40px; padding: 6px 8px; border-radius: 9px; font-size: 14.5px; font-weight: 600; color: var(--text-2); line-height: 1.18; text-wrap: balance; transition: color 0.2s ease; }
.segmented button[aria-checked="true"] { color: var(--text); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; min-height: 44px; font-size: 16px; }
.switch {
  -webkit-appearance: none; appearance: none; flex: none;
  width: 51px; height: 31px; border-radius: 31px; background: var(--surface-3);
  position: relative; cursor: pointer; transition: background-color 0.2s ease; margin: 0;
}
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); transition: transform 0.35s var(--ease-spring); }
.switch:checked { background: var(--green-dot); }
.switch:checked::after { transform: translateX(20px); }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-l); font-size: 14.5px; line-height: 1.5; margin: 0; }
.notice .ico { margin-top: 1px; }
.notice-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.notice-info { background: var(--green-bg); color: var(--text); align-items: center; }
.notice-info .ico { color: var(--green); }
.notice-soft { background: var(--surface); border: 1px solid var(--line); color: var(--text-2); }
.notice-soft strong { color: var(--text); }
.notice-warn { background: var(--amber-bg); color: var(--amber); display: block; margin-top: 12px; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 13px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--text); animation: spin 0.9s linear infinite; }
.spinner-light { border-color: rgba(255, 255, 255, 0.2); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.verify { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 16px 0 4px; }
.verify .mono { font-size: 40px; font-weight: 700; letter-spacing: 0.18em; color: var(--text); }

/* ---------------------------------------------------------------- viewer */
.viewer-panel { display: flex; flex-direction: column; gap: 14px; }
.wait-card, .end-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 28px 22px 22px; }
.wait-card .title-m, .end-card .title-m { margin-top: 6px; }
.wait-pulse { position: relative; width: 84px; height: 84px; display: grid; place-items: center; }
.wait-pulse > span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--green-dot); opacity: 0; animation: ripple 2.6s var(--ease-out) infinite; }
.wait-pulse > span + span { animation-delay: 1.3s; }
.wait-pulse .ico { position: relative; width: 58px; height: 58px; padding: 15px; border-radius: 50%; background: var(--green-bg); color: var(--green); }
.wait-card .muted, .end-card .muted { margin: 0; font-size: 15px; }
.end-card .btn { margin-top: 4px; }
.end-icon { animation: pop 0.45s var(--ease-spring) 0.08s backwards; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); }
.end-icon[data-tone="bad"] { background: var(--red-bg); color: var(--red); }
.end-icon[data-tone="ok"] { background: var(--green-bg); color: var(--green); }
.end-icon .ico { width: 28px; height: 28px; }

.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.steps-card .step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xl); padding: 16px; }
.step { display: flex; gap: 12px; align-items: flex-start; }
.step-n { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.step-body { flex: 1; min-width: 0; }
.step-body > strong { display: block; font-size: 16px; line-height: 1.35; padding-top: 3px; }
.step-done .step-n { background: var(--green-dot); color: #fff; }
.step-disabled { opacity: 0.45; }
.step-disabled .btn, .step-disabled .qr-box { pointer-events: none; }
.step-disabled .qr-box:empty { display: none; }
.paste-wrap { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.qr-box { display: grid; place-items: center; margin: 12px auto 0; width: min(100%, 260px); aspect-ratio: 1; background: #fff; border-radius: 16px; padding: 10px; border: 1px solid var(--line); }
.qr-box:empty::after { content: ""; width: 34%; height: 34%; border-radius: 50%; border: 3px solid #ddd; border-top-color: #555; animation: spin 0.9s linear infinite; }
.qr-box svg { width: 100%; height: 100%; display: block; image-rendering: pixelated; shape-rendering: crispEdges; }
.qr-dense { width: min(100%, 320px); }
.qr-box[role="button"] { cursor: zoom-in; }
.qr-box.qr-zoom {
  position: fixed; inset: 0; z-index: 300; margin: 0; width: 100%; height: 100%; aspect-ratio: auto;
  border-radius: 0; border: 0; cursor: zoom-out;
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
}
.qr-box.qr-zoom svg { width: min(100%, 100vh); height: auto; max-height: 100%; }
.qr-box .qr-error { color: #444; font-size: 13px; text-align: center; padding: 8px; }

/* --------------------------------------------------------------- stage */
.screen-stage, .stage { background: #000; color: #fff; }
.stage { position: fixed; inset: 0; overflow: hidden; z-index: 10; touch-action: manipulation; }
.stage-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage-video.mirror { transform: scaleX(-1); }
.video-frame { position: absolute; inset: 0; overflow: hidden; }
.video-frame .stage-video {
  inset: auto; left: 50%; top: 50%;
  width: var(--vw, 100%); height: var(--vh, 100%);
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  object-fit: var(--fit, contain);
}

.stage-top {
  position: absolute; z-index: 3; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 12px) 10px calc(var(--safe-l) + 12px);
  background: linear-gradient(rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0));
  pointer-events: none;
}
.stage-top > * { pointer-events: auto; }
.glass-btn {
  min-width: 44px; height: 44px; padding: 0 12px; border-radius: 22px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: rgba(40, 40, 44, 0.55); color: #fff;
  -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4);
  font-size: 15px; font-weight: 650; position: relative;
}
.glass-btn[aria-pressed="true"] { background: rgba(255, 255, 255, 0.9); color: #111; }
.glass-danger { background: rgba(217, 54, 62, 0.92); }
.glass-btn .ico { width: 20px; height: 20px; }
.badge { position: absolute; top: -3px; right: -3px; min-width: 19px; height: 19px; border-radius: 10px; background: var(--green-dot); color: #06210f; font-size: 11.5px; font-weight: 750; display: grid; place-items: center; padding: 0 5px; }

.status-chip {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  height: 34px; padding: 0 13px; border-radius: 17px;
  background: rgba(40, 40, 44, 0.55); color: #fff;
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  font-size: 13.5px; font-weight: 650; white-space: nowrap; overflow: hidden;
}
.status-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.status-chip .dot { background: #9a9aa0; }
.status-chip[data-tone="live"] { background: rgba(35, 130, 79, 0.85); }
.status-chip[data-tone="live"] .dot { background: #9ff0bd; box-shadow: 0 0 0 3px rgba(159, 240, 189, 0.25); animation: pulse 1.8s ease-in-out infinite; }
.status-chip[data-tone="ready"] .dot { background: var(--green-dot); }
.status-chip[data-tone="wait"] .dot { background: var(--amber-dot); }
.status-chip[data-tone="bad"] { background: rgba(217, 54, 62, 0.88); }
.status-chip[data-tone="bad"] .dot { background: #fff; }
@keyframes pulse { 50% { opacity: 0.45; } }

.stage-banner {
  position: absolute; z-index: 3; left: 50%; translate: -50% 0;
  top: calc(var(--safe-t) + 66px); width: max-content; max-width: calc(100% - 32px - var(--safe-l) - var(--safe-r));
  padding: 10px 14px; border-radius: 14px; font-size: 14.5px; line-height: 1.4; text-align: center;
  background: rgba(28, 28, 30, 0.82); color: #fff;
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.stage-banner[data-tone="warn"] { background: rgba(138, 90, 0, 0.9); }
.stage-banner[data-tone="bad"] { background: rgba(217, 54, 62, 0.92); }
.stage.recording .stage-banner { top: calc(var(--safe-t) + 106px); }
.stage.stats-open .stage-banner { top: calc(var(--safe-t) + 236px); }
#camStage .stage-banner { top: calc(var(--safe-t) + 100px); }
.stage-info {
  position: absolute; z-index: 2; left: calc(var(--safe-l) + 12px); top: calc(var(--safe-t) + 62px);
  max-width: calc(100% - 24px - var(--safe-l) - var(--safe-r));
  padding: 5px 10px; border-radius: 10px; background: rgba(20, 20, 22, 0.55);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font-size: 12px; color: rgba(255, 255, 255, 0.86); font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.stage-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: rgba(255, 255, 255, 0.85); font-size: 15px; pointer-events: none; z-index: 1; text-align: center; padding: 0 24px; }

.dock {
  position: absolute; z-index: 3;
  left: 50%; translate: -50% 0;
  bottom: calc(var(--safe-b) + 14px);
  width: max-content; max-width: calc(100% - 20px - var(--safe-l) - var(--safe-r));
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(64px, 1fr); gap: 2px;
  padding: 6px; border-radius: 24px;
  background: rgba(30, 30, 33, 0.62);
  -webkit-backdrop-filter: blur(22px) saturate(1.5); backdrop-filter: blur(22px) saturate(1.5);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.dock.dock-wrap { grid-auto-flow: row; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); width: calc(100% - 20px - var(--safe-l) - var(--safe-r)); }
.ctl {
  min-height: 58px; padding: 7px 4px 6px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: #fff; font-size: 11.5px; font-weight: 600; line-height: 1.15; text-align: center;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.25s var(--ease-spring);
}
.ctl .ico { width: 24px; height: 24px; }
.ctl:active { background: rgba(255, 255, 255, 0.12); transform: scale(0.93); transition-duration: 0.1s; }
@media (hover: hover) { .ctl:hover:not(.ctl-accent):not(.ctl-on):not([aria-pressed="true"].ctl-rec) { background: rgba(255, 255, 255, 0.08); } }
.ctl[aria-pressed="false"].ctl-toggle { color: #ff8a8f; }
.ctl[aria-pressed="true"].ctl-on { background: rgba(255, 255, 255, 0.92); color: #111; }
.ctl-accent { background: rgba(255, 255, 255, 0.92); color: #111; }
.ctl-accent:active { background: #fff; }
.ctl-rec[aria-pressed="true"] { background: var(--red); color: #fff; }

.stage-card-wrap { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; overflow-y: auto; padding: calc(var(--safe-t) + 70px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 16px); background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0) 60%); }
.stage-card { width: 100%; max-width: 420px; color: var(--text); }
.stage-card .muted { margin: 8px 0 0; font-size: 15px; }
.stage-card .btn-lg { margin-top: 22px; }

.stats {
  position: absolute; z-index: 3; margin: 0;
  right: calc(var(--safe-r) + 12px); top: calc(var(--safe-t) + 64px);
  display: grid; grid-template-columns: auto auto; gap: 6px 14px;
  padding: 12px 14px; border-radius: 16px; min-width: 210px;
  background: rgba(20, 20, 22, 0.72); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.stats > div { display: contents; }
.stats dt { color: rgba(255, 255, 255, 0.62); }
.stats dd { margin: 0; text-align: right; font-weight: 650; }

.rec-badge { position: absolute; z-index: 3; left: calc(var(--safe-l) + 12px); top: calc(var(--safe-t) + 64px); display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 14px; background: rgba(217, 54, 62, 0.92); font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: pulse 1.2s ease-in-out infinite; }

.pair-sheet {
  position: absolute; z-index: 4; left: 50%; translate: -50% 0;
  bottom: calc(var(--safe-b) + 92px); width: calc(100% - 20px - var(--safe-l) - var(--safe-r)); max-width: 440px;
  max-height: calc(100% - var(--safe-t) - var(--safe-b) - 170px); overflow-y: auto;
  background: var(--surface); color: var(--text); border-radius: var(--radius-xl); padding: 14px 16px 16px; box-shadow: var(--shadow-2);
}
.pair-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.pair-head strong { font-size: 16px; }
.pair-sheet .qr-box { width: min(100%, 300px); }

/* ---------------------------------------------------------------- dialogs */
dialog.sheet {
  border: 0; padding: 18px calc(var(--safe-r) + 20px) calc(var(--safe-b) + 22px) calc(var(--safe-l) + 20px);
  margin: auto auto 0; width: 100%;
  max-width: 560px; max-height: min(92dvh, 92vh);
  border-radius: 26px 26px 0 0;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-2); overflow-y: auto; overscroll-behavior: contain;
}
dialog.sheet[open] { animation: sheet-in 0.46s var(--ease-out); }
dialog.sheet::backdrop { background: rgba(18, 16, 12, 0.38); }
dialog.sheet[open]::backdrop { animation: fade 0.3s ease; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet-head h2 { font-size: 20px; margin: 0; font-weight: 700; }
.sheet-alert { max-width: 420px; }
.sheet-dark { background: #111; color: #fff; }
.sheet-dark .icon-btn { background: rgba(255, 255, 255, 0.12); color: #fff; }
.sheet-dark .fine { color: rgba(255, 255, 255, 0.65); text-align: center; }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; border-radius: 26px; padding-bottom: 22px; }
  dialog.sheet[open] { animation-name: sheet-pop; }
}

.choice-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.choice { display: flex; gap: 14px; align-items: flex-start; text-align: left; padding: 14px; border-radius: var(--radius-l); border: 1.5px solid var(--line); width: 100%; transition: border-color 0.2s ease, transform 0.25s var(--ease-spring); }
.choice:active { transform: scale(0.985); }
.choice[aria-checked="true"] { border-color: var(--ink); }
.choice-text { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.choice-text strong { font-size: 16px; }
.choice-text span { font-size: 14px; color: var(--text-2); line-height: 1.45; }
.choice .check { color: var(--text); opacity: 0; margin-top: 4px; transform: scale(0.4); transition: opacity 0.2s ease, transform 0.4s var(--ease-spring); }
.choice[aria-checked="true"] .check { opacity: 1; transform: none; }

.invite { display: flex; flex-direction: column; }
.invite .qr-box { width: min(100%, 240px); }
.room-code { display: flex; flex-direction: column; align-items: center; margin-top: 14px; }
.room-code .field-label { margin-bottom: 2px; }
.code-big { font-size: 30px; font-weight: 750; letter-spacing: 0.1em; user-select: all; -webkit-user-select: all; }
.invite .fine { text-align: center; }
.invite .list { margin-top: 16px; }

.request { display: flex; flex-direction: column; align-items: center; text-align: center; }
.request h2 { font-size: 20px; margin: 10px 0 0; }
.request-icon { width: 58px; height: 58px; border-radius: 50%; background: var(--green-bg); color: var(--green); display: grid; place-items: center; }
.request-icon .ico { width: 28px; height: 28px; }
.request-name { margin: 6px 0 0; font-size: 16px; color: var(--text-2); word-break: break-word; }
.request .btn-row-split { width: 100%; }

.viewer-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 10px; }
.viewer-item { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 14px; border-radius: var(--radius-l); background: var(--surface-2); }
.viewer-meta { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 2px; }
.viewer-meta strong { font-size: 16px; word-break: break-word; }
.viewer-meta span { font-size: 13.5px; color: var(--text-2); }
.viewer-actions { display: flex; gap: 8px; }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--surface); color: var(--text-2); width: max-content; }
.tag-live { background: var(--green-bg); color: var(--green); }
.tag-wait { background: var(--amber-bg); color: var(--amber); }
.empty { color: var(--text-2); text-align: center; margin: 18px 0 4px; }

input[type="range"] { width: 100%; accent-color: var(--ink); }
.actual { margin: 18px 0 0; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-m); font-size: 14.5px; font-variant-numeric: tabular-nums; }

.capture-preview { display: grid; place-items: center; background: #000; border-radius: var(--radius-l); overflow: hidden; margin-top: 6px; max-height: 52vh; }
.capture-preview img, .capture-preview video { max-width: 100%; max-height: 52vh; display: block; }

.scanner { position: relative; margin-top: 8px; border-radius: var(--radius-l); overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 62vh; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 16%; border: 3px solid rgba(255, 255, 255, 0.92); border-radius: 22px; box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35); }

/* ------------------------------------------------------------- settings */
.settings { display: flex; flex-direction: column; }
.group-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); margin: 26px 6px 8px; }
.group-title:first-child { margin-top: 4px; }
.list-form .form-row { cursor: default; }
label.form-row { cursor: pointer; }
.form-row-stack { flex-direction: column; align-items: stretch; gap: 10px; padding-top: 14px; padding-bottom: 14px; }
.form-row-stack .btn-row { margin-top: 0; }
.version { color: var(--text-3); font-size: 13px; text-align: center; margin: 28px 0 0; }

/* ---------------------------------------------------------------- prose */
.prose { display: flex; flex-direction: column; gap: 14px; font-size: 16px; line-height: 1.62; }
.prose.card { display: block; }
.prose h2 { font-size: 18px; margin: 0 0 8px; letter-spacing: -0.01em; }
.prose.card h2 { margin-top: 22px; }
.prose.card h2:first-of-type { margin-top: 8px; }
.prose p { margin: 8px 0; color: var(--text-2); }
.prose ol, .prose ul { padding-left: 22px; margin: 8px 0; color: var(--text-2); }
.prose li { margin: 6px 0; }
.prose b { color: var(--text); font-weight: 650; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; z-index: 100; left: 50%; translate: -50% 0;
  animation: toast-in 0.42s var(--ease-spring) backwards;
  bottom: calc(var(--safe-b) + 24px);
  width: max-content; max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 16px;
  background: rgba(28, 28, 30, 0.92); color: #fff; font-size: 15px; line-height: 1.4; text-align: center;
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.toast.is-leaving { animation: toast-out 0.22s ease-in forwards; }
body.has-stage .toast { bottom: calc(var(--safe-b) + 108px); }

/* ---------------------------------------------------------- responsive */
@media (min-width: 640px) {
  :root { --gutter: 28px; }
  .page-home { padding-top: calc(var(--safe-t) + 64px); }
  .hero-actions { grid-template-columns: 1fr 1fr; }
  .hero { flex-direction: column; align-items: flex-start; min-height: 200px; padding: 22px; }
  .hero .chevron { display: none; }
  .hero-text { margin-top: auto; }
  .hero-deco { width: 300px; height: 300px; right: -110px; bottom: -118px; }
  .page-home { max-width: 640px; }
}
@media (min-width: 768px) and (min-height: 700px) {
  .screen-page .page-home { justify-content: center; padding-top: calc(var(--safe-t) + 40px); gap: 26px; }
  .page-home { max-width: 760px; }
  .hero { min-height: 230px; padding: 26px; }
  .hero-icon { width: 64px; height: 64px; border-radius: 19px; }
  .hero-icon .ico { width: 32px; height: 32px; }
  .hero-title { font-size: 21px; }
  .hero-sub { font-size: 15.5px; }
  .title-xl { font-size: 44px; }
  .app-mark { width: 64px; height: 64px; }
}
@media (max-width: 360px) {
  :root { --gutter: 14px; }
  .title-xl { font-size: 30px; }
  .hero { min-height: 92px; padding: 16px; gap: 12px; }
  .hero-icon { width: 48px; height: 48px; }
  .hero-title { font-size: 17px; }
  .ctl { font-size: 10.5px; }
}

/* Phones held sideways: controls move to a rail on the right so the picture keeps its height. */
@media (orientation: landscape) and (max-height: 560px) {
  .dock, .dock.dock-wrap {
    left: auto; right: calc(var(--safe-r) + 10px); bottom: auto; top: 50%; translate: 0 -50%;
    width: auto; max-height: calc(100% - 20px);
    grid-auto-flow: row; grid-template-columns: repeat(var(--rail-cols, 1), 64px); grid-auto-columns: auto;
  }
  .ctl { min-height: 50px; }
  .stage-top { padding-top: calc(var(--safe-t) + 8px); }
  .stage-banner { top: calc(var(--safe-t) + 58px); }
  .stats { right: calc(var(--safe-r) + 96px); top: calc(var(--safe-t) + 58px); }
  .rec-badge { top: calc(var(--safe-t) + 58px); }
  .stage.recording .stage-banner { top: calc(var(--safe-t) + 98px); }
  .stage.stats-open .stage-banner { top: auto; bottom: calc(var(--safe-b) + 12px); left: calc(var(--safe-l) + 12px); translate: none; max-width: calc(100% - 330px); }
  .stage.chrome-hidden .dock { transform: translateX(18px); }
  .pair-sheet { bottom: calc(var(--safe-b) + 10px); left: calc(var(--safe-l) + 10px); translate: none; width: min(420px, calc(100% - 120px - var(--safe-l) - var(--safe-r))); max-height: calc(100% - var(--safe-t) - var(--safe-b) - 70px); }
  .stage-card-wrap { padding-top: calc(var(--safe-t) + 16px); }
  body.has-stage .toast { bottom: calc(var(--safe-b) + 16px); }
}

/* Tap on the live picture hides the controls for an unobstructed view. */
.stage .stage-top, .stage .dock, .stage .stats { transition: opacity 0.25s ease, transform 0.4s var(--ease-out); }
.stage.chrome-hidden .stage-top, .stage.chrome-hidden .dock, .stage.chrome-hidden .stats { opacity: 0; pointer-events: none; }
.stage.chrome-hidden .stage-top { transform: translateY(-12px); }
.stage.chrome-hidden .dock { transform: translateY(18px); }
.stage.chrome-hidden .stage-top > * { pointer-events: none; }
.ctl.ctl-off { color: #ff9a9e; }
.ctl.ctl-on { background: rgba(255, 255, 255, 0.92); color: #111; }

/* ---------------------------------------------------------------- motion
   Only transform and opacity are animated; entrances use "backwards" fill so nothing keeps a
   transform afterwards (position: fixed children such as the zoomed QR stay correct). */
.screen-page:not([hidden]) .page > :not(.nav) { animation: rise 0.48s var(--ease-out) backwards; }
.screen-page:not([hidden]) .page-home > :nth-child(3) { animation-delay: 0.06s; }
.screen-page:not([hidden]) .page-home > :nth-child(4) { animation-delay: 0.12s; }
.screen-page:not([hidden]) .page-home > :nth-child(5) { animation-delay: 0.18s; }
.screen-page:not([hidden]) .app-footer { animation: fade 0.6s ease 0.24s backwards; }
.screen-page:not([hidden]) .app-mark { animation: logo-in 0.8s var(--ease-spring) backwards; }

.stage-top { animation: drop-in 0.45s var(--ease-out) backwards; }
.dock:not([hidden]) { animation: dock-in 0.55s var(--ease-spring) 0.05s backwards; }
.stage-banner:not([hidden]) { animation: drop-in 0.35s var(--ease-out) backwards; }
.stats:not([hidden]) { transform-origin: 100% 0; animation: pop 0.3s var(--ease-out) backwards; }
.rec-badge:not([hidden]) { transform-origin: 0 0; animation: pop 0.35s var(--ease-spring) backwards; }
.badge:not([hidden]) { animation: pop 0.35s var(--ease-spring) backwards; }
.stage-info:not([hidden]) { animation: fade 0.3s ease backwards; }
.pair-sheet:not([hidden]) { animation: rise 0.45s var(--ease-out) backwards; }
.stage-card-wrap:not([hidden]) .stage-card { animation: rise 0.55s var(--ease-out) 0.05s backwards; }
.stage-video.reveal { animation: fade 0.7s ease-out; }
.step-done .step-n { animation: pop 0.4s var(--ease-spring); }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.9); } }
@keyframes drop-in { from { opacity: 0; transform: translateY(-10px); } }
@keyframes dock-in { from { opacity: 0; transform: translateY(22px) scale(0.96); } }
@keyframes logo-in { from { opacity: 0; transform: scale(0.72) rotate(-14deg); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(56px); } }
@keyframes sheet-pop { from { opacity: 0; transform: translateY(18px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(18px) scale(0.94); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.97); } }
@keyframes ping { from { opacity: 0.6; transform: scale(1); } to { opacity: 0; transform: scale(2.8); } }
@keyframes ripple { from { opacity: 0.55; transform: scale(0.62); } to { opacity: 0; transform: scale(1.5); } }

/* Browsers without the individual translate property keep the controls centred. */
@supports not (translate: 0) {
  .dock, .stage-banner, .pair-sheet, .toast { transform: translateX(-50%); }
  @media (orientation: landscape) and (max-height: 560px) {
    .dock, .dock.dock-wrap { transform: translateY(-50%); }
    .pair-sheet, .stage.stats-open .stage-banner { transform: none; }
  }
}

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