:root {
  --stage: #cfc3b2;
  --bg: #f3eee6;
  --surface: #fbf7f1;
  --raised: #fffdf9;
  --sunken: #ebe4d8;
  --ink: #1c1712;
  --muted: #6d645b;
  --faint: #9a9086;
  --line: rgba(28, 23, 18, 0.1);
  --accent: #3f5d45;
  --accent-soft: rgba(63, 93, 69, 0.12);
  --heat: #c45c26;
  --protein: #3d4f7c;
  --carbs: #b8892a;
  --fat: #8b4a62;
  --amber: #c4922a;
  --shadow: 0 18px 50px rgba(48, 36, 22, 0.18);
  color-scheme: light;
}

html[data-theme="dark"] {
  --stage: #12100e;
  --bg: #161311;
  --surface: #221e1a;
  --raised: #2c2621;
  --sunken: #0f0d0b;
  --ink: #f3ebe1;
  --muted: #a89a8c;
  --faint: #7a6e63;
  --line: rgba(243, 235, 225, 0.12);
  --accent: #8fad93;
  --accent-soft: rgba(143, 173, 147, 0.18);
  --heat: #e08a55;
  --protein: #9aabd4;
  --carbs: #d4b56a;
  --fat: #c4899e;
  --amber: #d4a84a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  min-height: 100%;
  min-height: 100dvh;
}
html, body {
  overflow-x: hidden;
  overflow-y: auto;
}
body {
  min-height: 100%;
  min-height: 100dvh;
  font-family: Figtree, system-ui, sans-serif;
  background: var(--stage);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app {
  width: 100%;
  max-width: none;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

/* Phone frame only on larger screens — mobile stays full-bleed (no beige gutters). */
@media (min-width: 500px) {
  html, body {
    overflow: auto;
  }
  body {
    min-height: 100dvh;
    padding: 24px 0;
  }
  .app {
    height: auto;
    max-width: 430px;
    min-height: min(844px, calc(100dvh - 48px));
    max-height: calc(100dvh - 48px);
    border-radius: 42px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}

/* Scan page: fixed viewport so the camera stage doesn’t bounce. */
body:has(.scanner) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: #0e0c0a;
}
.app:has(.scanner) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: #0e0c0a;
}

.screen {
  flex: 1 0 auto;
  overflow: visible;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px calc(108px + env(safe-area-inset-bottom, 0px));
  scrollbar-width: none;
}
.screen::-webkit-scrollbar { display: none; }
.screen.is-bare {
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px calc(28px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 500px) {
  .screen {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.kicker { font-size: 13px; font-weight: 550; color: var(--muted); }
.display {
  font-family: Fraunces, Georgia, serif;
  font-size: 34px;
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1.05;
}
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid; place-items: center;
}
.row-actions { display: flex; gap: 8px; }

.hero {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 22px 20px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
}
.hero .remaining {
  font-family: Fraunces, Georgia, serif;
  font-size: 64px;
  letter-spacing: -0.05em;
  line-height: 0.9;
}
.hero .unit { color: var(--muted); font-weight: 550; margin-top: 6px; }
.hero .eaten { font-size: 13px; color: var(--muted); margin-top: 14px; }
.ring { width: 92px; height: 92px; }
.ring circle { fill: none; stroke-width: 8; stroke-linecap: round; }
.ring .track { stroke: var(--sunken); }
.ring .value { stroke: var(--accent); transform-origin: 50% 50%; transform: rotate(-90deg); }

.glance {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-top: 12px;
  scrollbar-width: none;
}
.glance::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto;
  min-width: 108px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px 11px;
  text-align: left;
}
.pill b { display: block; font-size: 14px; }
.pill span { color: var(--muted); font-size: 11px; font-weight: 550; }
.pill .bar { margin-top: 8px; }

.macros {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.macro {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 12px 11px;
}
.macro b { display: block; font-size: 15px; font-weight: 650; }
.macro span { color: var(--muted); font-size: 12px; }
.bar {
  height: 4px; border-radius: 99px;
  background: var(--sunken); margin-top: 10px; overflow: hidden;
}
.bar i { display: block; height: 100%; border-radius: inherit; max-width: 100%; }

.section-title {
  margin: 26px 0 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.section-title h2 {
  font-family: Fraunces, Georgia, serif;
  font-size: 22px;
  font-weight: 500;
}
.section-title a, .section-title button { color: var(--accent); font-weight: 650; font-size: 13px; }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 20px;
}
.empty p { margin-top: 6px; font-size: 14px; }

.tabbar {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  height: 72px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 28px;
  display: grid;
  grid-template-columns: 1fr 56px 1fr;
  align-items: stretch;
  z-index: 6;
  padding: 0 6px;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
}
.tab svg { display: block; }
.tab.is-on { color: var(--ink); }
.tab-add { display: grid; place-items: center; }
.fab {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
}

.sheet-bg {
  position: fixed; inset: 0; background: rgba(20, 14, 8, 0.45);
  z-index: 10; display: none;
}
.sheet-bg.is-on { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(28px + env(safe-area-inset-bottom));
  z-index: 11;
  transform: translateY(110%);
  transition: transform 0.32s cubic-bezier(.2,.8,.2,1);
  visibility: hidden;
}
.sheet.is-on { transform: translateY(0); visibility: visible; }
.grab { width: 42px; height: 4px; border-radius: 99px; background: var(--sunken); margin: 6px auto 16px; }
.sheet h3 {
  font-family: Fraunces, Georgia, serif;
  font-size: 28px; font-weight: 500; letter-spacing: -0.03em;
}
.sheet p.sub { color: var(--muted); margin: 6px 0 18px; }

@media (min-width: 500px) {
  .tabbar,
  .sheet-bg,
  .sheet {
    position: absolute;
  }
}

.method {
  width: 100%;
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 14px;
  text-align: left;
  padding: 14px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  margin-bottom: 10px;
}
.method .mark {
  width: 48px; height: 48px; border-radius: 16px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.method strong { display: block; font-size: 16px; }
.method small { color: var(--muted); }

.back {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-weight: 550; margin-bottom: 14px;
}

.search {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
}
.shops {
  display: flex; gap: 8px; overflow-x: auto; margin: 14px 0 8px;
  scrollbar-width: none;
}
.shops::-webkit-scrollbar { display: none; }
.shop {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px; font-weight: 600;
}
.shop.is-on { background: var(--ink); color: var(--bg); border-color: transparent; }

.composer {
  min-height: 140px;
  width: 100%;
  resize: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  outline: none;
  margin-top: 14px;
}
.primary, .ghost {
  width: 100%; height: 52px; border-radius: 16px; font-weight: 650;
}
.primary { background: var(--ink); color: var(--bg); margin-top: 16px; }
.ghost { border: 1px solid var(--line); margin-top: 8px; }
.ghost.danger { color: var(--heat); border-color: rgba(196, 92, 38, 0.28); }
.note { font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 12px; }
.note a { color: var(--ink); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; }
.note code { font: inherit; font-weight: 650; color: var(--ink); }

.scanner {
  background: #0e0c0a;
  color: #f6efe7;
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
}
.scanner.has-confirm .scan-copy,
.scanner.has-confirm .scanner-stage,
.scanner.has-confirm .scan-actions {
  visibility: hidden;
}
.scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  opacity: 0;
  background: #0e0c0a;
}
.scan-video.is-on { opacity: 1; }
.scan-canvas { display: none; }
.scan-dim {
  position: absolute;
  inset: 0;
  background: rgba(14, 12, 10, 0.32);
  pointer-events: none;
  z-index: 1;
}
.scanner .back,
.scanner .scan-copy,
.scanner .finder,
.scanner .note,
.scanner .scan-actions {
  position: relative;
  z-index: 2;
}
.scanner .back {
  color: #cbb9a6;
  align-self: flex-start;
  margin-bottom: 10px;
}
.scanner .scan-copy {
  text-align: center;
  margin-bottom: 8px;
}
.scanner .kicker, .scanner .note { color: #cbb9a6; }
.scanner .display {
  color: #f6efe7;
  font-size: clamp(24px, 7vw, 28px);
}
.scanner-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0 20px;
}
.finder {
  width: min(280px, 78vw);
  height: min(168px, 22vh);
  border: 2px solid rgba(246,239,231,.85);
  border-radius: 18px;
  position: relative;
  z-index: 2;
  pointer-events: none;
  flex: 0 0 auto;
}
.finder.is-lock { border-color: #e07a4a; }
.finder::after {
  content: "";
  position: absolute; left: 16px; right: 16px; top: 46%;
  height: 2px; background: #e07a4a;
  animation: scan 1.8s ease-in-out infinite;
}
@keyframes scan {
  0%, 100% { top: 18%; }
  50% { top: 78%; }
}
.scanner #scan-status {
  margin: 0;
  text-align: center;
  max-width: 20rem;
  line-height: 1.35;
  padding: 0 8px;
}
.scan-actions {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 auto;
  padding-top: 8px;
}
.scan-actions .primary,
.scan-actions .ghost {
  margin-top: 0;
}
.scan-actions .ghost {
  display: grid;
  place-items: center;
  color: #f6efe7;
  border-color: rgba(246,239,231,.2);
}
.scan-input {
  background: rgba(246,239,231,.08);
  border-color: rgba(246,239,231,.22);
  color: #f6efe7;
  text-align: center;
  letter-spacing: 0.06em;
  margin-bottom: 0;
}
.scan-input::placeholder { color: #8a7d72; }
.scanner .banner {
  color: #e07a4a;
  margin: 0;
  text-align: center;
}

.scan-confirm {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px calc(28px + env(safe-area-inset-bottom, 0px));
}
.scan-confirm .back { color: var(--muted); }
.scan-confirm .display { color: var(--ink); }
.scan-confirm[hidden] { display: none !important; }

.portion-base {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 550;
}
.grams-field {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px auto 0;
  width: fit-content;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.grams-field[hidden] { display: none !important; }
.grams-field input {
  width: 5.5rem;
  border: 0;
  background: transparent;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 18px;
  outline: none;
}
.grams-field span {
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.scan-confirm .grams-field {
  background: var(--surface);
}
.stepper-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 7rem;
}

.field {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0; border-top: 1px solid var(--line);
  gap: 10px;
}
.field span { color: var(--muted); }
.field input, .field select {
  border: 0;
  background: transparent;
  text-align: right;
  color: var(--muted);
  min-width: 0;
  width: 9.5rem;
  outline: none;
}
.field .suffix { width: auto; }
.banner {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 650;
  color: var(--accent);
}
.banner.is-error { color: var(--heat); }

.theme-form { margin: 4px 0 8px; }
.theme-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.theme-chip {
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 650;
}
.theme-chip.is-on {
  background: var(--ink);
  color: var(--bg);
  border-color: transparent;
}

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 18px; }
.week-strip.compact { margin-top: 14px; }
.day {
  padding: 10px 0 8px; border-radius: 16px; text-align: center;
  background: var(--surface); border: 1px solid transparent;
  min-height: 62px;
}
.day.is-on { border-color: var(--ink); }
.day .d { font-size: 11px; color: var(--muted); }
.day .n { font-weight: 650; margin: 4px 0; }
.dot { width: 7px; height: 7px; border-radius: 99px; margin: 0 auto; background: var(--accent); }
.dot.low { background: var(--amber); }
.soon {
  margin-top: 22px;
  padding: 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.hints { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }
.hint {
  padding: 8px 12px; border-radius: 99px;
  background: var(--sunken); font-size: 13px;
}

.meal { margin-bottom: 18px; }
.meal-h {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; font-weight: 650; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 8px;
}
.food {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  text-align: left;
  width: 100%;
}
.result {
  width: 100%;
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  text-align: left;
}
.results { margin-top: 8px; }
.result strong, .food strong { display: block; font-size: 15px; font-weight: 600; }
.result small, .food small { display: block; color: var(--muted); font-size: 12px; }
.thumb {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--sunken);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 650; color: var(--muted);
}
.kcal { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 14px; }
.source {
  display: inline-flex; align-items: center;
  padding: 2px 7px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 650; margin-left: 4px;
}
.source.est { background: rgba(196, 92, 38, 0.12); color: var(--heat); }

.meals {
  display: flex; gap: 8px; flex-wrap: wrap;
  justify-content: center; margin-top: 14px;
}
.meal-chip {
  padding: 8px 12px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 600;
  position: relative;
}
.meal-chip input {
  position: absolute; opacity: 0; pointer-events: none;
}
.meal-chip.is-on { background: var(--ink); color: var(--bg); border-color: transparent; }

.product-hero { text-align: center; padding-top: 8px; }
.product-hero .big-thumb {
  width: 92px; height: 92px; border-radius: 28px;
  background: var(--sunken); margin: 0 auto 14px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 650; color: var(--muted);
}
.stepper {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin: 16px 0 6px;
}
.stepper b { font-size: 22px; font-family: Fraunces, Georgia, serif; }
.round {
  width: 40px; height: 40px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
}
.facts { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 14px; }
.facts td { padding: 9px 0; border-top: 1px solid var(--line); }
.facts td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }

.toast {
  position: absolute; left: 24px; right: 24px;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg);
  padding: 12px 16px; border-radius: 14px;
  font-weight: 600; font-size: 14px;
  z-index: 12; display: none; text-align: center;
}
.toast.is-on { display: block; }
.scanner .toast {
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  z-index: 8;
}
