:root {
  --bg: #F4F3F1;
  --bg-elevated: #FFFFFF;
  --bg-sunken: #EAE8E4;
  --ink: #14140F;
  --ink-soft: #55534C;
  --ink-faint: #8B887F;
  --line: #DEDBD4;
  --line-soft: #E9E7E2;
  --accent: #14140F;
  --accent-contrast: #F4F3F1;
  --danger: #B3413A;
  --good: #2E5B3E;
  --warn: #A8722E;

  --protein: #B3413A;
  --carbs: #A8722E;
  --fat: #5B4E9E;
  --streak: #C2542B;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  /* Spacing scale — use these everywhere instead of ad hoc pixel values, so vertical
     rhythm stays consistent across screens. Section-to-section spacing is always
     --space-6 (a "group" of cards/rows), card inner padding is --space-4, tight
     internal gaps are --space-2/--space-3. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;

  --shadow-sm: 0 1px 2px rgba(20, 20, 15, 0.06), 0 1px 1px rgba(20, 20, 15, 0.04);
  --shadow-md: 0 4px 16px rgba(20, 20, 15, 0.08), 0 1px 3px rgba(20, 20, 15, 0.06);
  --shadow-lg: 0 12px 32px rgba(20, 20, 15, 0.14), 0 2px 8px rgba(20, 20, 15, 0.08);

  --nav-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ff: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ff);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, textarea, select {
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
}

a { color: inherit; text-decoration: none; }

svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

img { max-width: 100%; display: block; }

::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; }

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

.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
  background: var(--bg);
}

.screen {
  padding: calc(var(--safe-top) + 16px) 18px calc(var(--nav-height) + var(--safe-bottom) + 24px);
  min-height: 100vh;
  min-height: 100dvh;
}

.screen--nonav {
  padding-bottom: calc(var(--safe-bottom) + 24px);
}

.app-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

.screen-loading {
  display: flex;
  justify-content: center;
  padding: var(--space-7) 0;
}

/* ---------- Bottom Nav ---------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(244, 243, 241, 0.86);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-faint);
  transition: color 0.15s ease;
  padding: 6px 0 2px;
}

.nav-item.active { color: var(--ink); }

.nav-item svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.nav-item.active svg { stroke-width: 2.1; }

.nav-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ---------- Cards / surfaces ---------- */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin: 0 2px 10px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-pill);
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  width: 100%;
}
.btn-primary:disabled { opacity: 0.4; }

.btn-secondary {
  background: var(--bg-sunken);
  color: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  padding: 10px 14px;
}
.btn-ghost-block { width: 100%; justify-content: center; }

.btn-danger {
  background: transparent;
  color: var(--danger);
}
.btn-danger-block { width: 100%; justify-content: center; }

.btn-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sunken);
  flex: none;
}
.btn-icon-sm { width: 38px; height: 38px; }
.btn-icon-good { background: var(--good); color: var(--accent-contrast); }

/* ---------- Inputs ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

.field input[type="text"],
.field input[type="number"],
.field textarea,
.field select {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--ink);
  width: 100%;
}

.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--ink);
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-option {
  padding: 11px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.pill-option.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.form-error {
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  margin-top: var(--space-2);
  display: none;
}
.form-error.visible { display: block; }

/* ---------- Utility ---------- */
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.col { display: flex; flex-direction: column; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--ink-faint); }
.soft { color: var(--ink-soft); }
.text-danger { color: var(--danger); }
.text-good { color: var(--good); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.leading-normal { line-height: 1.5; }
.mt-8 { margin-top: var(--space-2); }
.mt-16 { margin-top: var(--space-4); }
.mt-24 { margin-top: var(--space-6); }
.gap-8 { gap: var(--space-2); }
.gap-12 { gap: var(--space-3); }

/* Spacing-scale utilities (prefer these over the legacy mt-8/16/24 above in new code) */
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }
.w-full { width: 100%; }

.fade-in { animation: fadeIn 0.25s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.spinner {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2.5px solid rgba(20,20,15,0.15);
  border-top-color: var(--ink);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* For a spinner shown inside a dark/filled button (e.g. btn-primary) */
.spinner-on-dark {
  border-color: rgba(244, 243, 241, 0.3);
  border-top-color: var(--accent-contrast);
}

/* ---------- Avatars ---------- */
.avatar-circle {
  border-radius: 50%;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex: none;
  box-shadow: 0 1px 2px rgba(20, 20, 15, 0.12);
}
