:root {
  --bg: #0b0d10;
  --panel: #161a20;
  --line: #262c35;
  --text: #f4f5f7;
  --muted: #9aa3b0;
  --accent: #6b3ff0;
  --ok: #15803d;
  --used: #b45309;
  --bad: #b91c1c;
  --error: #3f3f46;
  --warn-bg: #facc15;
  --warn-fg: #1c1400;
  --radius: 14px;
  --tap: 56px;
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  font-size: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body.has-result { overflow: hidden; }

.test-banner {
  position: sticky; top: 0; z-index: 30;
  background: var(--warn-bg); color: var(--warn-fg);
  padding: 8px 12px; text-align: center; font-weight: 800; font-size: 0.85rem; letter-spacing: 0.02em;
}

.view { min-height: 100%; padding: 16px; max-width: 900px; margin: 0 auto; }

/* buttons */
.btn {
  display: block; width: 100%; min-height: var(--tap);
  border: 0; border-radius: var(--radius); padding: 14px 20px;
  font: inherit; font-weight: 800; font-size: 1.1rem; color: #fff; cursor: pointer;
  touch-action: manipulation;
}
.btn:focus-visible, input:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.6; }
.btn-primary { background: var(--accent); }
.btn-ghost { background: rgba(255, 255, 255, 0.16); }
.btn-solid { background: #fff; color: #111; }
.btn-danger { background: var(--bad); }

/* login */
.login { display: flex; flex-direction: column; justify-content: center; gap: 8px; max-width: 460px; }
.brand { margin: 0; font-size: 2.2rem; font-weight: 900; letter-spacing: -0.02em; }
.brand span { color: var(--accent); }
.lead { margin: 0 0 20px; color: var(--muted); }
.login-form { display: grid; gap: 12px; }
.login-form label { font-weight: 700; color: var(--muted); font-size: 0.9rem; }
.login-form input {
  min-height: var(--tap); padding: 12px 16px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--panel); color: var(--text);
  font: inherit; font-size: 1.4rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
}
.form-error { margin: 0; color: #ff8a8a; font-weight: 700; }

/* scanner */
.icon-btn {
  min-width: 48px; min-height: 48px; border: 0; border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.12); color: var(--text); font-size: 1.5rem; cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.menu { display: grid; gap: 10px; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; padding: 12px 16px 0; }
.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.7);
}
.modal-card {
  width: min(100%, 440px); display: grid; gap: 12px; padding: 20px;
  border-radius: 18px; background: var(--panel); border: 1px solid var(--line);
}
.modal-card h2 { margin: 0; font-size: 1.3rem; }
.modal-card p { margin: 0; color: var(--muted); }
.modal-card input {
  min-height: var(--tap); padding: 12px 16px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; font-size: 1.2rem; font-weight: 800;
}
.search-status { color: var(--muted); font-weight: 700; }
.search-results, .recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 45vh; overflow-y: auto; }
.search-hit {
  display: grid; gap: 2px; width: 100%; min-height: var(--tap); padding: 10px 14px; text-align: left;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--text);
  font: inherit; cursor: pointer; touch-action: manipulation;
}
.search-hit:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.search-hit strong { font-size: 1.1rem; overflow-wrap: anywhere; }
.search-hit span { color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.recent-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); font-weight: 700; }
.recent-list .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.recent-list .id { margin-left: auto; color: var(--muted); font-size: 0.85rem; letter-spacing: 0.08em; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; background: var(--error); }
.dot.ok { background: var(--ok); } .dot.used { background: var(--used); } .dot.bad { background: var(--bad); }
.modal-top { z-index: 45; }
.admit-name { color: var(--text) !important; font-size: 1.5rem; font-weight: 900; overflow-wrap: anywhere; }
.admit-detail { color: var(--text) !important; font-size: 1.1rem; font-weight: 800; }
.admit-note { font-size: 0.9rem; }
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; max-width: min(92vw, 420px); padding: 14px 20px; border-radius: var(--radius);
  background: #fff; color: #111; font-weight: 800; text-align: center; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.scan { padding: 0 0 var(--safe-bottom); display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.staff { font-weight: 900; font-size: 1.15rem; }
.mode-badge {
  padding: 3px 10px; border-radius: 999px; font-weight: 900; font-size: 0.8rem; letter-spacing: 0.05em;
  background: var(--warn-bg); color: var(--warn-fg);
}
.mode-badge.live { background: var(--ok); color: #fff; }
.stats { margin-left: auto; color: var(--muted); font-weight: 700; font-size: 0.95rem; }

.camera { position: relative; flex: 1; min-height: 60vh; background: #000; display: grid; place-items: center; overflow: hidden; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.start-camera { position: relative; z-index: 2; width: min(80%, 360px); }
.camera-error { position: relative; z-index: 2; margin: 12px 20px 0; padding: 12px 16px; border-radius: var(--radius); background: rgba(0, 0, 0, 0.75); color: #ffb4b4; font-weight: 700; text-align: center; }

.checking {
  position: fixed; inset: 0; z-index: 15; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 1.6rem; font-weight: 900; letter-spacing: 0.02em;
}

/* result card */
.result {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  display: flex; flex-direction: column; color: #fff;
}
.result.tone-ok { background: var(--ok); }
.result.tone-used { background: var(--used); }
.result.tone-bad { background: var(--bad); }
.result.tone-error { background: var(--error); }
.result .strip {
  background: var(--warn-bg); color: var(--warn-fg);
  padding: 6px 12px; text-align: center; font-weight: 900; font-size: 0.8rem; letter-spacing: 0.06em;
}
.result-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 20px 20px 8px; text-align: center; max-width: 720px; width: 100%; margin: 0 auto;
}
.result .icon { font-size: clamp(64px, 20vw, 110px); line-height: 1; font-weight: 900; }
.result .title { margin: 0; font-size: clamp(1.7rem, 7.5vw, 2.8rem); line-height: 1.1; font-weight: 900; letter-spacing: -0.01em; }
.result .badge { padding: 6px 16px; border-radius: 999px; font-weight: 900; font-size: 1.05rem; letter-spacing: 0.04em; }
.result .big { display: flex; align-items: baseline; justify-content: center; gap: 12px; }
.result .big-value { font-size: clamp(72px, 26vw, 120px); line-height: 1; font-weight: 900; font-variant-numeric: tabular-nums; }
.result .big-unit { font-size: clamp(1.4rem, 6vw, 2rem); font-weight: 800; }
.result .sub { font-size: 1.25rem; font-weight: 800; }
.result .note { font-size: 1.15rem; font-weight: 700; opacity: 0.95; }
.result .name { font-size: 1.4rem; font-weight: 800; overflow-wrap: anywhere; }
.result .short-id { font-size: 0.85rem; letter-spacing: 0.12em; opacity: 0.85; font-weight: 700; }
.result .lines { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 6px; font-size: 1.1rem; font-weight: 700; }
.result .warning {
  margin-top: 6px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn-fg); font-weight: 800;
}
.result .actions {
  display: grid; gap: 12px; padding: 12px 16px var(--safe-bottom);
  max-width: 720px; width: 100%; margin: 0 auto;
}

/* tablets: keep the camera a sensible size, put the stats next to it */
@media (min-width: 768px) {
  :root { font-size: 20px; }
  .scan { min-height: 100vh; }
  .camera { min-height: 70vh; border-radius: var(--radius); margin: 16px; }
}
