/* ────────────────────────────────────────────────────────────
   QR — локальный сканер и генератор
   Палитра: холодная бумага + чернила + ультрамарин
   Шрифты: только системные (serif-дисплей / sans-текст / mono-данные)
   ──────────────────────────────────────────────────────────── */

:root {
  --paper:   #e9eaee;
  --surface: #ffffff;
  --ink:     #14161c;
  --muted:   #646c7b;
  --line:    #d2d6de;
  --accent:  #2438c8;
  --accent-soft: #e5e7fb;
  --signal:  #9a5b00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,22,28,.06), 0 8px 24px -16px rgba(20,22,28,.35);

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:   #12141a;
    --surface: #1a1d25;
    --ink:     #e8eaef;
    --muted:   #949bab;
    --line:    #2b2f3a;
    --accent:  #8b9bff;
    --accent-soft: #21263c;
    --signal:  #e0a750;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -18px rgba(0,0,0,.9);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  max-width: 620px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ── Шапка ─────────────────────────────────────────────── */

.masthead {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.mark {
  flex: none;
  width: 38px; height: 38px;
  display: grid;
  grid-template: 1fr 1fr / 1fr 1fr;
  gap: 4px;
}
.mark-eye {
  border: 3px solid var(--ink);
  border-radius: 4px;
}
.mark-dots {
  background:
    radial-gradient(circle at 25% 25%, var(--accent) 32%, transparent 33%),
    radial-gradient(circle at 75% 75%, var(--accent) 32%, transparent 33%);
  background-size: 100% 100%;
  opacity: .9;
}
.mark-eye:nth-child(4) { border-color: var(--accent); }

.masthead-text { flex: 1; min-width: 0; }

h1 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: .06em;
  margin: 0;
  line-height: 1.1;
}

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

/* ── Вкладки ───────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  padding: 9px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14.5px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ── Кнопки и поля ─────────────────────────────────────── */

button, select, textarea, input { font: inherit; }

.primary, .ghost {
  padding: 11px 18px;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 15px;
  transition: transform .08s, background .15s, border-color .15s;
}
.primary { background: var(--accent); color: #fff; font-weight: 600; }
.ghost   { background: var(--surface); color: var(--ink); border-color: var(--line); }
.primary:active, .ghost:active { transform: translateY(1px); }
.ghost[aria-pressed="true"] { border-color: var(--signal); color: var(--signal); }

select.ghost { padding: 10px 12px; max-width: 45%; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.row > .primary { flex: 1; }

.field { display: block; margin-bottom: 14px; }
.field.inline { flex: 1; margin-bottom: 0; min-width: 160px; }
.field-label {
  display: block;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
textarea, .field select {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  resize: vertical;
}
textarea { font-family: var(--font-mono); font-size: 14px; }

/* ── Видоискатель ──────────────────────────────────────── */

.viewfinder {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0b0d12;
  margin-bottom: 14px;
}
#video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .35s;
}
.viewfinder[data-state="live"] #video { opacity: 1; }

/* Углы — это глаза QR-кода, а не просто рамка */
.frame { position: absolute; inset: 11%; pointer-events: none; }
.frame i {
  position: absolute;
  width: 30px; height: 30px;
  border: 3px solid rgba(255,255,255,.9);
}
.frame i:nth-child(1) { top: 0; left: 0;  border-right: 0; border-bottom: 0; border-radius: 6px 0 0 0; }
.frame i:nth-child(2) { top: 0; right: 0; border-left: 0;  border-bottom: 0; border-radius: 0 6px 0 0; }
.frame i:nth-child(3) { bottom: 0; left: 0;  border-right: 0; border-top: 0; border-radius: 0 0 0 6px; }
.frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0;  border-top: 0; border-radius: 0 0 6px 0; }

.sweep {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
}
.viewfinder[data-state="live"] .sweep {
  opacity: .95;
  animation: sweep 2.6s ease-in-out infinite;
}
@keyframes sweep { 0%,100% { top: 0; } 50% { top: 100%; } }

.viewfinder-hint {
  position: absolute;
  left: 0; right: 0; bottom: 14px;
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: rgba(255,255,255,.72);
}
.viewfinder[data-state="idle"] .frame i { border-color: rgba(255,255,255,.25); }
.viewfinder[data-state="hit"] .frame i { border-color: #4ade80; }

/* ── Загрузка файла ────────────────────────────────────── */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 38px 18px;
  text-align: center;
  background: var(--surface);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-title { font-weight: 600; }
.dropzone-sub { font-size: 13px; color: var(--muted); }

.preview { margin-top: 14px; }
.preview img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

/* ── Результаты ────────────────────────────────────────── */

.result-slot:not(:empty) { margin-top: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  animation: rise .2s ease-out;
}
.card + .card { margin-top: 10px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card-label {
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}

.payload {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.55;
  margin: 0 0 12px;
  word-break: break-word;
  white-space: pre-wrap;
}
.payload a { color: var(--accent); text-underline-offset: 3px; }

.card .row { gap: 8px; }
.card .ghost { padding: 8px 14px; font-size: 14px; }

.qr-out {
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 0 auto 14px;
  image-rendering: pixelated;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.note {
  padding: 13px 15px;
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--accent-soft);
  color: var(--ink);
  border: 1px solid var(--line);
}
.note.bad { border-color: color-mix(in srgb, var(--signal) 45%, var(--line)); background: transparent; }

/* ── Подвал ────────────────────────────────────────────── */

footer {
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
footer p { margin: 0; }
.dot {
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #3fbf63;
  vertical-align: middle;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── Служебное ─────────────────────────────────────────── */

.linkish { text-decoration: none; display: inline-block; }

.host-note {
  margin: -4px 0 12px;
  font-size: 12.5px;
  color: var(--muted);
}

.offscreen {
  position: fixed;
  top: -1000px;
  left: 0;
  opacity: 0;
  pointer-events: none;
}
