/* Recipes — single stylesheet. Light/dark via prefers-color-scheme. */

:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f2ece3;
  --text: #2a221d;
  --muted: #7b6f66;
  --border: #e7dfd3;
  --accent: #b9532e;
  --accent-hover: #a24624;
  --accent-soft: #f7e4da;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(70, 45, 20, .06), 0 6px 20px rgba(70, 45, 20, .07);
  --radius: 16px;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --topbar-h: 56px;
  --gutter-l: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #25201c;
    --surface-2: #2f2924;
    --text: #f2ece5;
    --muted: #a99e94;
    --border: #3b342e;
    --accent: #e8825a;
    --accent-hover: #f09670;
    --accent-soft: #3d2a21;
    --on-accent: #1b1714;
    --danger: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
[id] { scroll-margin-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 16px); }
img { max-width: 100%; }
h1, h2, h3 { text-wrap: balance; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  height: var(--topbar-h);
  margin: 0 auto;
  padding: 0 var(--gutter-r) 0 var(--gutter-l);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font: 700 1.35rem/1 var(--serif);
  letter-spacing: -.01em;
}
.brand img { border-radius: 8px; }
.back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px; margin-left: -8px; padding: 0 8px 0 2px;
  color: var(--accent); font-weight: 600; text-decoration: none;
}
.topbar-actions { display: flex; gap: 8px; }

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px var(--gutter-r) calc(40px + env(safe-area-inset-bottom)) var(--gutter-l);
}

/* ------------------------------------------------------------------ buttons & chips */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: 600 16px/1 var(--sans); text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.small { min-height: 38px; padding: 0 15px; font-size: 15px; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

.link-button {
  background: none; border: 0; padding: 8px; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 15px; text-decoration: underline;
}

.chip {
  flex: none;
  display: inline-flex; align-items: center;
  min-height: 34px; padding: 0 14px;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font: 500 15px/1 var(--sans); text-decoration: none; white-space: nowrap; cursor: pointer;
}
.chip.small { min-height: 30px; padding: 0 12px; font-size: 14px; }
.chip.active { background: var(--text); color: var(--bg); }
.chip.selected { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ------------------------------------------------------------------ list page */

.toolbar { margin-bottom: 4px; }
.search { position: relative; max-width: 560px; }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 46px; padding: 0 16px 0 42px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: 17px var(--sans);
  -webkit-appearance: none; appearance: none;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.tag-row {
  display: flex; gap: 8px;
  margin: 12px calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
  padding: 0 var(--gutter-r) 4px var(--gutter-l);
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tag-row::-webkit-scrollbar { display: none; }
@media (min-width: 760px) {
  .tag-row { flex-wrap: wrap; margin-inline: 0; padding-inline: 0; overflow: visible; }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 18px;
}
@media (max-width: 559px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 12px; }
}

.card {
  display: flex; flex-direction: column;
  background: var(--surface); color: inherit; text-decoration: none;
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease;
}
@media (hover: hover) {
  .card:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(70, 45, 20, .08), 0 12px 28px rgba(70, 45, 20, .12); }
}
.card:active { transform: scale(.985); }
.card-img { aspect-ratio: 4 / 3; background: var(--surface-2); }
.card-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.placeholder {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 30% 20%, var(--accent-soft), transparent 60%),
    linear-gradient(135deg, var(--surface-2), var(--accent-soft));
}
.placeholder span { font: 700 3rem/1 var(--serif); color: var(--accent); opacity: .65; }
.card-body { padding: 12px 14px 14px; }
.card-body h2 {
  margin: 0;
  font: 650 1.12rem/1.25 var(--serif);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  margin: 7px 0 0; color: var(--muted); font-size: 13.5px;
}
.card-meta .time { display: inline-flex; align-items: center; gap: 4px; }
.mini-tag::before { content: "#"; opacity: .6; }
@media (max-width: 559px) {
  .card-body { padding: 10px 11px 12px; }
  .card-body h2 { font-size: 1rem; }
  .card-meta { font-size: 12.5px; }
  .card-meta .mini-tag { display: none; }
}

.no-matches { text-align: center; color: var(--muted); padding: 48px 0; }
.list-footer { text-align: center; margin-top: 48px; }

.empty-state { text-align: center; max-width: 440px; margin: 10vh auto 0; }
.empty-state img { border-radius: 20px; box-shadow: var(--shadow); }
.empty-state h1 { font: 700 2rem/1.15 var(--serif); margin: 20px 0 8px; }
.empty-state p { color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }

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

.recipe { max-width: 1100px; margin: 0 auto; }

.hero { margin: -16px calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l)); }
.hero-button { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.hero img { display: block; width: 100%; height: auto; max-height: 72vh; aspect-ratio: 4 / 3; object-fit: cover; }
@media (min-width: 760px) {
  .hero { margin: 8px 0 0; }
  .hero img { border-radius: 22px; max-height: 540px; aspect-ratio: 16 / 9; box-shadow: var(--shadow); }
}

.recipe-head { padding: 22px 0 6px; }
.recipe-head h1 {
  margin: 0 0 10px;
  font: 700 clamp(1.9rem, 5.2vw, 3rem)/1.08 var(--serif);
  letter-spacing: -.015em;
}
.lede { margin: 0 0 18px; max-width: 68ch; color: var(--muted); font-size: 1.1rem; }

.facts { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 16px; }
.facts div {
  min-width: 86px; padding: 8px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.facts dt { font-size: 11.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 650; }
@media (max-width: 559px) {
  .facts { gap: 8px; }
  .facts div { min-width: 0; padding: 7px 11px; }
  .facts dt { font-size: 10.5px; }
  .facts dd { font-size: 15.5px; }
}

.byline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.source {
  display: inline-flex; align-items: center; gap: 4px; margin-right: 6px;
  min-height: 30px; font-weight: 600; text-decoration: none;
}

.recipe-body { display: grid; gap: 28px; margin-top: 22px; }
@media (min-width: 900px) {
  .recipe-body { grid-template-columns: minmax(300px, 1fr) 1.65fr; gap: 48px; align-items: start; }
  .ingredients {
    position: sticky;
    top: calc(var(--topbar-h) + env(safe-area-inset-top) + 16px);
    max-height: calc(100vh - var(--topbar-h) - 32px);
    overflow-y: auto;
  }
}

.recipe-body h2 { margin: 0 0 10px; font: 700 1.5rem/1.2 var(--serif); }
.recipe-body h3 {
  margin: 20px 0 4px;
  color: var(--accent);
  font-size: .82rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
}

.ingredients {
  padding: 20px 22px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.ingredients ul { list-style: none; margin: 0; padding: 0; }
.ingredients li { padding: 10px 0; border-bottom: 1px solid var(--border); line-height: 1.4; }
.ingredients li:last-child { border-bottom: 0; }

.steps { counter-reset: step; }
.method ol { list-style: none; margin: 0; padding: 0; }
.method li {
  position: relative;
  counter-increment: step;
  padding: 2px 0 24px 50px;
  font-size: 1.08rem; line-height: 1.65;
}
.method li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font: 700 15px/1 var(--sans);
}

/* Alternative methods: a segmented switch (with JS), or titled blocks one after another (without). */
.method-switch {
  display: flex; gap: 3px;
  width: fit-content; max-width: 100%;
  margin: 2px 0 20px; padding: 3px;
  background: var(--surface-2); border-radius: 13px;
  overflow-x: auto; scrollbar-width: none;
}
.method-switch::-webkit-scrollbar { display: none; }
.method-switch button {
  flex: none; min-height: 40px; padding: 0 18px;
  border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font: 600 15.5px/1 var(--sans); cursor: pointer;
  transition: background .15s, color .15s;
}
.method-switch button[aria-selected="true"] {
  background: var(--surface); color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 2px 8px rgba(0, 0, 0, .08);
}
@media (max-width: 559px) {
  .method-switch { width: 100%; }
  .method-switch button { flex: 1 0 auto; }
}
.recipe-body .variant-title { margin: 22px 0 10px; color: var(--text); font: 700 1.15rem/1.2 var(--serif); letter-spacing: 0; text-transform: none; }
.method-switch-ready .variant-title { display: none; }

.notes {
  margin-top: 8px; padding: 18px 20px;
  background: var(--surface-2); border-radius: var(--radius);
}
.notes h2 { font-size: 1.2rem; }
.notes p { margin: 0; }

.gallery { margin-top: 40px; }
.gallery h2 { margin: 0 0 12px; font: 700 1.5rem/1.2 var(--serif); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery-item {
  display: block; padding: 0; border: 0; background: var(--surface-2);
  aspect-ratio: 1; border-radius: 12px; overflow: hidden; cursor: zoom-in;
}
.gallery-item { position: relative; }
.gallery-item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.gallery-badge {
  position: absolute; left: 7px; bottom: 7px;
  padding: 3px 8px; border-radius: 7px;
  background: rgba(0, 0, 0, .55); color: #fff;
  font: 600 11.5px/1.2 var(--sans);
}

.recipe-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-top: 44px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.recipe-actions form { margin: 0; }

.lightbox {
  padding: 0; border: 0; background: transparent;
  max-width: 100vw; max-height: 100vh; overflow: visible;
}
.lightbox::backdrop { background: rgba(0, 0, 0, .88); }
.lightbox img { display: block; max-width: 96vw; max-height: 88vh; border-radius: 10px; }
.lightbox-close {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 14px;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .16); color: #fff; font-size: 28px; line-height: 1; cursor: pointer;
}

/* ------------------------------------------------------------------ forms */

.recipe-form { max-width: 760px; margin: 0 auto; }
.form-title { margin: 4px 0 18px; font: 700 2rem/1.15 var(--serif); }

.field { margin: 0 0 20px; }
.field > label:not(.btn), .field > .label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 15px; }
.opt { margin-left: 4px; color: var(--muted); font-weight: 400; font-size: 13px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.hint code { padding: 1px 6px; border-radius: 5px; background: var(--surface-2); font-size: 13px; }

.recipe-form input:not([type="radio"]):not([type="checkbox"]):not([type="file"]),
.recipe-form textarea,
.login-card input {
  display: block; width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: 17px/1.45 var(--sans);
  -webkit-appearance: none; appearance: none;
}
.recipe-form textarea { resize: vertical; min-height: 3.2em; }
.recipe-form input:focus, .recipe-form textarea:focus, .login-card input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.recipe-form ::placeholder, .login-card ::placeholder { color: var(--muted); opacity: .7; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (min-width: 640px) { .field-row { grid-template-columns: repeat(4, 1fr); } }

.form-error, .import-error {
  margin: 12px 0 16px; padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 11%, transparent);
  color: var(--danger); font-weight: 500;
}

.import-box {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.import-box h2 { margin: 0 0 4px; font: 700 1.3rem/1.2 var(--serif); }
.import-box .hint { margin: 0; }
.import-box.done { border-color: var(--accent); }
.import-row { display: flex; gap: 8px; margin-top: 14px; }
.import-row input { flex: 1; min-width: 0; }
.import-box .import-error { margin-bottom: 0; }
.import-status { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); }
.import-status.ok { color: var(--accent); font-weight: 600; }
.import-status.ok .spinner { display: none; }
.import-status.ok::before { content: "✓"; }
.import-notes { margin: 12px 0 0; padding-left: 20px; color: var(--muted); font-size: 14.5px; }
.spinner {
  flex: none; width: 18px; height: 18px;
  border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.divider { display: flex; align-items: center; gap: 12px; margin: 26px 0 22px; color: var(--muted); font-size: 14px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Photo picker */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
  margin: 8px 0 12px;
}
.photo-grid:empty { display: none; }
.photo {
  position: relative; margin: 0;
  aspect-ratio: 1; overflow: hidden;
  border-radius: 12px; background: var(--surface-2);
}
.photo img { display: block; width: 100%; height: 100%; object-fit: cover; transition: opacity .15s, filter .15s; }
.photo figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 7px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65));
  color: #fff; font-size: 11.5px; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  pointer-events: none;
}
.photo-cover, .photo-remove, .photo-include {
  position: absolute; top: 6px;
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .45); color: #fff;
  font-size: 17px; line-height: 1; cursor: pointer;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.photo button.photo-remove { border: 0; padding: 0; font: inherit; font-size: 20px; }
.photo-cover { left: 6px; }
.photo-remove, .photo-include { right: 6px; }
.photo label input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.photo-cover:has(input:checked) { background: var(--accent); color: var(--on-accent); }
.photo-include:has(input:checked) { background: var(--accent); color: var(--on-accent); }
.photo:has(.photo-remove input:checked) img { opacity: .3; filter: grayscale(1); }
.photo:has(.photo-include input:not(:checked)) img { opacity: .45; }
.photo:has(.photo-include input:not(:checked)) .photo-cover { display: none; }
.photo .badge {
  position: absolute; left: 6px; bottom: 6px;
  padding: 2px 7px; border-radius: 6px;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px;
}
.photo-hint { margin: 0; }
.other-photos { margin: 0 0 8px; }
.other-photos .link-button { padding-left: 0; }

.add-photo { position: relative; overflow: hidden; }
.add-photo input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* Alternative cooking methods in the form */
.methods-hint { display: none; margin: -2px 0 8px; }
.steps-field.has-methods .methods-hint { display: block; }
.methods { display: grid; gap: 12px; margin-top: 14px; }
.methods:empty { display: none; }
.method-block {
  margin: 0; padding: 12px;
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 12px; background: var(--surface);
}
.method-head { display: flex; gap: 8px; margin-bottom: 8px; }
.recipe-form .method-name { font-weight: 600; }
.method-remove {
  flex: none; width: 44px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer;
}
.add-method { display: block; margin-top: 8px; padding-left: 0; color: var(--accent); text-decoration: none; font-weight: 600; }

.form-actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; justify-content: flex-end; gap: 10px;
  margin: 28px calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter-l));
  padding: 12px var(--gutter-r) calc(12px + env(safe-area-inset-bottom)) var(--gutter-l);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
@media (min-width: 800px) {
  .form-actions { margin-inline: 0; padding-inline: 0; }
}

/* ------------------------------------------------------------------ login */

.login-page .topbar { display: none; }
.login-page .page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.login-card {
  width: 100%; max-width: 360px;
  padding: 34px 26px 28px;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-icon { border-radius: 18px; box-shadow: var(--shadow); }
.login-card h1 { margin: 16px 0 22px; font: 700 1.8rem/1.1 var(--serif); }
.login-card input { margin-bottom: 12px; text-align: center; }
.login-card .form-error { margin: 0 0 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
}
