:root {
  --basil: #1f4d3a;
  --basil-2: #2b6a50;
  --ink: #17241d;
  --muted: #5b6b62;
  --paper: #eef3ef;
  --card: #ffffff;
  --line: #d5dfd8;
  --excellent: #227547;
  --good: #6f9a2f;
  --poor: #c97a12;
  --bad: #c8382e;
  --unknown: #7a8580;
  --focus: #1a73e8;
  --radius-tag: 14px;
  --radius-ctl: 10px;
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.5 var(--body);
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--basil-2); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--basil); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
}
.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none;
  font: 700 20px/1 var(--display); letter-spacing: -0.01em;
}
.wordmark svg { width: 26px; height: 26px; }

main { max-width: 560px; margin: 0 auto; padding: 18px 16px 24px; }
.view-title {
  font: 800 clamp(28px, 7vw, 36px)/1.05 var(--display);
  letter-spacing: -0.02em; margin: 6px 0 18px;
}
.small-h { font: 700 15px/1.3 var(--body); color: var(--muted); margin: 0 0 10px; }
.hint, .fine { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 1.5px solid var(--basil); border-radius: var(--radius-ctl);
  background: var(--card); color: var(--basil);
  font: 700 16px/1 var(--body); cursor: pointer; text-decoration: none;
}
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--basil); color: #fff; min-height: 60px; font-size: 18px; }
.btn-primary:active { background: var(--basil-2); }
.btn-quiet { border-color: var(--line); color: var(--ink); }
.btn-wide { width: 100%; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .55; cursor: progress; }
input, select {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-ctl);
  background: var(--card); color: var(--ink); font: 17px var(--body);
}
input:focus, select:focus { border-color: var(--basil); }
label { display: block; font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row.gap { flex-wrap: wrap; margin-top: 18px; }
.row input { flex: 1; min-width: 0; }

.manual { margin: 22px 0 26px; }
.samples, .photo-path { margin-bottom: 26px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 4px 12px 4px 4px;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--card);
  font: 700 15px var(--body); color: var(--ink); cursor: pointer;
}
.chip img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--paper); }
.status { min-height: 1.5em; color: var(--muted); }
.status.error { color: var(--bad); font-weight: 700; }

/* Camera */
.viewfinder {
  position: relative; overflow: hidden; border-radius: var(--radius-tag);
  background: #000; aspect-ratio: 4 / 3; margin-bottom: 14px;
}
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.guide {
  position: absolute; inset: 30% 12%;
  border: 3px solid rgba(255,255,255,.9); border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.35);
}
.guide::after {
  content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px;
  background: #ff5a4f; animation: sweep 1.8s ease-in-out infinite alternate;
}
@keyframes sweep { from { transform: translateY(-28px); } to { transform: translateY(28px); } }
.on-video { position: absolute; bottom: 12px; right: 12px; min-height: 40px; }

/* The shelf tag: the one bold element */
.tag {
  position: relative; display: grid; grid-template-columns: 116px 1fr;
  background: var(--card); border-radius: var(--radius-tag);
  box-shadow: 0 1px 0 var(--line), 0 10px 24px -14px rgba(23, 36, 29, .45);
  overflow: hidden; margin-bottom: 18px;
}
.tag::before { /* punch hole */
  content: ""; position: absolute; top: 12px; left: 12px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--paper); box-shadow: inset 0 1px 2px rgba(0,0,0,.25);
}
.tag-score {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  color: #fff; padding: 22px 6px 16px;
  border-right: 3px dashed rgba(255,255,255,.65);
}
.tag-score .num { font: 800 64px/0.9 var(--display); letter-spacing: -0.04em; }
.tag-score .of { font-size: 13px; opacity: .85; margin-top: 4px; }
.tag-score .word { font: 700 16px/1 var(--display); margin-top: 8px; }
.tag[data-band="excellent"] .tag-score { background: var(--excellent); }
.tag[data-band="good"] .tag-score { background: var(--good); }
.tag[data-band="poor"] .tag-score { background: var(--poor); }
.tag[data-band="bad"] .tag-score { background: var(--bad); }
.tag[data-band="unknown"] .tag-score { background: var(--unknown); }
.tag[data-band="unknown"] .num { font-size: 40px; }
.tag-body { padding: 16px 16px 16px 18px; display: grid; grid-template-columns: 1fr 64px; gap: 4px 12px; align-items: start; }
.tag-body h2 { font: 800 22px/1.1 var(--display); letter-spacing: -0.01em; margin: 0; grid-column: 1; }
.tag-body .brand { color: var(--muted); grid-column: 1; }
.tag-body img { grid-column: 2; grid-row: 1 / span 3; width: 64px; height: 64px; object-fit: contain; border-radius: 8px; background: var(--paper); }
.tag-body .barcode { grid-column: 1 / -1; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; letter-spacing: .06em; margin-top: 6px; }
.source { display: inline-block; font-size: 13px; color: var(--muted); grid-column: 1 / -1; }

.scorecard { background: var(--card); border-radius: var(--radius-ctl); padding: 6px 16px; margin-bottom: 18px; }
.part { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.part:last-child { border-bottom: 0; }
.part .what { font-weight: 700; }
.part .pts { font-variant-numeric: tabular-nums; font-weight: 700; }
.part .bar { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--paper); overflow: hidden; }
.part .bar span { display: block; height: 100%; background: var(--basil-2); border-radius: 4px; }
.part .why { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.note { background: #fff6e5; border-left: 4px solid var(--poor); padding: 10px 14px; border-radius: 6px; margin: 0 0 18px; font-size: 15px; }

.section-h { font: 700 20px/1.2 var(--display); margin: 26px 0 10px; }
.additives { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius-ctl); }
.additives li { border-bottom: 1px solid var(--line); }
.additives li:last-child { border-bottom: 0; }
.additives details > summary, .additives .plain { display: grid; grid-template-columns: 14px 58px 1fr auto; gap: 10px; align-items: center; padding: 12px 16px; cursor: pointer; list-style: none; }
.additives summary::-webkit-details-marker { display: none; }
.additives .dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.high { background: var(--bad); } .dot.moderate { background: var(--poor); }
.dot.limited { background: #d8c13b; } .dot.none { background: var(--excellent); } .dot.unrated { background: var(--unknown); }
.additives .code { font-weight: 700; font-variant-numeric: tabular-nums; }
.additives .risk { font-size: 14px; color: var(--muted); }
.additives p { margin: 0; padding: 0 16px 14px 98px; font-size: 15px; color: var(--muted); }
.empty { color: var(--muted); padding: 12px 16px; margin: 0; }

.actions { display: grid; gap: 10px; margin-top: 22px; }
.price-row { display: flex; gap: 8px; align-items: center; }
.price-row .prefix { font-weight: 700; color: var(--muted); }
.ai-box { background: var(--card); border-radius: var(--radius-ctl); padding: 14px 16px; margin-top: 10px; }
.ai-box p { margin: 0 0 8px; }
.ai-box ul { margin: 0; padding-left: 20px; }

.alts { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.alt { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; background: var(--card); border-radius: var(--radius-ctl); padding: 10px 12px; }
.mini { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 10px; color: #fff; font: 800 22px/1 var(--display); }
.mini[data-band="excellent"] { background: var(--excellent); } .mini[data-band="good"] { background: var(--good); }
.mini[data-band="poor"] { background: var(--poor); } .mini[data-band="bad"] { background: var(--bad); }
.mini[data-band="unknown"] { background: var(--unknown); font-size: 15px; }
.alt b { display: block; line-height: 1.25; }
.alt span { color: var(--muted); font-size: 14px; }

/* History */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius-ctl); padding: 14px 16px; }
.stat b { display: block; font: 800 28px/1.1 var(--display); }
.stat span { color: var(--muted); font-size: 14px; }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history button { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; background: var(--card); border-radius: var(--radius-ctl); padding: 10px 12px; cursor: pointer; }
.history button:focus-visible { outline: 3px solid var(--focus); }
.history .when { color: var(--muted); font-size: 13px; }
.history .price { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Settings */
.panel { background: var(--card); border-radius: var(--radius-ctl); padding: 16px; margin-bottom: 14px; }
.panel h2 { font: 700 19px/1.2 var(--display); margin: 0 0 8px; }
.panel p { margin: 0 0 12px; }

/* Tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 10px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 700; }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--basil); }

.reveal { animation: reveal .35s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .reveal, .guide::after { animation: none; }
}
@media (min-width: 700px) {
  body { padding-bottom: 0; }
  .tabs { position: sticky; top: 52px; max-width: 560px; margin: 0 auto; border: 0; background: transparent; grid-template-columns: repeat(3, max-content); gap: 6px; padding: 12px 16px 0; }
  .tabs a { flex-direction: row; gap: 8px; padding: 8px 14px; border-radius: 999px; }
  .tabs a[aria-current="page"] { background: var(--card); }
  .tabs svg { width: 20px; height: 20px; }
}
