/* ==========================================================================
   Nutrition: protein tracker. Design: "Fresh Daylight" (owner's pick, option B).
   Light and calm by default, with a matching dark palette. Mobile first (360-430 px).
   All styling lives here (strict CSP: no inline styles or style attributes).
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #f1f4f1;
  --surface-3: #e6ebe7;
  --line: #e6ebe7;
  --line-strong: #d3dcd6;
  --text: #14201b;
  --text-2: #4f5d56;
  --text-3: #5c6b63;
  /* Fills carrying white text use the deeper green (4.7:1); the bright green is decoration. */
  --accent: #0b8550;
  --accent-strong: #0a7f4c;
  --field-border: #7f9087;
  --accent-soft: #e4f6ec;
  --on-accent: #ffffff;
  --accent-grad: linear-gradient(135deg, #18c277 0%, #0f9c5c 100%);
  --danger: #c4253f;
  --danger-soft: #fdecef;
  --shadow: 0 10px 30px rgba(20, 40, 30, 0.08);
  --shadow-sm: 0 2px 8px rgba(20, 40, 30, 0.06);
  --scrim: rgba(20, 32, 27, 0.38);
  --tab-bg: rgba(255, 255, 255, 0.94);
  --track: #eef1ee;

  --breakfast: #f6a43a;
  --snack: #e85d9a;
  --lunch: #13b26b;
  --dinner: #4a7cf0;

  --heat-0: #f1f4f1;
  --heat-1: #c9efd9;
  --heat-2: #84dcab;
  --heat-3: #36c47d;
  --heat-4: #0a7f4c;

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 26px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1311;
  --surface: #171e1a;
  --surface-2: #1e2722;
  --surface-3: #29342e;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #eef4f0;
  --text-2: #b8c6be;
  --text-3: #8fa198;
  --accent: #2bd38a;
  --accent-strong: #2bd38a;
  --field-border: rgba(255, 255, 255, 0.32);
  --accent-soft: rgba(43, 211, 138, 0.14);
  --on-accent: #062114;
  --accent-grad: linear-gradient(135deg, #34dc93 0%, #1fb877 100%);
  --danger: #ff6b81;
  --danger-soft: rgba(255, 107, 129, 0.12);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --scrim: rgba(0, 0, 0, 0.6);
  --tab-bg: rgba(23, 30, 26, 0.94);
  --track: rgba(255, 255, 255, 0.07);
  --heat-0: #1e2722;
  --heat-1: #1d4a33;
  --heat-2: #1f7a4c;
  --heat-3: #26a865;
  --heat-4: #4fe39f;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

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

.icon { flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- App shell ---------- */
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 28px);
}

/* No fill-mode: a transform left on .view after the animation would make it the
   containing block for position: fixed children (FAB, save bar). */
.view { padding: calc(var(--safe-t) + 16px) 20px 0; animation: view-in 320ms var(--ease); }

@keyframes view-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.topbar h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }

.eyebrow {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text-2);
  transition: transform 140ms var(--ease), background 140ms;
}
.icon-btn:active { transform: scale(0.92); background: var(--surface-2); }
.icon-btn[disabled] { opacity: 0.35; pointer-events: none; }

/* ---------- Day header ---------- */
.daynav { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
.daynav .title { display: grid; line-height: 1.1; margin-right: auto; min-width: 0; }
.daynav .title strong { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }

/* ---------- Hero: big number + stacked bar ---------- */
.hero {
  padding: 18px 20px 12px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.hero-label { font-size: 15px; font-weight: 700; color: var(--text-2); }
.big-row { display: flex; align-items: baseline; gap: 4px; margin-top: 2px; }
.big-number {
  font-size: clamp(68px, 22vw, 88px);
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.big-unit { font-size: 26px; font-weight: 700; color: var(--text-3); }
.big-sub { font-size: 14px; color: var(--text-3); margin-left: 8px; }

.stack {
  display: flex;
  gap: 3px;
  height: 18px;
  margin: 18px 0 14px;
  border-radius: 9px;
  overflow: hidden;
  background: var(--track);
}
.stack .seg { height: 100%; flex: 0 0 0%; transition: flex-basis 700ms var(--ease); }
.stack .seg.breakfast { background: var(--breakfast); }
.stack .seg.snack { background: var(--snack); }
.stack .seg.lunch { background: var(--lunch); }
.stack .seg.dinner { background: var(--dinner); }

.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.key { display: grid; gap: 1px; font-size: 13px; color: var(--text-2); min-width: 0; }
.key .k { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.key b { font-size: 18px; color: var(--text); font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.dot.breakfast, .bg-breakfast { background: var(--breakfast); }
.dot.snack, .bg-snack { background: var(--snack); }
.dot.lunch, .bg-lunch { background: var(--lunch); }
.dot.dinner, .bg-dinner { background: var(--dinner); }

.details-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--text-2);
  font-weight: 700;
  font-size: 14px;
}
.details-toggle .icon { transition: transform 240ms var(--ease); }
.details-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }

.details { display: grid; gap: 0; margin: 4px 0 6px; }
.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  min-height: 40px;
  padding: 10px 2px;
  font-size: 15px;
  color: var(--text-2);
}
.stat + .stat { border-top: 1px solid var(--line); }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.stat.sub { padding-left: 18px; font-size: 14px; color: var(--text-3); }
.stat.sub b { font-weight: 600; color: var(--text-2); }
.help { font-size: 13px; color: var(--text-3); padding: 6px 2px 8px; }

/* ---------- Copy yesterday ---------- */
.copy-btn {
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 15px;
  transition: transform 140ms var(--ease);
}
.copy-btn:active { transform: scale(0.98); }
.copy-btn[disabled] { background: var(--surface-2); color: var(--text-3); pointer-events: none; }

/* ---------- Meal cards ---------- */
.meal {
  margin-top: 12px;
  padding: 12px 12px 14px 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.meal-head { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.meal-head .mbar { width: 5px; height: 22px; border-radius: 3px; flex: none; }
.meal-head h2 { font-size: 18px; font-weight: 800; flex: 1; }
.meal-head .sum { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.meal-head .sum small { font-size: 14px; font-weight: 700; color: var(--text-3); }
.add-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  transition: transform 140ms var(--ease);
}
.add-btn:active { transform: scale(0.9); }

.foods { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.food-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 50px;
  padding: 5px 12px 5px 5px;
  border-radius: 16px;
  background: var(--surface-2);
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  transition: transform 140ms var(--ease), background 140ms;
  animation: pop-in 320ms var(--ease);
}
.food-chip:active { transform: scale(0.96); background: var(--surface-3); }
.food-chip .thumb { position: relative; width: 40px; height: 40px; border-radius: 12px; overflow: hidden; flex: none; }
.food-chip .thumb img, .food-chip .thumb .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; font-size: 18px; }
.food-chip .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food-chip .x { color: var(--accent-strong); font-weight: 800; }
.food-chip em { font-style: normal; font-weight: 600; color: var(--text-3); font-variant-numeric: tabular-nums; }
.food-chip .layers { color: var(--text-3); }
.food-chip.pending { opacity: 0.6; pointer-events: none; }
.meal-empty { margin-top: 4px; font-size: 14px; color: var(--text-3); }

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: none; }
}

/* Placeholder pictures (no photo): initial on a colour */
.ph {
  display: grid;
  place-items: center;
  font-size: 44px;
  font-weight: 800;
  color: #fff;
}
.ph-0 { background: #4a7cf0; }
.ph-1 { background: #d4573a; }
.ph-2 { background: #0b8550; }
.ph-3 { background: #c47612; }
.ph-4 { background: #d94a85; }
.ph-5 { background: #1f7fb5; }
.ph-6 { background: #4d8a24; }
.ph-7 { background: #8a63d2; }

/* Combo collage: up to four food photos in one picture */
.collage { position: absolute; inset: 0; display: grid; gap: 2px; background: var(--surface-3); }
.collage .cell { position: relative; overflow: hidden; }
.collage .cell img, .collage .cell .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.collage.n2 { grid-template-columns: 1fr 1fr; }
.collage.n3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.collage.n3 .cell:first-child { grid-row: span 2; }
.collage.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.collage .cell .ph { font-size: 13px; }
.photo-preview .collage .cell .ph { font-size: 40px; }
.entry-hero .thumb .collage .cell .ph { font-size: 24px; }
.parts-line { display: flex; align-items: center; gap: 6px; }
.parts-line .icon { color: var(--accent); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--tab-bg);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.tabbar nav { max-width: 560px; height: var(--tab-h); margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); }
.tab {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 3px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: color 160ms, transform 140ms var(--ease);
}
.tab:active { transform: scale(0.94); }
.tab[aria-current="page"] { color: var(--accent-strong); }
.tab[aria-current="page"] .icon { stroke-width: 2.4; }

/* ---------- Sheets / dialogs ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 240ms;
}
.backdrop.open { opacity: 1; }
.backdrop.over-sheet { z-index: 52; }

.sheet {
  position: fixed;
  z-index: 51;
  left: 50%;
  bottom: 0;
  width: min(100%, 560px);
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translate(-50%, 105%);
  transition: transform 320ms var(--ease);
  padding-bottom: var(--safe-b);
}
.sheet.open { transform: translate(-50%, 0); }
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 10px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 10px 20px 10px; flex: none; }
.sheet-head h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.sheet-head .grow { margin-right: auto; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 18px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 20px 14px; border-top: 1px solid var(--line); flex: none; }

.meal-badge {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 12px;
  color: #fff;
}

.dialog {
  position: fixed;
  z-index: 53;
  left: 50%;
  top: 50%;
  width: min(88vw, 360px);
  padding: 22px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translate(-50%, -46%) scale(0.96);
  opacity: 0;
  transition: transform 240ms var(--ease), opacity 200ms;
}
.dialog.open { transform: translate(-50%, -50%); opacity: 1; }
.dialog h2 { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.dialog p { color: var(--text-2); margin-bottom: 18px; }
.dialog-actions { display: flex; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 50px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  border-radius: 16px;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  transition: transform 140ms var(--ease), opacity 140ms;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); background: var(--danger-soft); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.small { min-height: 44px; flex: none; padding: 0 16px; }

.spinner {
  border-radius: 50%;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Lists (picker, foods, combo picker, copy) ---------- */
.list { display: grid; }
.sec {
  margin: 16px 2px 2px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}
.sec:first-child { margin-top: 4px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 66px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  color: inherit;
  text-decoration: none;
  transition: background 140ms;
}
.row:active { background: var(--surface-2); }
.mini-thumb { position: relative; width: 50px; height: 50px; border-radius: 14px; overflow: hidden; flex: none; background: var(--surface-2); }
.mini-thumb img, .mini-thumb .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; font-size: 20px; }
.row-main { display: grid; min-width: 0; flex: 1; }
.row-main b { font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main span { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.row-end { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.add-circle {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: transform 140ms var(--ease);
}
.row:active .add-circle { transform: scale(0.88); }
.added {
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.pick-note { font-size: 13px; color: var(--text-3); margin: 0 0 6px; }
.more-link { display: flex; justify-content: center; margin-top: 12px; }

.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 30px 12px;
  text-align: center;
  color: var(--text-2);
}
.empty .art {
  width: 80px;
  height: 80px;
  display: grid;
  place-items: center;
  border-radius: 26px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.empty h3 { font-size: 19px; color: var(--text); }

/* ---------- Entry sheet ---------- */
.entry-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.entry-hero .thumb { width: 80px; height: 80px; border-radius: 20px; overflow: hidden; position: relative; flex: none; }
.entry-hero .thumb img, .entry-hero .thumb .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; font-size: 32px; }
.entry-hero h3 { font-size: 20px; font-weight: 800; line-height: 1.15; }
.entry-hero p { color: var(--text-3); font-size: 14px; margin-top: 2px; }
.entry-parts { display: grid; gap: 6px; margin: -6px 0 16px; }
.entry-parts .part { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.entry-parts .mini-thumb { width: 34px; height: 34px; border-radius: 10px; }

.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 6px 0 18px; }
.stepper button {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  transition: transform 120ms var(--ease);
}
.stepper button:active { transform: scale(0.88); }
.stepper button[disabled] { opacity: 0.35; }
.stepper output { min-width: 70px; text-align: center; font-size: 48px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.total-line { text-align: center; color: var(--text-2); margin-bottom: 8px; }
.total-line b { color: var(--text); font-size: 22px; }

/* ---------- Copy sheet ---------- */
.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.check-row input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.check-row .mini-thumb { width: 44px; height: 44px; border-radius: 12px; }
.meal-label { margin: 14px 2px 2px; }

/* ---------- Foods ---------- */
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text-3);
}
.search input { flex: 1; min-width: 0; height: 48px; background: none; border: 0; outline: 0; color: var(--text); font-size: 16px; }
.search input::placeholder { color: var(--text-3); }
.search:focus-within { box-shadow: 0 0 0 2px var(--accent); }
.view > .search { background: var(--surface); border: 1px solid var(--line); }

.seg-control { display: inline-grid; grid-auto-flow: column; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); margin: 14px 0 6px; }
.seg-control button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 11px; font-weight: 700; color: var(--text-2); }
.seg-control button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.kind-switch { width: 100%; grid-template-columns: 1fr 1fr; margin: 0 0 4px; }
.kind-switch button { min-height: 44px; }

.card-list { margin-top: 10px; padding: 2px 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.card-list .row:last-child { border-bottom: 0; }
.view > .card-list:last-of-type { margin-bottom: 76px; }

.star {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  color: var(--text-3);
  transition: transform 160ms var(--ease), color 160ms;
}
.star[aria-pressed="true"] { color: #c98400; }
.star:active { transform: scale(0.8); }
.star[aria-pressed="true"] .icon { fill: currentColor; }

.fab {
  position: fixed;
  right: max(20px, calc(50% - 260px));
  bottom: calc(var(--tab-h) + var(--safe-b) + 18px);
  z-index: 20;
  min-height: 54px;
  padding: 0 22px 0 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 27px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(11, 133, 80, 0.32);
  text-decoration: none;
  transition: transform 140ms var(--ease);
}
.fab:active { transform: scale(0.94); }

/* ---------- Item form ---------- */
.form { display: grid; gap: 18px; padding-bottom: 96px; }
.photo-box { display: grid; grid-template-columns: 128px 1fr; gap: 14px; align-items: center; }
.photo-preview { width: 128px; height: 128px; border-radius: 26px; overflow: hidden; position: relative; background: var(--surface-2); border: 1px solid var(--line); }
.photo-preview img, .photo-preview .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; font-size: 52px; }
.photo-preview .chip { position: absolute; top: 8px; right: 8px; padding: 3px 8px; border-radius: 999px; background: rgba(20, 32, 27, 0.7); color: #fff; font-size: 12px; font-weight: 800; }
.photo-actions { display: grid; gap: 8px; }
.photo-actions .btn { justify-content: flex-start; min-height: 46px; font-size: 14px; background: var(--surface); border: 1px solid var(--line); }

.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-size: 13px; font-weight: 700; color: var(--text-2); }
.input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--field-border);
  color: var(--text);
  outline: 0;
  transition: border-color 140ms, box-shadow 140ms;
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input.big { min-height: 72px; font-size: 34px; font-weight: 800; text-align: center; letter-spacing: -0.02em; }
.field .err { color: var(--danger); font-size: 13px; }
.hint { font-size: 13px; color: var(--text-3); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--text-2);
  font-weight: 700;
  font-size: 14px;
}
.pill[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: transparent; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { padding: 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); display: grid; gap: 14px; }
.card h3 { font-size: 15px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--surface-3); transition: background 200ms; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 240ms var(--ease); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.savebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: 12px 20px calc(var(--safe-b) + 12px);
  background: var(--tab-bg);
  border-top: 1px solid var(--line);
}
.savebar .inner { display: flex; gap: 10px; width: min(100%, 520px); }

/* Combo editor */
.combo-card { padding: 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); display: grid; gap: 10px; }
.combo-card h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.combo-card .list { gap: 8px; }
.part-row { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 6px 6px 6px 8px; border-radius: var(--r-sm); background: var(--surface-2); }
.part-row .mini-thumb { width: 44px; height: 44px; border-radius: 12px; }
.part-row.gone { outline: 1px dashed var(--danger); }
.part-row .row-main span.warn { color: var(--danger); }
.mini-step { display: flex; align-items: center; gap: 2px; }
.mini-step button { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); color: var(--text-2); }
.mini-step button:active { transform: scale(0.9); }
.mini-step button.trash { color: var(--danger); }
.mini-step output { min-width: 26px; text-align: center; font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.add-part { min-height: 50px; border: 2px dashed var(--line-strong); background: transparent; color: var(--text-2); }
.combo-total { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 14px 16px; border-radius: var(--r-md); background: var(--accent-soft); }
.combo-total .big { font-size: 38px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.combo-total .big small { font-size: 16px; color: var(--text-2); margin-left: 3px; }
.combo-total .rest { font-size: 13px; color: var(--text-2); text-align: right; line-height: 1.5; }

/* ---------- Scanner (always dark: it is a camera view) ---------- */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
  display: flex;
  flex-direction: column;
  color: #fff;
}
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-top { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 14px) 16px 10px; background: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent); }
.scan-top h2 { font-size: 18px; }
.scan-mid { position: relative; z-index: 1; flex: 1; display: grid; place-items: center; }
.frame { width: min(78vw, 320px); aspect-ratio: 1.6; border-radius: 22px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55); position: relative; }
.frame::before, .frame::after { content: ""; position: absolute; width: 36px; height: 36px; border: 4px solid #fff; border-radius: 6px; }
.frame::before { left: -2px; top: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 22px; }
.frame::after { right: -2px; bottom: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 22px; }
.laser { position: absolute; left: 10px; right: 10px; top: 50%; height: 3px; border-radius: 2px; background: #2bd38a; box-shadow: 0 0 14px #2bd38a; animation: laser 1.8s ease-in-out infinite alternate; }
@keyframes laser { from { transform: translateY(-48px); } to { transform: translateY(48px); } }
.scan-bottom { position: relative; z-index: 2; padding: 14px 16px calc(var(--safe-b) + 18px); background: linear-gradient(to top, rgba(0, 0, 0, 0.82), transparent); display: grid; gap: 10px; }
.scan-bottom .msg { text-align: center; font-size: 14px; color: rgba(255, 255, 255, 0.85); min-height: 20px; }
.scan-bottom .manual { display: flex; gap: 8px; }
.scan-bottom .input { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.3); color: #fff; }
.scan-bottom .input::placeholder { color: rgba(255, 255, 255, 0.6); }
.scanner .icon-btn { background: rgba(255, 255, 255, 0.14); border-color: transparent; color: #fff; }
.nocam-art { display: none; justify-items: center; gap: 14px; max-width: 260px; text-align: center; font-size: 18px; font-weight: 700; color: var(--text); }
.nocam-art .icon { width: 96px; height: 96px; padding: 22px; border-radius: 30px; background: var(--accent-soft); color: var(--accent-strong); }
.scanner.nocam { background: var(--bg); color: var(--text); }
.scanner.nocam .scan-mid .frame, .scanner.nocam .laser { display: none; }
.scanner.nocam .nocam-art { display: grid; }
.scanner.nocam .scan-top, .scanner.nocam .scan-bottom { background: none; }
.scanner.nocam .scan-top h2 { color: var(--text); }
.scanner.nocam .icon-btn { background: var(--surface); border: 1px solid var(--line); color: var(--text-2); }
.scanner.nocam .scan-bottom .msg { color: var(--text-2); }
.scanner.nocam .scan-bottom .input { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.scanner.nocam .scan-bottom .input::placeholder { color: var(--text-3); }

/* ---------- Log: month heat-map + day list ---------- */
.cal { padding: 14px 14px 12px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px 4px; }
.cal-head h2 { font-size: 17px; font-weight: 800; }
.cal-head .nav { display: flex; gap: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-grid .dow { text-align: center; font-size: 11px; font-weight: 800; color: var(--text-3); padding-bottom: 2px; }
.cal-cell {
  position: relative;
  height: 46px; /* 44 px tap height; with 6 px gaps the tap area is wider than the cell */
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.cal-cell.l0 { background: var(--heat-0); color: var(--text-3); }
.cal-cell.l1 { background: var(--heat-1); }
.cal-cell.l2 { background: var(--heat-2); }
.cal-cell.l3 { background: var(--heat-3); color: #14201b; }
.cal-cell.l4 { background: var(--heat-4); color: #fff; }
:root[data-theme="dark"] .cal-cell.l4 { color: #062114; }
.cal-cell.future { background: transparent; color: var(--text-3); opacity: 0.5; }
.cal-cell.blank { background: transparent; }
.cal-cell.today { outline: 2.5px solid var(--text); outline-offset: 1px; }
a.cal-cell:active { transform: scale(0.92); }
.cal-legend { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 10px; font-size: 12px; color: var(--text-3); }
.cal-legend i { width: 12px; height: 12px; border-radius: 3px; }
.cal-legend .h0 { background: var(--heat-0); } .cal-legend .h1 { background: var(--heat-1); } .cal-legend .h2 { background: var(--heat-2); }
.cal-legend .h3 { background: var(--heat-3); } .cal-legend .h4 { background: var(--heat-4); }

.day-row .mini-stack { display: flex; gap: 2px; width: 84px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--track); flex: none; }
.day-row .mini-stack i { height: 100%; flex: 0 0 0%; }
.day-row .mini-stack i.all { background: var(--accent); }
.day-row .g { width: 54px; text-align: right; font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; flex: none; }
.day-row .g small { display: block; font-size: 11px; font-weight: 700; color: var(--text-3); }

/* ---------- Toast ---------- */
.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  z-index: 70;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 460px;
  min-height: 48px;
  padding: 6px 8px 6px 16px;
  border-radius: 16px;
  background: #14201b;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 14px;
  animation: toast-in 280ms var(--ease) both;
}
:root[data-theme="dark"] .toast { background: #eef4f0; color: #14201b; }
.toast.error { background: var(--danger); color: #fff; }
.toast .act { min-height: 40px; padding: 0 12px; border-radius: 12px; color: #6fe3a8; font-weight: 800; }
:root[data-theme="dark"] .toast .act { color: var(--accent-strong); }
.toast.error .act { color: #fff; text-decoration: underline; }
.toast.leaving { animation: toast-out 200ms ease-in both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Banner / skeleton / splash / settings ---------- */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: var(--r-md);
  background: var(--danger-soft);
  color: var(--text);
}
.banner .icon { color: var(--danger); }
.banner span { flex: 1; font-size: 14px; }
.banner .btn { background: var(--surface); }

.skel { border-radius: var(--r-md); background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%); background-size: 300% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.skel.hero-skel { height: 230px; border-radius: var(--r-lg); }
.skel.meal-skel { height: 120px; margin-top: 12px; border-radius: var(--r-lg); }
.skel.row-skel { height: 66px; margin-top: 8px; }

.splash {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: 32px;
  text-align: center;
}
.splash .logo { width: 96px; height: 96px; border-radius: 28px; box-shadow: var(--shadow); }
.splash h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }
.splash p { color: var(--text-2); max-width: 280px; }
.splash .btn { min-width: 220px; flex: none; min-height: 56px; }

.settings-section { margin-top: 16px; }
.about { color: var(--text-3); font-size: 13px; text-align: center; margin-top: 22px; }

/* ---------- Desktop polish ---------- */
@media (min-width: 720px) {
  .view { padding-top: 28px; }
  .sheet { border-radius: 28px; bottom: 5vh; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .laser { animation: none; }
}
