:root {
  --bg: #fffaf5;
  --surface: #ffffff;
  --surface-2: #fdf3e9;
  --text: #2a211b;
  --muted: #7a6a5e;
  --line: #eadfd4;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #ffedd5;
  --ok: #3f7d4e;
  --danger: #b42318;
  --shadow: 0 1px 2px rgb(60 30 10 / 6%), 0 6px 24px rgb(60 30 10 / 7%);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1512;
    --surface: #231c18;
    --surface-2: #2c231e;
    --text: #f3e9e0;
    --muted: #b3a294;
    --line: #3b2f28;
    --accent: #f08a4b;
    --accent-ink: #1a1512;
    --accent-soft: #3d2618;
    --ok: #7cc28d;
    --danger: #f2877d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--sans);
}
img { max-width: 100%; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; font-family: var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 1.2em; }
main { max-width: 1240px; margin: 0 auto; padding: 0 16px 96px; outline: none; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

/* --- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1240px; margin: 0 auto; padding: 14px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }

/* --- controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; text-decoration: none;
  font-size: .925rem; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.icon { padding: 8px 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .8rem; border: 1px solid transparent;
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--accent); color: var(--accent); }
input[type=text], input[type=url], input[type=search], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus, select:focus, .btn:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 90px; }
label { font-weight: 600; font-size: .925rem; }
.field { display: grid; gap: 6px; margin-bottom: 18px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* --- home --- */
.hero { text-align: center; padding: 36px 0 28px; }
.hero h1 { margin-bottom: .25em; }
.hero p { color: var(--muted); margin: 0 auto 22px; max-width: 560px; }
.import { max-width: 720px; margin: 0 auto; padding: 10px; display: grid; gap: 8px; }
.import-row { display: flex; gap: 8px; }
.import-row input { border: none; background: transparent; font-size: 1.05rem; padding: 10px; }
.import-row input:focus { outline: none; }
.import textarea { min-height: 160px; }
.import-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 6px; flex-wrap: wrap; }
.status { max-width: 720px; margin: 12px auto 0; text-align: center; color: var(--muted); min-height: 1.5em; }
.status.error { color: var(--danger); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.library-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 40px 0 16px; flex-wrap: wrap; }
.library-head h2 { margin: 0; }
.library-tools { display: flex; gap: 8px; align-items: center; flex: 1; justify-content: flex-end; min-width: 260px; }
.library-tools input { max-width: 320px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.tile { overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; transition: transform .15s; }
.tile:hover { transform: translateY(-2px); }
.tile .thumb { aspect-ratio: 4/3; background: var(--surface-2); position: relative; }
.tile .thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile .thumb .fav { position: absolute; top: 8px; right: 8px; background: var(--surface); border-radius: 999px; padding: 0 7px; color: var(--accent); }
.tile .body { padding: 12px 14px 14px; display: grid; gap: 4px; }
.tile .title { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; line-height: 1.25; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* --- recipe --- */
.recipe-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px; align-items: start; }
.recipe { padding: 0; overflow: hidden; }
.recipe-hero { background: var(--surface-2); }
.recipe-hero img { display: block; width: 100%; aspect-ratio: 21/9; max-height: 380px; object-fit: cover; }
.chat-close { display: none !important; }
.recipe-body { padding: 24px clamp(16px, 4vw, 36px) 36px; }
.recipe-source { font-size: .875rem; color: var(--muted); margin-bottom: 6px; }
.recipe-source a { color: inherit; }
.description { color: var(--muted); font-size: 1.05rem; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 16px 0; padding: 14px 0; border-block: 1px solid var(--line); }
.meta div { display: grid; }
.meta span { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.meta strong { font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.menu { position: relative; }
.menu-list { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 230px; padding: 6px; display: grid; }
.menu-list button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.version-bar { display: flex; align-items: center; gap: 8px; font-size: .875rem; color: var(--muted); }
.version-bar select { width: auto; padding: 4px 8px; font-size: .875rem; }
.method { font-size: .75rem; }

.columns { display: grid; grid-template-columns: minmax(220px, 2fr) 3fr; gap: 36px; margin-top: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.section-head h2 { margin: 0; }
.scaler { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 999px; padding: 2px; font-size: .875rem; }
.scaler button { border: 0; background: none; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 1rem; }
.scaler button:hover { background: var(--surface-2); }
.scaler output { min-width: 64px; text-align: center; font-weight: 600; }
.ingredients ul { list-style: none; padding: 0; margin: 6px 0 0; }
.ingredients li label { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px dashed var(--line); font-weight: 400; cursor: pointer; }
.ingredients input { margin-top: 5px; accent-color: var(--accent); width: 17px; height: 17px; flex: none; }
.ingredients li.done span { color: var(--muted); text-decoration: line-through; }
.qty { font-weight: 650; }
.qty.scaled { color: var(--accent); }
.steps ol { list-style: none; padding: 0; margin: 6px 0 0; }
.steps li { position: relative; padding: 10px 10px 10px 46px; border-radius: 10px; cursor: pointer; margin-bottom: 4px; }
.steps li::before {
  content: attr(data-n); position: absolute; left: 8px; top: 10px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.steps li:hover { background: var(--surface-2); }
.steps li.current { background: var(--accent-soft); }
.steps li.current::before { background: var(--accent); color: var(--accent-ink); }
.steps li.done { color: var(--muted); }
.steps li.done::before { content: "✓"; background: var(--ok); color: #fff; }
.timer-chip { border: 1px solid var(--accent); color: var(--accent); background: transparent; border-radius: 999px; padding: 0 8px; font-size: .9em; cursor: pointer; white-space: nowrap; }
.timer-chip:hover { background: var(--accent); color: var(--accent-ink); }
.notes ul { padding-left: 20px; }
.nutrition { display: flex; flex-wrap: wrap; gap: 8px; }
.personal textarea { min-height: 80px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* --- chat --- */
.chat { position: sticky; top: 12px; display: flex; flex-direction: column; height: calc(100vh - 24px); max-height: 860px; overflow: hidden; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-head h2 { margin: 0; font-size: 1.1rem; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 14px; font-size: .95rem; overflow-wrap: anywhere; }
.msg p { margin: 0 0 .6em; }
.msg p:last-child, .msg ul:last-child, .msg ol:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 .6em; padding-left: 20px; }
.msg h4 { margin: .4em 0; font-size: 1rem; }
.msg code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.error { align-self: stretch; background: transparent; color: var(--danger); border: 1px dashed var(--danger); }
.update-badge { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--ok); }
.update-badge button { font-size: .8rem; padding: 2px 8px; }
.chat-empty { color: var(--muted); font-size: .925rem; margin: auto 0; text-align: center; padding: 0 12px; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px 0; scrollbar-width: thin; }
.quick .chip { flex: none; }
.chat-form { display: flex; gap: 8px; padding: 12px 16px 16px; align-items: flex-end; }
.chat-form textarea { min-height: 44px; max-height: 160px; resize: none; }
.chat-fab { display: none; }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* --- settings --- */
.settings { max-width: 760px; margin: 12px auto; padding: 24px clamp(16px, 4vw, 32px); }
.settings section + section { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.bookmarklet { display: inline-block; padding: 8px 14px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; cursor: grab; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.row.spread { justify-content: space-between; }
.plain-list { list-style: none; padding: 0; margin: 8px 0 12px; }
.plain-list li { padding: 10px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.btn.small { padding: 5px 10px; font-size: .85rem; }

/* --- sign in / setup --- */
.auth-card { max-width: 420px; margin: 40px auto; padding: 28px clamp(16px, 5vw, 32px); }
.auth-card h1 { font-size: 1.8rem; }
.auth-card input[inputmode=numeric] { font-size: 1.4rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.auth-card .status { margin: 12px 0 0; }
.btn.wide { width: 100%; padding: 12px; }
.qr { display: grid; place-items: center; margin: 16px 0; }
.qr svg { width: 220px; height: 220px; border-radius: 8px; }
.secret { display: block; margin: 8px 0; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; font-size: 1rem; letter-spacing: .05em; word-break: break-all; }
details { margin: 0 0 16px; }
summary { cursor: pointer; color: var(--muted); }

/* --- timers & toasts --- */
.timers { position: fixed; left: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 55; }
.cook:not([hidden]) ~ .timers, body:has(.cook:not([hidden])) .timers { bottom: calc(84px + env(safe-area-inset-bottom)); }
#cook-ing { display: none; }
.timer { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.timer strong { font-size: 1.15rem; }
.timer.ringing { border-color: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--accent-soft); } }
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: min(92vw, 420px); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: .925rem; }
.toast.error { background: var(--danger); color: #fff; }

/* --- cook mode --- */
.cook { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; }
.cook-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.cook-top h2 { margin: 0; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cook-main { flex: 1; display: grid; grid-template-columns: 320px 1fr; min-height: 0; }
.cook-ingredients { border-right: 1px solid var(--line); overflow-y: auto; padding: 16px 20px; }
.cook-step { display: flex; flex-direction: column; justify-content: center; padding: 24px clamp(16px, 6vw, 80px); overflow-y: auto; }
.cook-step .count { color: var(--muted); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: .85rem; }
.cook-step .group { color: var(--accent); font-weight: 600; }
.cook-step p { font-size: clamp(1.3rem, 2.6vw, 2rem); line-height: 1.45; font-family: var(--serif); margin: 12px 0; }
.cook-nav { display: flex; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.cook-nav .btn { flex: 1; padding: 14px; font-size: 1.05rem; }
.progress { height: 4px; background: var(--line); }
.progress div { height: 100%; background: var(--accent); transition: width .2s; }

/* --- responsive --- */
@media (max-width: 1020px) {
  .recipe-layout { grid-template-columns: 1fr; }
  .chat {
    position: fixed; inset: auto 0 0 0; height: min(78vh, 680px); max-height: none; z-index: 45;
    border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .25s ease;
  }
  .chat.open { transform: none; }
  .chat-close { display: inline-flex !important; }
  .chat-fab {
    display: inline-flex; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 44;
    box-shadow: var(--shadow); border-radius: 999px; padding: 12px 18px;
  }
}
@media (max-width: 720px) {
  .columns { grid-template-columns: 1fr; gap: 12px; }
  .recipe-hero img { aspect-ratio: 16/10; }
  .import-row { flex-direction: column; }
  .cook-main { grid-template-columns: 1fr; }
  #cook-ing { display: inline-flex; }
  .cook-ingredients { display: none; border: 0; }
  .cook.show-ingredients .cook-ingredients { display: block; }
  .cook.show-ingredients .cook-step { display: none; }
  .library-tools { justify-content: stretch; }
  .library-tools input { max-width: none; }
}

/* --- print: just the recipe --- */
@media print {
  .topbar, .chat, .chat-fab, .toolbar, .version-bar, .timers, .toasts, .scaler, .personal textarea, .no-print { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main { padding: 0; max-width: none; }
  .recipe-layout { display: block; }
  .card { box-shadow: none; border: 0; }
  .recipe-hero img { aspect-ratio: auto; height: 180px; }
  .recipe-body { padding: 12px 0; }
  .steps li { break-inside: avoid; padding-top: 4px; padding-bottom: 4px; }
  .steps li.current { background: none; }
  .ingredients li label { padding: 3px 0; }
  .personal-print { display: block !important; white-space: pre-wrap; }
}
.personal-print { display: none; }
