:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #5d6b7a;
  --accent: #1f4e79;
  --ok: #2e9d5b;
  --ok-bg: #e5f5ec;
  --bad: #c0392b;
  --bad-bg: #fbe9e7;
  --border: #d5dce4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171d; --card: #1c232c; --text: #e6ebf0; --muted: #9aa8b6;
    --accent: #5b9bd5; --ok: #4cc27f; --ok-bg: #173325; --bad: #ef6b5b; --bad-bg: #3a1f1c;
    --border: #2f3a46;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: #1f4e79; color: #fff;
}
.bar h1 { font-size: 19px; margin: 0; }
main { flex: 1; display: flex; flex-direction: column; padding: 16px; max-width: 640px; width: 100%; margin: 0 auto; }
.screen { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.screen[hidden] { display: none; }
h2 { margin: 8px 0 0; }
.muted { color: var(--muted); margin: 0; }

button, .secondary-btn {
  font: inherit; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); padding: 14px 16px; cursor: pointer;
  text-align: center; -webkit-tap-highlight-color: transparent;
}
button:active, .secondary-btn:active { filter: brightness(.92); }
button:disabled { opacity: .5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { background: none; border: 0; color: #fff; padding: 6px 0; text-decoration: underline; font-size: 15px; }

form { display: flex; flex-direction: column; gap: 12px; }
input[type=password], input[type=text] {
  font: inherit; padding: 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--text);
}
.check { color: var(--muted); font-size: 15px; display: flex; gap: 8px; align-items: center; }

.msg { margin: 0; min-height: 1.4em; }
.msg.error { color: var(--bad); }
.msg.ok { color: var(--ok); }

input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.capture {
  flex: 1; min-height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; border: 2px dashed var(--accent); border-radius: 20px; background: var(--card);
  color: var(--accent); font-weight: 600; font-size: 19px; cursor: pointer; text-align: center; padding: 16px;
}
.capture-icon { font-size: 64px; line-height: 1; }

.crop-box { flex: 1; min-height: 300px; background: #000; border-radius: 12px; overflow: hidden; }
.crop-box img { display: block; max-width: 100%; }
.toolbar, .actions { display: flex; gap: 10px; }
.toolbar button, .actions button { flex: 1; }
.toolbar button { font-size: 22px; padding: 10px; }
.toolbar button#btn-reset { font-size: 16px; }

.verdict { border-radius: 16px; padding: 20px; font-size: 24px; font-weight: 700; text-align: center; }
.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.matches { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.matches li {
  background: var(--card); border: 1px solid var(--border); border-left: 5px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
}
.matches li.found { border-left-color: var(--ok); }
.matches li.missing { border-left-color: var(--bad); }
.m-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.m-tag { font-size: 14px; font-weight: 500; white-space: nowrap; color: var(--muted); }
.m-desc { color: var(--muted); font-size: 15px; }
.m-frag { font-size: 14px; color: var(--muted); font-family: ui-monospace, monospace; word-break: break-word; }
.thumb { max-width: 100%; max-height: 220px; object-fit: contain; align-self: center; border-radius: 8px; border: 1px solid var(--border); }

.busy {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 10;
}
.busy[hidden] { display: none; }
.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 5px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
