:root {
  --bg: #121418;
  --surface: #1b1f26;
  --surface-2: #242a33;
  --line: #313844;
  --text: #eef1f5;
  --muted: #98a2b0;
  --accent: #ffb41f;
  --accent-ink: #1d1400;
  --danger: #ff6464;
  --ok: #3ddc84;
  --warn: #ffb41f;
  --radius: 16px;
  --mono: ui-monospace, "Roboto Mono", "SF Mono", "DejaVu Sans Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Roboto", "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 8px 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; margin: 0; flex: 1; }
.icon-btn {
  width: 52px; height: 52px; border: 0; border-radius: 50%;
  background: transparent; display: grid; place-items: center; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; color: var(--muted);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.pill[data-state="synced"] .dot { background: var(--ok); }
.pill[data-state="syncing"] .dot { background: var(--accent); animation: pulse 1s infinite alternate; }
.pill[data-state="pending"] .dot,
.pill[data-state="offline"] .dot { background: var(--warn); }
.pill[data-state="error"] .dot,
.pill[data-state="auth"] .dot { background: var(--danger); }
@keyframes pulse { to { opacity: .3; } }

.banner {
  margin: 12px 16px 0; padding: 12px 14px; border-radius: 12px;
  background: #2b2210; color: #ffd98a; border: 1px solid #5a4314; font-size: 15px;
}

/* ---------- list ---------- */
main { padding: 12px 16px calc(120px + var(--safe-b)); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.item.nearest { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.row {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 14px 16px 12px; min-height: 88px;
}
.row:active { background: var(--surface-2); }
.row-top { display: flex; align-items: baseline; gap: 12px; }
.label { flex: 1; min-width: 0; font-size: 16px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dist { font-size: 15px; font-weight: 650; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.item:not(.nearest) .dist { color: var(--text); }
.code {
  display: block; margin-top: 2px;
  font: 700 40px/1.1 var(--mono); letter-spacing: 0.06em;
  overflow-wrap: anywhere;
}
.detail { padding: 0 16px 16px; display: grid; gap: 12px; }
.notes { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.photo { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 12px; background: #000; }
.meta { margin: 0; font-size: 13px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty-title { font-size: 20px; color: var(--text); font-weight: 650; margin: 0 0 8px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 54px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-weight: 600; text-align: center;
}
.btn:active { filter: brightness(1.2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:disabled { background: var(--surface-2); color: var(--muted); }
.btn-ghost { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn-block { width: 100%; }
.text-btn { border: 0; background: none; color: var(--accent); font-weight: 600; min-height: 48px; padding: 0 8px; }
.danger-text { color: var(--danger); }

.fab-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px 16px calc(14px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.fab {
  width: 100%; height: 72px; border: 0; border-radius: 20px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 22px; font-weight: 750;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.fab:active { transform: scale(.985); filter: brightness(1.08); }
.fab-plus { font-size: 26px; margin-right: 4px; }

/* ---------- sheet & screen dialogs ---------- */
dialog { color: var(--text); border: 0; padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.6); }

.sheet {
  width: 100%; max-width: 640px; margin: auto auto 0;
  max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
}
.sheet[open] { animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 8px 0; font-size: 20px; }
.fix { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.fix.good { color: var(--ok); }
.fix.bad { color: var(--warn); }

.field { display: grid; gap: 6px; margin: 12px 0; }
.field > span { font-size: 14px; color: var(--muted); }
.field em { font-style: normal; opacity: .7; }
input:not([type=checkbox]), textarea {
  width: 100%; min-height: 54px; padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  outline: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); }
.code-input { font: 700 32px/1.2 var(--mono); letter-spacing: 0.08em; }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; font-size: 15px; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); }

.photo-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 16px; }
.photo-pick { flex: 0 0 auto; }
.photo-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }

.screen {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0;
  background: var(--bg);
}
.screen-head {
  position: sticky; top: 0; display: flex; align-items: center; gap: 4px;
  padding: calc(8px + var(--safe-t)) 8px 8px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.screen-head h2 { margin: 0; font-size: 20px; }
.screen-body { padding: 16px; display: grid; gap: 14px; max-width: 640px; margin: 0 auto; padding-bottom: calc(24px + var(--safe-b)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.card h3 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.mode { margin: 0; font-size: 17px; }
.stats { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats div { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.stats dt { font-size: 13px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 650; }
.error-text { margin: 0; color: var(--danger); font-size: 15px; }
.muted { color: var(--muted); margin: 0; font-size: 15px; }
.small { font-size: 13px; }
.center { text-align: center; }
.paste summary { min-height: 44px; display: flex; align-items: center; color: var(--accent); font-weight: 600; cursor: pointer; }
.paste textarea { font: 14px/1.4 var(--mono); margin: 8px 0; }

/* ---------- scanner ---------- */
.scanner { width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; background: #000; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.reticle {
  position: absolute; left: 50%; top: 45%; width: min(70vw, 320px); aspect-ratio: 1;
  transform: translate(-50%, -50%); border-radius: 24px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); border: 3px solid var(--accent);
}
.scan-hint { position: absolute; left: 0; right: 0; top: calc(16px + var(--safe-t)); text-align: center; margin: 0; padding: 0 16px; text-shadow: 0 1px 4px #000; }
.scan-cancel { position: absolute; left: 16px; right: 16px; bottom: calc(20px + var(--safe-b)); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(104px + var(--safe-b)); z-index: 50;
  margin: 0 auto; max-width: 480px; padding: 14px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 600; text-align: center;
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--danger); color: #fff; }
