*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

a { color: var(--primary); text-decoration: none; }

/* App shell */
.app {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.view { display: none; }
.view[aria-hidden="false"] { display: block; }

.view-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--s-4);
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  height: var(--topbar-h);
  padding: 0 var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.topbar-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.topbar-title .brand-mark {
  color: var(--primary);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--tap-min);
  padding: 0 var(--s-5);
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: var(--fs-md);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--ink-100); }

/* --- Day strip --- */
.day-strip {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) 0;
}
.day-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: var(--r-full);
  color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast) var(--ease);
}
.day-btn:hover { background: var(--ink-100); color: var(--text); }
.day-btn:disabled { opacity: 0.35; pointer-events: none; }
.day-label { flex: 1; text-align: center; }
.day-label-main { font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.day-label-sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.day-today {
  padding: 0 var(--s-3);
  height: var(--tap-min);
  border-radius: var(--r-full);
  color: var(--primary);
  background: var(--accent-bg);
  font-weight: 600;
  font-size: var(--fs-sm);
}
.day-today:active { transform: scale(0.96); }

/* --- Budget ring --- */
.budget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-6) var(--s-5);
  margin: var(--s-2) 0 var(--s-5);
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.ring-wrap {
  position: relative;
  width: 160px;
  height: 160px;
  flex-shrink: 0;
}
.ring { width: 100%; height: 100%; display: block; }
.ring circle { fill: none; stroke-width: 14; stroke-linecap: round; }
.ring .ring-bg { stroke: var(--ink-100); }
.ring .ring-cal { stroke: var(--primary); transition: stroke-dashoffset var(--dur-base) var(--ease); }
.ring .ring-pro { stroke: var(--protein); transition: stroke-dashoffset var(--dur-base) var(--ease); stroke-width: 10; }
@media (prefers-color-scheme: dark) {
  .ring .ring-bg { stroke: #1E293B; }
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}
.ring-main {
  font-family: var(--font-num);
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}
.ring-unit {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}
.budget-stats { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.stat { display: grid; grid-template-columns: 10px auto 1fr; align-items: center; gap: var(--s-2) var(--s-3); }
.stat-dot { width: 10px; height: 10px; border-radius: 50%; }
.stat-dot-cal { background: var(--primary); }
.stat-dot-pro { background: var(--protein); }
.stat-k { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 500; }
.stat-v {
  grid-column: 2 / -1;
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.stat-goal { color: var(--text-muted); font-weight: 500; font-size: var(--fs-sm); }

/* --- Section titles --- */
.section-title {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 700;
  margin: var(--s-5) 0 var(--s-3);
}

/* --- Recents --- */
.recents { margin-bottom: var(--s-4); }
.chip-row {
  display: flex;
  gap: var(--s-2);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: var(--s-1) 0 var(--s-3);
  margin: 0 calc(-1 * var(--s-4));
  padding-left: var(--s-4);
  padding-right: var(--s-4);
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  scroll-snap-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  text-align: left;
  min-width: 140px;
  max-width: 200px;
  display: flex; flex-direction: column; gap: 2px;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.chip:hover { border-color: var(--primary); }
.chip:active { transform: scale(0.97); }
.chip-name {
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-family: var(--font-num);
}

/* --- Meal sections --- */
.meals { display: flex; flex-direction: column; gap: var(--s-3); margin-top: var(--s-4); }
.meal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.meal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3) var(--s-4);
  gap: var(--s-3);
}
.meal-head-left { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.meal-icon { font-size: var(--fs-md); opacity: 0.85; }
.meal-name { font-weight: 600; letter-spacing: -0.01em; }
.meal-head-right { display: flex; align-items: center; gap: var(--s-3); }
.meal-tot { font-family: var(--font-num); font-size: var(--fs-sm); color: var(--text); font-weight: 600; }
.meal-tot-empty { color: var(--text-muted); font-weight: 400; }
.meal-add {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  color: var(--primary);
  background: var(--accent-bg);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.meal-add:hover { background: var(--blue-200); }
.meal-add:active { transform: scale(0.92); }
.meal-empty {
  padding: var(--s-3) var(--s-4) var(--s-4);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  border-top: 1px dashed var(--border);
}
.entries { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.entry {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3) var(--s-4);
  gap: var(--s-3);
  border-bottom: 1px solid var(--border);
}
.entry:last-child { border-bottom: 0; }
.entry-main { min-width: 0; flex: 1; }
.entry-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
  font-family: var(--font-num);
}
.entry-del {
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: var(--r-full);
  color: var(--text-muted);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.entry-del:hover { color: var(--warn); background: var(--ink-100); }
.entry-del:active { transform: scale(0.9); }

/* --- Add card --- */
.add-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  box-shadow: var(--shadow-sm);
}
.add-note {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  padding: var(--s-2) var(--s-3);
  background: var(--accent-bg);
  color: var(--primary);
  border-radius: var(--r-sm);
  text-align: center;
}
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.field input[type="text"],
.field input[type="number"] {
  height: var(--tap-min);
  padding: 0 var(--s-3);
  font-size: var(--fs-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  width: 100%;
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--ink-100);
  padding: 4px;
  border-radius: var(--r-md);
}
@media (prefers-color-scheme: dark) {
  .seg { background: var(--surface-alt); }
}
.seg-btn {
  min-height: 40px;
  border-radius: calc(var(--r-md) - 2px);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.seg-btn.is-selected {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.add-actions {
  display: flex; gap: var(--s-3);
  margin-top: var(--s-2);
}
.add-actions .btn-primary { flex: 1; }
.add-actions .btn-ghost { flex: 0 0 auto; }

.add-status {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  min-height: 20px;
  text-align: center;
}
.add-status[data-kind="ok"] { color: var(--good); }
.add-status[data-kind="warn"] { color: var(--warn); }

/* Placeholder card (step 1 only) */
.placeholder {
  margin: var(--s-6) 0;
  padding: var(--s-8) var(--s-5);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
  text-align: center;
  color: var(--text-muted);
}
.placeholder .kicker {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--accent-bg);
  padding: var(--s-1) var(--s-3);
  border-radius: var(--r-full);
  margin-bottom: var(--s-3);
}
.placeholder h2 {
  color: var(--text);
  font-size: var(--fs-xl);
  margin-bottom: var(--s-2);
}
.placeholder p { margin: 0 auto; max-width: 36ch; }

/* Bottom navbar */
.navbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.navbar-inner {
  max-width: 640px;
  margin: 0 auto;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap-min);
  padding: var(--s-1) var(--s-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  transition: color var(--dur-fast) var(--ease);
}
.nav-item svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-item[aria-selected="true"] {
  color: var(--primary);
}
.nav-item:active {
  transform: scale(0.96);
}

/* Primary add button (center) */
.nav-item.nav-primary {
  position: relative;
  color: var(--primary-ink);
}
.nav-item.nav-primary .nav-fab {
  position: absolute;
  top: -18px;
  width: 56px;
  height: 56px;
  border-radius: var(--r-full);
  background: var(--primary);
  color: var(--primary-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md), 0 0 0 4px var(--surface);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.nav-item.nav-primary .nav-fab svg {
  width: 28px; height: 28px; stroke-width: 2.4;
}
.nav-item.nav-primary:active .nav-fab {
  transform: scale(0.94);
  background: var(--primary-hover);
}
.nav-item.nav-primary .nav-label {
  margin-top: 36px;
  color: var(--text-muted);
}
.nav-item.nav-primary[aria-selected="true"] .nav-label {
  color: var(--primary);
}
