:root {
  --bg: #faf7f2; --surface: #fff; --ink: #2b2420; --muted: #75685f; --line: #e8e0d6;
  --brand: #7a3e1d; --brand-ink: #fff; --brand-soft: #f3e6dc; --accent: #c8662b;
  --ok: #2f6b3a; --danger: #a23a2a; --radius: 12px; --shadow: 0 1px 2px rgba(60,40,20,.06), 0 4px 16px rgba(60,40,20,.06);
  --tabbar: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1916; --surface: #27221e; --ink: #f1ebe5; --muted: #b3a69b; --line: #3a332d; --brand: #e0a37a; --brand-ink: #1d1916; --brand-soft: #3a2b21; --accent: #e0a37a; --ok: #8fc79a; --danger: #ef8f7f; }
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.5; font-size: 16px; }
a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: .4em 0 .5em; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1rem; margin: 0; }
h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: .8em 0 .4em; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.ic { width: 1.1em; height: 1.1em; vertical-align: -.18em; flex: none; }
.ic.big { width: 56px; height: 56px; color: var(--brand); }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: .6em .7em; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .92rem; }
label > input, label > select, label > textarea { margin-top: .3em; font-weight: 400; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: .4em; padding: .55em .95em; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; min-height: 40px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.on { background: var(--brand-soft); border-color: var(--brand); }
.btn.small { padding: .3em .7em; font-size: .88rem; min-height: 32px; }
.btn.icon { width: 40px; justify-content: center; padding: 0; font-size: 1.2rem; }
.btn.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--brand); text-decoration: underline; }
.btn.link.danger, .btn.danger-ghost { color: var(--danger); }
.btn[disabled] { opacity: .6; cursor: default; }
.count { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--accent); color: #fff; font-size: .75rem; text-align: center; line-height: 1.5; }
.row { display: flex; gap: .5em; align-items: center; }
.row.wrap { flex-wrap: wrap; } .row.wrap input { flex: 1 1 200px; width: auto; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5em; font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--ink); }
.brand .ic { color: var(--brand); width: 1.5em; height: 1.5em; }
.topnav { display: none; gap: .25rem; margin-left: auto; }
.topnav a { display: flex; align-items: center; gap: .35em; padding: .45em .8em; border-radius: 999px; text-decoration: none; color: var(--ink); }
.topnav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.demo-badge { margin-left: auto; font-size: .75rem; background: #fff3c4; color: #5c4500; padding: .2em .6em; border-radius: 999px; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem 1rem calc(var(--tabbar) + 2rem + env(safe-area-inset-bottom)); }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: .75rem; color: var(--muted); text-decoration: none; position: relative; }
.tabbar a .ic { width: 24px; height: 24px; }
.tabbar a.on { color: var(--brand); font-weight: 600; }
.tabbar .dot { position: absolute; top: 6px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
@media (min-width: 820px) {
  .topnav { display: flex; } .demo-badge { margin-left: 0; }
  .tabbar { display: none; }
  main { padding: 1.5rem 1.5rem 3rem; }
}
.center-screen { min-height: 70vh; display: grid; place-items: center; padding: 1rem; text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.signin-card { max-width: 380px; background: var(--surface); padding: 2rem; border-radius: 20px; box-shadow: var(--shadow); }
.card-ish { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card-ish h2 { margin-top: 0; }
.banner { background: var(--brand-soft); border-radius: var(--radius); padding: .7rem 1rem; margin: 0 0 1rem; display: flex; flex-wrap: wrap; gap: .5em; align-items: center; }
.banner.warn { background: #fde8e3; color: #5d1f14; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); grid-column: 1 / -1; }
.empty h2 { color: var(--ink); }
.back { display: inline-flex; align-items: center; gap: .3em; text-decoration: none; }

/* browse */
.search-row { display: flex; gap: .5rem; }
.search { flex: 1; position: relative; }
.search .ic { position: absolute; left: .8em; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 2.4em; border-radius: 999px; min-height: 44px; }
.filters { display: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem 1rem 1rem; margin-top: .6rem; }
.filters.open { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .3em .75em; font-size: .88rem; cursor: pointer; display: inline-flex; align-items: center; gap: .3em; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.chip .x { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; display: inline-flex; }
.frow { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem; align-items: end; margin-top: .8rem; }
.result-count { color: var(--muted); font-size: .9rem; margin: .8rem 0 .4rem; min-height: 1em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .8rem; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; } }
.card { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s; }
.card:hover { transform: translateY(-2px); }
.thumb { position: relative; aspect-ratio: 4 / 3; background: var(--brand-soft); display: grid; place-items: center; overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.thumb .ph { width: 40%; height: 40%; color: var(--brand); opacity: .35; }
.thumb .flag { position: absolute; z-index: 2; left: 8px; top: 8px; background: var(--accent); color: #fff; font-size: .72rem; padding: .15em .55em; border-radius: 999px; }
.card-body { padding: .6rem .75rem .8rem; display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.card-body h3 { font-size: .98rem; line-height: 1.3; }
.meta { display: flex; flex-wrap: wrap; gap: .25rem .7rem; font-size: .8rem; color: var(--muted); }
.meta span { display: inline-flex; align-items: center; gap: .25em; }
.stars { color: var(--accent); letter-spacing: 1px; }
.card-body .btn { align-self: flex-start; margin-top: auto; }

/* recipe */
.recipe .hero { margin: -1rem -1rem 0; aspect-ratio: 16 / 9; max-height: 420px; overflow: hidden; background: var(--brand-soft); }
.recipe .hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.recipe .hero.noimg { display: none; }
@media (min-width: 820px) { .recipe .hero { margin: 0; border-radius: 16px; } }
.recipe-head h1 { font-size: 1.75rem; margin-top: .7em; }
.source { display: inline-flex; gap: .35em; align-items: center; font-size: .92rem; }
.facts { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; margin: .7rem 0; color: var(--muted); font-size: .92rem; }
.facts span { display: inline-flex; align-items: center; gap: .3em; }
.rating-row { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.rate button { border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--line); cursor: pointer; padding: 0 1px; }
.rate button.on { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }
.tags-section { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: .6rem 0; }
.tagline { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin: .3rem 0; }
.tg { font-size: .78rem; color: var(--muted); min-width: 92px; }
.tag { font-size: .82rem; padding: .12em .6em; border-radius: 999px; background: var(--brand-soft); color: var(--brand); border: 1px solid transparent; }
.tag.auto { background: transparent; border: 1px dashed var(--brand); }
.cols { display: grid; gap: 0 2rem; }
@media (min-width: 820px) { .cols { grid-template-columns: minmax(280px, 2fr) 3fr; } }
.sec-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.servings { display: flex; align-items: center; gap: .5rem; }
.hint { margin: .2rem 0 .4rem; }
.ing-list { list-style: none; padding: 0; margin: 0; }
.ing-list li { border-bottom: 1px solid var(--line); }
.ing-list .ing-head { font-weight: 700; padding: .8rem 0 .3rem; border: 0; }
.ing { display: block; width: 100%; text-align: left; border: 0; background: none; padding: .55rem 0; cursor: pointer; line-height: 1.4; }
.ing:hover, li.open .ing { color: var(--brand); }
.ing-panel { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: 0 0 .7rem; }
.scale-to { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.scale-to label { display: flex; align-items: center; gap: .4em; font-weight: 400; }
.scale-to input { width: 5em; margin: 0; padding: .35em .5em; }
.step-list { list-style: none; padding: 0; margin: 0; counter-reset: none; }
.step-list li { display: flex; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.step-list .num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: .88rem; }
.step-list li.done { color: var(--muted); text-decoration: line-through; }
.step-list li.done .num { background: var(--line); color: var(--muted); }
.step-list .step-head { font-weight: 700; cursor: default; border: 0; padding-top: 1rem; }
.notes { margin-top: 1rem; }
.note-form textarea { margin-bottom: .5rem; }
.note-form .row { justify-content: space-between; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: .4em; font-weight: 400; }
.check input { width: auto; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; margin-top: .6rem; }
.note.pinned { border-color: var(--accent); }
.note-top { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; font-size: .9rem; }
.note-text { margin: .35rem 0; white-space: pre-wrap; }
.note-actions { display: flex; gap: 1rem; font-size: .85rem; }
.note form textarea { margin-bottom: .4rem; }
.made-badge, .pin-badge { display: inline-flex; align-items: center; gap: .2em; font-size: .78rem; padding: .05em .5em; border-radius: 999px; }
.made-badge { background: #e3f1e5; color: var(--ok); }
.pin-badge { background: var(--brand-soft); color: var(--brand); }
@media (prefers-color-scheme: dark) { .made-badge { background: #22382a; } .banner.warn { background: #4a231c; color: #fde8e3; } }
.credit { margin-top: 2rem; }

/* forms */
.add-link .row { margin-top: .4rem; }
.add-link .row input { flex: 1; }
.or { text-align: center; color: var(--muted); margin: 1rem 0; }
.recipe-form { display: grid; gap: 1rem; max-width: 760px; }
.two, .three { display: grid; gap: 1rem; }
@media (min-width: 600px) { .two { grid-template-columns: 1fr 1fr; } .three { grid-template-columns: 1fr 1fr 1fr; } }
.tag-edit { border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem 1rem 1rem; }
.tag-edit legend { font-weight: 700; padding: 0 .4em; display: flex; gap: .8em; align-items: center; }
.chip-check input { position: absolute; opacity: 0; pointer-events: none; }
.chip-check span { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: .3em .75em; font-size: .88rem; font-weight: 400; cursor: pointer; background: var(--surface); }
.chip-check input:checked + span { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.chip-check input:focus-visible + span { outline: 2px solid var(--accent); }
.form-actions { display: flex; gap: .6rem; position: sticky; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); background: var(--bg); padding: .6rem 0; }
@media (min-width: 820px) { .form-actions { bottom: 0; } }
form.inline { display: inline-flex; gap: .3rem; }
form.inline input { width: 9em; padding: .25em .6em; border-radius: 999px; }

/* tools & lists */
.tools { display: grid; gap: 1rem; }
@media (min-width: 900px) { .tools { grid-template-columns: repeat(3, 1fr); align-items: start; } }
.tool p { margin-top: 0; }
.hits { list-style: none; padding: 0; margin: .6rem 0 0; }
.hits li { padding: .5rem 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
.hits li span { font-size: .85rem; }
.hits.big li { padding: .8rem 0; }
.menu-list { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
.menu-list a, .menu-list button { display: flex; justify-content: space-between; padding: 1rem; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; text-decoration: none; color: var(--ink); cursor: pointer; }
.menu-list > :last-child { border-bottom: 0; color: var(--danger); }
.menu-list span { color: var(--accent); font-weight: 700; }
.trash, .members { list-style: none; padding: 0; margin: 0 0 1rem; }
.trash li, .members li { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.trash li > div:first-child { display: flex; flex-direction: column; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); color: #fff; }
@media (min-width: 820px) { #toast { bottom: 24px; } }
