:root {
  --bg: #f2f2f7; --card: #fff; --text: #1c1c1e; --muted: #6e6e73; --line: #e5e5ea;
  --accent: #2f7d4f; --accent-soft: #e3f1e8; --danger: #d70015; --star: #ffb400;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --text: #f2f2f7; --muted: #98989f; --line: #38383a;
          --accent: #4cc27a; --accent-soft: #1d3326; --danger: #ff453a; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
main { max-width: 640px; margin: 0 auto; padding: 12px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.top .title { flex: 1; text-align: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .title small { display: block; color: var(--muted); font-size: .8rem; }
.top .actions { display: flex; gap: 6px; }
.nav-btn { font-size: 2rem; line-height: 1; padding: 0 10px; min-width: 44px; text-align: center; }

/* bottom tab bar */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: .7rem; color: var(--muted); }
.tabs a span { font-size: 1.4rem; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a.on span { filter: none; opacity: 1; }

/* cards */
.card { display: block; background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.pre { white-space: pre-wrap; margin: 0; }
.tag { font-size: .7rem; background: var(--accent-soft); color: var(--accent); padding: 1px 6px; border-radius: 6px; vertical-align: middle; }
.notice { background: var(--accent-soft); padding: 10px 14px; border-radius: var(--radius); }
.notice.error { background: color-mix(in srgb, var(--danger) 15%, var(--card)); color: var(--danger); }

/* forms — 16px+ font prevents iOS zoom on focus */
input, select, textarea, button, .btn { font: inherit; font-size: 17px; }
input:not([type=checkbox]), select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 30px; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label input, label textarea, label select { color: var(--text); }
button, .btn {
  display: inline-block; border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; text-align: center;
}
.btn.small, button.small { padding: 6px 12px; font-size: 15px; }
.secondary { background: var(--accent-soft); color: var(--accent); }
.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--card)); }
.search { display: flex; gap: 8px; margin-bottom: 12px; }
.search select { width: auto; flex-shrink: 0; }

/* week */
.day summary { list-style: none; cursor: pointer; }
.day summary::-webkit-details-marker { display: none; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.dow { font-weight: 700; font-size: 1.05rem; }
.day.today { box-shadow: 0 0 0 2px var(--accent); }
.day.past { opacity: .75; }
.meal { display: flex; gap: 12px; align-items: center; font-size: 1.1rem; }
.meal img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.meal.empty { color: var(--muted); font-style: italic; font-size: 1rem; }
.day details[open] form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.day-col { width: 76px; flex-shrink: 0; font-size: .85rem; padding-top: 2px; }
.week-link { font-weight: 600; font-size: .9rem; }
.count { font-weight: 700; font-size: 1.2rem; color: var(--accent); }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar div { height: 100%; background: var(--accent); }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.totals div { background: var(--card); border-radius: var(--radius); padding: 12px 6px; text-align: center; }
.totals b { display: block; font-size: 1.3rem; color: var(--accent); }
.totals span { font-size: .75rem; color: var(--muted); }

/* stars */
.stars i { font-style: normal; color: var(--line); font-size: .95rem; }
.stars i.f { color: var(--star); }
.rate { display: flex; gap: 4px; justify-content: center; margin-bottom: 8px; }
.rate button { background: none; color: var(--line); font-size: 2.2rem; padding: 0 4px; line-height: 1; }
.rate button.f { color: var(--star); }

/* recipes */
.recipe-row { display: flex; gap: 12px; align-items: center; }
.recipe-row img, .recipe-row .ph { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.recipe-row .ph { display: grid; place-items: center; background: var(--bg); font-size: 2rem; }
.hero { width: 100%; max-height: 280px; object-fit: cover; border-radius: var(--radius); margin-bottom: 12px; }
.meta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.checks label { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); font-size: 1rem; }
.checks input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.checks input:checked + span { text-decoration: line-through; color: var(--muted); }
.steps { padding-left: 1.4rem; margin: 0; }
.steps li { margin-bottom: 10px; }
