@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/SpaceGrotesk-500.woff2") format("woff2");
}

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/SpaceGrotesk-700.woff2") format("woff2");
}

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/Manrope-400.woff2") format("woff2");
}

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/Manrope-600.woff2") format("woff2");
}

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("fonts/Manrope-800.woff2") format("woff2");
}

:root {
  /* Brand colours derived from icons/buzzdar.svg: bronze #7f6240, black #140c02 */
  --bronze: #7f6240;
  --bronze-bright: #a58a63;
  --bronze-dark: #5f4527;
  --ink: #140c02;
  --paper: #faf7f2;
  --muted: #6e6152;
  --line: #e6dccd;
  --card: #ffffff;
  --error: #c4453b;
  --radius: 16px;
  color-scheme: light dark;
  --font-display: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bronze: #8f7048;
    --bronze-bright: #bb9c72;
    --bronze-dark: #b99a6d; /* "dark" slot is link text — needs the lighter value on dark bg */
    --ink: #f2ead9;
    --paper: #140c02;
    --muted: #a3937d;
    --line: #372a19;
    --card: #221808;
  }
}

* { box-sizing: border-box; }

/* display rules below (.view, .btn, .stat…) must not defeat the hidden attribute */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  text-align: center;
  padding: 24px 0 8px;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.85rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.topbar .logo {
  height: 1.1em;
  width: auto;
  color: var(--bronze);
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 0 32px;
}

.camera-frame {
  position: relative;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reticle {
  position: absolute;
  inset: 20% 8%;
  border: 3px solid rgba(187, 156, 114, 0.85);
  border-radius: 12px;
  pointer-events: none;
}

.torch-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  font-size: 1.2rem;
  cursor: pointer;
}

.torch-btn.torch-on {
  background: var(--bronze);
}

.camera-hint {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  margin: 0;
  color: #fff;
  font-size: 0.85rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  pointer-events: none;
}

.actions {
  display: flex;
  gap: 12px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--bronze);
  color: #ffffff;
}

.btn-primary:active { background: var(--bronze-dark); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.back-btn {
  flex: none;
  align-self: flex-start;
  padding: 10px 16px;
}

.manual-entry {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.manual-entry summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

#manual-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

#manual-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1rem;
}

#manual-form .btn {
  flex: none;
}

.recent {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.recent-clear {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.recent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error {
  color: var(--error);
  font-size: 0.9rem;
  text-align: center;
}

.label-scan-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 12px 0;
}

.label-scan-btn {
  width: 100%;
}

.ocr-bar {
  width: 70%;
  max-width: 260px;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.ocr-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: var(--bronze);
  transition: width 0.2s ease;
}

.state-detail {
  font-size: 0.85rem;
  margin: 0;
}

.result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 200px;
}

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 24px 0;
  color: var(--muted);
}

.state-title {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
  font-size: 1.1rem;
  margin: 0;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--bronze);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.barcode-value {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.product-image {
  display: block;
  max-width: 140px;
  max-height: 140px;
  margin: 0 auto 12px;
  border-radius: 12px;
  object-fit: contain;
}

.product-name {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}

.product-brand {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-warn {
  border-color: var(--bronze);
}

.stat-conflict-text {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--ink);
}

.stat-footnote {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  margin: 0 0 12px;
}

.no-data a {
  color: var(--bronze-dark);
}

.no-data {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.data-sources {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  margin: 12px 0 0;
}

.off-link {
  display: block;
  text-align: center;
  margin-top: 8px;
  color: var(--bronze-dark);
  font-size: 0.85rem;
}

.fix-link {
  display: block;
  text-align: center;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.install-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  max-width: 448px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.install-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex: none;
}

.install-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.install-text strong {
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.install-text span {
  color: var(--muted);
  font-size: 0.8rem;
}

.install-btn {
  flex: none;
  padding: 10px 18px;
  font-size: 0.9rem;
}

.install-dismiss {
  flex: none;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  align-self: flex-start;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 12px 0 24px;
}

.footer a { color: inherit; }

.version {
  margin-top: 4px;
  opacity: 0.7;
}
