:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #17201d;
  --muted: #5d6a65;
  --line: #dde3df;
  --accent: #0f5c4d;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --red: #b42318;
  --red-soft: #fdecea;
  --amber: #8a5300;
  --amber-soft: #fff4dc;
  --green: #1d6b3a;
  --green-soft: #e5f4ea;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1714; --surface: #15211d; --surface-2: #1c2a25; --text: #e6ece9; --muted: #9aa9a3;
    --line: #2a3a34; --accent: #5cc4a6; --accent-ink: #062019; --accent-soft: #173a31;
    --red: #ff8a7a; --red-soft: #3a1a17; --amber: #f5c26b; --amber-soft: #352910;
    --green: #7bd49a; --green-soft: #15301f; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1714; --surface: #15211d; --surface-2: #1c2a25; --text: #e6ece9; --muted: #9aa9a3;
  --line: #2a3a34; --accent: #5cc4a6; --accent-ink: #062019; --accent-soft: #173a31;
  --red: #ff8a7a; --red-soft: #3a1a17; --amber: #f5c26b; --amber-soft: #352910;
  --green: #7bd49a; --green-soft: #15301f; --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column;
}
main, .top, .foot { width: 100%; max-width: 600px; margin: 0 auto; padding-inline: 16px; }
main { flex: 1; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; padding-block: 14px; padding-top: max(14px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 18px; }
.db-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.db-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.db-status.ok::before { background: var(--green); }
.db-status.busy::before { background: var(--amber); }
.db-status.off::before { background: var(--red); }

.intro h1 { font-size: 26px; line-height: 1.2; margin: 8px 0 6px; letter-spacing: -.01em; text-wrap: balance; }
.intro p { margin: 0 0 18px; color: var(--muted); }

.step { border: 0; margin: 0 0 14px; padding: 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.step legend { float: left; width: 100%; display: flex; align-items: center; gap: 10px; font-weight: 650; margin-bottom: 12px; padding: 0; }
.step legend + * { clear: both; }
.num { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; flex: none; }
.opt { font-weight: 400; color: var(--muted); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px;
  cursor: pointer; font-size: 15px; min-height: 40px; transition: background .15s, border-color .15s;
}
.chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .link-btn:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px;
}
.more-select { margin-top: 10px; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }

.photo-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.photo-big {
  width: 100%; border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft);
  color: var(--accent); border-radius: 12px; padding: 22px 16px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 650; font-size: 17px;
}
.photo-big svg { width: 34px; height: 34px; margin-bottom: 4px; }
.photo-big small { font-weight: 400; color: var(--muted); font-size: 13px; }
.link-btn { color: var(--accent); cursor: pointer; font-size: 15px; padding: 6px 10px; border-radius: 8px; }
.photo-filled { position: relative; }
.photo-filled img { width: 100%; max-height: 320px; object-fit: contain; border-radius: 10px; background: var(--surface-2); display: block; }
.icon-btn { position: absolute; top: 8px; right: 8px; width: 38px; height: 38px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; cursor: pointer; }
.findings { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.findings li { display: flex; gap: 8px; align-items: center; overflow-wrap: anywhere; }
.findings li.good { color: var(--green); }
.findings .mini-spin { width: 14px; height: 14px; border-width: 2px; flex: none; }

.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); resize: vertical; }

.submit-bar { position: sticky; bottom: 0; padding: 10px 0 max(14px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.hint { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-align: center; min-height: 1em; }
.primary { width: 100%; min-height: 54px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 17px; cursor: pointer; }
.primary:disabled { opacity: .55; cursor: default; }
.secondary { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-decoration: none; color: var(--text); cursor: pointer; font-size: 15px; }

.back { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--accent); padding: 8px 0; cursor: pointer; font-weight: 600; margin-bottom: 6px; }
.back svg { width: 18px; height: 18px; }

.verdict { border-radius: var(--radius); padding: 18px; margin-bottom: 16px; display: flex; gap: 14px; align-items: flex-start; }
.verdict svg { width: 30px; height: 30px; flex: none; margin-top: 2px; }
.verdict h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.25; }
.verdict p { margin: 0; }
.verdict.match { background: var(--red-soft); color: var(--red); }
.verdict.similar { background: var(--amber-soft); color: var(--amber); }
.verdict.none { background: var(--green-soft); color: var(--green); }
.verdict.unchecked { background: var(--surface-2); color: var(--text); }
.verdict p, .verdict .sub { color: var(--text); }
.verdict .sub { font-size: 14px; color: var(--muted); margin-top: 6px; }

.results { display: flex; flex-direction: column; gap: 14px; }
.results > h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 6px 0 -4px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card.is-match { outline: 2px solid var(--red); }
.gallery { display: flex; gap: 2px; overflow-x: auto; scroll-snap-type: x mandatory; background: var(--surface-2); }
.gallery figure { margin: 0; flex: 0 0 auto; width: 70%; max-width: 280px; scroll-snap-align: start; position: relative; }
.gallery figure:only-child { width: 100%; max-width: none; }
.gallery img { width: 100%; height: 200px; object-fit: contain; display: block; background: #fff; }
.gallery figcaption { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.card-body { padding: 14px 16px 16px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge { font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.serious { background: var(--red-soft); color: var(--red); }
.badge.match { background: var(--red); color: #fff; }
.title { margin: 0; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.subtitle { margin: 2px 0 8px; color: var(--muted); font-size: 14px; }
.why-match { list-style: none; padding: 0; margin: 0 0 10px; font-size: 14px; }
.why-match li { padding-left: 20px; position: relative; margin-bottom: 2px; overflow-wrap: anywhere; }
.why-match li::before { content: "↳"; position: absolute; left: 2px; color: var(--accent); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14px; margin: 0 0 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.section { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.section h4 { margin: 0 0 4px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.section p { margin: 0; }
.advice-sec .advice { font-weight: 600; }
.measures { margin: 6px 0 0; padding-left: 18px; font-size: 14px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions > * { flex: 1 1 auto; }

.empty { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.empty h3 { margin: 0 0 6px; font-size: 16px; }
.empty ul { margin: 0; padding-left: 18px; color: var(--muted); }

.fineprint { color: var(--muted); font-size: 13px; margin: 18px 0; }

.loading { text-align: center; padding-top: 18vh; color: var(--muted); }
.spinner { width: 44px; height: 44px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 16px; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.camera { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; }
.camera video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.cam-frame { position: absolute; left: 10%; right: 10%; top: 22%; bottom: 30%; border: 2px solid rgba(255,255,255,.75); border-radius: 18px; pointer-events: none; transition: border-color .2s; }
.cam-frame.found { border-color: #5cf2b0; }
.cam-hint { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 16px; right: 16px; text-align: center; color: #fff; margin: 0; text-shadow: 0 1px 3px #000; font-weight: 600; }
.cam-bar { display: flex; align-items: center; justify-content: space-around; padding: 18px 16px max(22px, env(safe-area-inset-bottom)); background: #000; }
.cam-side { width: 52px; height: 52px; border: 0; background: rgba(255,255,255,.12); color: #fff; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
span.cam-side { background: none; }
.shutter { width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.25); cursor: pointer; }
.shutter:active { background: #fff; }

.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 15px; max-width: calc(100% - 32px); }

.foot { color: var(--muted); font-size: 12px; padding-block: 8px 20px; }
.foot p { margin: 0; }
