:root {
  --bg: #f7f1e8;
  --surface: #fffdf9;
  --surface-2: #f1e8db;
  --text: #2a211a;
  --muted: #7a6a5c;
  --line: #e6d9c7;
  --accent: #c2512f;
  --accent-ink: #ffffff;
  --accent-soft: #f6dfd4;
  --star: #e3a008;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 20px rgba(60, 40, 20, .08);
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, ui-serif, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1814;
    --surface: #26201b;
    --surface-2: #322a23;
    --text: #f3ebe1;
    --muted: #b3a393;
    --line: #3d342c;
    --accent: #e7784f;
    --accent-ink: #1c1814;
    --accent-soft: #4a2c20;
    --star: #f5b83d;
    --danger: #f97066;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-family: var(--serif); line-height: 1.15; margin: 0; font-weight: 700; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
main { outline: none; max-width: 1080px; margin: 0 auto; padding: 16px 16px 96px; }
.hidden { display: none !important; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand span { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; }
.brand img { border-radius: 8px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform .1s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn {
  width: 38px; height: 38px; min-height: 0; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; flex: none;
}
.icon-btn svg, .btn svg { width: 18px; height: 18px; }
.icon-btn[disabled] { opacity: .35; }

/* ---------- Liste ---------- */
.toolbar { display: grid; gap: 12px; margin: 4px 0 18px; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 16px; min-height: 46px; box-shadow: var(--shadow);
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; font-size: 16px; }
.filters { display: flex; gap: 8px; align-items: center; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; padding: 2px; margin: -2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.sort {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 10px; font-size: .9rem; max-width: 130px;
}
.count { color: var(--muted); font-size: .9rem; margin: 0 0 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
@media (max-width: 600px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .grid .card-body { padding: 10px 10px 12px; }
  .grid .card-body h3 { font-size: 1rem; }
  .grid .card-meta { flex-direction: column; align-items: flex-start; gap: 2px; font-size: .8rem; }
  .grid .card-img .badge { left: 8px; top: 8px; font-size: .7rem; padding: 2px 8px; }
}
.card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); text-decoration: none; color: inherit;
  display: flex; flex-direction: column; transition: transform .15s ease;
}
.card:active { transform: scale(.985); }
@media (hover: hover) { .card:hover { transform: translateY(-2px); } }
.card-img { aspect-ratio: 4 / 3; background: var(--surface-2); position: relative; }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-img .badge {
  position: absolute; left: 10px; top: 10px; background: rgba(20, 14, 10, .62); color: #fff;
  font-size: .75rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; backdrop-filter: blur(6px);
}
.card-body { padding: 12px 14px 14px; display: grid; gap: 4px; }
.card-body h3 { font-size: 1.15rem; }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .85rem; }
.placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 2.6rem; background: linear-gradient(135deg, var(--surface-2), var(--accent-soft));
}

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 8px; }
.empty .btn { margin-top: 16px; }

.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 24px rgba(194, 81, 47, .4);
  display: flex; align-items: center; justify-content: center; text-decoration: none;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- Étoiles ---------- */
.stars { display: inline-flex; gap: 1px; color: var(--star); line-height: 1; }
.stars svg { width: 16px; height: 16px; }
.stars .off { color: var(--line); }
.stars.lg svg { width: 22px; height: 22px; }
.star-input { display: flex; gap: 4px; }
.star-input button {
  background: none; border: 0; padding: 4px; cursor: pointer; color: var(--line);
  -webkit-tap-highlight-color: transparent;
}
.star-input button svg { width: 34px; height: 34px; transition: transform .1s ease; }
.star-input button.on { color: var(--star); }
.star-input button:active svg { transform: scale(1.2); }

/* ---------- Détail ---------- */
.detail { display: grid; gap: 20px; }
.hero { border-radius: var(--radius); overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow); }
.hero img { width: 100%; aspect-ratio: 4 / 3; max-height: 70vh; object-fit: cover; }
.hero .placeholder { aspect-ratio: 16 / 9; font-size: 4rem; }
.detail-head { display: grid; gap: 10px; }
.detail-head h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.facts { display: flex; gap: 8px; flex-wrap: wrap; }
.fact {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; font-size: .9rem; display: grid;
}
.fact b { font-size: 1rem; }
.fact span { color: var(--muted); font-size: .78rem; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h2 { font-size: 1.35rem; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.comment { white-space: pre-wrap; font-style: italic; color: var(--text); margin: 0; }
.cols { display: grid; gap: 20px; }
@media (min-width: 820px) {
  .cols { grid-template-columns: 1fr 1.6fr; align-items: start; }
  .cols .panel.sticky { position: sticky; top: 80px; }
}
.servings { display: inline-flex; align-items: center; gap: 6px; font-family: var(--sans); font-size: .9rem; font-weight: 500; }
.servings b { min-width: 2ch; text-align: center; }
.ing-list, .step-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.ing-list label {
  display: flex; gap: 12px; align-items: flex-start; padding: 8px 4px; border-bottom: 1px dashed var(--line); cursor: pointer;
}
.ing-list li:last-child label { border-bottom: 0; }
.ing-list input { width: 20px; height: 20px; accent-color: var(--accent); margin-top: 2px; flex: none; }
.ing-list input:checked + span { text-decoration: line-through; color: var(--muted); }
.ing-qty { font-weight: 700; }
.ing-note { color: var(--muted); }
.step-list { gap: 10px; counter-reset: step; }
.step-list li {
  display: flex; gap: 14px; padding: 12px; border-radius: 12px; background: var(--surface-2); cursor: pointer;
  transition: opacity .15s ease;
}
.step-list li::before {
  counter-increment: step; content: counter(step);
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.step-list li.done { opacity: .45; }
.step-list li.done::before { content: "✓"; }
.step-list p { margin: 3px 0 0; white-space: pre-wrap; }
.wake { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.wake input { accent-color: var(--accent); width: 18px; height: 18px; }

/* ---------- Formulaire ---------- */
.form { display: grid; gap: 18px; max-width: 760px; margin: 0 auto; }
.form h1 { font-size: 1.9rem; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: .95rem; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a6a5c' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
}

.photo-drop {
  position: relative; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface);
  aspect-ratio: 16 / 10; display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: pointer;
  text-align: center; color: var(--muted);
}
.photo-drop.has-img { border-style: solid; }
.photo-drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-drop svg { width: 38px; height: 38px; margin: 0 auto 6px; display: block; }
.photo-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-tools { display: flex; gap: 8px; justify-content: flex-end; }

.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-head h2 { font-size: 1.25rem; }

.ing-row {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: 76px 118px 1fr auto;
  padding-bottom: 10px; border-bottom: 1px dashed var(--line);
}
.ing-row:last-of-type { border-bottom: 0; padding-bottom: 0; }
.ing-row .input, .ing-row .select { min-height: 42px; padding-top: 8px; padding-bottom: 8px; }
.ing-row .note { grid-column: 3 / 4; min-height: 36px; font-size: 14px; padding: 6px 12px; }
@media (max-width: 560px) {
  .ing-row { grid-template-columns: 70px 1fr auto; }
  .ing-row .combo { grid-column: 1 / 3; grid-row: 2; }
  .ing-row .note { grid-column: 1 / 3; grid-row: 3; }
  .ing-row .row-actions { grid-row: 1 / 3; grid-column: 3; flex-direction: column; }
}
.row-actions { display: flex; gap: 4px; }

.combo { position: relative; }
.combo .input { padding-right: 38px; }
.combo-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border: 0; background: none; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.combo-toggle svg { width: 18px; height: 18px; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  max-height: min(320px, 50vh); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  margin: 0; padding: 4px; list-style: none;
}
.combo-list .group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px 4px; font-weight: 700; }
.combo-list .opt { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.combo-list .opt.active { background: var(--accent-soft); }
.combo-list .opt.create { color: var(--accent); font-weight: 600; }
.combo-list mark { background: none; color: var(--accent); font-weight: 700; }

.step-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: start; }
.step-num {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; display: flex; align-items: center; justify-content: center; margin-top: 8px;
}
.step-row .row-actions { flex-direction: column; }
.step-row .textarea { min-height: 72px; }

.form-actions {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.form-actions .btn { min-width: 120px; }

/* ---------- Connexion ---------- */
.login { max-width: 380px; margin: 40px auto; display: grid; gap: 14px; text-align: center; }
.login p { color: var(--muted); margin: 0; }

/* ---------- Divers ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
.install-hint { margin-top: 28px; text-align: center; color: var(--muted); font-size: .85rem; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }
.section, .field, .panel { scroll-margin-top: 80px; }
