:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f2ece3;
  --text: #23201c;
  --muted: #6f675d;
  --line: #e2d9cb;
  --accent: #7c2d12;
  --accent-ink: #fff;
  --needed: #c53030;
  --optional: #b7791f;
  --ok: #2f855a;
  --radius: 14px;
  --tabbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --surface: #211e17;
    --surface-2: #2b271f;
    --text: #f0ece4;
    --muted: #a49a8b;
    --line: #38332a;
    --accent: #e07a5f;
    --accent-ink: #1a1610;
    --needed: #f87171;
    --optional: #fbbf24;
    --ok: #6ee7a8;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: -0.01em; }

/* ── Buttons ─────────────────────────────────────────────── */
button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 44px;
}
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 8px 10px; }
.big { width: 100%; padding: 18px; font-size: 1.05rem; }
button:disabled { opacity: .5; cursor: default; }

.state-btns { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 14px 0; }
.state-btn { text-align: left; background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.state-btn[data-current="1"] { border-color: var(--accent); border-width: 2px; font-weight: 600; }
.state-btn small { display: block; color: var(--muted); font-size: .8rem; }

/* ── Layout ──────────────────────────────────────────────── */
.pad { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; }
.row > input { flex: 1; min-width: 0; }
.hint { color: var(--muted); font-size: .87rem; margin: 0; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 12px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
label { display: block; font-size: .82rem; color: var(--muted); margin: 10px 0 4px; }

/* ── Scanner ─────────────────────────────────────────────── */
.scanner-wrap { position: relative; background: #000; aspect-ratio: 4/3; }
.scanner-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle {
  position: absolute; inset: 22% 10%;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35);
  pointer-events: none;
}
.stop { position: absolute; top: 8px; right: 8px; color: #fff; background: rgba(0,0,0,.5); border-radius: 8px; }

/* ── Lists ───────────────────────────────────────────────── */
.list { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 8px; }

.card {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
}
.card .grow { flex: 1; min-width: 0; }
.card .name { font-weight: 600; display: block; }
.card .sub { color: var(--muted); font-size: .82rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.group-title {
  margin: 20px 16px 8px;
  font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted);
}
.group-note { margin: 0 16px 8px; color: var(--muted); font-size: .85rem; }

.tag {
  display: inline-block; font-size: .7rem; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; margin-left: 6px;
  text-transform: uppercase; letter-spacing: .04em;
}
.tag.stale { background: color-mix(in srgb, var(--optional) 22%, transparent); color: var(--optional); }
.tag.unconfirmed { background: color-mix(in srgb, var(--muted) 22%, transparent); color: var(--muted); }
.tag.wanted { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }

/* ── Quantity ────────────────────────────────────────────── */
.qty-pill {
  flex: none;
  font-size: .82rem; font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 9px;
}

.qty-row {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0 4px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.qty-row .qty-label { flex: 1; color: var(--muted); font-size: .9rem; }
.qty-row .qty-btn {
  min-height: 40px; min-width: 44px;
  font-size: 1.2rem; line-height: 1; padding: 0;
}
.qty-row strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ── Tab bar ─────────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none; border: none; color: var(--muted);
  font-size: .72rem; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 8px 0; min-height: var(--tabbar-h); position: relative;
}
.tabbar button span { font-size: 1.25rem; line-height: 1; }
.tabbar button.active { color: var(--accent); }
.badge {
  position: absolute; top: 6px; left: 50%; margin-left: 6px;
  background: var(--needed); color: #fff;
  font-size: .62rem; font-style: normal; font-weight: 700;
  border-radius: 999px; padding: 1px 6px;
}

/* ── Sheet ───────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6 } to { transform: none; opacity: 1 } }
.grabber { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 14px; }
.sheet h2 { margin: 0 0 2px; font-size: 1.25rem; }
.sheet .sub { color: var(--muted); font-size: .85rem; margin: 0 0 8px; }

.thumb { width: 100%; max-height: 200px; object-fit: contain; border-radius: 10px; background: var(--surface-2); }

details { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: .88rem; }

.danger { color: var(--needed); background: none; border: none; padding: 12px 0; }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 60;
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 999px;
  font-size: .9rem; max-width: 88vw; text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg) } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
