:root {
  color-scheme: light dark;
  --bg: #faf6ef;
  --surface: #fffdf9;
  --soft: #f2e9db;
  --ink: #2b2118;
  --muted: #736355;
  --line: #e4d9c8;
  --accent: #a8401f;
  --accent-ink: #fffaf5;
  --danger: #a12a2a;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1612;
    --surface: #241e19;
    --soft: #2f2720;
    --ink: #f1e8dc;
    --muted: #ad9d8d;
    --line: #3d3329;
    --accent: #e58a67;
    --accent-ink: #1b1612;
    --danger: #f08a8a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 5vw, 2.7rem); letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { font: 600 1.3rem var(--serif); color: var(--ink); text-decoration: none; }
.site-nav { display: flex; gap: 8px; align-items: center; }

main { max-width: 1120px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 40px) 64px; outline: none; }

/* ---------- controls */

.btn, .chip, .seg, .tab, select, input, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-quiet { border-color: transparent; background: none; color: var(--muted); }
.btn-on { border-color: var(--accent); color: var(--accent); }
.btn-danger { color: var(--danger); }

input[type='text'], input[type='url'], input[type='number'], input[type='search'], input[type='password'], select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
textarea { line-height: 1.5; resize: vertical; }
input[type='file'] { width: 100%; padding: 18px 12px; border: 1px dashed var(--muted); border-radius: var(--radius); background: var(--surface); }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: 0.9rem;
}
.chip-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.eyebrow { font-size: 0.75rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.heart { color: var(--accent); }
.back { display: inline-block; margin-bottom: 18px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--ink); }

/* ---------- library */

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .search { flex: 1 1 240px; }
.toolbar select { width: auto; flex: 0 1 auto; }
.toolbar .chip { min-height: 42px; }
.count { margin: 16px 0 12px; color: var(--muted); font-size: 0.9rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgb(0 0 0 / 0.1); }
.card-art { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--soft); }
.card-art-empty {
  display: grid;
  place-items: center;
  font: 600 3.4rem var(--serif);
  color: hsl(var(--hue) 35% 38%);
  background: hsl(var(--hue) 45% 88%);
}
.card-body { padding: 12px 14px 16px; display: grid; gap: 4px; }
.card-body h3 { font-size: 1.15rem; }
.card-facts { color: var(--muted); font-size: 0.88rem; }
.empty { grid-column: 1 / -1; padding: 40px 0; text-align: center; color: var(--muted); }
.footnote { margin-top: 36px; font-size: 0.9rem; color: var(--muted); }

.message { max-width: 460px; margin: 12vh auto; text-align: center; display: grid; gap: 14px; justify-items: center; }
.message p { color: var(--muted); }

/* ---------- recipe page */

.recipe-head { display: grid; gap: 24px; align-items: start; }
.recipe-head > div { display: grid; gap: 12px; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }
.source { font-size: 0.92rem; color: var(--muted); }
.hero { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); }

.facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 4px 0 0; padding: 14px 0; border-block: 1px solid var(--line); }
.facts dt { font-size: 0.72rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 22px 0 8px; }

.columns { display: grid; gap: 32px; margin-top: 24px; }
.columns h2 { margin-bottom: 14px; }
.columns h3 { margin: 18px 0 8px; color: var(--accent); }

.scale { display: flex; align-items: stretch; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); width: fit-content; max-width: 100%; }
.seg { min-width: 48px; min-height: 40px; border: 0; border-right: 1px solid var(--line); background: none; cursor: pointer; font-variant-numeric: tabular-nums; }
.seg-on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.scale .scale-custom { width: 84px; min-height: 40px; border: 0; border-radius: 0; background: none; text-align: center; }
.scale-note { margin-top: 12px; font-size: 0.86rem; color: var(--muted); }

.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li { border-bottom: 1px solid var(--line); }
.ingredients label { display: flex; gap: 12px; align-items: flex-start; padding: 10px 2px; cursor: pointer; }
.ingredients input { width: 18px; height: 18px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }
.ingredients strong { font-variant-numeric: tabular-nums; }
.ingredients input:checked + span { color: var(--muted); text-decoration: line-through; }

.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 18px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 34px 1fr; gap: 12px; font-size: 1.05rem; line-height: 1.6; }
.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--soft);
  font: 600 0.95rem var(--serif);
  color: var(--accent);
}
.notes { margin-top: 32px; padding: 18px 20px; border-radius: var(--radius); background: var(--soft); display: grid; gap: 8px; }
.notes h2 { margin: 0; font-size: 1.1rem; }

.originals { margin-top: 40px; }
.originals h2 { margin-bottom: 12px; }
.original-photos { display: flex; flex-wrap: wrap; gap: 12px; }
.original-photos img { height: 180px; border-radius: var(--radius); border: 1px solid var(--line); display: block; }

@media (min-width: 820px) {
  .recipe-head:has(.hero) { grid-template-columns: 1.3fr 1fr; }
  .columns { grid-template-columns: minmax(280px, 1fr) 1.7fr; gap: 48px; }
  .col-ingredients { position: sticky; top: 16px; align-self: start; max-height: calc(100vh - 32px); overflow: auto; padding-right: 4px; }
}

/* ---------- add / edit */

.add { max-width: 760px; margin: 0 auto; }
.add h1 { margin-bottom: 18px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; border-bottom: 3px solid transparent; background: none; cursor: pointer; white-space: nowrap; color: var(--muted); }
.tab-on { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.panel form, .recipe-form { display: grid; gap: 16px; }
.panel form > .btn { justify-self: start; }

.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 0.92rem; }
.field small, .hint { color: var(--muted); font-size: 0.88rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; align-items: start; }
.hint.warn, .hint.review { padding: 12px 14px; border-radius: var(--radius); background: var(--soft); color: var(--ink); }
.hint.review { margin-bottom: 18px; }
.form-error { color: var(--danger); font-weight: 600; }
.form-actions { display: flex; gap: 10px; }
.previews { display: flex; flex-wrap: wrap; gap: 10px; }
.previews img { height: 120px; border-radius: 8px; border: 1px solid var(--line); }

/* ---------- landing, notices, sign-in, account */

.landing { display: grid; gap: 28px; max-width: 760px; margin: 0 auto; }
.hero-copy { display: grid; gap: 12px; padding-top: clamp(8px, 4vh, 40px); }
.try-box { padding: clamp(18px, 4vw, 28px); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); display: grid; gap: 14px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }
.features { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; }
.features li { display: grid; gap: 4px; align-content: start; }
.features p { color: var(--muted); font-size: 0.95rem; }

.notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; padding: 14px 18px; margin-bottom: 20px; border-radius: var(--radius); background: var(--soft); }
.notice p { flex: 1 1 260px; }
.try-box .notice, .panel .notice { margin-bottom: 0; }

.card-page { max-width: 520px; margin: clamp(8px, 6vh, 60px) auto 0; display: grid; gap: 16px; }
.stack { display: grid; gap: 14px; justify-items: start; }
.stack .field { width: 100%; }
.plan { padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); display: grid; gap: 12px; justify-items: start; }
.plan-list { margin: 0; padding-left: 20px; color: var(--muted); display: grid; gap: 4px; }
input[type='email'] { width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

/* ---------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
}

/* ---------- print: just the recipe, on paper */

@media print {
  :root { --bg: #fff; --surface: #fff; --soft: #f3f3f3; --ink: #000; --muted: #444; --line: #ccc; --accent: #000; }
  .site-header, .back, .actions, .notice, .scale, .scale-custom, .originals, .toast, .tags, .ingredients input { display: none !important; }
  main { padding: 0; max-width: none; }
  .hero { display: none; }
  .columns { grid-template-columns: 1fr 1.8fr; gap: 28px; }
  .col-ingredients { position: static; max-height: none; overflow: visible; }
  .steps li { break-inside: avoid; font-size: 1rem; }
  .ingredients input:checked + span { color: inherit; text-decoration: none; }
  a { color: inherit; text-decoration: none; }
}
