/* ===========================================================
   BiteCheck — design tokens
   Subject: a phone-camera food/label "scanner" for teens.
   Signature element: viewfinder corner brackets + scan-line
   sweep, and a nutrition-label-style circular score ring set
   in mono numerals.
   =========================================================== */
:root {
  --ink: #16241F;
  --ink-soft: #4B5A54;
  --paper: #FBFBF6;
  --paper-raised: #FFFFFF;
  --line: #E4E2D6;

  --citrus: #A9D428;    /* fresh / healthy accent */
  --citrus-dark: #7FA31E;
  --berry: #E23E57;     /* allergen / warning accent */
  --berry-soft: #FDE7EA;
  --sky: #2F97AC;        /* info / secondary accent */
  --sky-soft: #E3F4F6;
  --amber: #E2A83E;
  --amber-soft: #FBF0DC;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;

  --shadow-card: 0 1px 2px rgba(22,36,31,0.04), 0 8px 24px rgba(22,36,31,0.06);

  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img, svg { display: block; max-width: 100%; }

button, input, textarea { font-family: inherit; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 10px;
}

.topbar__brand { display: flex; align-items: center; gap: 8px; flex: 1; }

.logo-mark {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: linear-gradient(135deg, var(--citrus), var(--sky));
  display: inline-block;
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.topbar__tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-soft);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

/* ---------- App shell ---------- */
.app {
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 18px 32px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--line);
  padding: 4px;
  border-radius: var(--radius-md);
  margin: 12px 0 18px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  border-radius: calc(var(--radius-md) - 4px);
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.tab.is-active {
  background: var(--paper-raised);
  color: var(--ink);
  box-shadow: var(--shadow-card);
}

.panel[hidden] { display: none; }

/* ---------- Scanner / viewfinder (signature element) ---------- */
.scanner__frame {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, #10201A, #1C3229);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner__preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner__placeholder {
  color: rgba(251, 251, 246, 0.65);
  text-align: center;
  font-size: 0.85rem;
  padding: 0 30px;
}
.scanner__placeholder svg { margin: 0 auto 10px; color: var(--citrus); }
.scanner__placeholder p { margin: 0; line-height: 1.5; }

.scanner__corner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--citrus);
  opacity: 0.9;
}
.scanner__corner.tl { top: 14px; left: 14px; border-right: none; border-bottom: none; border-top-left-radius: 8px; }
.scanner__corner.tr { top: 14px; right: 14px; border-left: none; border-bottom: none; border-top-right-radius: 8px; }
.scanner__corner.bl { bottom: 14px; left: 14px; border-right: none; border-top: none; border-bottom-left-radius: 8px; }
.scanner__corner.br { bottom: 14px; right: 14px; border-left: none; border-top: none; border-bottom-right-radius: 8px; }

.scanner__scanline {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--citrus), transparent);
  box-shadow: 0 0 14px 2px rgba(169,212,40,0.7);
  animation: sweep 1.6s ease-in-out infinite;
}

@keyframes sweep {
  0%   { top: 10%; opacity: 0; }
  15%  { opacity: 1; }
  50%  { top: 88%; opacity: 1; }
  85%  { opacity: 1; }
  100% { top: 10%; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .scanner__scanline { animation: none; top: 50%; }
}

/* ---------- Capture buttons ---------- */
.capture-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  text-align: center;
  transition: transform .1s ease, opacity .15s ease;
  user-select: none;
}
.btn:active { transform: scale(0.97); }

.btn--primary {
  flex: 1.3;
  background: var(--ink);
  color: var(--paper);
}
.btn--ghost {
  flex: 1;
  background: var(--paper-raised);
  color: var(--ink);
  border: 1.5px solid var(--line);
}

.btn--analyze {
  width: 100%;
  margin-top: 18px;
  background: linear-gradient(120deg, var(--citrus), var(--sky));
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1rem;
  padding: 15px;
}
.btn--analyze:disabled { opacity: 0.6; cursor: default; }

.btn--reset { width: 100%; margin-top: 4px; }

/* ---------- Text panel ---------- */
.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--ink-soft);
}

textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 0.92rem;
  background: var(--paper-raised);
  color: var(--ink);
  resize: vertical;
  line-height: 1.5;
}
textarea:focus, .tab:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 2px;
}

/* ---------- Error ---------- */
.error-banner {
  margin-top: 14px;
  background: var(--berry-soft);
  color: #8E1F32;
  border: 1px solid rgba(226,62,87,0.25);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ---------- Results ---------- */
.results { margin-top: 22px; flex-direction: column; gap: 12px; }
.results:not([hidden]) { display: flex; }

.result-card {
  background: var(--paper-raised);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

.result-card__title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 600;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.result-card__title .dim { color: var(--ink-soft); font-weight: 500; font-size: 0.8em; font-family: var(--font-body); }
.watch-title { color: var(--berry); }
.good-title { color: var(--citrus-dark); }

/* Score card */
.score-card { display: flex; align-items: center; gap: 16px; }

.score-ring { position: relative; width: 84px; height: 84px; flex-shrink: 0; }
.score-ring__svg { transform: rotate(-90deg); width: 84px; height: 84px; }
.score-ring__track { fill: none; stroke: var(--line); stroke-width: 9; }
.score-ring__fill {
  fill: none;
  stroke: var(--citrus);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .8s ease, stroke .3s ease;
}
.score-ring__value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.35rem;
}
.score-ring__value small {
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-left: 1px;
}

.score-card__info h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0 0 2px;
  line-height: 1.25;
}
.score-label {
  margin: 0 0 4px;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--sky);
}
.serving-info {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.summary-text { margin: 0; line-height: 1.55; font-size: 0.94rem; }
.estimated-note {
  margin: 10px 0 0;
  font-size: 0.76rem;
  color: var(--amber);
  background: var(--amber-soft);
  padding: 5px 10px;
  border-radius: 20px;
}
.estimated-note:not([hidden]) { display: inline-block; }

/* Allergen chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 20px;
  border: 1.5px solid transparent;
}
.chip--contains { background: var(--berry-soft); color: #8E1F32; border-color: rgba(226,62,87,0.3); }
.chip--maycontain { background: var(--amber-soft); color: #86611C; border-color: rgba(226,168,62,0.35); }
.chip--traces { background: var(--sky-soft); color: #1D6E7E; border-color: rgba(47,151,172,0.3); }
.chip--none { background: var(--sky-soft); color: #1D6E7E; }

/* Nutrition grid */
.nutrition-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.nutri-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.nutri-item__value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.98rem;
  display: block;
}
.nutri-item__label {
  font-size: 0.68rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Watch outs / positives */
.split-card { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tag-list li {
  font-size: 0.82rem;
  line-height: 1.4;
  padding-left: 16px;
  position: relative;
}
.tag-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
#watchOuts li { color: var(--berry); }
#watchOuts li::before { background: var(--berry); }
#positives li { color: var(--citrus-dark); }
#positives li::before { background: var(--citrus-dark); }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--ink-soft);
  padding: 10px 20px 26px;
}

/* ---------- Small screens polish ---------- */
@media (max-width: 360px) {
  .capture-row { flex-direction: column; }
  .split-card { grid-template-columns: 1fr; }
}

/* ===========================================================
   Allergy profile — setup screen + topbar entry point + the
   personalized in-results warning banner.
   =========================================================== */

.edit-allergies-btn {
  align-items: center;
  gap: 5px;
  border: 1.5px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 20px;
  cursor: pointer;
}
.edit-allergies-btn:not([hidden]) { display: inline-flex; }
.edit-allergies-btn:active { transform: scale(0.97); }

.allergy-setup {
  padding-top: 14px;
}

.setup-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  line-height: 1.25;
  margin: 6px 0 8px;
}

.setup-subtitle {
  color: var(--ink-soft);
  font-size: 0.87rem;
  line-height: 1.5;
  margin: 0 0 20px;
}

.allergy-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.allergy-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  border: 1.5px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease, transform .08s ease;
}
.allergy-chip:active { transform: scale(0.98); }
.allergy-chip.is-selected {
  border-color: var(--berry);
  background: var(--berry-soft);
  color: #8E1F32;
  font-weight: 600;
}

#otherAllergies {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  font-size: 0.9rem;
  background: var(--paper-raised);
  color: var(--ink);
}
#otherAllergies:focus { outline: 2px solid var(--sky); outline-offset: 2px; }

.setup-actions {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.setup-continue { width: 100%; }

.btn-link {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}
.btn-link--muted {
  margin: 18px auto 0;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--line);
  text-decoration: none;
}
.btn-link--muted:not([hidden]) { display: block; }

/* Personalized allergy warning shown above scan results when a detected
   allergen matches something the user listed in their profile. */
.personal-alert {
  background: var(--berry);
  color: #FFF8F5;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.4;
  align-items: flex-start;
  gap: 10px;
}
/* Only actually shown when its `hidden` attribute is removed — without
   this, the `display: flex` above wins the cascade tie against the
   browser's default [hidden] { display: none } and the banner shows
   even when it shouldn't. */
.personal-alert:not([hidden]) { display: flex; }
.personal-alert::before {
  content: "⚠️";
  font-size: 1.1rem;
  line-height: 1;
}

.chip--personal {
  box-shadow: 0 0 0 2px var(--berry) inset;
}

/* ===========================================================
   Menu Check — a distinct third mode: scan/paste a whole menu
   and get a per-dish verdict against the saved allergy profile.
   =========================================================== */

.menu-intro {
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0 0 14px;
}

/* Reuses .scanner styling; a subtle teal tint distinguishes menu mode
   from the citrus-accented single-item scanner. */
.scanner--menu .scanner__frame {
  background: linear-gradient(160deg, #0F262A, #163A3F);
}
.scanner--menu .scanner__corner { border-color: var(--sky); }
.scanner--menu .scanner__placeholder svg { color: var(--sky); }
.scanner--menu .scanner__scanline {
  background: linear-gradient(90deg, transparent, var(--sky), transparent);
  box-shadow: 0 0 14px 2px rgba(47,151,172,0.7);
}

.menu-or-label { margin-top: 16px; }

#menuTextNotes {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 0.88rem;
  background: var(--paper-raised);
  color: var(--ink);
  resize: vertical;
  line-height: 1.5;
}
#menuTextNotes:focus { outline: 2px solid var(--sky); outline-offset: 2px; }

.menu-disclaimer {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.menu-no-profile-note {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: #86611C;
  background: var(--amber-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.5;
}
.menu-no-profile-note:not([hidden]) { display: block; }
.menu-no-profile-note .btn-link {
  display: inline;
  padding: 0;
  margin-left: 4px;
  color: #86611C;
}

.menu-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.menu-item {
  background: var(--paper-raised);
  border-radius: var(--radius-md);
  padding: 14px;
  border-left: 4px solid var(--line);
  box-shadow: var(--shadow-card);
}
.menu-item--avoid { border-left-color: var(--berry); background: var(--berry-soft); }
.menu-item--caution { border-left-color: var(--amber); background: var(--amber-soft); }
.menu-item--safe { border-left-color: var(--citrus); }
.menu-item--unknown { border-left-color: var(--sky); }

.menu-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.menu-item__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.94rem;
  line-height: 1.35;
}

.menu-item__badge {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 20px;
  background: rgba(22,36,31,0.06);
  white-space: nowrap;
}

.menu-item__reason {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.menu-item__allergens {
  margin: 6px 0 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.menu-empty-note {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 20px 10px;
  line-height: 1.5;
}

/* Slightly tighter tab labels once there are 3 tabs instead of 2. */
.tab { font-size: 0.88rem; }
@media (max-width: 380px) {
  .tab { font-size: 0.76rem; padding: 9px 2px; }
}
