:root {
  --paper: #f7f1e6;
  --card: #fffdf8;
  --ink: #3d2b1f;
  --muted: #8a7563;
  --line: #e6dccb;
  --accent: #b5532f;
  --accent-soft: #f3dfd2;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.55 var(--sans);
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }

.top {
  max-width: 1100px;
  margin: 0 auto;
  padding: 22px 20px 6px;
}
.brand {
  font: 600 30px/1 var(--serif);
  text-decoration: none;
  letter-spacing: 0.01em;
}
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 20px 120px;
}
.empty { color: var(--muted); padding: 40px 0; }

/* ---------- buttons ---------- */

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 15px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn:disabled { opacity: 0.5; }

/* ---------- grid ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 22px; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 4px 13px;
  font-size: 14px;
  color: var(--muted);
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 26px 22px;
}
.card a { display: block; text-decoration: none; }
.card img, .card .ph {
  width: 100%;
  aspect-ratio: 9 / 7;
  object-fit: cover;
  border-radius: 6px;
  background: var(--card);
  box-shadow: 0 1px 0 var(--line), 0 6px 18px -12px rgba(61, 43, 31, 0.35);
  transition: transform 0.15s;
}
.card a:hover img { transform: translateY(-2px); }
.card h2 { font-size: 20px; margin: 12px 0 2px; }
.card .meta { margin: 0; color: var(--muted); font-size: 14px; }

.ph {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  background: var(--card);
}
.ph.busy span { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

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

.draft-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 -20px 18px;
  padding: 10px 20px;
  background: var(--accent-soft);
  border-bottom: 1px solid #e8c7b4;
  font-size: 15px;
}
.draft-bar .actions { display: flex; flex-wrap: wrap; gap: 6px; }

.recipe { max-width: 900px; }
.recipe-top { display: flex; justify-content: space-between; margin-bottom: 14px; }
.hero { position: relative; margin: 0 0 6px; }
.hero img, .hero .ph {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 7;
  max-height: 520px;
  object-fit: cover;
  border-radius: 8px;
}
.hero .regen { position: absolute; right: 12px; bottom: 12px; background: rgba(255, 253, 248, 0.9); }
.recipe h1 { font-size: clamp(30px, 5vw, 44px); margin: 18px 0 6px; }
.lead { font-family: var(--serif); font-size: 19px; color: #5b4636; margin: 0 0 14px; max-width: 46em; }
.facts { list-style: none; padding: 0; margin: 0 0 26px; display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 15px; }
.facts b { color: var(--ink); font-weight: 600; }
.facts .tag { color: var(--accent); }

.columns { display: grid; grid-template-columns: minmax(250px, 1fr) 2fr; gap: 40px; }
@media (max-width: 760px) { .columns { grid-template-columns: 1fr; gap: 10px; } }
.columns h2 { font-size: 24px; margin: 0 0 10px; }
.columns h3 { font-size: 16px; margin: 18px 0 4px; color: var(--muted); }

.servings { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.servings h2 { margin: 0; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: 14px; }
.stepper button { border: 0; background: none; width: 32px; height: 30px; font-size: 18px; }
.stepper span { min-width: 92px; text-align: center; }

.ingredients ul { list-style: none; padding: 0; margin: 0; }
.ingredients li { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px dotted var(--line); }
.amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.steps ol { list-style: none; counter-reset: step; padding: 0; margin: 0; }
.steps li { counter-increment: step; position: relative; padding: 0 0 18px 46px; }
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -2px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 16px/1 var(--serif);
}

/* ---------- chat ---------- */

.bubble {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 20;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px -8px rgba(120, 50, 20, 0.6);
}
.bubble.open { background: var(--ink); }

.chat {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + 74px);
  z-index: 20;
  width: min(400px, calc(100vw - 40px));
  height: min(560px, calc(100dvh - 130px));
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 50px -20px rgba(61, 43, 31, 0.45);
  overflow: hidden;
}
.chat[hidden] { display: none; }
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--line);
  font: 600 18px var(--serif);
}
.chat-head .icon-btn { width: 32px; height: 32px; border: 0; font-size: 15px; }
.chat-log { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 14px; font-size: 15px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--paper); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--paper); border-bottom-left-radius: 4px; }
.msg.typing { animation: pulse 1.2s ease-in-out infinite; }
.msg.error { align-self: center; color: #a4281b; font-size: 14px; background: none; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}
.chat-form textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.send { border: 0; border-radius: 10px; background: var(--accent); color: #fff; width: 44px; font-size: 18px; }

@media (max-width: 520px) {
  .chat { right: 0; left: 0; bottom: 0; width: 100%; height: 100dvh; border-radius: 0; }
  .bubble.open { display: none; }
}

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

body.login { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.login-card { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { font-size: 40px; margin: 0 0 10px; text-align: center; }
.login-card label { font-size: 14px; color: var(--muted); }
.login-card input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.login-card .btn { padding: 10px; margin-top: 6px; }
.login-error { color: #a4281b; margin: 0; font-size: 14px; }
