:root {
  --bg: #fbf7f3;
  --card: #ffffff;
  --text: #2b2420;
  --muted: #7a6d64;
  --line: #eadfd6;
  --accent: #c4522f;
  --accent-soft: #f6e3da;
  --danger: #b3261e;
  --shadow: 0 1px 3px rgba(60, 40, 30, .08), 0 4px 14px rgba(60, 40, 30, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --card: #282320;
    --text: #f3ece6;
    --muted: #b0a39a;
    --line: #3d3531;
    --accent: #e57a55;
    --accent-soft: #43302a;
    --danger: #ff8a80;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; scroll-padding-bottom: calc(env(safe-area-inset-bottom) + 90px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  border: 0; background: none; color: var(--accent);
  font-size: 30px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer;
}

main {
  max-width: 1100px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left));
}

.btn {
  border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 15px;
  white-space: nowrap; text-decoration: none; display: inline-block;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: none; color: var(--danger); }
.btn:disabled { opacity: .5; }

.search { display: flex; gap: 8px; margin-bottom: 12px; }
.search input {
  flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 4px 12px; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr 1fr; gap: 10px; } }
.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.card .ph { aspect-ratio: 4 / 3; background: var(--accent-soft); display: grid; place-items: center; font-size: 40px; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .body { padding: 10px 12px 12px; }
.card h3 { margin: 0; font-size: 16px; line-height: 1.3; }
.card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.fav { color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 48px; }

/* Recipe view */
.recipe { max-width: 820px; margin: 0 auto; }
.hero { width: 100%; max-height: 420px; object-fit: cover; border-radius: 16px; display: block; margin-bottom: 16px; }
.recipe h2 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; }
.recipe .desc { color: var(--muted); margin: 0 0 12px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.fact { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: 14px; }
.scaler { display: inline-flex; align-items: center; gap: 4px; }
.scaler button { border: 0; background: var(--accent-soft); color: var(--accent); width: 30px; height: 30px; border-radius: 8px; font-size: 18px; cursor: pointer; }
.cols { display: grid; gap: 24px; }
@media (min-width: 760px) { .cols { grid-template-columns: 2fr 3fr; } }
.recipe h4 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 20px 0 8px; }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; cursor: pointer; }
.ingredients li.heading { font-weight: 700; border: 0; padding-top: 14px; cursor: default; }
.ingredients li.done { color: var(--muted); text-decoration: line-through; }
.ingredients .box { flex: none; width: 20px; height: 20px; margin-top: 3px; border: 2px solid var(--line); border-radius: 6px; }
.ingredients li.done .box { background: var(--accent); border-color: var(--accent); }
.steps { padding-left: 0; list-style: none; counter-reset: step; margin: 0; }
.steps li { counter-increment: step; position: relative; padding: 0 0 16px 40px; cursor: pointer; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.steps li.current { background: var(--accent-soft); border-radius: 10px; margin-left: -8px; padding-left: 48px; padding-top: 6px; padding-right: 8px; }
.steps li.current::before { left: 8px; top: 6px; background: var(--accent); color: #fff; }
.notes { white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 13px; color: var(--accent); background: var(--accent-soft); padding: 2px 10px; border-radius: 999px; text-decoration: none; }
a { color: var(--accent); }

/* Forms */
form.edit { max-width: 720px; margin: 0 auto; display: grid; gap: 14px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 600; }
label small { font-weight: 400; }
input[type=text], input[type=number], input[type=url], input[type=password], textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 16px; /* 16px stops iOS zooming in */
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.photo-pick { display: flex; align-items: center; gap: 12px; }
.photo-pick img { width: 96px; height: 72px; object-fit: cover; border-radius: 10px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 400; font-size: 16px; }
.form-actions { display: flex; gap: 10px; justify-content: space-between; margin-top: 8px; }

.login { max-width: 360px; margin: 12vh auto 0; text-align: center; display: grid; gap: 14px; }
.login img { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto; }
.error { color: var(--danger); font-size: 15px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: 15px;
  box-shadow: var(--shadow); z-index: 20; max-width: calc(100% - 32px);
}

/* ---------- v2: weeks, prep and keep-back ---------- */
body { padding-bottom: calc(env(safe-area-inset-bottom) + 64px); }
body.logged-out #tabbar { display: none; }
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 6px) max(8px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
#tabbar a { display: grid; justify-items: center; gap: 1px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 2px 0; }
#tabbar a span { font-size: 20px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
#tabbar a.on { color: var(--accent); font-weight: 600; }
#tabbar a.on span { filter: none; opacity: 1; }
#toast { bottom: calc(env(safe-area-inset-bottom) + 76px); }
a.icon-btn { text-decoration: none; }

:root { --ok: #2e7d4f; --ok-soft: #e3f2e8; --warn: #a35a00; --warn-soft: #fff1dc; }
@media (prefers-color-scheme: dark) { :root { --ok: #7fd3a0; --ok-soft: #1f3327; --warn: #ffbf66; --warn-soft: #3a2c16; } }

.weeknav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; margin-bottom: 12px; }
.weeknav .icon-btn { font-size: 34px; padding: 0; }
.weeknav .range { font-weight: 700; }
.theme-name { font-size: 14px; text-decoration: none; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.segmented a { text-align: center; padding: 7px 4px; border-radius: 9px; text-decoration: none; color: var(--text); font-size: 14px; font-weight: 600; white-space: nowrap; }
.segmented a.on { background: var(--accent); color: #fff; }
@media (max-width: 380px) { .segmented a { font-size: 12px; } }

.days { display: grid; gap: 10px; }
.day-card { display: flex; align-items: stretch; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); text-decoration: none; color: inherit; overflow: hidden; }
.day-card.prep { background: var(--accent-soft); border-color: transparent; }
.day-card.cooked { opacity: .6; }
.day-link { display: flex; flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.day-name { flex: none; width: 58px; display: grid; place-content: center; text-align: center; font-weight: 800; color: var(--accent); border-right: 1px solid var(--line); padding: 10px 0; }
.day-name small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.day-card.prep .day-name { border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.thumb { width: 64px; object-fit: cover; flex: none; }
.day-body { flex: 1; min-width: 0; padding: 10px 12px; display: grid; gap: 2px; align-content: center; }
.day-body b { line-height: 1.25; }
.day-body > span { color: var(--muted); font-size: 14px; }
.day-actions { display: grid; gap: 6px; align-content: center; padding: 8px; border-left: 1px solid var(--line); }
.day-actions select { font-size: 13px; max-width: 74px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 4px; }
.check { width: 36px; height: 36px; margin: 0 auto; border-radius: 50%; border: 2px solid var(--line); background: none; color: transparent; font-size: 18px; cursor: pointer; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.bar { height: 6px; background: color-mix(in srgb, var(--accent) 18%, transparent); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.chips .mini, .mini { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin: 3px 4px 0 0; }
.mini.warn { background: var(--warn-soft); color: var(--warn); }

.refchip { display: inline-block; font-size: 11px; font-weight: 700; line-height: 1; padding: 3px 6px; margin-left: 4px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); vertical-align: 2px; }
.refchip.done { background: var(--line); color: var(--muted); text-decoration: line-through; }
.hint { color: var(--muted); font-size: 14px; }
.checklist { list-style: none; padding: 0; margin: 0 0 16px; }
.cl-heading { font-weight: 800; margin-top: 16px; padding-bottom: 4px; }
.cl-heading.depth-1 { font-weight: 700; margin-top: 10px; color: var(--muted); }
.cl-note { color: var(--muted); font-size: 14px; font-style: italic; }
.cl-plain { padding: 4px 0 4px 16px; }
.cl-plain.depth-2 { padding-left: 32px; }
.cl-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.cl-item.depth-2 { padding-left: 24px; }
.cl-item.depth-3 { padding-left: 48px; }
.cl-item.task { font-weight: 600; }
.cl-item .box { flex: none; width: 22px; height: 22px; margin-top: 1px; border: 2px solid var(--line); border-radius: 6px; }
.cl-item.done .box { background: var(--ok); border-color: var(--ok); }
.cl-item.done .cl-text { color: var(--muted); text-decoration: line-through; }
.cl-text { flex: 1; min-width: 0; }
.uses-detail summary { font-size: 13px; color: var(--accent); cursor: pointer; margin-top: 2px; text-decoration: none; }
.cl-item.done .uses-detail { text-decoration: none; }
.toolbar.top { margin: 0 0 8px; }

.el-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.el-card { display: grid; gap: 2px; padding: 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit; }
.el-card span { color: var(--muted); font-size: 13px; }
.el-card .refchip { margin: 4px 4px 0 0; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 16px 0; }
.panel h4 { margin-top: 2px !important; }
.panel summary { font-weight: 700; cursor: pointer; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.subtitle { margin: -2px 0 8px; font-size: 18px; color: var(--muted); }
.prep-panel { background: var(--accent-soft); border-color: transparent; }
.el { padding: 8px 0; border-top: 1px solid color-mix(in srgb, var(--accent) 20%, transparent); }
.el:first-of-type { border-top: 0; }
.el-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 700; }
.el-head a { color: var(--text); }
.share { font-weight: 700; color: var(--accent); font-size: 14px; }
.line { font-size: 14px; color: var(--muted); }
.keep { margin-top: 4px; font-size: 14px; color: var(--warn); font-weight: 600; }
.keep a { color: var(--warn); }
.ok { margin-top: 4px; font-size: 14px; color: var(--ok); }
.keep-panel { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: var(--warn-soft); }
.keep-panel h4 { color: var(--warn) !important; }
.kb { padding: 10px 0; border-top: 1px solid color-mix(in srgb, var(--warn) 25%, transparent); scroll-margin-top: 90px; transition: background .4s; border-radius: 8px; }
.kb:first-of-type { border-top: 0; }
.kb.flash { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.kb-head { display: flex; justify-content: space-between; gap: 8px; }
.bought { font-size: 13px; color: var(--muted); }
.kb-row { display: grid; grid-template-columns: 96px 1fr; gap: 8px; margin-top: 6px; font-size: 15px; }
.kb-row .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-top: 2px; }
.kb-row.keep .lbl { color: var(--warn); }
.kb-row.keep .lbl b { display: block; font-size: 15px; text-transform: none; letter-spacing: 0; }
.kb-row.used { opacity: .7; }
@media (max-width: 420px) { .kb-row { grid-template-columns: 1fr; gap: 2px; } }
.uses { list-style: none; margin: 0; padding: 0; }
.uses li { padding: 3px 0; }
.uses a { color: var(--text); font-weight: 600; }
.when { display: inline-block; min-width: 38px; font-size: 12px; font-weight: 800; color: var(--accent); }
.when.done { color: var(--muted); text-decoration: line-through; }
.badge { display: inline-block; margin-left: 4px; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); text-decoration: none; white-space: nowrap; }
.ingredients li.from-prep span:last-child { color: var(--accent); }
.steps .ref-el { color: var(--accent); font-weight: 700; text-decoration: underline; text-decoration-style: dotted; cursor: pointer; }
.amt { display: inline-block; margin-left: 3px; font-size: 12px; font-weight: 600; padding: 0 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); vertical-align: 1px; }
.videos { display: grid; gap: 10px; margin: 16px 0; }
.video { margin: 0; }
.video video, .video iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 12px; background: #000; display: block; }
.video video { aspect-ratio: auto; max-height: 70vh; }
.video-title { font-size: 14px; color: var(--muted); margin-top: 4px; }
.video-link { display: grid; padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); text-decoration: none; font-weight: 700; }
.video-link small { color: var(--muted); font-weight: 400; }
.video-row { display: grid; gap: 6px; margin-bottom: 12px; justify-items: start; }
.video-row figure, .video-row .video-link { width: 100%; }
.row-form { display: flex; gap: 8px; margin: 8px 0; }
.row-form input { flex: 1; min-width: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 16px; }
input[type=date] { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 16px; width: 100%; }
.file-btn { cursor: pointer; }
[hidden] { display: none !important; }

.theme-list { display: grid; gap: 10px; }
.theme-card { display: grid; gap: 2px; text-align: left; padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer; font: inherit; }
.theme-card span { color: var(--muted); font-size: 14px; }
.theme-card small { color: var(--accent); font-size: 13px; }
.preview-list { padding-left: 20px; }
.preview-list li { margin-bottom: 6px; }
.preview-list small { display: block; color: var(--muted); }
.warn-box { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 8px 0; }
.import { max-width: 720px; margin: 0 auto; }

.cal { display: grid; gap: 6px; }
.cal-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; align-items: center; padding: 8px 6px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit; }
.cal-head { background: none; border: 0; font-size: 12px; color: var(--muted); font-weight: 700; text-align: center; padding: 0 6px; }
.cal-row.planned { border-color: var(--accent); }
.cal-day { text-align: center; font-weight: 600; padding: 4px 0; border-radius: 8px; }
.cal-day.sun { color: var(--accent); }
.cal-day.other { color: var(--muted); opacity: .5; }
.cal-day.today { background: var(--accent); color: #fff; opacity: 1; }
.cal-theme { grid-column: 1 / -1; font-size: 13px; color: var(--accent); font-weight: 600; padding: 2px 4px 0; }
.cal-theme em { color: var(--muted); font-weight: 400; }
.day-body .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chips .mini, .mini { margin: 0; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
