:root {
  color-scheme: dark;
  --blue: #0a84ff;
  --blue-dark: #0670d9;
  --bg: #000000; /* page, overscroll and lock screen are pure black */
  --card: #1c1c1e;
  --field: #2c2c2e;
  --text: #f2f2f7;
  --muted: #98989f;
  --border: #38383a;
  --danger: #ff6961;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; } /* no double-tap zoom */
html { -webkit-text-size-adjust: 100%; }
button, .keypad, .lock { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

html { margin: 0; background: #000; min-height: 100%; overscroll-behavior: none; }
body { margin: 0; background: #000; color: var(--text); overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Green bar also fills the notch / status bar area (status bar is translucent). */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--blue); color: #fff;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
}
.topbar h1 { font-size: 20px; margin: 0; line-height: 52px; }
.icon-btn {
  min-width: 44px; min-height: 44px;
  background: none; border: 0; color: #fff; font-size: 26px; cursor: pointer;
}
.icon-btn[hidden] { display: block; visibility: hidden; } /* keeps title centered */

main {
  max-width: 560px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}
section[hidden] { display: none; }

h2 { font-size: 18px; margin: 24px 0 8px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px;
}

/* Buttons */
button { font: inherit; }
.primary, .secondary {
  min-height: 48px; padding: 0 20px; border-radius: 12px; font-weight: 600;
  border: 0; cursor: pointer; width: 100%;
}
.primary { background: var(--blue); color: #fff; }
.primary:active { background: var(--blue-dark); }
.primary:disabled { opacity: 0.45; }
.secondary { background: var(--field); color: var(--text); }
.large { min-height: 56px; font-size: 18px; margin-top: 12px; }
.row { display: flex; gap: 12px; }

/* Inputs: 16px+ stops Safari zooming on focus */
input[type="text"], input[type="password"], input[type="number"] {
  font-size: 16px; min-height: 44px; width: 100%;
  padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--field); color: var(--text);
}
.field-label { display: block; font-weight: 600; margin: 16px 0 6px; }

/* Home */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 4px; text-align: center; }
.total span { display: block; font-size: 22px; font-weight: 700; }
.total small { color: var(--muted); font-size: 12px; }
.total.big { grid-column: 1 / -1; }
.total.big span { font-size: 40px; color: var(--blue); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.meal { display: flex; align-items: center; gap: 10px; }
.meal-info { flex: 1; min-width: 0; }
.meal-info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-info small { color: var(--muted); }
.del-btn {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 10px;
  background: #3a1f1e; color: var(--danger); font-size: 20px; cursor: pointer;
}

/* Add */
.photo-pick {
  display: flex; align-items: center; justify-content: center;
  min-height: 240px; border: 2px dashed var(--border); border-radius: 14px;
  background: var(--card); overflow: hidden; cursor: pointer; color: var(--muted); font-size: 18px;
}
.photo-pick img { width: 100%; max-height: 360px; object-fit: cover; }

/* Loading */
.spinner {
  width: 48px; height: 48px; margin: 80px auto 16px;
  border: 5px solid var(--border); border-top-color: var(--blue);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */
.food { margin-bottom: 12px; }
.food-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.food-head b { font-size: 17px; }
.badge {
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; white-space: nowrap;
}
.badge.high { background: #12351f; color: #5ddc8a; }
.badge.medium { background: #3a2f10; color: #ffd060; }
.badge.low { background: #3a1a17; color: #ff8a80; }
.src { font-size: 13px; color: var(--muted); margin: 4px 0; }
.src .est { color: #ffd060; font-weight: 600; }
.grams-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.grams-row input { width: 110px; }
.macros { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 4px; }
.macros span { display: block; font-weight: 700; }
.macros small { color: var(--muted); font-size: 12px; }
.notes { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.totals-live { margin-top: 4px; }
.disclaimer { font-size: 13px; color: var(--muted); text-align: center; margin: 14px 0 0; }

@media (orientation: landscape) and (max-height: 500px) {
  .spinner { margin-top: 24px; }
  .photo-pick { min-height: 160px; }
}

/* Lock screen (full-screen PIN pad) */
.lock {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.lock[hidden] { display: none; }
.lock-inner { text-align: center; width: 100%; max-width: 320px; padding: 0 16px; }
.lock-inner h2 { font-size: 22px; margin: 0 0 20px; }
.dots { display: flex; justify-content: center; gap: 16px; }
.dots i {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--text); display: block;
}
.dots i.on { background: var(--text); }
.dots.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.lock-msg { min-height: 22px; margin: 14px 0 20px; color: var(--danger); font-size: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px; justify-content: center; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0;
  background: var(--field); color: var(--text); font-size: 30px; cursor: pointer;
}
.keypad button:active { background: var(--blue); }
.keypad button.del { background: none; font-size: 26px; }
.keypad button:disabled { opacity: 0.5; }
@media (max-height: 560px) {
  .keypad { gap: 8px; }
  .keypad button { width: 60px; height: 60px; font-size: 24px; }
  .lock-inner h2 { margin-bottom: 8px; }
  .lock-msg { margin: 6px 0 8px; }
}
.lock.checking .lock-inner { visibility: hidden; } /* no PIN-pad flash while the session is checked */

/* Photo source buttons */
.photo-actions { margin-top: 12px; }
.btn-label { display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer; }
.photo-pick { cursor: default; text-align: center; padding: 0 16px; }
