:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1b1f1d;
  --muted: #69716c;
  --border: #dfe3e0;
  --accent: #1f7a4d;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --badge-hoch: #d6f0e0;
  --badge-mittel: #fbefc9;
  --badge-niedrig: #f9d8d6;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --card: #1c201e;
    --text: #e7ebe8;
    --muted: #9aa39e;
    --border: #2f3532;
    --accent: #3fae75;
    --accent-text: #0b130f;
    --danger: #f2827b;
    --badge-hoch: #1f4a33;
    --badge-mittel: #4d4120;
    --badge-niedrig: #5a2724;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.3rem; margin: 0 0 4px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; }
.topbar nav { display: flex; gap: 14px; align-items: center; font-size: 0.95rem; }
.topbar a { color: var(--muted); text-decoration: none; }
.topbar a.active { color: var(--accent); font-weight: 600; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--muted); }
button:disabled { opacity: 0.6; }

.photo-drop {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 240px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}
.photo-drop img { width: 100%; max-height: 420px; object-fit: cover; display: block; }
.photo-actions { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.photo-btn {
  position: relative;
  display: block;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  text-align: center;
  cursor: pointer;
}
.photo-btn:first-child { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.photo-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

.range { font-size: 1.15rem; margin: 0; }
.badge { display: inline-block; font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.badge.hoch { background: var(--badge-hoch); }
.badge.mittel { background: var(--badge-mittel); }
.badge.niedrig { background: var(--badge-niedrig); }

.components { margin: 0; padding-left: 18px; }
.components li { margin: 2px 0; }

.muted { color: var(--muted); margin: 0; }
.center { text-align: center; }
.error { color: var(--danger); margin: 0; }

.day { margin-bottom: 20px; }
.day-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 4px 8px;
}

.meal { padding: 0; margin-bottom: 10px; overflow: hidden; }
.meal summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  list-style: none;
  cursor: pointer;
}
.meal summary::-webkit-details-marker { display: none; }
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; }
.meal-main { flex: 1; min-width: 0; }
.meal-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-time { color: var(--muted); font-weight: 400; }
.meal-note { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-kcal { font-weight: 600; white-space: nowrap; }
.meal-kcal.unlogged { color: var(--muted); font-weight: 400; }
.meal-detail { padding: 0 12px 12px; }
.meal-detail .photo { width: 100%; border-radius: 10px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(4px);
}
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

[hidden] { display: none !important; }
