/* GF Check — warm, mobile-first, one-handed. No frameworks. */

/* Self-hosted so it renders identically everywhere and needs no third-party
   request. Variable weight 400-900. */
@font-face {
  font-family: "Nunito";
  src: url("/fonts/nunito.woff2") format("woff2-variations");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --cream: #fbf7f0;
  --surface: #ffffff;
  --surface-2: #f4ede2;
  --ink: #2e2a26;
  --ink-2: #5c5349;
  --muted: #8a7d70;
  --line: #e6dccd;

  /* Plum, deliberately not green/red/amber: those three now mean SAFE,
     NOT SAFE and UNCERTAIN and nothing else. */
  --brand: #7c3f5f;
  --brand-dark: #5b2c45;
  --brand-tint: #f7eaf0;

  --safe: #1c8347;
  --safe-tint: #e7f5ec;
  --unsafe: #c0392b;
  --unsafe-tint: #fbeae8;
  --uncertain: #b07206;
  --uncertain-tint: #fdf3e0;

  /* Bread mascot — matches the app icon. */
  --crust: #c68a3e;
  --crumb: #f7e2b8;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 2px 10px rgba(60, 45, 25, 0.07);
  --shadow-lg: 0 10px 30px rgba(60, 45, 25, 0.14);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --cream: #1a1815;
    --surface: #24211d;
    --surface-2: #2d2926;
    --ink: #f2ece2;
    --ink-2: #cfc5b8;
    --muted: #9d9284;
    --line: #3a352f;

    --brand: #c07f9d;
    --brand-dark: #a36280;
    --brand-tint: #37232d;

    --safe: #34a862;
    --safe-tint: #1e3226;
    --unsafe: #e2685a;
    --unsafe-tint: #362320;
    --uncertain: #d9a13c;
    --uncertain-tint: #33291a;

    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--cream);
  color: var(--ink);
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", -apple-system,
    BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- view plumbing ---------- */

.view { display: none; }
.view.is-active { display: flex; flex-direction: column; }

#app[hidden], [hidden] { display: none !important; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 24px;
}

#view-home, #view-verdict, #view-chat {
  flex: 1;
  min-height: 0;
}

/* ---------- lock screen ---------- */

#view-lock {
  min-height: 100%;
  align-items: center;
  justify-content: center;
  padding: 24px calc(24px + env(safe-area-inset-left, 0px)) calc(24px + var(--safe-bottom));
}

.lock-wrap { width: 100%; max-width: 380px; text-align: center; }

.lock-logo {
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 18px;
}

.lock-title {
  font-size: 32px;
  margin: 0 0 6px;
  letter-spacing: -0.5px;
}

.lock-sub {
  color: var(--muted);
  margin: 0 0 30px;
  font-size: 16px;
}

.lock-form { text-align: left; }

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 8px;
}

input[type="password"], input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 15px 16px;
  min-height: 54px;
}

input::placeholder { color: var(--muted); opacity: 0.85; }

input:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}

.form-error {
  color: var(--unsafe);
  font-size: 15px;
  margin: 10px 0 0;
  font-weight: 600;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  min-height: 54px;
  padding: 14px 22px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:active { transform: scale(0.985); }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:disabled { filter: grayscale(0.4) opacity(0.6); cursor: default; }

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

.btn-outline {
  background: var(--surface);
  color: var(--brand);
  border: 1.5px solid var(--brand);
}

.btn-block { display: block; width: 100%; margin-top: 12px; }

.btn-with-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-with-icon svg { width: 22px; height: 22px; flex: 0 0 22px; }

.card-hint {
  color: var(--muted);
  font-size: 13.5px;
  margin: 10px 0 0;
  line-height: 1.4;
}

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 11px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 44px;
}

.icon-btn:active { background: var(--surface-2); }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  background: var(--cream);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.topbar-title {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 17px;
}

/* keeps the title centred when the back button is hidden */
.topbar > .icon-btn[hidden] + .topbar-title { margin-left: 44px; }

/* ---------- scan button ---------- */

.scan-block { text-align: center; padding: 18px 0 6px; }

.scan-btn {
  width: min(72vw, 260px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 32% 28%, #9b5478 0%, var(--brand) 55%, var(--brand-dark) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 auto;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.1s ease;
}

.scan-btn:active { transform: scale(0.97); }

.scan-icon { width: 76px; height: 76px; stroke-width: 1.9; }

.scan-label { font-size: 21px; font-weight: 800; letter-spacing: -0.2px; }

.scan-hint {
  color: var(--muted);
  font-size: 14.5px;
  margin: 14px auto 0;
  max-width: 260px;
}

/* ---------- composer ---------- */

.composer-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 22px;
  box-shadow: var(--shadow);
}

.composer { display: flex; gap: 10px; align-items: stretch; }

.composer input { flex: 1; min-width: 0; }

.send-btn {
  flex: 0 0 54px;
  width: 54px;
  min-height: 54px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  padding: 15px;
  cursor: pointer;
}

.send-btn:active { transform: scale(0.96); }

.composer-docked {
  flex: 0 0 auto;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--cream);
  border-top: 1px solid var(--line);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip {
  font: inherit;
  font-size: 14.5px;
  color: var(--brand);
  background: var(--brand-tint);
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  min-height: 40px;
  cursor: pointer;
}

.chip:active { filter: brightness(0.95); }

/* ---------- history ---------- */

.history-block { margin-top: 26px; }

.section-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 700;
}

.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  min-height: 62px;
  cursor: pointer;
  color: var(--ink);
}

.history-item:active { background: var(--surface-2); }

.dot {
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 1px;
}

.dot.safe { background: var(--safe); }
.dot.unsafe { background: var(--unsafe); }
.dot.uncertain { background: var(--uncertain); }
.dot.menu { background: var(--brand); }
.dot.chat { background: var(--muted); }

.history-body { flex: 1; min-width: 0; }

.history-title {
  font-weight: 700;
  font-size: 15px;
  display: block;
  margin-bottom: 2px;
}

.history-sub {
  color: var(--muted);
  font-size: 14px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  padding: 18px 8px;
  margin: 0;
}

/* ---------- verdict ---------- */

#view-verdict .scroll { padding: 0 0 24px; }

.banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 34px 20px 30px;
  color: #fff;
  text-align: center;
}

.banner.safe { background: var(--safe); }
.banner.unsafe { background: var(--unsafe); }
.banner.uncertain { background: var(--uncertain); }

.banner-eyebrow {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  font-weight: 700;
  opacity: 0.9;
}

.banner-verdict {
  font-size: clamp(38px, 13vw, 58px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -1.5px;
}

.banner-confidence {
  font-size: 14.5px;
  opacity: 0.92;
  margin-top: 4px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 16px 16px 0;
  box-shadow: var(--shadow);
}

.verdict-summary { margin: 0; font-size: 17px; }

.product-name {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

/* Filled star once a scan is on the saved list. */
.btn.is-saved { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.is-saved svg { fill: currentColor; }

.flagged-list, .questions-list { margin: 0; padding: 0; list-style: none; }

.flagged-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.flagged-list li:last-child { border-bottom: none; padding-bottom: 0; }
.flagged-list li:first-child { padding-top: 0; }

.flag-name {
  display: block;
  font-weight: 700;
  margin-bottom: 3px;
}

.flag-reason {
  display: block;
  color: var(--ink-2);
  font-size: 15.5px;
}

.questions-list li {
  position: relative;
  padding: 9px 0 9px 24px;
  font-size: 16px;
}

.questions-list li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 18px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
}

.panel-actions { padding: 20px 16px 0; }

/* ---------- menu results ---------- */

#view-menu .scroll { padding: 0 0 24px; }

.menu-header {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 26px 20px 22px;
  background: var(--brand);
  color: #fff;
  text-align: center;
}

.menu-eyebrow {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  font-weight: 700;
  opacity: 0.9;
}

.menu-restaurant {
  font-size: clamp(24px, 7vw, 33px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.6px;
}

.menu-caution {
  margin: 10px 0 0;
  font-size: 14.5px;
  line-height: 1.4;
  opacity: 0.95;
}

.dish-list { margin: 0; padding: 0; list-style: none; }

.dish-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.dish-list li:first-child { padding-top: 0; }
.dish-list li:last-child { border-bottom: none; padding-bottom: 0; }

.dish-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 5px;
}

.dish-name { font-weight: 700; flex: 1; min-width: 0; }

.pill {
  flex: 0 0 auto;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
  margin-top: 2px;
}

.pill.good { background: var(--safe-tint); color: var(--safe); }
.pill.ask { background: var(--uncertain-tint); color: var(--uncertain); }
.pill.avoid { background: var(--unsafe-tint); color: var(--unsafe); }

.dish-reason {
  display: block;
  color: var(--ink-2);
  font-size: 15.5px;
}

.dish-mod {
  display: block;
  margin-top: 6px;
  font-size: 15px;
  color: var(--brand);
  background: var(--brand-tint);
  border-radius: 10px;
  padding: 8px 11px;
}

/* ---------- chat ---------- */

.chat-thread { display: flex; flex-direction: column; gap: 12px; }

.bubble {
  max-width: 86%;
  padding: 12px 15px;
  border-radius: 18px;
  font-size: 16.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble.user {
  align-self: flex-end;
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.bubble.thinking { color: var(--muted); font-style: italic; }

/* An app-authored nudge rather than a model answer — reads as chrome. */
.bubble.prompt {
  align-self: stretch;
  max-width: none;
  background: var(--brand-tint);
  border: none;
  color: var(--brand);
  font-size: 15.5px;
  text-align: center;
  border-radius: var(--radius-sm);
}

/* ---------- disclaimer ---------- */

.disclaimer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  line-height: 1.35;
}

/* ---------- bread mascot ---------- */

/* The visual language: bread shows up when gluten is the subject. It never
   appears on a SAFE verdict — there, its absence is the good news. */
.bread { display: block; }

.bread .loaf {
  fill: var(--crumb);
  stroke: var(--crust);
  stroke-width: 4.5;
}

.bread .eye { fill: var(--ink); stroke: none; }

.bread .mouth {
  fill: none;
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
}

.bread-empty {
  width: 96px;
  height: 96px;
  margin: 4px auto 12px;
}

/* ---------- verdict banner drama ---------- */

.banner { position: relative; overflow: hidden; }

.banner > * { position: relative; z-index: 1; }

.banner-glyph {
  position: absolute;
  right: 4px;
  bottom: -34px;
  z-index: 0;
  font-size: 168px;
  font-weight: 900;
  line-height: 1;
  opacity: 0.17;
  pointer-events: none;
  user-select: none;
}

@keyframes stamp {
  0% { transform: scale(1.4); opacity: 0; }
  55% { transform: scale(0.97); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes rise {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.stamp-in { animation: stamp 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.25) both; }
.rise-in { animation: rise 0.32s ease-out both; }
.rise-in:nth-of-type(2) { animation-delay: 0.05s; }
.rise-in:nth-of-type(3) { animation-delay: 0.1s; }

/* ---------- loading overlay ---------- */

.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(28, 24, 20, 0.5);
  backdrop-filter: blur(3px);
}

.loading-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 30px 26px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

/* Bread being inspected under a sweeping magnifier — this is on screen for
   13-19s during a menu scan, so it earns a bit of character. */
.inspect {
  width: 132px;
  height: 108px;
  margin: 0 auto 16px;
  overflow: visible;
}

.inspect .lens {
  fill: rgba(255, 255, 255, 0.18);
  stroke: var(--brand);
  stroke-width: 4.5;
}

.inspect .handle {
  stroke: var(--brand);
  stroke-width: 6;
  stroke-linecap: round;
  fill: none;
}

.inspect .magnifier {
  animation: sweep 2.6s ease-in-out infinite;
  transform-origin: center;
}

@keyframes sweep {
  0%   { transform: translate(-16px, 4px) rotate(-8deg); }
  50%  { transform: translate(18px, -4px) rotate(6deg); }
  100% { transform: translate(-16px, 4px) rotate(-8deg); }
}

@media (prefers-reduced-motion: reduce) {
  .inspect .magnifier { animation: none; }
  .stamp-in, .rise-in { animation: none; }
  .btn:active, .scan-btn:active, .send-btn:active { transform: none; }
}

.loading-msg { margin: 0; font-weight: 700; font-size: 17px; }
.loading-sub { margin: 6px 0 0; color: var(--muted); font-size: 14.5px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 60;
  background: var(--ink);
  color: var(--cream);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 15.5px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
