:root {
  --bg: #faf6ef;
  --surface: #ffffff;
  --surface-2: #f3ece1;
  --ink: #2a211b;
  --ink-2: #6b5d52;
  --line: #e6dccd;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3d8;
  --good: #3f7a4a;
  --danger: #a8322d;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 14px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #25201c;
    --surface-2: #2e2823;
    --ink: #f2ebe2;
    --ink-2: #b6a898;
    --line: #3b342e;
    --accent: #e0814f;
    --accent-ink: #1b1714;
    --accent-soft: #3d2a20;
    --good: #7fbf8a;
    --danger: #ef7a72;
    --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(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; }
main { max-width: 1080px; margin: 0 auto; padding: 16px 16px 64px; outline: none; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; text-decoration: none; color: var(--ink); line-height: 1; }
.brand-kicker { font: 600 11px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.brand-title { font: 600 22px/1.1 var(--serif); }
.top-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: 15px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { border-color: var(--ink-2); }

/* Home */
.hero { padding: 18px 0 8px; }
.hero h1 { font-size: clamp(28px, 6vw, 40px); }
.hero p { margin: 6px 0 0; color: var(--ink-2); }
.searchbar {
  position: sticky; top: 61px; z-index: 5;
  background: var(--bg); padding: 12px 0 10px; margin-bottom: 4px;
}
.search-input {
  width: 100%; padding: 12px 16px 12px 42px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23998877' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 15px center;
  font-size: 16px; box-shadow: var(--shadow);
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 26px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.section-title h2 { font-size: 22px; }
.section-title span { color: var(--ink-2); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  padding: 16px 16px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  text-decoration: none; color: var(--ink); min-height: 112px;
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h3 { font-size: 18px; padding-right: 26px; }
.card .meta { color: var(--ink-2); font-size: 13px; margin-top: auto; }
.card .fav { position: absolute; top: 12px; right: 12px; color: var(--accent); font-size: 18px; }
.empty { text-align: center; color: var(--ink-2); padding: 48px 16px; }

/* Recipe page */
.crumbs { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 14px; }
.back { text-decoration: none; font-weight: 500; }
.recipe-head { padding: 8px 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.kicker { font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.recipe-head h1 { font-size: clamp(30px, 6.5vw, 46px); margin: 10px 0 12px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { padding: 4px 12px; border-radius: 999px; background: var(--surface-2); font-size: 14px; font-weight: 500; }
.tag { padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; }
.recipe-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.recipe-body { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; gap: 32px; }
@media (max-width: 760px) { .recipe-body { grid-template-columns: 1fr; gap: 24px; } }
.label { font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 12px; display: flex; justify-content: space-between; align-items: center; }
.label button { font: 500 13px var(--sans); letter-spacing: 0; text-transform: none; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; }
.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li { border-bottom: 1px dashed var(--line); }
.ingredients label { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; cursor: pointer; }
.ingredients input { flex: none; width: 20px; height: 20px; margin-top: 2px; accent-color: var(--good); }
.ingredients input:checked + span { text-decoration: line-through; color: var(--ink-2); }
.ingredients .ing-head { font-family: var(--serif); font-weight: 600; padding: 14px 0 4px; border-bottom: 0; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  position: relative; padding: 12px 12px 12px 52px; margin-bottom: 8px; border-radius: 12px; cursor: pointer;
  counter-increment: step; transition: background .12s ease;
}
.steps li::before {
  content: counter(step); position: absolute; left: 10px; top: 10px;
  width: 30px; height: 30px; border-radius: 999px; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 600; font-size: 14px;
}
.steps li.active { background: var(--accent-soft); }
.steps li.active::before { background: var(--accent); color: var(--accent-ink); }
.steps li.done { color: var(--ink-2); }
.steps li.done::before { content: "✓"; background: var(--good); color: #fff; }
.steps .step-head { padding-left: 0; cursor: default; font-family: var(--serif); font-weight: 600; counter-increment: none; }
.steps .step-head::before { display: none; }
.hint { color: var(--ink-2); font-size: 13px; margin: 4px 0 0; }
.note {
  margin-top: 28px; padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface-2); border-left: 4px solid var(--accent);
}
.note p { margin: 6px 0 0; white-space: pre-wrap; }
.source { margin-top: 24px; color: var(--ink-2); font-size: 14px; }
.source ul { margin: 8px 0 0; padding: 0; list-style: none; display: flex; gap: 8px; flex-wrap: wrap; }
.source a { display: inline-block; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; font-weight: 500; background: var(--surface); }
.cook-mode .steps li { font-size: 19px; }
.cook-mode .ingredients label { font-size: 18px; }

/* Forms */
.form { display: grid; gap: 18px; max-width: 760px; }
.form h1 { font-size: 30px; margin-top: 6px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 14px; }
.field small { color: var(--ink-2); font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
.input, .textarea, select.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  font-size: 16px;
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.textarea.tall { min-height: 220px; }
.input:focus, .textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; position: sticky; bottom: 0; padding: 12px 0; background: var(--bg); border-top: 1px solid var(--line); }
.form-actions .spacer { flex: 1; }

/* Settings */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h2 { font-size: 20px; margin-bottom: 6px; }
.panel p { color: var(--ink-2); margin: 0 0 12px; font-size: 15px; }
.stack { display: grid; gap: 16px; max-width: 760px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; background: var(--ink-2); margin-right: 6px; }
.status-dot.on { background: var(--good); }

.sync-banner { max-width: 1080px; margin: 8px auto 0; padding: 8px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-size: 14px; width: calc(100% - 32px); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  #addBtn { padding: 8px 12px; }
  .brand-title { font-size: 20px; }
}

@media print {
  .topbar, .searchbar, .crumbs, .recipe-actions, .hint, .label button, .toast, .sync-banner { display: none !important; }
  body { background: #fff; color: #000; }
  .ingredients input { display: none; }
  .steps li { cursor: auto; background: none !important; color: #000 !important; }
  .steps li::before { content: counter(step) !important; background: #eee !important; color: #000 !important; }
  .recipe-body { grid-template-columns: 1fr 2fr; }
  a { color: #000; }
}
