:root {
  --bg: #faf6f0; --surface: #ffffff; --surface-2: #f3ede4; --text: #292524; --muted: #78716c; --line: #e7e0d6;
  --accent: #b8482c; --accent-ink: #ffffff; --accent-soft: #f6e3dc; --gold: #d99a1e; --danger: #b42318;
  --radius: 14px; --shadow: 0 1px 2px rgba(41, 37, 36, .06), 0 4px 16px rgba(41, 37, 36, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1917; --surface: #26221f; --surface-2: #2f2a26; --text: #f5f0ea; --muted: #a8a29e; --line: #3a3430;
    --accent: #e0745a; --accent-ink: #1c1917; --accent-soft: #3d2620; --gold: #e8b04a; --danger: #f97066;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--sans); padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.loading, .empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }

/* top bar */
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .5rem;
  padding: calc(.5rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .5rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; font: 600 1.25rem var(--serif); }
.brand img { width: 28px; height: 28px; }
.bar-title { flex: 1; font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.bar-actions { display: flex; align-items: center; gap: .25rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 42px; padding: .5rem 1rem;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.wide { width: 100%; }
.btn.small { min-height: 32px; padding: .25rem .75rem; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger-text { color: var(--danger); background: transparent; border-color: transparent; }
.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: transparent; color: var(--text); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 32px; height: 32px; font-size: 1.1rem; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn[aria-pressed="true"] svg { fill: currentColor; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 2px; }

/* forms */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .95rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
p.hint { margin: -.5rem 0 0; }
input:not([type=checkbox]), select, textarea { width: 100%; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-weight: 400; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: .6rem; }
.row2, .row4 { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; }
@media (min-width: 640px) { .row4 { grid-template-columns: repeat(4, 1fr); } }
.actions { display: flex; justify-content: flex-end; gap: .5rem; position: sticky; bottom: 0; padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%); }

/* pages */
.page { max-width: 1100px; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-right)) 3rem max(1rem, env(safe-area-inset-left)); }
.page.narrow { max-width: 720px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: min(380px, 100%); background: var(--surface); border-radius: 20px; padding: 2rem 1.5rem; box-shadow: var(--shadow); text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 1rem; text-align: left; margin-top: 1.25rem; }
.auth-logo { width: 64px; height: 64px; }
.auth-card h1 { margin: .5rem 0; }

/* list */
.search { position: relative; }
.search svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 2.5rem; border-radius: 999px; min-height: 46px; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding: .75rem 0 .25rem; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: .35rem .85rem; cursor: pointer; font-size: .9rem; }
.chip svg { width: 15px; height: 15px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.small { padding: .15rem .6rem; font-size: .85rem; }
.list-tools { display: flex; justify-content: space-between; align-items: center; margin: .5rem 0 .75rem; }
.list-tools select { width: auto; padding: .3rem .6rem; border-radius: 8px; font-size: .9rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit; box-shadow: var(--shadow);
  transition: transform .15s ease; display: flex; flex-direction: column; }
.card:hover { transform: translateY(-2px); }
.card-img { position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph { display: grid; place-items: center; width: 100%; height: 100%; font: 600 2.5rem var(--serif); color: var(--muted); background: var(--accent-soft); }
.fav-badge { position: absolute; top: .5rem; right: .5rem; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%;
  background: rgba(255, 255, 255, .9); color: var(--accent); }
.fav-badge svg { width: 16px; height: 16px; fill: currentColor; }
.card-body { padding: .6rem .8rem .8rem; }
.card-body h3 { margin: 0 0 .25rem; font-size: 1.05rem; }
.card-meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .85rem; gap: .5rem; }
.stars { display: inline-flex; }
.stars button { border: 0; background: none; padding: 0 1px; color: var(--line); font-size: .9rem; line-height: 1; }
.stars button.on { color: var(--gold); }
.stars.interactive button { font-size: 1.5rem; cursor: pointer; padding: 0 2px; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; }
.empty-state > svg { width: 56px; height: 56px; color: var(--accent); stroke-width: 1.5; }
.empty-state p { color: var(--muted); max-width: 26rem; margin: 0 auto 1.5rem; }

/* recipe */
.recipe .hero { width: 100%; max-height: 440px; object-fit: cover; border-radius: var(--radius); display: block; }
.recipe h1 { font-size: clamp(1.75rem, 5vw, 2.5rem); margin: 1rem 0 .5rem; }
.rating-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.tag { background: var(--accent-soft); color: var(--accent); padding: .15rem .65rem; border-radius: 999px; font-size: .85rem; text-decoration: none; }
.desc { color: var(--muted); font-size: 1.05rem; }
.facts { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin: 1rem 0; padding: .75rem 1rem; background: var(--surface); border-radius: var(--radius); }
.facts div { display: flex; flex-direction: column; }
.facts dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.cook-toggle { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.columns { display: grid; gap: 1.5rem; }
@media (min-width: 820px) { .columns { grid-template-columns: minmax(260px, 2fr) 3fr; align-items: start; }
  .ingredients { position: sticky; top: 72px; } }
.columns section, .notes { background: var(--surface); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow); }
.notes { margin-top: 1.5rem; }
.notes p { white-space: pre-wrap; margin: 0; }
.columns h2, .notes h2 { margin: 0 0 .75rem; font-size: 1.35rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.section-head h2 { margin: 0; }
.scaler { display: flex; align-items: center; gap: .3rem; font-size: .9rem; }
.scaler .icon-btn { border: 1px solid var(--line); }
#ings, #steps { list-style: none; margin: 0; padding: 0; }
#ings li { display: flex; gap: .65rem; padding: .45rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
#ings li:last-child { border-bottom: 0; }
#ings .box { flex: none; width: 20px; height: 20px; margin-top: 2px; border: 2px solid var(--line); border-radius: 6px; }
#ings li.done { color: var(--muted); }
#ings li.done > span:last-child { text-decoration: line-through; }
#ings li.done .box { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }
li.sub { font: 600 1rem var(--serif); padding: .9rem 0 .2rem !important; border: 0 !important; cursor: default !important; color: var(--accent); }
#steps li { display: flex; gap: .85rem; padding: .65rem .5rem; border-radius: 10px; cursor: pointer; }
#steps .num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 600; font-size: .9rem; }
#steps li.current { background: var(--accent-soft); }
#steps li.current .num { background: var(--accent); color: var(--accent-ink); }
.source { margin-top: 1.5rem; text-align: center; }
.source p { margin: .25rem 0; }

/* cook mode */
body.cook .recipe { font-size: 1.25rem; }
body.cook .recipe .hero, body.cook .desc, body.cook .source { display: none; }
body.cook #ings li, body.cook #steps li { padding-top: .7rem; padding-bottom: .7rem; }
body.cook .ingredients { position: static; }

/* add */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1.25rem; }
.tabs button { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .85rem .5rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; }
.tabs svg { width: 26px; height: 26px; }
.tabs button[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.or { margin-top: 2rem; }
.notice { background: var(--accent-soft); border-radius: 10px; padding: .75rem 1rem; margin: 0 0 1rem; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb > span { position: absolute; left: .35rem; bottom: .35rem; background: rgba(0, 0, 0, .6); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .8rem; }
.thumb .icon-btn { position: absolute; top: .2rem; right: .2rem; background: rgba(0, 0, 0, .55); color: #fff; }
.filebtn { cursor: pointer; flex-direction: row; }
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 1rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(4px); font-weight: 500; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* edit */
.photo-edit { display: flex; gap: 1rem; align-items: center; }
.photo-preview { width: 140px; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: var(--surface-2); flex: none; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .ph svg { width: 32px; height: 32px; }

/* settings */
.panel { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 .5rem; }
.panel h3 { margin: 1rem 0 .25rem; font-size: 1.05rem; }
.panel > .btn { margin-top: .75rem; }
.users { list-style: none; padding: 0; margin: .5rem 0 1rem; }
.users li { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.copyrow { display: flex; gap: .5rem; }
.copyrow input { font-size: .8rem; font-family: ui-monospace, Menlo, monospace; }
.bookmarklet { font-weight: 600; }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom)); transform: translate(-50%, 150%); z-index: 60;
  background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 12px; max-width: min(92vw, 480px);
  transition: transform .25s ease; box-shadow: var(--shadow); }
#toast.show { transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

@media print {
  .bar, .cook-toggle, .source .btn, .scaler, .rating-row .stars { display: none !important; }
  body { background: #fff; color: #000; }
  .columns section, .notes { box-shadow: none; border: 1px solid #ddd; }
}
