/* SnackCheck web: tokens, base, shell, shared components and the core screens.
   pages.css builds the remaining screens from these tokens and component classes. */

@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("fonts/nunito-normal.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("fonts/nunito-italic.woff2") format("woff2");
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  --bg: #FDF6EC;
  --bg-glow-1: radial-gradient(ellipse 70% 46% at 100% 0%, rgba(74, 158, 142, .26), transparent 72%);
  --bg-glow-2: radial-gradient(ellipse 60% 42% at 0% 22%, rgba(232, 115, 90, .15), transparent 70%);
  --bg-dot: rgba(45, 52, 54, .07);
  --surface: #FFFFFF;
  --surface-2: #F8EFE1;
  --text: #2D3436;
  --text-muted: #5B6568;
  --border: rgba(45, 52, 54, .12);

  --primary: #357D6E;
  --primary-ink: #FFFFFF;
  --primary-soft: rgba(74, 158, 142, .15);
  --brand: #4A9E8E;
  --accent: #E8735A;
  --accent-text: #B5472D;
  --accent-soft: rgba(232, 115, 90, .15);
  --warn: #A66A00;
  --warn-soft: rgba(245, 176, 65, .22);
  --danger: #C23B37;
  --danger-ink: #FFFFFF;
  --danger-soft: rgba(217, 83, 79, .12);
  --ok: #2E7B38;
  --ok-soft: rgba(92, 184, 92, .17);
  --focus: #2563C9;

  --score-red: #D9534F;
  --score-amber: #F5B041;
  --score-green: #5CB85C;

  --radius: 20px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --shadow: 0 1px 2px rgba(45, 52, 54, .05), 0 10px 28px -12px rgba(45, 52, 54, .16);
  --shadow-lg: 0 2px 4px rgba(45, 52, 54, .06), 0 28px 52px -20px rgba(45, 52, 54, .28);

  --font-display: "Fredoka", ui-rounded, "Hiragino Maru Gothic ProN", Quicksand, sans-serif;
  --font-body: "Nunito", ui-rounded, "Hiragino Maru Gothic ProN", sans-serif;

  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 2.5rem;
  --space-8: 3rem;

  --tabbar-h: 4.25rem;
  --sidebar-w: 16rem;
  --page-max: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1E2E;
    --bg-glow-1: radial-gradient(ellipse 70% 46% at 100% 0%, rgba(74, 158, 142, .26), transparent 72%);
    --bg-glow-2: radial-gradient(ellipse 60% 42% at 0% 22%, rgba(232, 115, 90, .14), transparent 70%);
    --bg-dot: rgba(255, 255, 255, .05);
    --surface: #252A3A;
    --surface-2: #2E3448;
    --text: #F3F0EA;
    --text-muted: #A9B1C0;
    --border: rgba(255, 255, 255, .11);

    --primary: #62BFAC;
    --primary-ink: #0C1E1A;
    --primary-soft: rgba(98, 191, 172, .17);
    --accent: #F0836B;
    --accent-text: #F6A08D;
    --accent-soft: rgba(240, 131, 107, .17);
    --warn: #F5B041;
    --warn-soft: rgba(245, 176, 65, .17);
    --danger: #F58581;
    --danger-ink: #2B0B0A;
    --danger-soft: rgba(245, 133, 129, .15);
    --ok: #76CF7D;
    --ok-soft: rgba(118, 207, 125, .16);
    --focus: #8DB6FF;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px -12px rgba(0, 0, 0, .55);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .35), 0 30px 56px -20px rgba(0, 0, 0, .7);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 1rem; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    var(--bg-glow-1),
    var(--bg-glow-2),
    radial-gradient(circle at 1px 1px, var(--bg-dot) 1px, transparent 0) 0 0 / 22px 22px;
}
img, svg, video { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -.005em;
  text-wrap: balance;
}
h1 { font-size: clamp(1.8rem, 1.2rem + 2.6vw, 2.7rem); font-weight: 700; }
h2 { font-size: clamp(1.3rem, 1.1rem + .8vw, 1.65rem); }
h3 { font-size: 1.15rem; }
p { margin: 0; }
a { color: var(--primary); text-underline-offset: .18em; text-decoration-thickness: .08em; }
a:hover { text-decoration-thickness: .14em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--primary-soft); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-4); top: -5rem; z-index: 100;
  padding: .7rem 1rem; border-radius: var(--radius-sm);
  background: var(--primary); color: var(--primary-ink); font-weight: 800;
}
.skip-link:focus { top: var(--space-3); }

.muted { color: var(--text-muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.break { overflow-wrap: anywhere; }
.lead { font-size: clamp(1.05rem, 1rem + .35vw, 1.25rem); color: var(--text-muted); line-height: 1.5; }
.display {
  font-size: clamp(2.5rem, 1.4rem + 5.6vw, 4.6rem);
  line-height: 1.02;
  font-weight: 700;
  letter-spacing: -.015em;
}
.eyebrow {
  font-family: var(--font-body);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent-text);
}
.clamp-1, .clamp-3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-1 { -webkit-line-clamp: 1; line-clamp: 1; }
.clamp-3 { -webkit-line-clamp: 3; line-clamp: 3; }
.danger-text { color: var(--danger); }
.accent-text { color: var(--accent-text); }
.ico-warn { color: var(--warn); display: inline-flex; }
.ico-danger { color: var(--danger); display: inline-flex; }
.ico-accent { color: var(--accent-text); display: inline-flex; }
.ico-primary { color: var(--primary); display: inline-flex; }

.icon { width: 1.25rem; height: 1.25rem; flex: none; }

/* ---------- Layout primitives ---------- */
.stack { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.stack > * { min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 768px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.page {
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--space-5) var(--space-4) 0;
}
@media (min-width: 768px) { .page { padding: var(--space-6) var(--space-6) 0; } }
@media (min-width: 1024px) { .page { padding-top: var(--space-7); } }
.page-header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: var(--space-3) var(--space-4); margin-bottom: var(--space-5);
}
.page-header > div { min-width: 0; }
.page-header .eyebrow { margin-bottom: var(--space-1); }

.app { min-height: 100vh; min-height: 100dvh; }
.app-main {
  min-width: 0;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-6));
  outline: none;
}
.app-footer {
  display: flex; justify-content: center; gap: var(--space-5);
  padding: var(--space-6) var(--space-4) 0;
}
.app-footer a, .sidebar-foot a, .bare-footer a { color: var(--text-muted); }

/* Wordmark */
.wordmark {
  display: inline-flex; align-items: center; gap: .6rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.35rem;
  color: var(--text); text-decoration: none;
}
.wordmark .mark { width: 2rem; height: 2rem; flex: none; }

/* ---------- Navigation ---------- */
.nav-link {
  display: flex; align-items: center; text-decoration: none;
  color: var(--text-muted); font-weight: 800;
}
.nav-ico { display: inline-grid; place-items: center; }
.nav-ico .icon { width: 1.4rem; height: 1.4rem; }

.sidebar { display: none; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: end;
  padding: .3rem .4rem calc(.3rem + env(safe-area-inset-bottom));
  min-height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-top: 1px solid var(--border);
}
.tabbar .nav-link {
  flex-direction: column; justify-content: flex-end; gap: .1rem;
  min-height: 3.5rem; padding: .25rem 0; font-size: .75rem; line-height: 1.1;
  border-radius: var(--radius-sm);
}
.tabbar .nav-ico { width: 3.1rem; height: 1.85rem; border-radius: 999px; transition: background .2s, color .2s; }
.tabbar .nav-link[aria-current="page"] { color: var(--primary); }
.tabbar .nav-link[aria-current="page"] .nav-ico { background: var(--primary-soft); }
.tabbar .nav-scan { color: var(--primary); }
.tabbar .nav-scan .nav-ico {
  width: 3.6rem; height: 3.6rem; border-radius: 50%;
  margin-top: -1.7rem;
  background: linear-gradient(145deg, #4A9E8E, #276658);
  color: #fff;
  box-shadow: 0 10px 22px -8px rgba(39, 102, 88, .7), 0 0 0 .32rem var(--bg);
}
.tabbar .nav-scan .nav-ico .icon { width: 1.7rem; height: 1.7rem; }
.tabbar .nav-scan[aria-current="page"] .nav-ico { background: linear-gradient(145deg, #4A9E8E, #276658); box-shadow: 0 10px 22px -8px rgba(39, 102, 88, .7), 0 0 0 .32rem var(--bg), 0 0 0 .5rem var(--primary-soft); }

@media (min-width: 1024px) {
  .tabbar, .app-footer { display: none; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
    width: var(--sidebar-w);
    display: flex; flex-direction: column; gap: var(--space-5);
    padding: var(--space-5) var(--space-4);
    background: color-mix(in srgb, var(--surface) 72%, transparent);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    border-right: 1px solid var(--border);
  }
  .sidebar .wordmark { padding: var(--space-2) var(--space-3); }
  .sidebar-nav { display: flex; flex-direction: column; gap: var(--space-1); }
  .sidebar .nav-link {
    gap: var(--space-3); min-height: 48px; padding: .6rem var(--space-3);
    border-radius: var(--radius-sm); font-size: 1rem;
    transition: background .15s, color .15s;
  }
  .sidebar .nav-link:hover { background: var(--primary-soft); color: var(--text); }
  .sidebar .nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
  .sidebar .nav-scan {
    order: -1; margin-bottom: var(--space-2);
    background: var(--primary); color: var(--primary-ink);
    box-shadow: 0 10px 22px -12px rgba(39, 102, 88, .8);
  }
  .sidebar .nav-scan:hover { background: var(--primary); color: var(--primary-ink); filter: brightness(1.06); }
  .sidebar .nav-scan[aria-current="page"] { background: var(--primary); color: var(--primary-ink); outline: 3px solid var(--primary-soft); outline-offset: 2px; }
  .sidebar-foot { margin-top: auto; display: flex; gap: var(--space-4); padding: 0 var(--space-3); }
  .app-main { margin-left: var(--sidebar-w); padding-bottom: var(--space-8); }
  .toast { bottom: var(--space-6) !important; }
}

/* ---------- Surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
  min-width: 0;
}
.card > :last-child { margin-bottom: 0; }
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card-title {
  display: inline-flex; align-items: center; gap: .5rem;
  margin: 0; font-size: 1.15rem; font-weight: 600;
}
.card-title .icon { width: 1.3rem; height: 1.3rem; }
.inset { background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); }
.inset-title { font-family: var(--font-display); font-weight: 600; margin-bottom: var(--space-2); }
.inset-warn { display: flex; gap: var(--space-3); align-items: flex-start; background: var(--warn-soft); }
.inset-warn .icon { color: var(--warn); margin-top: .2rem; }
.inset-accent { background: var(--accent-soft); }
.inset-accent .inset-title { display: flex; align-items: center; gap: .4rem; margin-bottom: var(--space-1); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 48px; padding: .7rem 1.25rem;
  border: 2px solid transparent; border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: 1rem; font-weight: 800; line-height: 1.2;
  text-align: center; text-decoration: none; cursor: pointer;
  background: transparent; color: var(--text);
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, filter .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn .icon { width: 1.2rem; height: 1.2rem; }
.btn:active:not([disabled]) { transform: scale(.98); }
.btn-primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 8px 18px -10px rgba(39, 102, 88, .8); }
.btn-primary:hover:not([disabled]) { filter: brightness(1.07); transform: translateY(-1px); }
.btn-secondary { border-color: color-mix(in srgb, var(--primary) 55%, transparent); color: var(--primary); background: var(--surface); }
.btn-secondary:hover:not([disabled]) { background: var(--primary-soft); }
.btn-ghost { color: var(--primary); }
.btn-ghost:hover:not([disabled]) { background: var(--primary-soft); }
.btn-danger { background: var(--danger); color: var(--danger-ink); }
.btn-danger:hover:not([disabled]) { filter: brightness(1.08); }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover:not([disabled]) { background: var(--danger-soft); }
.btn-light { background: #FDF6EC; color: #1F5648; box-shadow: 0 12px 24px -14px rgba(0, 0, 0, .55); }
.btn-light:hover:not([disabled]) { transform: translateY(-2px); }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 56px; padding: .85rem 1.6rem; font-size: 1.125rem; }
.btn-sm { min-height: 44px; padding: .5rem 1rem; font-size: .95rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn.is-loading { position: relative; cursor: progress; }
.btn.is-loading::after {
  content: ""; width: 1.05em; height: 1.05em; flex: none;
  border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .75s linear infinite;
}
.spinner {
  width: 2rem; height: 2rem; flex: none; border-radius: 50%;
  border: 3px solid var(--primary-soft); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.field label, .fieldset > legend { font-weight: 800; }
.fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.input {
  display: block; width: 100%; min-height: 48px;
  padding: .65rem .95rem;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: color-mix(in srgb, var(--text-muted) 75%, transparent); }
.input:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 4px var(--primary-soft); }
.input:focus-visible { outline: none; }
.input-lg { min-height: 56px; font-size: 1.2rem; }
.input-code { font-family: var(--font-display); letter-spacing: .12em; }
select.input { appearance: auto; }
.input-file { padding: .6rem; }
.field-error { color: var(--danger); font-weight: 700; font-size: .92rem; }
.help { color: var(--text-muted); font-size: .9rem; }
.input[aria-invalid="true"] { border-color: var(--danger); }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .28rem .7rem; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
  font-size: .85rem; font-weight: 800; line-height: 1.3;
}
.chip .icon { width: 1em; height: 1em; }
.chip-xs { padding: .12rem .5rem; font-size: .75rem; }
.chip-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-toggle {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: .4rem .95rem;
  border: 2px solid var(--border); border-radius: 999px;
  background: var(--surface); cursor: pointer; user-select: none;
  font-weight: 800; transition: background .15s, border-color .15s, color .15s, transform .15s;
}
.chip-toggle > input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  opacity: 0; cursor: pointer;
}
.chip-toggle > span { display: inline-flex; align-items: center; gap: .4rem; pointer-events: none; }
.chip-toggle:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.chip-toggle:active { transform: scale(.97); }
.chip-toggle:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.chip-toggle:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.chip-toggle .chip-check { display: none; width: 1em; height: 1em; }
.chip-toggle:has(input:checked) .chip-check { display: inline-block; }
.chip-grid { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr)); gap: var(--space-2); }
.emoji-chip { padding: 0; min-width: 44px; min-height: 48px; font-size: 1.5rem; line-height: 1; border-radius: var(--radius-sm); }

/* ---------- Notices ---------- */
.notice {
  --tone: var(--primary);
  display: flex; align-items: flex-start; flex-wrap: wrap; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--tone) 13%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--tone) 28%, transparent);
  border-radius: var(--radius-sm);
}
.notice > .icon { color: var(--tone); margin-top: .15rem; }
.notice > p, .notice > div, .notice-text { flex: 1 1 12rem; min-width: 0; margin: 0; }
.notice > div > p { margin-bottom: var(--space-2); }
.notice .btn { flex: none; }
.notice-danger { --tone: var(--danger); }
.notice-warn { --tone: var(--warn); }
.notice-ok { --tone: var(--ok); }
.notice-info { --tone: var(--primary); }

/* ---------- Lists, avatars, badges ---------- */
.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card .list { box-shadow: none; background: var(--surface-2); border: 0; }
.list-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); min-width: 0; }
.list-row + .list-row { border-top: 1px solid var(--border); }
.list-row:has(> a) { padding: 0; }
.list-row > a {
  display: flex; align-items: center; gap: var(--space-3); flex: 1; min-width: 0;
  min-height: 60px; padding: var(--space-3) var(--space-4);
  color: inherit; text-decoration: none; transition: background .15s;
}
.list-row > a:hover { background: var(--primary-soft); }
.list-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.avatar {
  flex: none; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-size: 1.3rem; line-height: 1;
}
.avatar-sm { width: 28px; height: 28px; font-size: .95rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 2rem; }
.avatar-sq { border-radius: 12px; }
.avatar-sq .icon { width: 1.3rem; height: 1.3rem; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { border: 2px solid var(--surface); }
.avatar-stack .avatar + .avatar { margin-left: -8px; }

.score-badge {
  display: inline-flex; align-items: center; gap: .35rem; flex: none;
  padding: .22rem .7rem; border-radius: 999px;
  font-size: .82rem; font-weight: 800; line-height: 1.3; white-space: nowrap;
}
.score-badge b { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; }
.score-safe { background: var(--ok-soft); color: var(--ok); }
.score-caution { background: var(--warn-soft); color: var(--warn); }
.score-avoid { background: var(--danger-soft); color: var(--danger); }

.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-3); padding: var(--space-7) var(--space-5);
}
.empty-ico {
  display: grid; place-items: center; width: 4rem; height: 4rem; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
}
.empty-ico .icon { width: 1.8rem; height: 1.8rem; }
.empty-title { font-size: 1.35rem; }
.empty-state p { max-width: 26rem; }

/* Dialog */
.dialog {
  width: min(28rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
  padding: var(--space-5); border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog[open] { animation: pop .22s cubic-bezier(.2, .8, .2, 1); }
.dialog::backdrop { background: rgba(14, 18, 30, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog h2 { font-size: 1.35rem; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-3); }

/* Toast (created by app.js) */
.toast {
  position: fixed; left: 50%; z-index: 90;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-4));
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 2rem); padding: .65rem 1.2rem; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg); font-weight: 800; box-shadow: var(--shadow-lg);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Content pages (privacy, terms) */
.prose { max-width: 46rem; margin-inline: auto; }
.prose > * + * { margin-top: var(--space-4); }
.prose h1 { margin-bottom: var(--space-2); }
.prose h2 { margin-top: var(--space-6); }
.prose h3 { margin-top: var(--space-5); }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li + li { margin-top: var(--space-2); }

/* ---------- Gauge ---------- */
.gauge { position: relative; width: var(--gauge-size, 168px); max-width: 100%; aspect-ratio: 1; margin-inline: auto; flex: none; }
.gauge svg { width: 100%; height: 100%; display: block; overflow: visible; }
.gauge-track, .gauge-arc { fill: none; stroke-width: 9; }
.gauge-track { stroke: color-mix(in srgb, var(--text) 10%, transparent); }
.gauge-arc {
  stroke: var(--score-color); stroke-linecap: round;
  stroke-dasharray: var(--score) 100;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--score-color) 45%, transparent));
  animation: gauge-draw 1.2s cubic-bezier(.2, .8, .2, 1) .3s backwards;
}
.gauge-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.gauge-num { font-family: var(--font-display); font-weight: 700; font-size: calc(var(--gauge-size, 168px) * .32); letter-spacing: -.02em; }
.gauge-label { margin-top: .15em; font-weight: 800; font-size: calc(var(--gauge-size, 168px) * .1); text-transform: uppercase; letter-spacing: .08em; }
.gauge-safe .gauge-num, .gauge-safe .gauge-label { color: var(--ok); }
.gauge-caution .gauge-num, .gauge-caution .gauge-label { color: var(--warn); }
.gauge-avoid .gauge-num, .gauge-avoid .gauge-label { color: var(--danger); }

/* ---------- Bare shell (welcome, sign-in) ---------- */
.bare-shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.bare-header { padding: calc(var(--space-4) + env(safe-area-inset-top)) 0 0; width: min(100% - 2rem, 70rem); margin-inline: auto; }
@media (min-width: 768px) { .bare-header { padding-top: var(--space-5); } }
.bare-main {
  --bare-max: 30rem;
  flex: 1; display: grid; align-content: center;
  width: min(100% - 2rem, var(--bare-max)); margin-inline: auto;
  padding-block: var(--space-5) var(--space-6);
}
.bare-main:has(.welcome) { --bare-max: 70rem; }
.bare-main:has(.onboard) { --bare-max: 36rem; }
.bare-footer { display: flex; justify-content: center; gap: var(--space-5); padding: 0 var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom)); }

.auth {
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: clamp(var(--space-5), 5vw, var(--space-7));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px); box-shadow: var(--shadow-lg);
}
.auth h1 { font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.2rem); }
.auth-ico {
  display: grid; place-items: center; width: 3.5rem; height: 3.5rem; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
}
.auth-ico .icon { width: 1.6rem; height: 1.6rem; }
.auth-ico-warn { background: var(--warn-soft); color: var(--warn); }

/* Welcome */
.welcome { display: grid; gap: var(--space-7); align-items: center; }
.welcome-copy { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.welcome-copy .lead { max-width: 32rem; }
.how { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-4); }
.how li { display: flex; gap: var(--space-3); align-items: flex-start; }
.how li > div { display: flex; flex-direction: column; min-width: 0; }
.how-ico {
  flex: none; display: grid; place-items: center; width: 2.75rem; height: 2.75rem;
  border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary);
}
.welcome-cta { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }
.welcome-art { position: relative; display: flex; flex-direction: column; gap: var(--space-4); padding-block: var(--space-2); }
.art-card {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.art-card .gauge { margin: 0; }
.art-text { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; min-width: 0; }
.art-text strong { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }
.art-caption { text-align: center; }
@media (min-width: 900px) {
  .welcome { grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: var(--space-8); }
  .welcome-cta { max-width: 26rem; }
  .art-card-a { transform: rotate(-2.2deg) translateX(-1.5rem); }
  .art-card-b { transform: rotate(1.8deg) translateX(2rem); }
  .art-card { padding: var(--space-5) var(--space-6); }
}

/* Onboarding */
.steps-progress { display: flex; gap: var(--space-2); list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.steps-progress li { flex: 1; height: .4rem; border-radius: 999px; background: color-mix(in srgb, var(--text) 12%, transparent); transition: background .3s; }
.steps-progress li.is-current, .steps-progress li.is-done { background: var(--primary); }
.steps-progress li.is-current { box-shadow: 0 0 0 3px var(--primary-soft); }
.onboard-card { display: flex; flex-direction: column; gap: var(--space-5); padding: clamp(var(--space-5), 5vw, var(--space-6)); box-shadow: var(--shadow-lg); }
.step { padding: 0; }
.step + .step { border-top: 1px dashed var(--border); padding-top: var(--space-5); }
.is-stepping .step + .step { border-top: 0; padding-top: 0; }
.step-title { font-size: clamp(1.55rem, 1.2rem + 1.5vw, 2.1rem); margin-bottom: var(--space-2); outline: none; }
.step-actions { display: flex; gap: var(--space-3); }
.step-actions [data-step-next], .step-actions [data-step-submit] { margin-left: auto; }
.stepper-nav { display: flex; gap: var(--space-3); }

/* ---------- Home ---------- */
.home-grid { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); }
.home-grid > * { min-width: 0; }
.home-head { margin-bottom: 0; }
.scan-hero {
  position: relative; isolation: isolate; overflow: hidden;
  display: flex; flex-direction: column; gap: var(--space-5);
  padding: clamp(var(--space-5), 5vw, var(--space-7));
  border-radius: calc(var(--radius) + 6px);
  background: linear-gradient(135deg, #1B4F43 0%, #2B7466 62%, #3A8878 100%);
  color: #fff; box-shadow: var(--shadow-lg);
}
.scan-hero::before, .scan-hero::after { content: ""; position: absolute; z-index: -1; border-radius: 50%; }
.scan-hero::before { width: 16rem; height: 16rem; right: -4rem; top: -6rem; background: radial-gradient(circle, rgba(232, 115, 90, .6), transparent 68%); }
.scan-hero::after { width: 22rem; height: 22rem; right: -9rem; bottom: -13rem; border: 2px solid rgba(255, 255, 255, .14); box-shadow: 0 0 0 2.2rem rgba(255, 255, 255, .05), 0 0 0 4.4rem rgba(255, 255, 255, .03); }
.scan-hero h2 { font-size: clamp(1.5rem, 1.1rem + 1.8vw, 2.2rem); max-width: 22rem; color: #fff; }
.scan-hero p { color: rgba(255, 255, 255, .92); max-width: 28rem; }
.scan-hero-copy { display: flex; flex-direction: column; gap: var(--space-2); }
.scan-left { margin-top: var(--space-1); }
.scan-left strong { font-family: var(--font-display); font-size: 1.3rem; }
.scan-hero-btn { align-self: flex-start; }
@media (min-width: 640px) { .scan-hero { flex-direction: row; align-items: center; justify-content: space-between; } .scan-hero-btn { align-self: center; } }
.premium-pill { align-self: center; }
.kids-row { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-4); }
.kid { display: flex; flex-direction: column; align-items: center; gap: .15rem; min-width: 5rem; min-height: 44px; padding: var(--space-2); border-radius: var(--radius-sm); color: inherit; text-decoration: none; text-align: center; }
a.kid:hover { background: var(--primary-soft); }
.kid-name { font-weight: 800; max-width: 7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signup-card { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-3); background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.signup-ico { display: grid; place-items: center; width: 2.9rem; height: 2.9rem; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); }
@media (min-width: 640px) { .signup-card { flex-direction: row; align-items: center; } .signup-card > div { flex: 1; } }
.recent .card-header { margin-bottom: var(--space-3); }
.recent .empty-state { box-shadow: var(--shadow); }
@media (min-width: 900px) {
  .home-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: var(--space-5) var(--space-6); align-items: start; }
  .home-grid > .home-head, .home-grid > .scan-hero { grid-column: 1 / -1; }
}

/* ---------- Scan ---------- */
.page-scan { max-width: 46rem; }
.scanner { position: relative; padding: 0; overflow: hidden; }
.scan-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .25rem; padding: .4rem; background: var(--surface-2); }
.scan-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
  min-height: 56px; padding: .4rem .3rem; border: 0; border-radius: 12px;
  background: transparent; color: var(--text-muted); cursor: pointer;
  font-size: .85rem; font-weight: 800; line-height: 1.15; text-align: center;
  transition: background .15s, color .15s, box-shadow .15s;
}
.scan-tab .icon { width: 1.35rem; height: 1.35rem; }
.scan-tab:hover { color: var(--text); }
.scan-tab[aria-selected="true"] { background: var(--surface); color: var(--primary); box-shadow: 0 2px 8px -2px rgba(0, 0, 0, .18); }
@media (min-width: 560px) { .scan-tab { flex-direction: row; gap: .5rem; font-size: .95rem; } }
.scan-stage { position: relative; padding: var(--space-5); }
.scan-panel { display: flex; flex-direction: column; gap: var(--space-4); }
.camera-box {
  position: relative; overflow: hidden; width: 100%;
  aspect-ratio: 4 / 3; max-height: 62vh;
  border-radius: var(--radius-sm); background: #10151C;
}
.camera-box video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: transparent; }
.camera-idle {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2);
  color: rgba(255, 255, 255, .72); font-weight: 700;
}
.camera-idle .icon { width: 3rem; height: 3rem; }
.scan-frame { position: absolute; left: 50%; top: 50%; width: 74%; height: 46%; transform: translate(-50%, -50%); pointer-events: none; opacity: .55; transition: opacity .3s; }
.scan-frame i { position: absolute; width: 1.8rem; height: 1.8rem; border: 0 solid #8FE0CD; }
.scan-frame i:nth-child(1) { left: 0; top: 0; border-width: 4px 0 0 4px; border-top-left-radius: 12px; }
.scan-frame i:nth-child(2) { right: 0; top: 0; border-width: 4px 4px 0 0; border-top-right-radius: 12px; }
.scan-frame i:nth-child(3) { left: 0; bottom: 0; border-width: 0 0 4px 4px; border-bottom-left-radius: 12px; }
.scan-frame i:nth-child(4) { right: 0; bottom: 0; border-width: 0 4px 4px 0; border-bottom-right-radius: 12px; }
.scan-frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #FF8A72; box-shadow: 0 0 12px #FF8A72; opacity: 0; }
[data-camera-state="live"] .camera-idle, [data-camera-state="live"] [data-camera-start] { display: none; }
[data-camera-state="live"] .scan-frame { opacity: 1; }
[data-camera-state="live"] .scan-frame::after { opacity: .9; animation: laser 2.2s ease-in-out infinite alternate; }
.camera-select-field:has(select[hidden]) { display: none; }
.photo-preview { width: 100%; max-height: 18rem; object-fit: contain; border-radius: var(--radius-sm); background: var(--surface-2); }
.scan-busy {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  font-weight: 800;
}
.scan-result:empty { display: none; }
.scan-result { padding: 0 var(--space-5) var(--space-5); }
.scan-note { margin-top: var(--space-4); }

/* ---------- Result ---------- */
.back-row { margin-bottom: var(--space-2); }
.back-link { display: inline-flex; align-items: center; gap: var(--space-1); min-height: 44px; color: var(--text-muted); font-weight: 800; text-decoration: none; }
.back-link:hover { color: var(--primary); }
.back-link .icon { width: 1.1rem; height: 1.1rem; }
.split { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); }
.split > * { min-width: 0; }
@media (min-width: 900px) {
  .split { grid-template-columns: minmax(18rem, 22rem) minmax(0, 1fr); gap: var(--space-6); align-items: start; }
  .split-side { position: sticky; top: var(--space-5); }
}
.verdict-card {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-4);
  text-align: center; padding: var(--space-6) var(--space-5) var(--space-5);
  background: linear-gradient(180deg, color-mix(in srgb, var(--tint, var(--primary)) 16%, var(--surface)) 0%, var(--surface) 62%);
  box-shadow: var(--shadow-lg);
}
.verdict-safe { --tint: var(--score-green); }
.verdict-caution { --tint: var(--score-amber); }
.verdict-avoid { --tint: var(--score-red); }
.verdict-text { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); min-width: 0; max-width: 100%; }
.verdict-name { font-size: clamp(1.4rem, 1.1rem + 1vw, 1.8rem); overflow-wrap: anywhere; }
.product-img { width: 4rem; height: 4rem; object-fit: contain; border-radius: var(--radius-sm); background: #fff; border: 1px solid var(--border); margin-bottom: var(--space-2); }
.glance { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--space-2); }
.glance li { display: flex; flex-direction: column; align-items: center; padding: var(--space-2); border-radius: var(--radius-sm); background: var(--surface-2); line-height: 1.2; }
.glance b { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; }
.glance span { font-size: .8rem; color: var(--text-muted); font-weight: 700; }
.verdict-actions { display: grid; gap: var(--space-2); width: 100%; }
.split-main { display: flex; flex-direction: column; gap: var(--space-4); }
.split-main > [data-safety], .split-main > [data-insight] { min-width: 0; }
.insight { background: linear-gradient(135deg, var(--primary-soft), var(--surface) 55%); }
.insight-summary { font-size: 1.05rem; margin-bottom: var(--space-3); }
.insight-rec { display: flex; gap: var(--space-3); margin-top: var(--space-3); align-items: flex-start; }
.insight-rec .icon { color: var(--primary); margin-top: .2rem; }
.insight .notice { margin-top: var(--space-2); }
.insight-caption { margin-top: var(--space-3); }
.insight-loading { display: flex; align-items: center; gap: var(--space-3); color: var(--text-muted); font-weight: 700; animation: vanish 0s 45s forwards; }
.insight-loading .spinner { width: 1.4rem; height: 1.4rem; border-width: 2.5px; }
[data-insight][aria-busy="false"] .insight-loading { display: none; }

.safety { gap: var(--space-4); }
.verdict-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.verdict-head .card-title { font-size: 1.3rem; }
.verdict-ico { flex: none; display: grid; place-items: center; width: 2.9rem; height: 2.9rem; border-radius: 50%; }
.verdict-ok { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); background: linear-gradient(135deg, var(--ok-soft), var(--surface) 65%); }
.verdict-ok .verdict-ico { background: var(--ok-soft); color: var(--ok); }
.verdict-danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: linear-gradient(135deg, var(--danger-soft), var(--surface) 65%); }
.verdict-danger .verdict-ico { background: var(--danger-soft); color: var(--danger); }
.verdict-ok .avatar-stack { margin-top: var(--space-1); }
.verdict-safe-for { margin-top: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }

.recall-alert { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.recall-item { display: flex; flex-direction: column; gap: var(--space-2); background: var(--danger-soft); }
.recall-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.recall-firm { display: flex; align-items: center; gap: .35rem; }
.recall-firm .icon { width: 1rem; height: 1rem; }

.sugar-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); }
.sugar-num { display: flex; flex-direction: column; line-height: 1.1; }
.sugar-num b { font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; }
.sugar-serving { text-align: right; }
.sugar-ok { color: var(--ok); }
.sugar-warn { color: var(--warn); }
.sugar-danger { color: var(--danger); }
.sugar-kids { list-style: none; margin: var(--space-4) 0 0; padding: var(--space-4) 0 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--space-4); }
.sugar-kids li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-1) var(--space-3); }
.sugar-kid-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sugar-kids .small { font-weight: 800; text-align: right; }
.meter { grid-column: 1 / -1; display: block; height: .5rem; border-radius: 999px; background: color-mix(in srgb, var(--text) 10%, transparent); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: inherit; background: currentColor; }

.ingredients { list-style: none; margin: 0; padding: 0; }
.ing { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); padding: .6rem 0; color: var(--text-muted); }
.ing + .ing { border-top: 1px solid var(--border); }
.ing-dot { flex: none; width: .5rem; height: .5rem; border-radius: 50%; background: color-mix(in srgb, var(--brand) 55%, transparent); }
.ing-name { flex: 1 1 8rem; min-width: 0; overflow-wrap: anywhere; }
.ing-dye, .ing-allergen { color: var(--text); font-weight: 700; }
.ing-dye .ing-dot { background: var(--accent); }
.ing-allergen .ing-dot { background: var(--danger); }

.result-foot { display: flex; justify-content: center; }
.disclaimer { text-align: center; max-width: 38rem; margin: var(--space-2) auto 0; }

/* ---------- Motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes gauge-draw { from { stroke-dasharray: 0 100; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes laser { from { top: 12%; } to { top: 88%; } }
@keyframes vanish { to { opacity: 0; visibility: hidden; height: 0; margin: 0; padding: 0; border: 0; overflow: hidden; } }
@keyframes sc-pulse { 50% { opacity: .45; } }

.reveal > * { animation: rise .65s cubic-bezier(.2, .7, .2, 1) backwards; }
.reveal > :nth-child(1) { animation-delay: .04s; }
.reveal > :nth-child(2) { animation-delay: .11s; }
.reveal > :nth-child(3) { animation-delay: .18s; }
.reveal > :nth-child(4) { animation-delay: .25s; }
.reveal > :nth-child(5) { animation-delay: .32s; }
.reveal > :nth-child(6) { animation-delay: .39s; }
.reveal > :nth-child(7) { animation-delay: .46s; }
.reveal > :nth-child(8) { animation-delay: .53s; }
.reveal > :nth-child(n + 9) { animation-delay: .6s; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .spinner, .btn.is-loading::after { animation: spin 1.8s linear infinite !important; }
  .insight-loading { animation: none !important; }
}
