/* =========================================================
   Kochbuch — warmes, ruhiges Design. Mobile-first.
   ========================================================= */

:root {
  --bg: #faf5ec;
  --bg-card: #ffffff;
  --bg-sunken: #f1e9db;
  --ink: #2b241c;
  --ink-soft: #6f6558;
  --line: #e7ddcc;
  --accent: #c2512c;
  --accent-soft: #f7e3d9;
  --green: #3d6b4f;
  --green-soft: #e2ede6;
  --shadow: 0 2px 12px rgba(84, 62, 38, 0.10);
  --shadow-big: 0 8px 32px rgba(84, 62, 38, 0.18);
  --radius: 18px;
  --nav-h: 64px;
  --serif: ui-serif, Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1a16;
    --bg-card: #29241e;
    --bg-sunken: #171310;
    --ink: #f0e9de;
    --ink-soft: #a89c8c;
    --line: #3a332b;
    --accent: #e07048;
    --accent-soft: #45301f;
    --green: #7fb094;
    --green-soft: #26332b;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --shadow-big: 0 8px 32px rgba(0, 0, 0, 0.5);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  line-height: 1.5;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3 { font-family: var(--serif); font-weight: 700; letter-spacing: -0.01em; }
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 16px; color: var(--ink); }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.82rem; }

.view { max-width: 640px; margin: 0 auto; padding: 16px 16px 24px; }

/* ---------- Kopfzeilen ---------- */
.home-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 14px; }
.app-title { font-size: 2rem; color: var(--ink); }
.sub-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 14px; }
.sub-header h1 { font-size: 1.6rem; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-soft); background: var(--bg-card); box-shadow: var(--shadow);
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(0.94); }

/* ---------- Suche & Tags ---------- */
.search-wrap { position: relative; margin-bottom: 12px; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); pointer-events: none; }
#searchInput {
  width: 100%; padding: 12px 16px 12px 42px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--bg-card); outline: none;
}
#searchInput:focus { border-color: var(--accent); }

.tag-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 14px; scrollbar-width: none; }
.tag-row::-webkit-scrollbar { display: none; }
.tag-chip {
  padding: 6px 14px; border-radius: 999px; white-space: nowrap;
  background: var(--bg-card); border: 1px solid var(--line);
  color: var(--ink-soft); font-size: 0.88rem; font-weight: 500;
}
.tag-chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- Rezeptkarten ---------- */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.recipe-card {
  background: var(--bg-card); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
  text-align: left; display: flex; flex-direction: column; position: relative;
  transition: transform 0.12s ease;
}
.recipe-card:active { transform: scale(0.97); }
.card-img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--bg-sunken); }
.card-img-placeholder {
  width: 100%; aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem; background: linear-gradient(135deg, var(--accent-soft), var(--bg-sunken));
}
.card-body { padding: 10px 12px 12px; }
.card-title { font-family: var(--serif); font-size: 1.02rem; font-weight: 700; line-height: 1.25; }
.card-meta { display: flex; gap: 8px; margin-top: 5px; color: var(--ink-soft); font-size: 0.8rem; }
.card-fav { position: absolute; top: 8px; right: 8px; font-size: 1.1rem; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.35)); }

/* ---------- Leerer Zustand ---------- */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-emoji { font-size: 3.4rem; margin-bottom: 12px; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { color: var(--ink-soft); margin-bottom: 20px; max-width: 380px; margin-left: auto; margin-right: auto; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px; border-radius: 14px; font-size: 0.95rem; font-weight: 600;
  transition: transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-secondary { background: var(--bg-card); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { color: var(--ink-soft); }
.btn-danger { color: #c0392b; }
.btn-block { width: 100%; margin-bottom: 10px; }
.btn-sm { padding: 10px 16px; border-radius: 12px; }

/* ---------- Detail-Ansicht ---------- */
.detail-hero { position: relative; margin: -16px -16px 0; }
.detail-hero img { width: 100%; aspect-ratio: 16/10; object-fit: cover; }
.detail-hero .card-img-placeholder { aspect-ratio: 16/10; border-radius: 0; }
.detail-back {
  position: absolute; top: 14px; left: 14px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.92); color: #2b241c;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
}
.detail-actions { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; }
.detail-actions .icon-btn { background: rgba(255,255,255,0.92); color: #2b241c; }
.detail-body { padding-top: 18px; }
.detail-title { font-size: 1.7rem; line-height: 1.2; margin-bottom: 8px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.meta-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-card); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: 999px; font-size: 0.84rem; color: var(--ink-soft);
}
.meta-chip a { color: var(--accent); text-decoration: none; font-weight: 600; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; }
.section-head h2 { font-size: 1.25rem; }

.portion-stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.portion-stepper button { width: 32px; height: 32px; border-radius: 50%; font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.portion-stepper button:active { background: var(--accent-soft); }
.portion-stepper span { min-width: 74px; text-align: center; font-size: 0.88rem; font-weight: 600; }

.ing-list { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.ing-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.ing-item:last-child { border-bottom: none; }
.ing-check {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; color: #fff;
}
.ing-item.done .ing-check { background: var(--green); border-color: var(--green); }
.ing-item.done .ing-text { text-decoration: line-through; color: var(--ink-soft); }

.step-list { counter-reset: step; }
.step-item {
  display: flex; gap: 14px; background: var(--bg-card);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 10px;
}
.step-num {
  counter-increment: step;
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
}
.step-num::before { content: counter(step); }

.detail-cta-row { display: flex; gap: 10px; margin: 20px 0 8px; }
.detail-cta-row .btn { flex: 1; }

.video-link {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 16px; margin-top: 8px; text-decoration: none; color: var(--ink); font-weight: 600;
}

.notes-box { background: var(--bg-sunken); border-radius: var(--radius); padding: 14px 16px; color: var(--ink-soft); font-size: 0.92rem; white-space: pre-wrap; }

/* ---------- Editor ---------- */
.editor-field { margin-bottom: 16px; }
.editor-field label { display: block; font-size: 0.84rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.editor-field input, .editor-field textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg-card); outline: none; resize: vertical;
}
.editor-field input:focus, .editor-field textarea:focus { border-color: var(--accent); }
.editor-field .hint { font-size: 0.78rem; color: var(--ink-soft); margin-top: 4px; }
.editor-row { display: flex; gap: 12px; }
.editor-row .editor-field { flex: 1; }

.img-pick {
  width: 100%; aspect-ratio: 16/9; border-radius: var(--radius);
  border: 2px dashed var(--line); background: var(--bg-card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--ink-soft); overflow: hidden; position: relative;
}
.img-pick img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.img-remove {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  background: rgba(0,0,0,0.55); color: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 0.8rem; font-weight: 600;
}

/* ---------- Bottom Sheet ---------- */
.sheet-backdrop, .modal-backdrop {
  position: fixed; inset: 0; background: rgba(30, 22, 14, 0.45);
  z-index: 50; display: flex; backdrop-filter: blur(2px);
}
.sheet-backdrop { align-items: flex-end; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; margin: 0 auto;
  border-radius: 24px 24px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-big); animation: sheetUp 0.22s ease;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.5; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 1.3rem; margin-bottom: 14px; }
.sheet-option {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--bg-card); border-radius: 16px; padding: 13px 16px;
  margin-bottom: 10px; box-shadow: var(--shadow); text-align: left;
}
.sheet-option:active { transform: scale(0.98); }
.sheet-ico { font-size: 1.5rem; }
.sheet-option strong { display: block; font-size: 0.98rem; }
.sheet-option small { color: var(--ink-soft); font-size: 0.8rem; }

/* ---------- Modal ---------- */
.modal-backdrop { align-items: center; justify-content: center; padding: 20px; }
.modal {
  background: var(--bg); border-radius: 22px; padding: 22px;
  width: 100%; max-width: 460px; box-shadow: var(--shadow-big);
  max-height: 86vh; overflow-y: auto; animation: sheetUp 0.2s ease;
}
.modal h2 { font-size: 1.3rem; margin-bottom: 10px; }
.modal p { margin-bottom: 14px; }
.modal textarea, .modal input[type="url"], .modal input[type="text"] {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg-card); outline: none; margin-bottom: 14px; resize: vertical;
}
.modal-btns { display: flex; gap: 10px; }
.modal-btns .btn { flex: 1; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.import-status { text-align: center; padding: 16px 0; color: var(--ink-soft); }

/* ---------- Kochmodus ---------- */
.cook-mode {
  position: fixed; inset: 0; z-index: 80; background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px));
}
.cook-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cook-progress { font-weight: 700; color: var(--ink-soft); font-size: 0.95rem; }
.cook-close { font-size: 0.9rem; font-weight: 700; color: var(--accent); padding: 8px 14px; background: var(--accent-soft); border-radius: 999px; }
.cook-bar { height: 5px; border-radius: 3px; background: var(--bg-sunken); margin-bottom: 22px; overflow: hidden; }
.cook-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.25s ease; }
.cook-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; justify-content: center; }
.cook-step-text { font-size: 1.5rem; line-height: 1.45; font-family: var(--serif); }
.cook-ing-title { font-size: 1.35rem; margin-bottom: 14px; font-family: var(--serif); font-weight: 700; }
.cook-ing-list li { margin: 0 0 9px 20px; font-size: 1.1rem; }
.cook-nav { display: flex; gap: 12px; margin-top: 18px; }
.cook-nav .btn { flex: 1; padding: 16px; font-size: 1.05rem; }

/* ---------- Einkaufsliste ---------- */
.shopping-add { display: flex; gap: 10px; margin-bottom: 16px; }
.shopping-add input {
  flex: 1; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg-card); outline: none;
}
.shop-group-title { font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; margin: 18px 2px 8px; }
.shop-empty { text-align: center; color: var(--ink-soft); padding: 40px 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 18px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 20px;
  border-radius: 999px; font-size: 0.9rem; font-weight: 600;
  box-shadow: var(--shadow-big); z-index: 90; max-width: 88vw; text-align: center;
  animation: toastUp 0.25s ease;
}
@keyframes toastUp { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- Untere Navigation ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-card); border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-around;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--ink-soft); font-size: 0.72rem; font-weight: 600;
  padding: 6px 22px; position: relative;
}
.nav-btn.active { color: var(--accent); }
.nav-add {
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(194, 81, 44, 0.45);
  margin-top: -22px;
}
.nav-add:active { transform: scale(0.94); }
.badge {
  position: absolute; top: 2px; right: 14px;
  background: var(--accent); color: #fff;
  font-size: 0.66rem; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
