:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #2a2620;
  --ink-2: #6a6257;
  --line: #e2d9c8;
  --accent: #b4472e;
  --accent-ink: #fff;
  --accent-soft: #f3dfd6;
  --sage: #5f7356;
  --sage-soft: #e3e9dc;
  --warn: #8a5a00;
  --warn-soft: #fbefd2;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1a17;
    --card: #26231f;
    --ink: #eee6d8;
    --ink-2: #a89f91;
    --line: #3a352e;
    --accent: #e0775c;
    --accent-ink: #1c1a17;
    --accent-soft: #43281f;
    --sage: #9db38f;
    --sage-soft: #2c3428;
    --warn: #f0c46a;
    --warn-soft: #3a3020;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.boot { text-align: center; margin-top: 30vh; color: var(--ink-2); }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }

/* ---------- Kopfzeile ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
}
.top-row { display: flex; align-items: center; gap: 10px; max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.top h1 { font-size: 1.5rem; flex: 1; }
.top h1 a { color: inherit; text-decoration: none; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- Knöpfe ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 16px; cursor: pointer; text-decoration: none; color: var(--ink);
  min-height: 40px; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.icon { width: 40px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- Suche & Filter ---------- */
.search {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 10px 16px 10px 40px; min-height: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 14px center; background-size: 18px;
}
.filters { margin: 14px 0 6px; display: grid; gap: 8px; }
.chip-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; align-items: center; }
.chip-row::-webkit-scrollbar { display: none; }
.chip-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); min-width: 78px; flex: none; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 5px 12px; font-size: .9rem; cursor: pointer; white-space: nowrap; flex: none;
}
.chip.on { background: var(--sage); border-color: var(--sage); color: #fff; }
.chip .n { opacity: .6; font-size: .8em; margin-left: 3px; }
.result-info { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; color: var(--ink-2); font-size: .9rem; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }

/* ---------- Rezeptkarten ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr 1fr; gap: 10px; } }
.card {
  background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  text-decoration: none; color: inherit; display: flex; flex-direction: column;
  transition: transform .12s ease;
}
.card:hover { transform: translateY(-2px); }
.card .ph { aspect-ratio: 4 / 3; background: var(--accent-soft); position: relative; overflow: hidden; }
.card .ph img { width: 100%; height: 100%; object-fit: cover; }
.card .ph .noimg {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--serif); font-size: 2.6rem; color: var(--accent); opacity: .55;
}
.card .fav { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.35); color: #ffd66b; border-radius: 99px; width: 28px; height: 28px; display: grid; place-items: center; font-size: 15px; }
.card .body { padding: 10px 12px 12px; display: grid; gap: 4px; }
.card h3 { font-size: 1.05rem; }
.card .meta { font-size: .8rem; color: var(--ink-2); }
.empty { text-align: center; padding: 60px 20px; color: var(--ink-2); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }

/* ---------- Detailansicht ---------- */
.detail { max-width: 860px; margin: 0 auto; padding-bottom: 60px; }
.hero { position: relative; background: var(--accent-soft); aspect-ratio: 16 / 9; overflow: hidden; }
@media (min-width: 900px) { .hero { border-radius: 0 0 var(--radius) var(--radius); } }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.hero .add-img {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: var(--accent); cursor: pointer; border: 0; background: none; width: 100%;
}
.hero .add-img span { display: block; font-size: .95rem; }
.hero .add-img b { font-family: var(--serif); font-size: 3rem; display: block; font-weight: 400; }
.hero .img-actions { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 8px; }
.hero .img-actions .btn { background: rgba(255,255,255,.88); color: #222; border: 0; }
.d-head { padding: 20px 16px 0; display: grid; gap: 10px; }
.d-head h2 { font-size: clamp(1.6rem, 5vw, 2.3rem); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--sage-soft); color: var(--sage); border-radius: 999px; padding: 2px 10px; font-size: .82rem; }
.facts { display: flex; flex-wrap: wrap; gap: 16px; color: var(--ink-2); font-size: .92rem; }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px 0; }
.d-desc { padding: 0 16px; font-style: italic; color: var(--ink-2); }

.d-cols { display: grid; gap: 24px; padding: 24px 16px 0; }
@media (min-width: 760px) { .d-cols { grid-template-columns: 300px 1fr; align-items: start; } .ing-box { position: sticky; top: 80px; } }
.ing-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.d-cols h3 { font-size: 1.25rem; margin-bottom: 12px; }

.servings { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.servings .count { font-size: 1.4rem; font-family: var(--serif); min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; }
.servings .lbl { flex: 1; color: var(--ink-2); font-size: .9rem; }
.stepper { width: 38px; height: 38px; border-radius: 99px; border: 1px solid var(--line); background: var(--paper); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.scaled-note { font-size: .78rem; color: var(--ink-2); margin: -8px 0 12px; }

.ings { list-style: none; margin: 0; padding: 0; }
.ings li { display: grid; grid-template-columns: 5.2em 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.ings li:last-child { border-bottom: 0; }
.ings li.sec { display: block; font-weight: 600; font-family: var(--serif); border: 0; padding-top: 14px; cursor: default; }
.ings li.done { opacity: .4; text-decoration: line-through; }
.ings .qty { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li {
  counter-increment: s; position: relative; padding: 12px 12px 12px 52px; margin-bottom: 8px;
  background: var(--card); border-radius: var(--radius); cursor: pointer; box-shadow: var(--shadow);
}
.steps li::before {
  content: counter(s); position: absolute; left: 12px; top: 10px; width: 28px; height: 28px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .9rem;
}
.steps li.done { opacity: .45; }
.steps li.done::before { content: "✓"; background: var(--sage-soft); color: var(--sage); }
.notes { background: var(--warn-soft); border-radius: var(--radius); padding: 14px 16px; margin-top: 18px; white-space: pre-wrap; }
.source { margin-top: 18px; font-size: .9rem; color: var(--ink-2); word-break: break-all; }

/* ---------- Formulare ---------- */
.form { max-width: 860px; margin: 0 auto; padding: 16px 16px 120px; display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
.field > span, .legend { font-size: .82rem; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea.input { resize: vertical; min-height: 80px; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; border-color: var(--accent); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .row3 { grid-template-columns: 1fr 1fr; } .row3 .field:first-child { grid-column: 1 / -1; } }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: grid; gap: 10px; }

.ing-edit { display: grid; gap: 6px; }
.ing-row { display: grid; grid-template-columns: 4.6em 5.4em 1fr auto; gap: 6px; align-items: center; }
.ing-row.sec { grid-template-columns: 1fr auto; }
.ing-row.sec .input { font-weight: 600; font-family: var(--serif); background: var(--paper); }
.ing-row .input { min-height: 40px; padding: 8px 10px; }
.row-tools { display: flex; gap: 2px; }
.row-tools button { border: 0; background: none; width: 30px; height: 36px; cursor: pointer; color: var(--ink-2); border-radius: 8px; font-size: 1rem; }
.row-tools button:hover { background: var(--paper); color: var(--ink); }
@media (max-width: 520px) {
  .ing-row { grid-template-columns: 4em 4.6em 1fr; }
  .ing-row .row-tools { grid-column: 1 / -1; justify-content: flex-end; margin-top: -4px; }
  .ing-row.sec { grid-template-columns: 1fr; }
  .ing-row { padding-bottom: 6px; border-bottom: 1px dashed var(--line); }
}
.step-row { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: start; }
.step-row .num { padding-top: 10px; color: var(--accent); font-weight: 700; text-align: right; }
.step-row textarea { min-height: 64px; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }

.cat-group { display: grid; gap: 6px; }
.cat-group .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.img-edit { display: flex; gap: 14px; align-items: center; }
.img-edit .thumb { width: 120px; aspect-ratio: 4/3; border-radius: 10px; overflow: hidden; background: var(--accent-soft); flex: none; display: grid; place-items: center; color: var(--accent); font-size: .8rem; }
.img-edit .thumb img { width: 100%; height: 100%; object-fit: cover; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 94%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.savebar .in { max-width: 860px; margin: 0 auto; display: flex; gap: 10px; justify-content: flex-end; }

.banner { border-radius: var(--radius); padding: 12px 14px; background: var(--warn-soft); color: var(--warn); font-size: .92rem; }
.banner.ok { background: var(--sage-soft); color: var(--sage); }

/* ---------- Import ---------- */
.import { max-width: 640px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.tabs button { border: 0; background: none; border-radius: 999px; padding: 9px 6px; cursor: pointer; font-size: .95rem; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 34px 18px; text-align: center; cursor: pointer;
  background: var(--card); display: grid; gap: 8px; justify-items: center;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop b { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }
.file-list { display: grid; gap: 6px; }
.file-list .f { display: flex; justify-content: space-between; align-items: center; background: var(--card); border-radius: 10px; padding: 8px 12px; font-size: .9rem; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 2px; flex: none; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.working { display: grid; justify-items: center; gap: 14px; padding: 40px 10px; text-align: center; }
.spinner { width: 42px; height: 42px; border-radius: 99px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Anmeldung ---------- */
.login { max-width: 360px; margin: 12vh auto 0; padding: 24px; display: grid; gap: 14px; text-align: center; }
.login h1 { font-size: 2.2rem; }
.err { color: var(--accent); font-size: .9rem; min-height: 1.2em; }

/* ---------- Einstellungen ---------- */
.settings { max-width: 720px; margin: 0 auto; padding: 16px; display: grid; gap: 18px; }
.cat-list { display: grid; gap: 6px; }
.cat-item { display: grid; grid-template-columns: 1fr 9em auto; gap: 6px; align-items: center; }
@media (max-width: 520px) { .cat-item { grid-template-columns: 1fr 7em auto; } }
.stat { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 16px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.stat > span:last-child { text-align: right; margin-left: auto; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 100; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--accent); color: #fff; }

@media print {
  .top, .d-actions, .hero .img-actions, .savebar, .stepper { display: none !important; }
  body { background: #fff; }
  .ing-box, .steps li { box-shadow: none; border: 1px solid #ddd; }
}

/* ---------- Passwortfeld mit Auge ---------- */
.pw { position: relative; }
.pw .input { padding-right: 48px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 36px; border: 0; background: none; border-radius: 8px; cursor: pointer;
  color: var(--ink-2); display: grid; place-items: center;
}
.pw-toggle:hover { color: var(--ink); background: var(--paper); }
.pw-toggle svg { width: 20px; height: 20px; }
.pwform { display: grid; gap: 8px; }

/* ---------- Verwaltung ---------- */
.admin-link { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; grid-template-columns: none; }
.admin-link svg { width: 28px; height: 28px; color: var(--accent); flex: none; }
.ok { color: var(--sage); font-weight: 700; }
.bad { color: var(--accent); }
code { font-size: .88em; background: var(--paper); padding: 1px 6px; border-radius: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }
.users { display: grid; gap: 8px; }
details.user { border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
details.user summary { list-style: none; cursor: pointer; padding: 10px 14px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; align-items: baseline; }
details.user summary::-webkit-details-marker, details.newuser summary::-webkit-details-marker { display: none; }
details.user[open] summary { border-bottom: 1px solid var(--line); }
.userform { display: grid; gap: 10px; padding: 14px; }
details.newuser summary { list-style: none; width: max-content; }
details.newuser[open] .userform { border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; background: var(--paper); }
.yield { display: grid; grid-template-columns: 5em 1fr; gap: 6px; }

/* ---------- Import ---------- */
.rktable { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 10px 0; }
.rktable th { text-align: left; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line); padding: 6px 4px; }
.rktable td { border-bottom: 1px dashed var(--line); padding: 5px 4px; }
.rktable td:nth-child(2) { text-align: right; width: 4em; padding-right: 14px; }
.progress { height: 10px; background: var(--paper); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress .bar { height: 100%; width: 0; background: var(--sage); transition: width .3s ease; }
.rklog { max-height: 220px; overflow: auto; font-size: .85rem; background: var(--paper); border-radius: 10px; padding: 8px 12px; display: grid; gap: 4px; }
.rklog:empty { display: none; }
.login-icon { width: 112px; height: 112px; border-radius: 26px; margin: 0 auto -4px; box-shadow: var(--shadow); }
