:root {
  --bg: #f5f6f3;
  --card: #ffffff;
  --ink: #1b211d;
  --muted: #667069;
  --line: #dfe3dd;
  --brand: #1f7a4d;
  --brand-ink: #ffffff;
  --warn: #b3402a;
  --track: #e6eae4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --card: #1c211d;
    --ink: #edf1ec;
    --muted: #9aa59d;
    --line: #2d342f;
    --brand: #3fae76;
    --brand-ink: #08130c;
    --warn: #ef8a72;
    --track: #2a312c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* 18px body and nothing you have to read under 16px: the app is used at arm's length. */
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

h1 { font-size: 26px; margin: 4px 0 16px; }
h2 { font-size: 20px; margin: 20px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 16px; }
/* Classes that set `display` would otherwise show an element marked hidden. */
[hidden] { display: none !important; }
.error { color: var(--warn); margin: 8px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 46px;
  cursor: pointer;
}
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--warn); }
button.link { border: 0; background: none; padding: 6px 8px; min-height: 0; color: var(--brand); }
button.link.danger { color: var(--warn); }
button:disabled { opacity: 0.5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }
.wide { width: 100%; }

label { display: grid; gap: 4px; font-size: 16px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
  font-size: 18px; /* below 16px, iOS zooms the page on focus */
  color: var(--ink);
}
textarea { resize: vertical; min-height: 60px; }

/* Day header */
.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.daynav strong { font-size: 24px; }
.daynav button { min-width: 52px; font-size: 24px; }

/* Summary */
.big { font-size: 52px; font-weight: 700; line-height: 1.1; }
.big .unit { font-size: 20px; font-weight: 400; color: var(--muted); }
.bar { height: 14px; background: var(--track); border-radius: 7px; overflow: hidden; margin: 12px 0 8px; }
.bar > div { height: 100%; background: var(--brand); border-radius: 7px; }
.bar.over > div { background: var(--warn); }
.left { font-size: 20px; color: var(--muted); margin-bottom: 6px; }
.left b { color: var(--ink); }
.left.over b { color: var(--warn); }
/* Full-strength ink, not grey: it is a sentence to be read, and grey made it harder. */
.planline { font-size: 19px; line-height: 1.35; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; text-align: center; }
.macros b { display: block; font-size: 24px; }

/* Meal list */
.meal { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; }
.meal img, .meal .nothumb {
  width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; background: var(--track);
}
/* Larger text fits fewer letters on a line, so a title wraps to a second line before it is cut. */
.meal .title {
  font-weight: 600; line-height: 1.25; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.meal .kcal { font-size: 22px; font-weight: 700; white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Meal editor */
.preview { width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; display: block; margin-bottom: 12px; }
.item { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.item:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.nums input { padding: 10px 6px; text-align: center; }
.badge { display: inline-block; font-size: 15px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.totals { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); }

/* Weight */
.chart { width: 100%; height: 160px; display: block; }
.chart polyline { fill: none; stroke: var(--brand); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart polyline.raw { stroke: var(--muted); stroke-width: 1; opacity: 0.6; }
.chart polyline.goal { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 5 4; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.legend span::before {
  content: ""; display: inline-block; width: 16px; margin-right: 6px; vertical-align: middle;
  border-top: 2.5px solid var(--brand);
}
.legend .raw::before { border-top: 1px solid var(--muted); }
.legend .goal::before { border-top: 1.5px dashed var(--ink); }
.chart text { fill: var(--muted); font-size: 11px; }
.weightrow { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.weightrow:first-child { border-top: 0; }

/* Waist sizes */
.cardtitle { margin: 0 0 6px; }
.weightrow .sizecol { font-size: 22px; min-width: 60px; }
.weightrow .grow { color: var(--muted); }
.reached { color: var(--brand); }
.sizenote { margin-top: 8px; }

/* Bottom nav */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs div { display: flex; width: 100%; max-width: 560px; }
nav.tabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: 14px 4px; color: var(--muted); }
nav.tabs button.on { color: var(--brand); font-weight: 700; }

.overlay {
  position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 85%, transparent);
  display: grid; place-items: center; text-align: center; padding: 24px; z-index: 10;
}
.spinner {
  width: 36px; height: 36px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid var(--track); border-top-color: var(--brand); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
