/* FOUC guard — body is hidden until i18n paints the first translation pass */
body { visibility: hidden; }
body.i18n-ready { visibility: visible; }

:root {
  --bg: #f6f7f3;
  --bg-2: #eef3ea;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --ink-2: #555;
  --ink-3: #888;
  --line: #e5e7de;
  --line-2: #d6dacd;

  --brand: #2e7d32;
  --brand-dark: #1b5e20;
  --brand-light: #66bb6a;
  --accent: #fdd835;

  --ns-a: #2e7d32;
  --ns-b: #66bb6a;
  --ns-c: #fdd835;
  --ns-d: #fb8c00;
  --ns-e: #c62828;

  --sev-low: #fbc02d;
  --sev-medium: #f57c00;
  --sev-high: #c62828;

  --danger: #c62828;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20, 40, 20, 0.05), 0 2px 6px rgba(20, 40, 20, 0.04);
  --shadow-md: 0 2px 4px rgba(20, 40, 20, 0.06), 0 8px 24px rgba(20, 40, 20, 0.08);
  --shadow-brand: 0 6px 20px rgba(46, 125, 50, 0.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 500px at 50% -200px, rgba(46,125,50,0.10), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0 0 12px; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: 26px; font-weight: 700; }
h3 { font-size: 20px; font-weight: 600; }
h4 { font-size: 18px; font-weight: 600; }
p { margin: 0 0 12px; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-3); font-size: 14px; }

/* Topbar */
.topbar {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  max-width: 720px;
  margin: 0 auto;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-brand);
}
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.brand-name {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.brand-tag {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 600;
}

.topbar-nav { display: flex; align-items: center; gap: 2px; }

/* Language selector — flag bubble (header RIGHT) + dropdown.
   Sacred-Verse style; vanilla CSS instead of Tailwind. */
.lang-selector {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  margin-left: 4px;
}
.lang-bubble {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(46, 125, 50, 0.35);
  background-color: #eef3ea;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.lang-bubble:hover { border-color: var(--brand); }
.lang-bubble:active { transform: scale(0.94); }
.lang-bubble:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.35);
}
.lang-backdrop {
  position: fixed;
  inset: 0;
  background: transparent;
  display: none;
  z-index: 40;
}
.lang-backdrop.is-open { display: block; }
.lang-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: auto;
  width: 220px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 50;
  padding: 6px;
  display: none;
  scrollbar-width: thin;
}
.lang-dropdown.is-open { display: block; }
.lang-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  text-align: left;
}
.lang-dropdown-item:hover { background: rgba(46, 125, 50, 0.08); }
.lang-dropdown-item.is-active { background: rgba(46, 125, 50, 0.12); font-weight: 600; }
.lang-dropdown-flag {
  flex: 0 0 auto;
  width: 28px;
  height: auto;
  border-radius: 3px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.lang-dropdown-name { flex: 1 1 auto; min-width: 0; }

/* Translation overlay (shown while /api/translate is in flight) */
.translation-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 20, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.translation-overlay.is-visible { display: flex; }
.translation-overlay-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 28px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
  max-width: 320px;
}
.translation-overlay-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(46, 125, 50, 0.2);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: foolab-spin 0.9s linear infinite;
}
.translation-overlay-text { font-size: 15px; color: var(--ink); }
@keyframes foolab-spin { to { transform: rotate(360deg); } }

/* RTL: dropdown swaps to left edge when whole UI is RTL */
html[dir="rtl"] .lang-dropdown { right: auto; left: 0; }

/* Catalog translation queue badge — shown while the server-side tier-1
   cache is being populated for the active language. Hides on drain.
   See docs/i18n-instruct.md §11.4. Pill-shaped, sits above the toast
   area so the two can coexist briefly without fighting. */
.translate-badge {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  border-radius: 999px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  z-index: 90;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.translate-badge.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.translate-badge::before {
  content: '';
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(46, 125, 50, 0.2);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: foolab-spin 0.9s linear infinite;
}
html[dir="rtl"] .translate-badge { left: auto; right: 16px; }

/* Render-then-swap fade for catalog cards / detail when a translation
   arrives. Subtle so it doesn't feel like a re-paint. */
@keyframes foolab-translate-fade-in {
  from { opacity: 0.55; }
  to   { opacity: 1; }
}
.translation-just-arrived {
  animation: foolab-translate-fade-in 0.3s ease-out;
}

/* Phone-width: keep the topbar single-line. The brand "tag" line wraps the
   header to two rows on narrow screens once the flag bubble is added —
   hide it below 380px so the icons stay aligned. */
@media (max-width: 380px) {
  .brand-tag { display: none; }
  .topbar-nav { gap: 0; }
  .icon-btn { width: 36px; height: 36px; }
  .topbar-inner { gap: 6px; padding: 8px 12px; }
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  color: var(--ink-2);
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease, transform 0.06s ease;
}
.icon-btn:hover { background: rgba(46,125,50,0.08); color: var(--brand-dark); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn .count {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.9);
}
.icon-btn .count:empty,
.icon-btn .count[data-zero="true"] { display: none; }

/* Layout */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}
.screen { display: block; }
.screen[hidden] { display: none !important; }

.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.screen-header h2 { margin: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  min-height: 48px;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-icon { flex: 0 0 auto; }

.btn-primary {
  background: linear-gradient(180deg, var(--brand-light) 0%, var(--brand) 60%, var(--brand-dark) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover { filter: brightness(1.03); }
.btn-secondary {
  background: var(--surface);
  border-color: var(--line-2);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { border-color: var(--brand-light); color: var(--brand-dark); }
.btn-ghost {
  background: transparent;
  padding-left: 8px;
  padding-right: 8px;
  color: var(--ink-2);
}
.btn-ghost:hover { color: var(--ink); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-hero {
  font-size: 18px;
  padding: 18px 24px;
  width: 100%;
  border-radius: 16px;
}

/* Scan screen */
.hero-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px 20px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
  margin-bottom: 18px;
  overflow: hidden;
}
.hero-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% -40%, rgba(102,187,106,0.18), transparent 60%);
  pointer-events: none;
}
.hero-card > * { position: relative; }
.hero-badge {
  display: inline-flex;
  margin-bottom: 12px;
  border-radius: 18px;
  box-shadow: var(--shadow-brand);
}
.hero-badge svg { border-radius: 18px; display: block; }
.hero-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.015em;
  margin: 4px 0 6px;
}
.hero-sub {
  color: var(--ink-2);
  font-size: 15px;
  max-width: 420px;
  margin: 0 auto 18px;
}
.hero-card .btn-secondary { width: 100%; margin-top: 10px; }

.feature-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 18px;
}
@media (min-width: 520px) {
  .feature-row { grid-template-columns: repeat(3, 1fr); }
}
.feature {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
}
.feature-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  font-size: 18px;
}
.feature-icon.flag { background: linear-gradient(135deg, #f57c00, #c62828); }
.feature-icon.lock { background: linear-gradient(135deg, #455a64, #263238); }
.feature-title { font-size: 14px; font-weight: 700; }
.feature-sub { font-size: 12px; color: var(--ink-3); }

.tips-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.tips-card h2 {
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--brand-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
}
.tips-card ul { margin: 0; padding-left: 20px; font-size: 15px; color: var(--ink-2); }
.tips-card li { margin-bottom: 6px; }

/* Crop screen */
.crop-stage {
  background: #0a0a0a;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  aspect-ratio: 3 / 4;
  max-height: 70vh;
  touch-action: none;
  box-shadow: var(--shadow-md);
}
#cropCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.crop-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: space-between;
}
.crop-actions .btn-primary { margin-left: auto; }
.photo-meta { text-align: center; color: var(--ink-2); font-size: 14px; margin: 12px 0 8px; }
.photo-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0;
}
.photo-strip img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}
.photo-strip img.active { border-color: var(--brand); }

/* Analyzing */
.analyzing-box {
  text-align: center;
  padding: 72px 20px;
}
.scan-animation {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
}
.scan-ring {
  position: absolute;
  inset: 0;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-right-color: var(--brand-light);
  border-radius: 50%;
  animation: spin 1.1s linear infinite;
}
.scan-beam {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 14px rgba(253,216,53,0.7);
  border-radius: 2px;
  transform: translateY(-50%);
  animation: beam 1.6s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes beam {
  0%, 100% { top: 20%; opacity: 0.3; }
  50% { top: 80%; opacity: 1; }
}
.analyzing-tip { font-size: 17px; color: var(--ink-2); font-weight: 500; }

/* Scorecard */
.scorecard {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  padding: 20px;
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
  overflow: hidden;
}
.ns-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 120px;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  border-radius: var(--radius);
  padding: 24px 0;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: relative;
}
.ns-letter::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.15), transparent 50%);
  pointer-events: none;
}
.ns-letter.ns-A { background: linear-gradient(135deg, #388e3c, #1b5e20); }
.ns-letter.ns-B { background: linear-gradient(135deg, #7cb342, #558b2f); }
.ns-letter.ns-C { background: linear-gradient(135deg, #ffeb3b, #fbc02d); color: var(--ink); text-shadow: none; }
.ns-letter.ns-D { background: linear-gradient(135deg, #ffa726, #e65100); }
.ns-letter.ns-E { background: linear-gradient(135deg, #ef5350, #b71c1c); }

.product-head { margin-bottom: 14px; }
.product-head h2 { font-size: 24px; margin-bottom: 4px; }
.product-brand { color: var(--ink-2); font-size: 15px; }
.product-summary {
  font-size: 16px;
  color: var(--ink);
  margin-top: 8px;
}

.score-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  margin: 14px 0;
  font-size: 15px;
}
.score-line .big { font-size: 22px; font-weight: 800; color: var(--brand-dark); }

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-3);
  margin: 18px 0 8px;
  font-weight: 700;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--ink);
}
.chip-low { background: var(--sev-low); color: var(--ink); }
.chip-medium { background: var(--sev-medium); }
.chip-high { background: var(--sev-high); }
.chip-detail { font-weight: 400; opacity: 0.95; }

.enumbers { list-style: none; padding: 0; margin: 0; }
.enumbers li {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.enumbers li:last-child { border-bottom: 0; }
.enumber-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 600;
}
.enumber-note { font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.enumber-concern {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
}
.enumber-concern.low { background: var(--sev-low); color: var(--ink); }
.enumber-concern.medium { background: var(--sev-medium); }
.enumber-concern.high { background: var(--sev-high); }

.enumber-panel { margin-top: 6px; }
.enumber-panel[hidden] { display: none; }

.enumber-detail {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  border: 1px solid var(--line);
}
.enumber-detail-row { margin-bottom: 8px; }
.enumber-detail-row:last-child { margin-bottom: 0; }
.enumber-detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-3);
  font-weight: 700;
  margin-bottom: 2px;
}
.enumber-detail-text {
  font-size: 14px;
  color: var(--ink);
  margin: 0;
  line-height: 1.5;
}

/* Additive traffic light — additive load, separate from NutriScore nutrition grade */
.additive-rating {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  margin: 14px 0;
}
.additive-rating .additive-dot {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-top: 4px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.04);
}
.additive-rating.rating-green .additive-dot { background: #2e7d32; }
.additive-rating.rating-yellow .additive-dot { background: #fdd835; }
.additive-rating.rating-red .additive-dot { background: #c62828; }
.additive-rating.rating-green { background: rgba(46,125,50,0.08); border-color: rgba(46,125,50,0.25); }
.additive-rating.rating-yellow { background: rgba(253,216,53,0.14); border-color: rgba(251,192,45,0.4); }
.additive-rating.rating-red { background: rgba(198,40,40,0.08); border-color: rgba(198,40,40,0.25); }
.additive-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.additive-detail { font-size: 13px; color: var(--ink-2); line-height: 1.4; }

/* Condition-specific warning chips */
.condition-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.condition-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
}
.condition-chip.sev-low {
  border-color: rgba(251,192,45,0.55);
  background: rgba(253,216,53,0.14);
}
.condition-chip.sev-medium {
  border-color: rgba(245,124,0,0.45);
  background: rgba(245,124,0,0.10);
  color: #b35300;
}
.condition-chip.sev-high {
  border-color: rgba(198,40,40,0.45);
  background: rgba(198,40,40,0.08);
  color: #9a1c1c;
}
.condition-details { margin-top: 8px; }
.condition-line {
  font-size: 13px;
  color: var(--ink-2);
  margin: 3px 0;
  line-height: 1.45;
}

.ingredients-list {
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-2);
  word-break: break-word;
}

.nutrition-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
.nutrition-table td {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.nutrition-table td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.confidence-badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--ink-2);
  margin-top: 8px;
  font-weight: 700;
  border: 1px solid var(--line);
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.result-actions .btn { width: 100%; padding: 12px 10px; font-size: 15px; }

/* Archive */
.archive-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 520px) {
  .archive-grid { grid-template-columns: repeat(3, 1fr); }
}
.archive-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.archive-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.archive-card-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--line) center/cover no-repeat;
  position: relative;
}
.archive-card-letter {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.archive-card-body { padding: 8px 10px 10px; }
.archive-card-name {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.archive-card-meta {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
}

.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--ink-2);
}
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--bg-2);
  color: var(--brand);
  margin: 0 auto 16px;
}

/* About */
.about-body p { font-size: 16px; margin-bottom: 14px; color: var(--ink-2); }
.about-body strong { color: var(--ink); }

/* Toast */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--ink);
  color: #fff;
  padding: 14px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 50;
  font-size: 15px;
  max-width: 720px;
  margin: 0 auto;
}
.toast[hidden] { display: none; }
.toast.toast-error { background: var(--danger); }

/* Catalog CTA on scan screen */
.catalog-cta {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin: 16px auto 8px;
  max-width: 720px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.catalog-cta:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }

/* Bigger / more prominent variant on the landing page. */
.catalog-cta-hero {
  gap: 16px;
  padding: 18px 18px;
  border: 2px solid var(--brand);
  background: linear-gradient(135deg, rgba(46,125,50,0.06), rgba(102,187,106,0.08));
  box-shadow: var(--shadow-brand);
}
.catalog-cta-hero .catalog-cta-icon { width: 48px; height: 48px; border-radius: 12px; }
.catalog-cta-hero .catalog-cta-title { font-size: 17px; }
.catalog-cta-hero .catalog-cta-sub { font-size: 14px; color: var(--ink-2); }

.catalog-cta-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-light), var(--brand));
  color: #fff;
  flex-shrink: 0;
}
.catalog-cta-text { flex: 1; min-width: 0; }
.catalog-cta-title { font-weight: 700; font-size: 15px; }
.catalog-cta-sub { font-size: 13px; color: var(--ink-3); }
.catalog-cta-chev { color: var(--ink-3); flex-shrink: 0; }

/* Tips card numbered list */
.tips-lead { font-weight: 600; margin: 4px 0 8px; color: var(--ink); }
.tips-numbered {
  margin: 0 0 12px;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tips-numbered li { font-size: 15px; color: var(--ink-2); }
.tips-numbered strong { color: var(--ink); }
.tips-foot { font-size: 14px; color: var(--ink-3); margin: 0; }

/* Publish toggle on result screen */
.publish-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  margin: 12px auto;
  max-width: 720px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
}
.publish-toggle[hidden] { display: none; }
.publish-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.publish-toggle-track {
  width: 40px;
  height: 24px;
  border-radius: 12px;
  background: var(--line-2);
  position: relative;
  flex-shrink: 0;
  margin-top: 2px;
  transition: background 0.18s ease;
}
.publish-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.18s ease;
}
.publish-toggle input:checked + .publish-toggle-track { background: var(--brand); }
.publish-toggle input:checked + .publish-toggle-track::after { transform: translateX(16px); }
.publish-toggle-text { flex: 1; min-width: 0; }
.publish-toggle-title { font-weight: 700; font-size: 15px; display: block; }
.publish-toggle-sub { font-size: 13px; color: var(--ink-3); display: block; margin-top: 2px; }

/* Catalog screen */
.catalog-tabs {
  display: flex;
  gap: 6px;
  max-width: 720px;
  margin: 0 auto 12px;
  padding: 4px 16px 0;
}
.catalog-tab {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.catalog-tab.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.catalog-filters-wrap {
  max-width: 720px;
  margin: 0 auto 12px;
  padding: 0 16px;
}
.catalog-filters-wrap > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  list-style: none;
  padding: 8px 0;
}
.catalog-filters-wrap > summary::-webkit-details-marker { display: none; }
.catalog-filters-wrap > summary::after {
  content: ' ▾';
  color: var(--ink-3);
}
.catalog-filters-wrap[open] > summary::after { content: ' ▴'; }

.catalog-search {
  max-width: 720px;
  margin: 0 auto 12px;
  padding: 0 16px;
}
.catalog-search input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.catalog-search input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(46,125,50,0.15);
}

.catalog-filters {
  max-width: 720px;
  margin: 0 auto 12px;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.catalog-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.catalog-filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-right: 4px;
  min-width: 38px;
}
.filter-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.filter-chip.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.filter-chip.ns-A.is-active { background: var(--ns-a); border-color: var(--ns-a); }
.filter-chip.ns-B.is-active { background: var(--ns-b); border-color: var(--ns-b); color: var(--ink); }
.filter-chip.ns-C.is-active { background: var(--ns-c); border-color: var(--ns-c); color: var(--ink); }
.filter-chip.ns-D.is-active { background: var(--ns-d); border-color: var(--ns-d); }
.filter-chip.ns-E.is-active { background: var(--ns-e); border-color: var(--ns-e); }
.filter-chip.avoid-chip.is-active {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.catalog-meta {
  max-width: 720px;
  margin: 0 auto 8px;
  padding: 0 16px;
  font-size: 13px;
  color: var(--ink-3);
}

.catalog-card { position: relative; }
.catalog-card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}

.archive-card-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}
.catalog-card-share {
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-3);
  padding: 4px;
  border-radius: 6px;
  transition: color 0.12s ease;
}
.catalog-card-share:active { color: var(--brand); }

.detail-share-btn {
  position: absolute;
  top: 0;
  right: 0;
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-3);
  padding: 4px;
  border-radius: 8px;
  transition: color 0.12s ease;
}
.detail-share-btn:active { color: var(--brand); }

.catalog-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  gap: 12px;
  color: var(--ink-3);
  font-size: 14px;
}
.catalog-loading[hidden] { display: none; }
.catalog-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--ink-4, #ddd);
  border-top-color: var(--brand, #1a1a1a);
  border-radius: 50%;
  animation: catalog-spin 0.7s linear infinite;
}
@keyframes catalog-spin { to { transform: rotate(360deg); } }

.catalog-loadmore {
  display: flex;
  justify-content: center;
  padding: 16px;
}
.catalog-loadmore[hidden] { display: none; }

.catalog-detail-meta {
  max-width: 720px;
  margin: 0 auto 12px;
  padding: 0 16px;
  font-size: 13px;
  color: var(--ink-3);
}

@media (prefers-reduced-motion: reduce) {
  .scan-ring, .scan-beam { animation: none; }
  .btn, .icon-btn, .archive-card, .publish-toggle-track::after { transition: none; }
}
