:root {
  color-scheme: light;
  --page: #F4F5F2;
  --card: #FFFFFF;
  --line: #E3E5DF;
  --ink: #121514;
  --ink-2: #4A514E;
  --ink-3: #5F6663;
  --accent: #2A78D6;
  --accent-ink: #1C5CAB;
  --accent-track: #CDE2FB;
  --accent-soft: #EAF1FB;
  --good-ink: #006300;
  --good-soft: #E8F3E8;
  --bad-ink: #B42318;
  --field-line: #C3C6BE;
  --btn: #121514;
  --btn-ink: #FFFFFF;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0D0D0D;
    --card: #1A1A19;
    --line: #2C2C2A;
    --ink: #F0EFEC;
    --ink-2: #C3C2B7;
    --ink-3: #A3A29A;
    --accent: #3987E5;
    --accent-ink: #86B6EF;
    --accent-track: #1B3352;
    --accent-soft: #10294A;
    --good-ink: #4CC94C;
    --good-soft: #12300F;
    --bad-ink: #F97066;
    --field-line: #4A4A46;
    --btn: #F0EFEC;
    --btn-ink: #121514;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 600; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 600; }
p { margin: 0; }

.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(20px, env(safe-area-inset-top)) 16px 12px;
}
.heading { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sub { font-size: 14px; color: var(--ink-2); }

.cards {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 16px max(24px, env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty { color: var(--ink-2); }

.narrow {
  max-width: 430px;
  margin: 0 auto;
  padding: max(48px, env(safe-area-inset-top)) 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 13px; color: var(--ink-2); }
input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--field-line);
  border-radius: 12px;
  padding: 0 14px;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--card);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--btn);
  color: var(--btn-ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-quiet {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--field-line);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.error { color: var(--bad-ink); font-size: 14px; font-weight: 500; }

.link-btn {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Header day arrows */
.day-nav { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.icon-btn:hover { background: var(--accent-soft); }

/* Calories */
.hero { display: flex; flex-direction: column; gap: 4px; }
.hero-number { font-size: 56px; line-height: 1; font-weight: 600; letter-spacing: -0.02em; }
.hero-label { color: var(--ink-2); }
.note { font-size: 13px; color: var(--ink-2); }

/* Macros */
.meter-block { display: flex; flex-direction: column; gap: 8px; }
.meter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.meter-name { font-size: 14px; font-weight: 500; }
.meter-figure { font-size: 14px; color: var(--ink-2); }
.strong { font-weight: 600; color: var(--ink); }
.meter { height: 8px; border-radius: 4px; background: var(--accent-track); overflow: hidden; }
.meter-fill { height: 8px; border-radius: 4px; background: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--page);
}
.tile-label { font-size: 12px; color: var(--ink-3); }
.tile-value { font-size: 17px; font-weight: 600; }

/* Meals */
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.count { font-size: 13px; color: var(--ink-2); }
.meal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.meal {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.meal-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; }
.meal-end { display: flex; align-items: center; gap: 4px; }
.meal-desc { font-size: 14px; overflow-wrap: anywhere; }
.meal-meta { font-size: 13px; color: var(--ink-3); }
/* 44 px touch target; the negative margin keeps the row as tall as its text. */
.delete-btn {
  width: 44px;
  height: 44px;
  margin: -12px -12px -12px 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.delete-btn:hover { color: var(--bad-ink); background: var(--accent-soft); }

/* Weight */
.weight-form { display: flex; align-items: flex-end; gap: 10px; }
.grow { flex-grow: 1; min-width: 0; }
.weight-form .btn-quiet { min-height: 48px; padding: 0 18px; font-weight: 600; }

.foot {
  display: flex;
  justify-content: center;
  padding: 0 16px max(24px, env(safe-area-inset-bottom));
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
