:root {
  --bg: #0a0a0c;
  --bg2: #101013;
  --card: #141418;
  --line: #232328;
  --red: #e10600;
  --red-soft: #ff6b62;
  --text: #f2f2f2;
  --muted: #9a9aa3;
  --green: #22c55e;
  --amber: #eab308;
  --r-lg: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
.eyebrow {
  margin: 0; font-size: 11px; letter-spacing: .22em;
  color: var(--red-soft); font-weight: 800;
}

/* ---- header ---- */
.app-header {
  display: flex; align-items: center; gap: 14px;
  padding: 22px 20px 6px;
  max-width: 560px; margin: 0 auto;
}
.brand-mark { width: 52px; height: 52px; border-radius: 14px; }
.app-header h1 { margin: 2px 0 0; font-size: 26px; font-weight: 800; letter-spacing: .01em; }

main { max-width: 560px; margin: 0 auto; padding: 10px 20px 40px; }

/* ---- hero ---- */
.hero-sub { color: var(--muted); font-size: 15px; line-height: 1.55; margin: 14px 0 18px; }
.btn-scan {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; min-height: 60px;
  background: linear-gradient(135deg, #f11, #b00500);
  border: none; border-radius: 16px;
  color: #fff; font-size: 18px; font-weight: 800; letter-spacing: .02em;
  cursor: pointer; box-shadow: 0 6px 24px rgba(225,6,0,.35);
}
.btn-scan:active { transform: scale(.98); }
.btn-scan svg { width: 26px; height: 26px; }
.manual-row { display: flex; gap: 8px; margin-top: 12px; }
.manual-row input {
  flex: 1; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 12px; padding: 13px 14px; color: #fff; font-size: 16px;
}
.manual-row input:focus { outline: none; border-color: var(--red); }
#btn-manual-go {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font-weight: 700; font-size: 15px; padding: 0 20px; cursor: pointer;
}
#btn-manual-go:active { transform: scale(.97); }
.net-note { color: var(--amber); font-size: 13px; margin-top: 12px; }

/* ---- nudge banner ---- */
.nudge {
  background: linear-gradient(135deg, rgba(225,6,0,.18), rgba(225,6,0,.05));
  border: 1px solid rgba(225,6,0,.5); border-radius: 16px;
  padding: 16px; margin: 22px 0 0;
}
.nudge p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--text); }
.nudge-actions { display: flex; gap: 10px; align-items: center; }
.btn-red-sm {
  background: var(--red); color: #fff; text-decoration: none;
  font-weight: 800; font-size: 14px; border-radius: 12px; padding: 10px 18px;
}
#nudge-dismiss {
  background: none; border: none; color: var(--muted);
  font-size: 14px; cursor: pointer; padding: 10px;
}

/* ---- history ---- */
.history { margin-top: 28px; }
.history h2 { font-size: 17px; font-weight: 800; margin: 0 0 12px; }
.hist-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 24px 10px; }
.hist-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
  width: 100%; text-align: left; color: var(--text); cursor: pointer;
}
.hist-item:active { transform: scale(.99); }
.hist-grade {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 900; color: #fff;
}
.hist-grade.gA { background: #22c55e; } .hist-grade.gB { background: #84cc16; }
.hist-grade.gC { background: #eab308; } .hist-grade.gD { background: #f97316; }
.hist-grade.gE { background: #e10600; } .hist-grade.gX { background: #444; }
.hist-item .hist-info { flex: 1; min-width: 0; }
.hist-item .hist-info b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-item .hist-info small { color: var(--muted); font-size: 12px; }
.hist-clear {
  display: block; margin: 8px auto 0; background: none; border: none;
  color: var(--muted); font-size: 13px; cursor: pointer; padding: 8px;
}

/* ---- modals ---- */
.scan-modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.scan-modal[hidden] { display: none; }
.scan-box {
  position: relative; width: min(480px, 100%); max-height: 92vh; overflow-y: auto;
  background: #101013; border: 1px solid var(--line); border-radius: 18px;
  padding: 22px 18px 18px;
}
.scan-close {
  position: absolute; top: 8px; right: 12px; z-index: 2;
  background: none; border: none; color: var(--muted);
  font-size: 30px; line-height: 1; cursor: pointer; padding: 6px;
}
.scan-close:active { color: #fff; }

/* ---- viewfinder ---- */
.scan-viewfinder { position: relative; border-radius: 14px; overflow: hidden; background: #000; }
.scan-viewfinder video { width: 100%; display: block; aspect-ratio: 4/3; object-fit: cover; background: #000; }
.scan-frame { position: absolute; inset: 0; pointer-events: none; }
.scan-frame .corner { position: absolute; width: 28px; height: 28px; border: 3px solid var(--red); }
.scan-frame .tl { top: 18%; left: 12%; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.scan-frame .tr { top: 18%; right: 12%; border-left: none; border-bottom: none; border-radius: 0 8px 0 0; }
.scan-frame .bl { bottom: 18%; left: 12%; border-right: none; border-top: none; border-radius: 0 0 0 8px; }
.scan-frame .br { bottom: 18%; right: 12%; border-left: none; border-top: none; border-radius: 0 0 8px 0; }
.scan-line {
  position: absolute; left: 12%; right: 12%; top: 18%; height: 2px;
  background: var(--red); box-shadow: 0 0 12px var(--red);
  animation: scanSweep 2.2s ease-in-out infinite;
}
@keyframes scanSweep { 0%, 100% { top: 18%; } 50% { top: calc(82% - 2px); } }
.scan-status {
  position: absolute; bottom: 0; left: 0; right: 0;
  margin: 0; padding: 12px 10px; text-align: center;
  font-size: 13px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.78));
}

/* ---- result card ---- */
.scan-product-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.scan-product-head img {
  width: 76px; height: 76px; object-fit: contain;
  background: #fff; border-radius: 12px; flex-shrink: 0;
}
.scan-product-head h3 { margin: 0; font-size: 17px; line-height: 1.25; }
.scan-product-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.scan-grade-row { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.scan-grade {
  width: 64px; height: 64px; border-radius: 16px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 900; color: #fff;
}
.scan-grade.gA { background: #22c55e; } .scan-grade.gB { background: #84cc16; }
.scan-grade.gC { background: #eab308; } .scan-grade.gD { background: #f97316; }
.scan-grade.gE { background: #e10600; } .scan-grade.gX { background: #444; }
.scan-grade-label { font-size: 13px; color: var(--muted); }
.scan-grade-label b { color: #fff; display: block; font-size: 14px; }
.scan-nutri-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.scan-nutri { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 6px; text-align: center; }
.scan-nutri b { display: block; font-size: 15px; }
.scan-nutri small { color: var(--muted); font-size: 10px; letter-spacing: .06em; }
.scan-nova {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 13px;
}
.scan-nova .nova-dots { display: flex; gap: 4px; }
.scan-nova .nova-dots i { width: 10px; height: 10px; border-radius: 50%; background: #333; }
.scan-nova .nova-dots i.on { background: var(--red); }
.scan-flags { margin-bottom: 12px; }
.scan-flag {
  display: inline-block; font-size: 12px; font-weight: 700;
  background: rgba(225,6,0,.14); color: #ff8a80;
  border: 1px solid rgba(225,6,0,.4); border-radius: 20px;
  padding: 5px 12px; margin: 0 6px 6px 0;
}
.scan-flag.good { background: rgba(34,197,94,.12); color: #7ee2a8; border-color: rgba(34,197,94,.4); }
.scan-verdict {
  border-left: 3px solid var(--red); padding: 10px 14px; margin-bottom: 16px;
  background: rgba(225,6,0,.06); border-radius: 0 10px 10px 0;
}
.scan-verdict .eyebrow { margin-bottom: 4px; }
.scan-verdict p { margin: 0; font-size: 15px; font-weight: 600; }
.scan-actions { display: flex; flex-direction: column; gap: 8px; }
.btn-red-block {
  width: 100%; min-height: 52px; border: none; border-radius: 14px;
  background: var(--red); color: #fff; font-size: 16px; font-weight: 800; cursor: pointer;
}
.btn-red-block:active { transform: scale(.98); }
.link-btn {
  background: none; border: none; color: var(--muted);
  font-size: 14px; cursor: pointer; padding: 10px;
}
.link-btn:active { color: #fff; }
.scan-error { text-align: center; padding: 20px 10px; }
.scan-error p { color: var(--muted); margin: 10px 0 16px; font-size: 14px; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto;
  border: 3px solid var(--line); border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- footer ---- */
.app-footer { text-align: center; margin-top: 36px; }
.app-footer p { color: var(--muted); font-size: 12px; }
