:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #2b2520;
  --muted: #7a6f66;
  --border: #e6ded4;
  --accent: #b4532a;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1916;
    --surface: #26221e;
    --text: #f1ebe4;
    --muted: #a59a8f;
    --border: #3a342e;
    --accent: #e07a4b;
    --accent-text: #1c1916;
    --danger: #f2948c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; }
.topbar nav a { text-decoration: none; color: var(--muted); }
.topbar nav a.active { color: var(--accent); font-weight: 600; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

h1 { font-size: 1.6rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
.muted { color: var(--muted); }
.center { text-align: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.narrow { max-width: 420px; margin: 2rem auto; }

form { display: grid; gap: 0.9rem; margin-top: 1rem; }
label { display: grid; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
input {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-error { color: var(--danger); font-weight: 400; font-size: 0.85rem; }
.form-error { color: var(--danger); margin: 0; }

button, .button {
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button:disabled { opacity: 0.6; cursor: default; }

.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.row input { flex: 1 1 240px; }

.list { list-style: none; padding: 0; margin: 0; }
.list li {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
}

/* ---------- shared ---------- */
.small { font-size: 0.85rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
code { font-size: 0.9em; background: var(--border); padding: 0.05rem 0.3rem; border-radius: 4px; }
textarea {
  font: inherit;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
  resize: vertical;
}
textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select {
  font: inherit;
  padding: 0.6rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.button { display: inline-block; text-decoration: none; }
.button.secondary { background: transparent; color: var(--accent); }
button.danger { border-color: var(--danger); color: var(--danger); }
.stack { display: grid; gap: 0.9rem; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* ---------- list ---------- */
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.filters input { flex: 1 1 220px; width: auto; }
.toggle {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}
.toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0 1rem; }
.chip {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .count { opacity: 0.6; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.9rem; }
.recipe-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
}
.recipe-card:hover { border-color: var(--accent); }
.thumb { aspect-ratio: 4 / 3; background: var(--border); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb span { font-size: 2.5rem; font-weight: 700; color: var(--muted); }
.card-body { padding: 0.7rem 0.85rem; }
.card-body h3 { font-size: 1rem; margin: 0 0 0.2rem; }
.card-body p { margin: 0; }
.star { color: var(--accent); }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
}

/* ---------- detail ---------- */
.hero { width: 100%; max-height: 420px; object-fit: cover; border-radius: var(--radius); margin-bottom: 1rem; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.icon-button {
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 1.8rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
}
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.5rem; }
.section-head h2 { margin: 0; }
.stepper { display: flex; align-items: center; gap: 0.5rem; }
.stepper button { padding: 0.2rem 0.7rem; }
.stepper output { min-width: 2.5ch; text-align: center; font-weight: 600; }
.ingredients { padding-left: 1.2rem; }
.ingredients li, .steps li { margin: 0.35rem 0; }
.steps li { padding-left: 0.25rem; margin-bottom: 0.75rem; }
.notes { white-space: pre-line; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* ---------- edit ---------- */
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
@media (max-width: 480px) { .three { grid-template-columns: 1fr 1fr; } }

/* ---------- import ---------- */
.import-list { list-style: none; padding: 0.25rem 1rem; }
.import-row { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.import-row:last-child { border-bottom: 0; }
.import-row p { margin: 0.25rem 0 0 1.75rem; }
.check { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; font-weight: 400; font-size: 1rem; }
.check input { width: auto; }
.status { font-size: 0.8rem; padding: 0.05rem 0.5rem; border-radius: 999px; background: var(--border); color: var(--muted); }
.ok .status { color: #2e7d32; }
.dup .status { color: #a86b00; }
.bad .status { color: var(--danger); }
.errors { color: var(--danger); margin: 0.3rem 0 0 1.75rem; padding-left: 1rem; font-size: 0.9rem; }
.reference { margin-top: 1.5rem; }
.reference summary { cursor: pointer; font-weight: 600; }
.reference table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; }
.reference td, .reference th { text-align: left; padding: 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.reference pre { overflow-x: auto; background: var(--bg); padding: 0.75rem; border-radius: 8px; font-size: 0.8rem; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  transform: translate(-50%, 1rem);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100% - 2rem);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
.card > h2:first-child { margin-top: 0; }
.card + .card { margin-top: 1rem; }
#ai-prompt { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.8rem; color: var(--muted); }
.ok-text { color: #2e7d32; }
.warn-text { color: #a86b00; }
@media (prefers-color-scheme: dark) {
  .ok-text, .ok .status { color: #81c784; }
  .warn-text, .dup .status { color: #e6b35a; }
}

/* ---------- PWA / offline ---------- */
.offline-bar {
  background: #5c4a3a;
  color: #fff;
  text-align: center;
  font-size: 0.85rem;
  padding: 0.4rem 1rem;
}
body.offline .online-only { display: none !important; }
.topbar .install { padding: 0.25rem 0.75rem; font-size: 0.85rem; }
.topbar nav { align-items: center; }
.thumb { position: relative; }
.thumb img { position: absolute; inset: 0; }
img.broken { display: none; }
@media (display-mode: standalone) {
  .topbar .install { display: none; }
}

/* ---------- invite / QR ---------- */
.invite { display: grid; gap: 0.9rem; }
.invite p { margin: 0; }
.qr-button {
  justify-self: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: zoom-in;
  line-height: 0;
}
.qr-button .qr { width: 200px; height: 200px; }
.qr-dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  max-width: calc(100vw - 2rem);
}
.qr-dialog::backdrop { background: rgb(0 0 0 / 0.6); }
.qr-dialog .qr { width: min(80vw, 70vh, 420px); height: auto; display: block; margin: 0 auto; }
.direct { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.direct[hidden] { display: none; }

/* ---------- add a recipe ---------- */
.choices { display: grid; gap: 0.75rem; margin-top: 1rem; }
.choice {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  min-height: 4.5rem;
}
.choice:hover, .choice:focus-visible { border-color: var(--accent); }
.choice-icon { font-size: 1.8rem; line-height: 1; width: 2.2rem; text-align: center; }
.choice-text { display: grid; gap: 0.15rem; flex: 1; }
.choice-text strong { font-size: 1.05rem; }
.choice-text span { color: var(--muted); font-size: 0.9rem; }
.choice-arrow { font-size: 1.6rem; color: var(--muted); }

#link-form input { font-size: 1.05rem; }
#link-form button, .helper button, .helper .button { min-height: 2.9rem; }

.guide { list-style: none; counter-reset: step; padding: 0; margin: 1rem 0; display: grid; gap: 0.75rem; }
.guide > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  gap: 0.6rem 0.75rem;
  align-items: start;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.guide > li::before {
  content: counter(step);
  grid-row: span 3;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--border);
  color: var(--muted);
}
.guide > li.current { border-color: var(--accent); }
.guide > li.current::before { background: var(--accent); color: var(--accent-text); }
.guide > li.done::before { content: '✓'; background: #2e7d32; color: #fff; }
.guide-text { display: grid; gap: 0.15rem; }
.guide > li > :not(.guide-text) { grid-column: 2; justify-self: start; }
.guide > li > textarea { justify-self: stretch; }
.guide p { margin: 0; }
.prompt-preview { white-space: pre-wrap; max-height: 16rem; overflow: auto; background: var(--bg); padding: 0.75rem; border-radius: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }

.notice { background: color-mix(in srgb, #e6b35a 18%, var(--surface)); border: 1px solid #e6b35a; border-radius: var(--radius); padding: 0.75rem 1rem; }
.review h2 { margin-top: 0.25rem; }
.review h3 { font-size: 1rem; margin: 1.25rem 0 0.4rem; }

.recipe-form input.short { max-width: 8rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.more { border-top: 1px solid var(--border); padding-top: 0.75rem; }
.more summary { cursor: pointer; font-weight: 600; padding: 0.25rem 0; }
.more[open] summary { margin-bottom: 0.75rem; }

/* ---------- account ---------- */
.list li { align-items: center; gap: 0.75rem; }
.small-button { font-size: 0.8rem; padding: 0.3rem 0.65rem; }
.notice.temp { margin-top: 0.75rem; display: grid; gap: 0.5rem; }
.notice.temp p { margin: 0; }
#temp-value { font-family: ui-monospace, Consolas, monospace; font-size: 1.1rem; letter-spacing: 0.05em; }
