:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --ink: #2b2420;
  --ink-2: #74675d;
  --line: #ebe2d6;
  --brand: #c2562b;
  --brand-soft: #fbe8de;
  --ok: #3f8a5a;
  --danger: #b3412f;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1714;
    --card: #25211d;
    --ink: #f1ebe4;
    --ink-2: #a89b8f;
    --line: #3a332d;
    --brand: #ec8a5c;
    --brand-soft: #3d2a20;
    --ok: #7cc495;
    --danger: #e0715f;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
a { color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 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; min-width: 0; margin: 0; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back, .top-action {
  background: none; border: 0; color: var(--brand); cursor: pointer; flex: none;
  font-size: 26px; line-height: 1; padding: 4px 8px; border-radius: 10px;
}
.back { font-size: 34px; margin-left: -8px; padding: 0 6px 4px; }
.top-action { font-size: 22px; background: var(--brand-soft); min-width: 40px; height: 40px; }

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

.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 18px; }
.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }
.muted, .hint { color: var(--ink-2); font-size: 14px; }
.center { text-align: center; }
.banner { background: var(--brand-soft); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; }

/* ---------- Liste ---------- */
.search {
  width: 100%; font: inherit; padding: 11px 14px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink);
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; scrollbar-width: none; }
.chip {
  flex: none; font: inherit; font-size: 14px; padding: 5px 12px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.static { cursor: default; }
.recipe-card { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.recipe-card:active { transform: scale(.99); }
.recipe-card .emoji { font-size: 34px; width: 52px; height: 52px; display: grid; place-items: center; background: var(--brand-soft); border-radius: 14px; flex: none; }
.rc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rc-body b { font-size: 17px; }
.meta { color: var(--ink-2); font-size: 13px; }
.chev { color: var(--ink-2); font-size: 24px; }

.empty { text-align: center; color: var(--ink-2); padding: 48px 16px; line-height: 1.8; }
.empty .big { font-size: 48px; }
.empty .btn { margin-top: 12px; }

/* ---------- Fiche ---------- */
.hero { text-align: center; margin: 4px 0 14px; }
.hero-emoji { font-size: 56px; line-height: 1.1; }
.hero h2 { margin: 6px 0 8px; font-size: 24px; line-height: 1.2; }
.facts { display: flex; gap: 8px; margin-bottom: 8px; }
.facts > div {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 6px; text-align: center;
}
.facts span { font-size: 20px; }
.facts b { font-size: 15px; }
.facts small { color: var(--ink-2); font-size: 12px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper b { min-width: 20px; font-size: 17px; }
.stepper button {
  width: 30px; height: 30px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand-soft); color: var(--brand); font-size: 20px; font-weight: 700; line-height: 1;
}
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); text-decoration: underline; cursor: pointer; }
.facts + .card, .hint + .card { margin-top: 12px; }

.card h4 { margin: 14px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--brand); }
.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients:empty { display: none; }
.ingredients li { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.ingredients li:last-child { border-bottom: 0; }
.box { flex: none; width: 22px; height: 22px; margin-top: 1px; border: 2px solid var(--line); border-radius: 7px; display: grid; place-items: center; }
.checked .box { background: var(--ok); border-color: var(--ok); }
.checked .box::after { content: "✓"; color: #fff; font-size: 14px; font-weight: 700; }
.checked > span:last-child { color: var(--ink-2); text-decoration: line-through; }

.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.steps li:last-child { border-bottom: 0; }
.num {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 14px;
}
.done .num { background: var(--ok); }
.done > span:last-child { color: var(--ink-2); }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }

/* ---------- Formulaire ---------- */
.form label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 12px; }
.form label small { font-weight: 400; color: var(--ink-2); }
.form input, .form textarea, .modal input {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; font-size: 16px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink);
}
.form textarea { resize: vertical; line-height: 1.5; }
.row { display: flex; gap: 10px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.small { width: 100px; flex: none; }
.emoji-field { width: 76px; flex: none; }
.emoji-field input { text-align: center; font-size: 22px; padding: 6px; }

.btn {
  display: inline-block; font: inherit; font-weight: 600; text-decoration: none; text-align: center;
  padding: 11px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--danger); background: none; border-color: transparent; }
.btn.block { display: block; width: 100%; margin-top: 8px; }
.btn.sm { padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .6; }

.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; }
.modal-box { width: 100%; max-width: 360px; }
.modal-box h2 { margin: 0 0 4px; font-size: 19px; }
.modal-box input { margin: 12px 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px;
  width: max-content; max-width: calc(100vw - 32px); box-shadow: 0 6px 18px rgba(0,0,0,.2);
}

/* ---------- Mise à jour ---------- */
.update {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 25;
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; width: max-content; max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); border-radius: 99px; font-size: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.update button { font: inherit; font-weight: 700; border: 0; border-radius: 99px; padding: 6px 12px; background: var(--brand); color: #fff; cursor: pointer; }

/* ---------- Bandeau d'installation ---------- */
.install {
  position: fixed; left: 12px; right: 12px; z-index: 15;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  max-width: 656px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px 10px 10px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,.15);
}
.install img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.install-text { flex: 1; min-width: 0; font-size: 13px; color: var(--ink-2); line-height: 1.3; }
.install-text > b { display: block; font-size: 15px; color: var(--ink); }
.install-close { background: none; border: 0; color: var(--ink-2); font-size: 18px; padding: 6px; cursor: pointer; flex: none; }
/* le bandeau ne doit rien cacher : on remonte les messages et on laisse de la place en bas */
body.has-install main { padding-bottom: 96px; }
body.has-install .toast { bottom: calc(env(safe-area-inset-bottom) + 96px); }
.share-ico { width: 16px; height: 16px; vertical-align: -3px; color: var(--brand); }

/* ---------- Onglets ---------- */
:root { --tabbar-h: 60px; }
body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 200px; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-2); font-size: 12px; font-weight: 600;
}
.tabbar a span { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar a.on { color: var(--brand); }
.tabbar a.on span { filter: none; opacity: 1; }
.install { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); }
.toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); }
body.has-install .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 92px); }

/* ---------- Frigo ---------- */
.scan .hint { margin: 10px 0 0; }
.photo-btn { margin-top: 0; font-size: 17px; padding: 14px; }
.card h3 small { color: var(--ink-2); font-weight: 400; font-size: 14px; }
.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.items li:last-child { border-bottom: 0; }
.it-name { flex: 1; min-width: 0; }
.it-qty { color: var(--ink-2); font-size: 14px; text-align: right; }
.it-del { background: none; border: 0; color: var(--ink-2); font-size: 15px; padding: 6px 4px 6px 8px; cursor: pointer; }
.idea { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.idea:last-child { border-bottom: 0; }
.emoji.sm { font-size: 24px; width: 40px; height: 40px; display: grid; place-items: center; background: var(--brand-soft); border-radius: 12px; flex: none; }
.form select {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; font-size: 16px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink);
}
.modal-box.form label { margin-bottom: 10px; }
.modal-box.form input { margin: 4px 0 0; }
.modal-box h2 { margin-bottom: 12px; }

.scan-list { list-style: none; margin: 0; padding: 0; }
.scan-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.scan-list li:last-child { border-bottom: 0; }
.scan-list input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.scan-list input:not([type]) {
  font: inherit; font-size: 16px; padding: 6px 8px; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--ink); min-width: 0;
}
.scan-list input:not([type]):focus { border-color: var(--line); background: var(--bg); outline: none; }
.sc-name { flex: 1; }
.sc-qty { width: 112px; flex: none; color: var(--ink-2) !important; text-align: right; }
.scan-list li.off input:not([type]) { text-decoration: line-through; color: var(--ink-2); }
.tag { flex: none; font-size: 11px; padding: 2px 6px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); }
.btn.block + .btn.block { margin-top: 10px; }

.busy {
  position: fixed; inset: 0; z-index: 28; background: color-mix(in srgb, var(--bg) 90%, transparent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center;
}
.busy small { color: var(--ink-2); max-width: 260px; }
.spinner { width: 44px; height: 44px; border: 4px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Connexion ---------- */
/* pas de zoom au double-tap (le pincement reste possible) */
html { touch-action: manipulation; }
body.auth .tabbar, body.auth .topbar { display: none; }
body.auth { padding-bottom: 0; }
body.auth .install { bottom: calc(16px + env(safe-area-inset-bottom)); }
.auth-box { max-width: 380px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 4px 40px; }
.auth-box .logo { display: block; width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 12px; }
.auth-box h1 { text-align: center; margin: 0 0 4px; font-size: 28px; }
.auth-box .sub { text-align: center; color: var(--ink-2); margin: 0 0 24px; }
.auth-box .btn.block { margin-top: 16px; }
.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.center-link { display: block; margin: 16px auto 0; }
.member { padding: 4px 0; color: var(--ink); font-size: 16px; }
.member small { color: var(--ink-2); }
#members { margin-bottom: 10px; }
.form #invite-link { margin-bottom: 8px; }
