:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --accent: #c2410c;
  --border: #e7e2da;
  --on-accent: #ffffff; /* text on accent-coloured backgrounds */
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --text: #ece8e1;
    --muted: #a39d93;
    --accent: #fb923c;
    --border: #34312c;
    --on-accent: #1c1206; /* the dark-mode accent is light, so text on it must be dark */
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.topbar {
  padding: calc(env(safe-area-inset-top) + 12px) 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-inner { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.brand { color: var(--accent); font-weight: 700; text-decoration: none; font-size: 1.1rem; }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px); }
.muted { color: var(--muted); }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
h3 { font-size: 0.95rem; margin: 18px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
a { color: var(--accent); }
.count { font-size: 0.9rem; font-weight: 500; color: var(--muted); vertical-align: middle; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--text);
  font-size: 0.8rem;
}

/* Library */
.recipe-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.recipe-card {
  display: flex; gap: 12px; align-items: center;
  min-height: 72px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: inherit; text-decoration: none;
}
.thumb { width: 64px; height: 64px; flex: none; border-radius: 8px; object-fit: cover; background: var(--border); }
.thumb-empty {
  display: grid; place-items: center;
  font-size: 1.6rem; font-weight: 700; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.card-body { min-width: 0; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.85rem; margin-top: 2px; }

/* Recipe */
.hero { width: calc(100% + 32px); margin: -16px -16px 0; max-height: 320px; object-fit: cover; display: block; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.facts div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; }
.facts dt { font-size: 0.75rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ingredients { padding-left: 20px; margin: 0; }
.ingredients li { padding: 4px 0; }
.steps { padding-left: 22px; margin: 0; }
.steps li { padding: 6px 0 6px 4px; }
.steps li::marker { color: var(--accent); font-weight: 700; }
.notes { white-space: pre-line; }
.source { margin-top: 32px; font-size: 0.9rem; }
@media (min-width: 641px) {
  .hero { width: 100%; margin: 0 0 8px; border-radius: 12px; }
}

/* Navigation: links in the header on wide screens, a bottom tab bar on phones */
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topnav { display: flex; gap: 4px; }
.topnav a, .tabbar a { color: var(--muted); text-decoration: none; display: flex; align-items: center; gap: 6px; }
.topnav a { padding: 6px 10px; border-radius: 8px; }
.topnav a.active, .tabbar a.active { color: var(--accent); }
nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tabbar { display: none; }
@media (max-width: 640px) {
  .topnav { display: none; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { flex: 1; flex-direction: column; gap: 2px; justify-content: center; min-height: 54px; font-size: 0.75rem; }
  main { padding-bottom: calc(env(safe-area-inset-bottom) + 80px); }
}

/* Add form */
.add-form { display: grid; gap: 10px; margin-bottom: 16px; }
.add-form label { font-weight: 600; }
input[type=url], input[type=text], input[type=search] {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button {
  font: inherit; font-weight: 600; min-height: 46px; padding: 10px 16px;
  border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); cursor: pointer;
}
[data-progress] .busy { display: none; align-items: center; justify-content: center; gap: 8px; }
[data-progress].is-busy .label { display: none; }
[data-progress].is-busy .busy { display: inline-flex; }
[data-progress].is-busy button { opacity: 0.8; cursor: progress; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--on-accent) 40%, transparent); border-top-color: var(--on-accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.error {
  margin: 0; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, #dc2626 12%, var(--surface)); color: var(--text);
  border: 1px solid color-mix(in srgb, #dc2626 40%, transparent);
}
.flash {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, #16a34a 12%, var(--surface)); border: 1px solid color-mix(in srgb, #16a34a 35%, transparent);
}
.small { font-size: 0.9rem; }

/* Servings and unit controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.stepper .step {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 8px;
  font-size: 1.4rem; line-height: 1; text-decoration: none; color: var(--accent);
}
.stepper .step:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.stepper .step.disabled { color: var(--muted); pointer-events: none; opacity: 0.5; }
.stepper .value { min-width: 96px; text-align: center; }
.segmented { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.segmented a {
  flex: 1; display: grid; place-items: center; min-height: 42px; padding: 0 14px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 0.95rem; white-space: nowrap;
}
.segmented a[aria-current] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.view-notes { display: grid; gap: 2px; margin: 10px 0 0; }
@media (max-width: 640px) {
  .controls > * { flex: 1 1 100%; }
  .stepper { justify-content: space-between; }
}

/* Adapting recipes */
.transform { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--border); }
.tform { display: grid; gap: 8px; padding: 12px; margin: 10px 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.tform label { font-weight: 600; }
.tform-help { margin: 0; color: var(--muted); font-size: 0.9rem; }
select, textarea {
  font: inherit; font-size: 16px; width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
textarea { resize: vertical; }
.tform input[type=text] { background: var(--bg); }
.transform-result {
  margin: 12px 0; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 2px solid color-mix(in srgb, var(--accent) 45%, var(--border));
}
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--border); color: var(--muted); }
.md h2 { font-size: 1.25rem; margin: 14px 0 6px; }
.md h3 { font-size: 0.95rem; margin: 16px 0 6px; }
.md ul, .md ol { padding-left: 22px; }
.md li { padding: 3px 0; }
.md strong { color: var(--accent); }

/* Library search and tag filter */
.search { margin: 0 0 10px; }
.tag-filter { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tag-filter::-webkit-scrollbar { display: none; }
.tag-filter .tag { white-space: nowrap; padding: 6px 12px; font-size: 0.85rem; text-decoration: none; min-height: 32px; display: inline-flex; align-items: center; }
.tag-filter .tag.selected { background: var(--accent); color: var(--on-accent); }
.no-results[hidden], .recipe-list > li.is-hidden { display: none; }

/* Delete and error pages */
.danger-link { color: #b91c1c; }
@media (prefers-color-scheme: dark) { .danger-link { color: #f87171; } }
button.danger { background: #b91c1c; color: #fff; }
.confirm-actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.button-secondary {
  display: inline-grid; place-items: center; min-height: 46px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600;
}
.problem { white-space: pre-wrap; font-size: 0.85rem; padding: 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); overflow-x: auto; }
code { font-size: 0.9em; }

/* Add page extras and the Shortcut help page */
.failures ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.failures li { padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.failures .host { font-weight: 600; margin-right: 4px; }
.howto { padding-left: 22px; }
.howto li { padding: 6px 0; }
code.copy { word-break: break-all; user-select: all; -webkit-user-select: all; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; }

/* Saving adapted versions */
.draft-title { font-size: 1.2rem; margin: 12px 0 4px; text-transform: none; letter-spacing: 0; color: var(--text); }
.transform-result h4 { margin: 14px 0 6px; font-size: 0.95rem; }
.transform-result li.changed { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 6px; padding-left: 6px; margin-left: -6px; font-weight: 600; }
.changed-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; background: color-mix(in srgb, var(--accent) 30%, transparent); }
.legend { margin: 10px 0 4px; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.adapted-from { margin: -8px 0 12px; }
.restore { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -6px 0 12px; }
.link-button { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

/* Accounts: login, signup, settings, admin */
input[type=email], input[type=password] {
  font: inherit; font-size: 16px;
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.stack-form { display: grid; gap: 8px; margin-bottom: 16px; }
.stack-form label { font-weight: 600; margin-top: 4px; }
.stack-form button { margin-top: 8px; }
.token-once { display: grid; gap: 8px; margin: 12px 0; }
.token-once p, .notice p { margin: 0; }
.notice { display: grid; gap: 8px; margin: 12px 0; }
code.token { font-size: 0.95rem; padding: 8px 10px; }
.token-list, .admin-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.token-list li, .admin-list li {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.token-list li > div, .admin-list li > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.button-secondary { cursor: pointer; font: inherit; font-weight: 600; }
.button-link {
  display: inline-grid; place-items: center; min-height: 46px; padding: 10px 16px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent); text-decoration: none; font-weight: 600;
}
details { margin: 12px 0; }
summary { cursor: pointer; font-weight: 600; min-height: 42px; display: flex; align-items: center; }
.welcome { margin: 0 0 16px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 2px solid color-mix(in srgb, var(--accent) 35%, var(--border)); }
.welcome h2 { margin: 0 0 4px; font-size: 1.05rem; }
.welcome p { margin: 0 0 6px; }
.paste-form { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.paste-form textarea { background: var(--surface); }

/* Saving a recipe (the job page) */
.saving { display: flex; gap: 14px; align-items: center; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.saving p { margin: 0; }
.spinner.big { width: 28px; height: 28px; flex: none; border-width: 3px; border-color: color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); }

/* Admin usage */
.meter { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 8px 0 4px; }
.meter-fill { display: block; height: 100%; background: var(--accent); width: 0; }
.meter-1 { width: 10%; } .meter-2 { width: 20%; } .meter-3 { width: 30%; } .meter-4 { width: 40%; } .meter-5 { width: 50%; }
.meter-6 { width: 60%; } .meter-7 { width: 70%; } .meter-8 { width: 80%; background: #d97706; } .meter-9 { width: 90%; background: #dc2626; } .meter-10 { width: 100%; background: #dc2626; }
.usage { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 10px 0; }
.usage th, .usage td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.usage td:not(:first-child), .usage th:not(:first-child) { text-align: right; white-space: nowrap; }
@media (max-width: 640px) {
  .usage thead { display: none; }
  .usage tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .usage td { border: 0; padding: 0; text-align: left !important; white-space: normal !important; }
  .usage td:first-child { grid-column: 1 / -1; font-weight: 600; }
  .usage td:not(:first-child)::before { content: attr(data-label) ": "; color: var(--muted); }
}

/* "‹ Back" at the top of every page but the library. Padding gives a 44px tap target; the negative
   margin keeps the text lined up with the page edge. */
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; padding: 0 12px; margin: -8px 0 0 -12px;
  text-decoration: none; font-weight: 500;
}
.back-link span { font-size: 1.4rem; line-height: 1; }
.back-link + h1 { margin-top: 0; }

/* ---- Phase 6: edit, share, import ---- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.recipe-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.recipe-actions .button-secondary { min-height: 40px; }
/* The recipe text editor: monospaced so lists line up, 16px so iOS doesn't zoom, and growing with
   its content where the browser supports field-sizing (the rows attribute covers the rest). */
.editor {
  width: 100%; box-sizing: border-box; font: 16px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  field-sizing: content; min-height: 50vh; resize: vertical;
}
.edit-form .confirm-actions { margin-top: 12px; }
.format-guide { margin-top: 20px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.format-guide summary { cursor: pointer; font-weight: 600; }
.format-guide ul { padding-left: 20px; }
.format-guide li { margin: 6px 0; }
.shared-banner { padding: 12px; margin: 0 0 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); display: grid; gap: 10px; }
.shared-banner p { margin: 0; }
.plain-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.library-foot { margin-top: 20px; }
.error ul, .notice ul { margin: 4px 0 0; padding-left: 20px; }
/* Buttons that app.js reveals: a display rule on the class would otherwise beat the hidden attribute. */
button[hidden] { display: none; }
.error > p:first-child, .notice > p:first-child { margin-top: 0; }
