:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --ink: #1f1b16;
  --muted: #7a7064;
  --line: #ebe3d7;
  --accent: #e2553b;
  --accent-soft: #fde8e2;
  --ok: #3c8d5a;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916; --card: #262320; --ink: #f3ede4; --muted: #a59a8c; --line: #38332d;
    --accent: #ff7a5c; --accent-soft: #3d2620; --ok: #6cc08a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-bottom: calc(76px + var(--safe-bottom));
  overscroll-behavior-y: contain;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
}
.top h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
#top-actions { display: flex; gap: 6px; align-items: center; }

main { padding: 4px 16px 24px; max-width: 760px; margin: 0 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs button {
  border: 0; background: none; padding: 6px 0; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button span { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs button.active span { filter: none; opacity: 1; }

.btn {
  border: 0; border-radius: 999px; padding: 9px 16px; background: var(--accent); color: #fff; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent-soft); color: var(--accent);
  font-size: 18px; display: inline-grid; place-items: center; flex: none;
}

.card { background: var(--card); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 42px; margin-bottom: 8px; }

input[type=text], input[type=search], input[type=url], textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 13px;
  font-size: 16px; /* verhindert iOS-Zoom */
}
textarea { min-height: 140px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Woche */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.week-nav .label { font-weight: 600; }
.day { margin-bottom: 14px; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 6px; }
.day-head .d { font-weight: 700; }
.day.today .d { color: var(--accent); }
.day-head .date { color: var(--muted); font-size: 13px; margin-left: 6px; font-weight: 400; }
.meal { display: flex; gap: 12px; align-items: center; padding: 8px; }
.meal + .meal { margin-top: 8px; }
.thumb { width: 58px; height: 58px; border-radius: 12px; object-fit: cover; background: var(--accent-soft); flex: none; display: grid; place-items: center; font-size: 26px; }
.meal .title { font-weight: 600; line-height: 1.25; }
.stepper { display: inline-flex; align-items: center; gap: 2px; background: var(--bg); border-radius: 999px; padding: 2px; }
.stepper button { width: 28px; height: 28px; border: 0; border-radius: 50%; background: var(--card); font-weight: 700; }
.stepper span { min-width: 34px; text-align: center; font-size: 14px; }
.add-meal { width: 100%; border: 1.5px dashed var(--line); background: transparent; color: var(--muted); border-radius: var(--radius); padding: 10px; }

/* Rezepte */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; white-space: nowrap; font-size: 14px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.rcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-align: left; padding: 0; position: relative; }
.rcard .img { aspect-ratio: 1; width: 100%; object-fit: cover; background: var(--accent-soft); display: grid; place-items: center; font-size: 40px; }
.rcard .body { padding: 9px 10px 11px; }
.rcard .t { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rcard .a { color: var(--muted); font-size: 12px; margin-top: 3px; }
.rcard .fav { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.45); color: #fff; border-radius: 999px; padding: 2px 7px; font-size: 13px; }
.banner { background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; display: flex; gap: 8px; align-items: center; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Detail */
.hero { width: calc(100% + 32px); margin: -16px -16px 12px; aspect-ratio: 4/3; object-fit: cover; border-radius: 22px 22px 0 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.ing { list-style: none; padding: 0; margin: 0; }
.ing li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.ing .q { min-width: 86px; color: var(--muted); font-variant-numeric: tabular-nums; }
.steps { padding-left: 22px; margin: 0; }
.steps li { padding: 5px 0; }
h3 { margin: 18px 0 8px; font-size: 18px; }
.days-pick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.days-pick button { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 0; font-size: 13px; }
.days-pick button b { display: block; font-size: 15px; }
.days-pick button.today { border-color: var(--accent); }

/* Einkauf */
.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 2px 0 14px; }
.progress > div { height: 100%; background: var(--ok); transition: width .3s; }
.cat { margin: 16px 2px 6px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 6px; user-select: none; }
.item .box { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; color: #fff; font-size: 14px; transition: .15s; }
.item.checked .box { background: var(--ok); border-color: var(--ok); }
.item.checked .name { text-decoration: line-through; color: var(--muted); }
.item .qty { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 15px; }
.item .src { font-size: 12px; color: var(--muted); }
.item .del { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 0 4px; }
.add-row { display: flex; gap: 8px; margin-bottom: 8px; }

/* Quellen */
.blogger { display: flex; gap: 12px; align-items: center; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; font-weight: 700; color: var(--accent); flex: none; overflow: hidden; }
.err { color: #c0392b; font-size: 13px; }
.status-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.status-pill.done { background: #dff2e5; color: #2f7a4a; }
.status-pill.error { background: #fbe0dc; color: #b23a2a; }
.status-pill.pending, .status-pill.processing { background: var(--accent-soft); color: var(--accent); }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }
.post { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.post .thumb { width: 44px; height: 44px; border-radius: 8px; font-size: 18px; }

/* Sheet */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .2s; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 16px calc(24px + var(--safe-bottom));
  max-width: 760px; margin: 0 auto; animation: up .25s cubic-bezier(.2,.8,.2,1);
  -webkit-overflow-scrolling: touch;
}
#sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: -6px auto 12px; }
#sheet .sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
#sheet .sheet-head h2 { margin: 0; font-size: 20px; }
.pick-list .pick { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px; margin-bottom: 8px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-bottom)); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
}

/* Offline / Sync */
.sync { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 9px; background: var(--line); color: var(--muted); white-space: nowrap; }
.sync.offline { background: #fbe0dc; color: #b23a2a; }
.sync.pending { background: var(--accent-soft); color: var(--accent); }
.meal.pending { opacity: .65; }
.item.pending .name::after { content: ' ⏳'; font-size: 12px; }

/* Filter & Badges */
.chip .cnt { opacity: .55; font-size: 12px; margin-left: 2px; }
.badge-warn { position: absolute; top: 8px; left: 8px; background: #b23a2a; color: #fff; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.tag.soft { background: var(--line); color: var(--muted); }
.tag.warn { background: #fbe0dc; color: #b23a2a; }
