:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-2: #f3ece2;
  --text: #2a211b;
  --muted: #7a6b5f;
  --line: #e7ddd0;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3d8;
  --meat: #a8322d;
  --meat-soft: #f8dedb;
  --dairy: #2f6690;
  --dairy-soft: #dce9f4;
  --parve: #3f7d4e;
  --parve-soft: #ddeedf;
  --warn: #9a6a00;
  --warn-soft: #fbefd0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 8px rgba(60, 40, 20, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Arial Hebrew", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412;
    --surface: #221e1b;
    --surface-2: #2c2723;
    --text: #f1ebe4;
    --muted: #a99a8c;
    --line: #3a332d;
    --accent: #e07a4b;
    --accent-ink: #1b1411;
    --accent-soft: #3d2a20;
    --meat: #f08c86;
    --meat-soft: #3f2220;
    --dairy: #8cbde6;
    --dairy-soft: #1f3040;
    --parve: #8fcf9c;
    --parve-soft: #1f3324;
    --warn: #f0c35a;
    --warn-soft: #3a3017;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  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; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid; place-items: center;
  min-width: 44px; height: 44px; padding: 0 10px;
  border: 0; border-radius: 12px; background: transparent; color: var(--text);
  font-size: 22px; cursor: pointer; text-decoration: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.primary { background: var(--accent); color: var(--accent-ink); font-size: 26px; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 48px; }

/* ---------- home ---------- */
.search {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 17px;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 0; }

.seg { display: flex; gap: 6px; margin: 12px 0 8px; }
.seg button {
  flex: 1; height: 38px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-size: 15px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; margin: 0 -16px; padding-inline: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 15px; white-space: nowrap; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip-sep { flex: none; width: 1px; background: var(--line); margin: 6px 2px; }

.banner {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 14px; margin: 6px 0 12px;
  border-radius: 12px; background: var(--warn-soft); color: var(--text); font-size: 15px;
}
.banner.info { background: var(--accent-soft); }
.banner button { margin-inline-start: auto; }

.section-title { margin: 18px 0 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.cards { display: grid; gap: 10px; }
.card {
  display: block; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: inherit; text-decoration: none;
}
.card:active { background: var(--surface-2); }
.card h2 { margin: 0 0 6px; font-size: 18px; font-weight: 650; line-height: 1.3; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); }
.empty { padding: 32px 8px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge.k-בשרי { background: var(--meat-soft); color: var(--meat); }
.badge.k-חלבי { background: var(--dairy-soft); color: var(--dairy); }
.badge.k-פרווה { background: var(--parve-soft); color: var(--parve); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.soft { background: var(--surface-2); color: var(--muted); font-weight: 500; }

/* ---------- recipe ---------- */
.recipe-head h1 { margin: 6px 0 8px; font-size: 26px; line-height: 1.25; }
.recipe-head .badges { display: flex; flex-wrap: wrap; gap: 6px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.fact { flex: 1 1 30%; min-width: 96px; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); }
.fact b { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.fact span { font-size: 15px; font-weight: 600; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 6px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 16px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); grid-column: 1 / -1; }
.btn:disabled { opacity: .5; }
.btn.small { min-height: 38px; font-size: 15px; padding: 0 12px; }

.panel { margin: 18px 0; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2 { margin: 0 0 10px; font-size: 20px; }
.panel h3 { margin: 14px 0 6px; font-size: 16px; color: var(--accent); }
.panel h3:first-of-type { margin-top: 0; }
.ing { list-style: none; margin: 0; padding: 0; }
.ing li { padding: 7px 0; border-bottom: 1px solid var(--line); }
.ing li:last-child { border-bottom: 0; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { position: relative; padding: 4px 40px 12px 0; counter-increment: s; }
.steps li::before {
  content: counter(s); position: absolute; right: 0; top: 3px;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 15px;
}
.tips { margin: 0; padding-inline-start: 20px; }
.tips li { margin-bottom: 6px; }

.log { list-style: none; margin: 0 0 10px; padding: 0; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-size: 13px; margin-inline-end: 6px; }
.form { display: grid; gap: 8px; margin-top: 8px; }
textarea, .input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 16px;
}
textarea { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }
.originals img { display: block; max-width: 100%; border-radius: 10px; border: 1px solid var(--line); margin: 8px 0; }

/* ---------- cook mode ---------- */
.cook { font-size: 22px; line-height: 1.5; }
.cook .topbar h1 { font-size: 18px; }
.cook main { padding-top: 8px; }
.cook h2 { font-size: 22px; margin: 18px 0 8px; }
.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.check-list .box {
  flex: none; width: 30px; height: 30px; margin-top: 3px;
  border: 2px solid var(--muted); border-radius: 8px; display: grid; place-items: center; font-size: 18px;
  color: transparent;
}
.check-list li.done { color: var(--muted); }
.check-list li.done .text { text-decoration: line-through; }
.check-list li.done .box { background: var(--parve); border-color: var(--parve); color: #fff; }
.check-list .num { color: var(--accent); font-weight: 700; margin-inline-end: 4px; }
.check-list li.group-title { display: block; padding: 16px 4px 4px; border-bottom: 0; cursor: default; font-size: 18px; font-weight: 700; color: var(--accent); }
.wake { font-size: 14px; color: var(--muted); text-align: center; margin: 4px 0 0; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
