:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --text: #1a1d1b;
  --muted: #5f6661;
  --border: #d9ddd8;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --green: #15803d;
  --green-bg: #dcfce7;
  --orange: #b45309;
  --orange-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --grey-bg: #e7e9e6;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413;
    --surface: #1b1f1d;
    --text: #eef1ee;
    --muted: #a3aaa5;
    --border: #2e3431;
    --accent: #2dd4bf;
    --accent-text: #06201d;
    --green: #4ade80;
    --green-bg: #12301f;
    --orange: #fbbf24;
    --orange-bg: #33280c;
    --red: #f87171;
    --red-bg: #3a1616;
    --grey-bg: #262b28;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2 { margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: .9rem; }

/* tabs */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 12px 0;
}
.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1; padding: 12px 4px; border: 0; background: none; color: var(--muted);
  font-size: 1rem; font-weight: 600; border-bottom: 3px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px 40px; }
.panel { display: flex; flex-direction: column; gap: 12px; }

/* form elements */
.row { display: flex; gap: 8px; align-items: flex-end; }
.grow { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
input, select {
  width: 100%; font-size: 16px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn {
  border: 0; border-radius: 10px; padding: 12px 16px; font-size: 1rem; font-weight: 600;
  background: var(--accent); color: var(--accent-text); white-space: nowrap;
}
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.buy { background: var(--green); color: #fff; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--accent); font-size: .95rem; padding: 4px; text-decoration: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }

.price-field { width: 150px; }
.stepper { display: flex; }
.stepper input { text-align: center; border-radius: 0; border-left: 0; border-right: 0; padding: 11px 4px; }
.stepper button {
  width: 42px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.2rem;
}
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }

/* camera */
.camera {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: #000;
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.aim {
  position: absolute; left: 12%; right: 12%; top: 50%; height: 2px; background: rgba(255, 60, 60, .8);
  box-shadow: 0 0 8px rgba(255, 60, 60, .8); pointer-events: none;
}
.cam-start {
  position: absolute; inset: 0; margin: auto; width: 70%; height: 56px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-size: 1.1rem; font-weight: 700;
}
.cam-status {
  position: absolute; left: 8px; bottom: 8px; right: 8px; color: #fff; font-size: .85rem;
  background: rgba(0, 0, 0, .55); padding: 4px 8px; border-radius: 8px;
}
.camera.flash { animation: flash .35s; }
@keyframes flash { from { box-shadow: inset 0 0 0 6px #22c55e; } to { box-shadow: none; } }

.name-form { display: flex; flex-direction: column; gap: 8px; }

.busy { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box, .error { background: var(--red-bg); color: var(--red); padding: 10px 12px; border-radius: 10px; }

/* result */
.result { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.verdict { padding: 14px 16px; font-size: 1.5rem; font-weight: 800; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.verdict small { font-size: .95rem; font-weight: 600; }
.v-green { background: var(--green-bg); color: var(--green); }
.v-orange { background: var(--orange-bg); color: var(--orange); }
.v-red { background: var(--red-bg); color: var(--red); }
.v-grey { background: var(--grey-bg); color: var(--muted); }
.result-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.release { display: flex; gap: 12px; }
.release img { width: 76px; height: 76px; border-radius: 6px; object-fit: cover; background: var(--grey-bg); flex: none; }
.release .t { font-weight: 700; font-size: 1.05rem; }
.release .m { color: var(--muted); font-size: .9rem; }
.figures { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.figure { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.figure b { display: block; font-size: 1.15rem; }
.figure span { color: var(--muted); font-size: .8rem; }
.basis { color: var(--muted); font-size: .85rem; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.result-actions .btn { flex: 1; }

/* stack */
.stack-head { display: flex; justify-content: space-between; align-items: center; }
.stack-list, .bought-list, .picker-list, .status-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.stack-item, .bought-item, .picker-item {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 10px;
}
.stack-item .info, .bought-item .info, .picker-item .info { flex: 1; min-width: 0; }
.stack-item .t, .bought-item .t, .picker-item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stack-item .m, .bought-item .m, .picker-item .m { color: var(--muted); font-size: .82rem; }
.stack-item input[type=checkbox] { width: 24px; height: 24px; flex: none; accent-color: var(--green); }
.stack-item.bought { opacity: .55; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.dot.v-green { background: var(--green); } .dot.v-orange { background: var(--orange); }
.dot.v-red { background: var(--red); } .dot.v-grey { background: var(--muted); }
.stack-foot { display: flex; flex-direction: column; gap: 10px; }
.stack-summary { font-size: .95rem; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.2rem; padding: 4px 6px; }
.picker-item img, .bought-item img { width: 48px; height: 48px; border-radius: 4px; object-fit: cover; background: var(--grey-bg); flex: none; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-grid div b { display: block; font-size: 1.25rem; }
.summary-grid div span { color: var(--muted); font-size: .85rem; }

.settings { display: flex; flex-direction: column; gap: 10px; }
.settings h2 { margin-top: 6px; }
.status-list { margin-bottom: 8px; font-size: .95rem; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; }
.sheet-body {
  background: var(--bg); width: 100%; max-height: 85vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 12px; text-align: center;
}

/* login */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; }
.login-box button {
  border: 0; border-radius: 10px; padding: 12px; font-size: 1rem; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.result { scroll-margin-top: 64px; }
a.btn { text-decoration: none; text-align: center; }
