:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-strong: #edf5ef;
  --text: #14211d;
  --muted: #64716a;
  --line: #d6ded7;
  --brand: #123c32;
  --brand-2: #2d6a55;
  --accent: #d58a58;
  --warn: #a84d2d;
  --ok: #25734d;
  --soft-warn: #f7e7dd;
  --shadow: 0 16px 46px rgb(18 38 32 / 10%);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, #e4efe8 0, transparent 390px),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 4vw, 32px) 40px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 12px;
}

.brand-logo {
  display: block;
  width: min(260px, 68vw);
  height: auto;
  margin-bottom: 12px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 0.95rem;
  font-weight: 900;
  text-transform: none;
  letter-spacing: 0;
}

.eyebrow::before {
  content: "V";
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  font-weight: 950;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 720px;
  margin-bottom: 0;
  font-size: clamp(1.55rem, 4.5vw, 2.65rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 620px;
  margin: 12px 0 0;
  font-size: 1rem;
}

h2 {
  margin-bottom: 4px;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
  letter-spacing: 0;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.08rem;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

main {
  display: grid;
  gap: 14px;
}

.app-footer {
  padding: 18px 4px 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.band {
  padding: clamp(16px, 4vw, 24px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 84%);
  box-shadow: var(--shadow);
}

.profile-band,
.dashboard-band {
  background: var(--surface);
}

.mode-band {
  background:
    linear-gradient(90deg, rgb(18 60 50 / 5%), rgb(213 138 88 / 8%)),
    var(--surface);
}

.section-header,
.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-header p,
.dialog-header p {
  margin-bottom: 0;
}

.meter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.meter {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.meter-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.meter-value {
  margin-bottom: 10px;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 800;
}

.meter-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #d7e1db;
}

.meter-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand-2);
}

.meter-fill.warn {
  background: var(--warn);
}

.mode-selector {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.mode-card {
  display: grid;
  gap: 6px;
  min-height: 128px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.mode-card[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--surface-strong);
  box-shadow: inset 0 0 0 2px rgb(18 60 50 / 18%);
}

.mode-card span {
  color: var(--brand-2);
  font-size: 0.82rem;
  font-weight: 860;
  text-transform: uppercase;
}

.mode-card strong {
  font-size: clamp(1.08rem, 3vw, 1.45rem);
  line-height: 1.12;
}

.mode-card small {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

body:not(.advanced-mode) .advanced-only,
body:not(.advanced-mode) .advanced-only-inline {
  display: none;
}

.quick-entry {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcf9;
}

.quick-entry-header h3,
.quick-entry-header p {
  margin-bottom: 4px;
}

.quick-entry-form {
  display: grid;
  grid-template-columns: 1.3fr 1fr repeat(4, minmax(92px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.entry-list {
  display: grid;
  gap: 10px;
}

.saved-meal-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}

.saved-meals {
  margin-top: 16px;
}

.saved-meals h3 {
  margin-bottom: 10px;
}

.empty-log {
  margin: 0;
  padding: 14px;
  border: 1px dashed #b8c5bd;
  border-radius: var(--radius);
  color: var(--muted);
  background: #fff;
}

.entry-item {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(90px, 0.6fr) minmax(0, 2fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.entry-name {
  display: grid;
  gap: 2px;
}

.entry-name strong {
  overflow-wrap: anywhere;
}

.entry-name span,
.entry-values {
  color: var(--muted);
  font-size: 0.86rem;
}

.entry-amount input {
  min-height: 38px;
}

.entry-values {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.scan-layout,
.controls-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.camera-panel,
.text-panel {
  display: grid;
  gap: 10px;
  align-content: start;
}

.scan-actions {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 10px;
}

.file-drop {
  display: grid;
  min-height: 158px;
  place-content: center;
  gap: 8px;
  padding: 18px;
  border: 2px dashed #a8b8af;
  border-radius: var(--radius);
  background: #fbfcf9;
  text-align: center;
  cursor: pointer;
}

.compact-drop {
  min-height: 118px;
}

.file-drop-title {
  color: var(--brand);
  font-size: 1.1rem;
  font-weight: 850;
}

.file-drop-subtitle,
.hint {
  color: var(--muted);
  font-size: 0.92rem;
}

#image-input,
#front-image-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.preview-image {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.analysis-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(12 28 23 / 58%);
  backdrop-filter: blur(2px);
}

.analysis-overlay[hidden] {
  display: none;
}

.analysis-box {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(100%, 340px);
  padding: 24px;
  border: 1px solid #cfd9d3;
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  text-align: center;
  box-shadow: var(--shadow);
}

.analysis-box strong {
  font-size: 1.2rem;
}

.analysis-box span {
  color: var(--muted);
}

.analysis-spinner {
  width: 52px;
  height: 52px;
  border: 5px solid #d9e2dd;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

label {
  display: grid;
  gap: 6px;
  color: #2c3733;
  font-size: 0.92rem;
  font-weight: 760;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 11px;
  border: 1px solid #c9d2cc;
  border-radius: var(--radius);
  color: var(--text);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 154px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgb(45 106 85 / 18%);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.confidence {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--brand);
  background: #dfeee6;
  font-size: 0.82rem;
  font-weight: 800;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 10px;
  color: #2c3733;
  font-weight: 820;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.meal-segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented button,
.secondary-button,
.primary-button,
.icon-button {
  border: 1px solid #b8c5bd;
  border-radius: var(--radius);
  cursor: pointer;
}

.segmented button {
  min-height: 42px;
  padding: 8px 9px;
  color: #2f3c37;
  background: #fff;
  font-size: 0.9rem;
  font-weight: 780;
}

.segmented button[aria-pressed="true"] {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

.amount-input {
  max-width: 220px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 10px 14px;
  font-weight: 850;
}

.primary-button {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

.secondary-button {
  color: var(--brand);
  background: #fff;
}

.primary-button:hover,
.secondary-button:hover,
.mode-card:hover,
.segmented button:hover {
  border-color: var(--brand-2);
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--brand);
  background: #fff;
  font-size: 1.45rem;
  line-height: 1;
}

.full-width {
  width: 100%;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.entry-actions {
  justify-content: flex-end;
  margin-top: 0;
}

.entry-actions .secondary-button {
  min-height: 38px;
  padding: 8px 10px;
}

.result-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.verdict {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--brand-2);
  font-size: 0.86rem;
  font-weight: 880;
}

.verdict.limit,
.verdict.not_best_today {
  background: var(--warn);
}

.verdict.unknown {
  color: #3e3326;
  background: #efd6a3;
}

.nutrition-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.comparison-note,
.source-note {
  margin-bottom: 12px;
}

.source-note {
  font-size: 0.82rem;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.comparison-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf8;
}

.comparison-item.better {
  border-color: #a7cdbc;
  background: #edf7f1;
}

.comparison-item.worse {
  border-color: #e2c0b0;
  background: var(--soft-warn);
}

.comparison-item span,
.comparison-item small {
  color: var(--muted);
}

.comparison-item span {
  font-size: 0.78rem;
  font-weight: 780;
}

.comparison-item strong {
  font-size: 1.05rem;
}

.comparison-item small {
  line-height: 1.28;
}

.summary-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf8;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 780;
}

.summary-item strong {
  display: block;
  margin-top: 4px;
  font-size: 1.05rem;
}

.reason-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.reason-list li {
  padding: 9px 10px;
  border-radius: var(--radius);
  background: #f2f6f3;
  color: #33413c;
}

.reason-list li.warning {
  background: var(--soft-warn);
  color: #703019;
}

dialog {
  width: min(760px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(14 24 20 / 56%);
}

.dialog-content {
  padding: clamp(16px, 4vw, 24px);
}

.disclaimer {
  margin: 14px 0 0;
  padding: 12px;
  border-radius: var(--radius);
  background: #f7f1e8;
  color: #5e4b38;
  font-size: 0.92rem;
}

.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;
}

@media (max-width: 840px) {
  .meter-grid,
  .mode-selector,
  .scan-layout,
  .controls-grid,
  .form-grid,
  .quick-entry-form,
  .saved-meal-tools,
  .entry-item,
  .comparison-grid,
  .nutrition-summary {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar,
  .section-header,
  .dialog-header,
  .result-head {
    align-items: stretch;
  }

  .section-header,
  .dialog-header,
  .result-head {
    flex-direction: column;
  }

  .meter-grid,
  .scan-layout,
  .controls-grid,
  .form-grid,
  .quick-entry-form,
  .saved-meal-tools,
  .scan-actions,
  .entry-item,
  .comparison-grid,
  .nutrition-summary {
    grid-template-columns: 1fr;
  }

  .segmented,
  .meal-segmented {
    grid-template-columns: 1fr 1fr;
  }

  .amount-input {
    max-width: none;
  }

  .button-row > * {
    flex: 1 1 180px;
  }
}
