:root {
  --bg: #f7f3ec;
  --card: #fffdf9;
  --ink: #2a241e;
  --muted: #7a6f63;
  --line: #e6ddd0;
  --accent: #c2562b;
  --accent-soft: #f6e3d9;
  --done: #a99f93;
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1714;
    --card: #24201c;
    --ink: #f1ebe3;
    --muted: #a99d8f;
    --line: #3a332c;
    --accent: #ec8a5e;
    --accent-soft: #3d2a20;
    --done: #6f665c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 var(--font);
}
a { color: var(--accent); }
.muted { color: var(--muted); }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font: 700 1.25rem/1 var(--serif); color: var(--ink); text-decoration: none; }
.add {
  font-size: .9rem; font-weight: 600; text-decoration: none;
  padding: 7px 12px; border-radius: 999px; background: var(--accent-soft);
}

main { max-width: 760px; margin: 0 auto; padding: 18px 16px 64px; }

/* search + filters */
.search {
  width: 100%; font: inherit; color: inherit;
  padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card);
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font: 600 .85rem/1 var(--font); color: var(--ink);
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.count { font-size: .85rem; color: var(--muted); margin: 10px 2px; }

/* recipe cards */
.grid { display: grid; gap: 12px; }
@media (min-width: 620px) { .grid { grid-template-columns: 1fr 1fr; } }
.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.card .body { padding: 14px 16px 16px; }
.card h2 { font: 700 1.15rem/1.25 var(--serif); margin: 0 0 4px; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: .95rem; }
.cat { font: 700 .72rem/1 var(--font); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: .78rem; padding: 3px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--ink); }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }

/* recipe page */
.back { display: inline-block; margin-bottom: 14px; text-decoration: none; font-weight: 600; }
.hero { width: 100%; border-radius: var(--radius); margin-bottom: 16px; aspect-ratio: 16 / 9; object-fit: cover; }
.recipe h1 { font: 700 clamp(1.7rem, 6vw, 2.3rem)/1.15 var(--serif); margin: 6px 0 8px; }
.recipe .lede { color: var(--muted); margin: 0 0 14px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 16px 0; }
.fact { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.fact b { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }
.btn {
  font: 600 .85rem/1 var(--font); color: var(--ink); text-decoration: none;
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
}
.btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.content h2 { font: 700 1.35rem/1.25 var(--serif); margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.content h3 { font-size: 1.05rem; margin: 20px 0 6px; }
.content ul, .content ol { padding-left: 1.3em; }
.content li { margin: 6px 0; padding: 2px 4px; border-radius: 6px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.content li > ul, .content li > ol { margin: 4px 0; }
.content li.done { color: var(--done); text-decoration: line-through; }
.content li.done > ul, .content li.done > ol { text-decoration: none; }
.content blockquote { margin: 16px 0; padding: 10px 14px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; }
.content blockquote p { margin: 4px 0; }
.content img { max-width: 100%; border-radius: 10px; }
.content .table { overflow-x: auto; }
.content table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.content th, .content td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.content code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.tip { font-size: .85rem; color: var(--muted); margin-top: 28px; }

@media print {
  .top, .tools, .back, .tip { display: none; }
  body { background: #fff; color: #000; }
  .content li.done { color: inherit; text-decoration: none; }
}

/* ================= Recipe editor ================= */
:root { --danger: #b3261e; --ok: #2e7d4f; --ok-soft: #e3f2e8; --shadow: 0 1px 2px rgba(40,30,20,.06), 0 4px 16px rgba(40,30,20,.06); }
@media (prefers-color-scheme: dark) { :root { --danger: #ff8a80; --ok: #7fd69f; --ok-soft: #1f3327; --shadow: none; } }

body.is-editing main { padding-bottom: 120px; }
.small { font-size: .82rem; }
.center { text-align: center; }
.editor-title { font: 700 clamp(1.6rem, 6vw, 2rem)/1.15 var(--serif); margin: 4px 0 14px; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.panel h2 { font: 700 1.15rem/1.2 var(--serif); margin: 0 0 10px; }
.field { display: block; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-size: .78rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.label em { font-style: normal; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--accent); margin-left: 4px; }
.hint { display: block; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.field-error { display: block; color: var(--danger); font-size: .85rem; margin-top: 6px; font-weight: 600; }

.editor input[type="text"], .editor textarea, .modal input[type="password"] {
  width: 100%; font: inherit; font-size: 16px; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  transition: border-color .12s, box-shadow .12s;
}
.editor input[type="text"]:focus, .editor textarea:focus, .modal input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.editor .input-title { font: 700 1.25rem/1.3 var(--serif); padding: 12px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding: 0; }
.chip-new { border-style: dashed; color: var(--accent); }
.small-chip { font-size: .78rem; padding: 6px 10px; color: var(--muted); }
#f-newcat { margin-top: 10px; }

.tag-box {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px; min-height: 46px; cursor: text;
}
.tag-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-box input[type="text"] { flex: 1 1 120px; border: 0 !important; box-shadow: none !important; background: transparent; padding: 6px; min-width: 100px; }
.tag-chip {
  font: 600 .85rem/1 var(--font); color: var(--ink); background: var(--accent-soft);
  border: 0; border-radius: 7px; padding: 7px 9px; cursor: pointer;
}
.tag-chip span { opacity: .55; margin-left: 2px; }
.suggest { margin-top: 8px; }

.trio { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.trio .field { margin: 0; }
.trio .field:last-child { grid-column: 1 / -1; }
@media (min-width: 560px) { .trio { grid-template-columns: 1fr 1fr 1.1fr; } .trio .field:last-child { grid-column: auto; } }
.stepper { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); }
.stepper button { width: 46px; border: 0; background: transparent; color: var(--accent); font-size: 1.4rem; cursor: pointer; }
.stepper button:active { background: var(--accent-soft); }
.stepper input[type="text"] { border: 0 !important; border-radius: 0; text-align: center; box-shadow: none !important; background: transparent; padding: 11px 0; }

.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 4px 0 14px;
  background: var(--line); border-radius: 12px;
}
.mode-switch button {
  font: 600 .9rem/1 var(--font); color: var(--muted); padding: 10px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
}
.mode-switch button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* list rows */
.list { display: flex; flex-direction: column; gap: 6px; }
.row { display: grid; grid-template-columns: 28px 1fr 36px; align-items: start; gap: 4px; }
.row .marker {
  height: 44px; display: grid; place-items: center; font-weight: 700; font-size: .85rem; color: var(--accent);
}
.row textarea { resize: none; overflow: hidden; min-height: 44px; line-height: 1.4; padding: 11px 12px; }
.row .del {
  height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 1.3rem; cursor: pointer; border-radius: 8px; opacity: .55;
}
.row:focus-within .del, .row .del:hover { opacity: 1; }
.row.heading { margin-top: 10px; }
.row.heading:first-child { margin-top: 0; }
.row.heading textarea { font-weight: 700; background: var(--accent-soft); border-color: transparent; }
.list-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-left: 32px; }
.list-actions button {
  font: 600 .85rem/1 var(--font); padding: 10px 12px; border-radius: 9px; cursor: pointer;
  border: 1px dashed var(--line); background: transparent; color: var(--accent);
}
.list-actions .add-item { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }

/* markdown mode */
.md-tools { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; scrollbar-width: none; }
.md-tools button {
  flex: none; font: 600 .82rem/1 var(--font); padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer;
}
.editor textarea.md { min-height: 320px; font: 15px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }

.notice { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: .92rem; }
.link { font: inherit; font-weight: 700; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.error-box { background: color-mix(in srgb, var(--danger) 12%, var(--card)); color: var(--danger); border-radius: 10px; padding: 12px 14px; font-weight: 600; margin: 4px 0 14px; }

/* sticky save bar */
.save-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 12px max(16px, calc((100vw - 760px) / 2 + 16px)) calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 700 1rem/1 var(--font); padding: 14px 20px; border-radius: 12px; cursor: pointer; text-decoration: none; min-height: 48px;
}
.btn-primary { background: var(--accent); color: #fff; border: 0; }
.btn-primary:disabled { opacity: .7; cursor: progress; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.save-bar .btn-primary { flex: 1; max-width: 260px; }

.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* password modal */
.modal-wrap {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 15, 10, .45); animation: fade .15s ease;
}
.modal {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 18px; padding: 22px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: pop .18s ease;
}
.modal-icon { font-size: 2rem; }
.modal h2 { font: 700 1.3rem/1.2 var(--serif); margin: 6px 0 4px; }
.modal p { margin: 0 0 14px; }
.modal .field-error { margin: -4px 0 10px; }
.check { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: .9rem; color: var(--muted); margin: 12px 0 16px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.modal-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s ease;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* success screen */
.success { text-align: center; padding: 30px 0; }
.success-icon {
  width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ok-soft); color: var(--ok); font-size: 2.2rem; font-weight: 700; animation: pop .3s ease;
}
.success h1 { font: 700 1.9rem/1.15 var(--serif); margin: 0 0 6px; }
.publish {
  display: flex; gap: 12px; align-items: center; text-align: left; max-width: 380px; margin: 20px auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--accent);
}
.publish div { color: var(--ink); }
.publish.live { border-color: var(--ok); background: var(--ok-soft); }
.live-dot { color: var(--ok); font-weight: 700; font-size: 1.2rem; }
.success-actions { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 0 auto 16px; }

a.btn-primary { color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary, a.btn-primary { color: #1a1714; } }

/* edit entry points + lock screen */
.recipe-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.recipe-top .back { margin: 0; }
.edit-btn {
  font: 600 .9rem/1 var(--font); text-decoration: none; color: var(--ink);
  padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
}
.edit-btn:hover { border-color: var(--accent); }
.edit-bottom {
  display: block; text-align: center; margin-top: 18px; padding: 14px; border-radius: 12px;
  border: 1px dashed var(--line); text-decoration: none; font-weight: 600;
}
.edit-bottom:hover { border-color: var(--accent); background: var(--accent-soft); }
@media print { .recipe-top .edit-btn, .edit-bottom { display: none; } }

.lock {
  max-width: 380px; margin: 40px auto 0; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 28px 22px; box-shadow: var(--shadow);
}
.lock-icon { font-size: 2.4rem; }
.lock h1 { font: 700 1.5rem/1.2 var(--serif); margin: 8px 0 6px; }
.lock p { margin: 0 0 16px; }
.lock input[type="password"] {
  width: 100%; font: inherit; font-size: 16px; color: inherit; text-align: center;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 13px;
}
.lock input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.lock .field-error { margin: 10px 0 0; }
.lock .btn-primary { width: 100%; }
