:root {
  color-scheme: light;
  --surface-0: #f3f2ef;
  --surface-1: #fcfcfb;
  --border: #e2e1dc;
  --grid: #e8e7e3;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --series-1: #2a78d6;   /* blue */
  --series-2: #eb6834;   /* orange */
  --series-3: #1baf7a;   /* aqua */
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --critical: #d03b3b;
  --track: #ecebe7;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --border: #2e2e2c;
    --grid: #2a2a28;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --accent: #3987e5;
    --critical: #e66767;
    --track: #2a2a28;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
.top { display: flex; align-items: center; gap: 10px; padding: 14px 16px 4px; max-width: 640px; margin: 0 auto; }
.top h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-secondary); }

.view { max-width: 640px; margin: 0 auto; padding: 8px 12px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card h3 { margin: 18px 0 8px; font-size: 15px; }
label { display: block; font-size: 14px; color: var(--text-secondary); margin: 10px 0; }
input, textarea, select {
  display: block; width: 100%; margin-top: 4px; font: inherit; color: var(--text-primary);
  background: var(--surface-0); border: 1px solid var(--border); border-radius: 10px; padding: 10px;
}
textarea { resize: vertical; }
button {
  font: inherit; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-0);
  color: var(--text-primary); padding: 10px 14px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; width: 100%; margin-top: 6px; }
button.primary:disabled { opacity: .6; cursor: progress; }
button.link { background: none; border: 0; color: var(--accent); padding: 6px 0; }
button.icon { width: 44px; font-size: 22px; padding: 4px; }
.row { display: flex; gap: 10px; align-items: end; }
.row.between { justify-content: space-between; }
.row.center { align-items: center; }
.row #day-date { width: auto; margin: 0; }
.grow { flex: 1; }
.row > button.grow { margin-top: 10px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.err { color: var(--critical); font-size: 14px; min-height: 1em; margin: 6px 0 0; }

.photo-drop {
  display: grid; place-items: center; min-height: 140px; border: 2px dashed var(--border);
  border-radius: var(--radius); cursor: pointer; overflow: hidden; margin: 0; color: var(--text-secondary);
}
.photo-drop img { width: 100%; max-height: 320px; object-fit: cover; display: block; }

.title-input { font-size: 18px; font-weight: 600; border: 0; background: none; padding: 0; margin: 0; }
.item { border-top: 1px solid var(--border); padding: 10px 0; }
.item-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-name { font-weight: 600; }
.item-meta { font-size: 13px; color: var(--text-muted); }
.item-controls { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.item-controls input { width: 70px; display: inline-block; margin: 0; padding: 6px 8px; }
.item-controls button { padding: 6px 10px; }
.item-macros { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.item details { font-size: 13px; }
.edit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; }
.edit-grid label { margin: 4px 0; font-size: 12px; }
.edit-grid input { padding: 6px; }
.conf { font-size: 11px; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-secondary); }

.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; text-align: center; }
.totals div { background: var(--surface-0); border-radius: 10px; padding: 8px 4px; }
.totals b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.totals span { font-size: 12px; color: var(--text-muted); }

.prog { margin: 10px 0; }
.prog-label { display: flex; justify-content: space-between; font-size: 14px; font-variant-numeric: tabular-nums; }
.prog-label .over { color: var(--critical); font-weight: 600; }
.bar { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--series-1); border-radius: 99px; }
.prog.minor .bar { height: 5px; }
details.more { margin-top: 6px; }
details summary { cursor: pointer; color: var(--text-secondary); font-size: 14px; padding: 6px 0; }

.meal { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
.meal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meal-head b { font-size: 16px; }
.meal ul { margin: 6px 0; padding-left: 18px; font-size: 14px; color: var(--text-secondary); }
.meal .actions { display: flex; gap: 8px; }
.meal .actions button { padding: 6px 10px; font-size: 14px; }
.empty { text-align: center; color: var(--text-muted); padding: 24px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 6px 14px; background: none; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .goal { stroke: var(--text-secondary); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .goal-label { fill: var(--text-secondary); font-size: 11px; }
.chart .bar-mark { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar-mark, .chart .bar-mark.active { opacity: .75; }
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  font-variant-numeric: tabular-nums; }

.split { display: flex; height: 22px; gap: 2px; border-radius: 6px; overflow: hidden; }
.split > i { display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; margin-top: 8px; color: var(--text-secondary); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 5px 6px; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-muted); font-weight: 500; }

.goals { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--surface-1); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; max-width: 160px; border: 0; background: none; border-radius: 0; padding: 8px 0 10px; font-size: 20px; opacity: .55; }
.tabs button span { display: block; font-size: 12px; color: var(--text-secondary); }
.tabs button.on { opacity: 1; }

.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-1);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
