/* ---------- fonts (bundled, works offline) ---------- */
@font-face { font-family: "Playfair Display"; font-weight: 600; font-display: swap; src: url(fonts/playfair-display-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Playfair Display"; font-weight: 700; font-display: swap; src: url(fonts/playfair-display-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "Playfair Display"; font-weight: 400; font-style: italic; font-display: swap; src: url(fonts/playfair-display-latin-400-italic.woff2) format("woff2"); }
@font-face { font-family: "Lato"; font-weight: 400; font-display: swap; src: url(fonts/lato-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Lato"; font-weight: 400; font-style: italic; font-display: swap; src: url(fonts/lato-latin-400-italic.woff2) format("woff2"); }
@font-face { font-family: "Lato"; font-weight: 700; font-display: swap; src: url(fonts/lato-latin-700-normal.woff2) format("woff2"); }

/* ---------- tokens ---------- */
:root {
  --paper: #f6f7f5;
  --surface: #ffffff;
  --ink: #1e2421;
  --muted: #5b655f;
  --line: #dce1dd;
  --basil: #2e5e4e;
  --basil-ink: #ffffff;
  --danger: #a3302a;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "Lato", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 14px;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1240px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141816;
    --surface: #1c211e;
    --ink: #e7ebe8;
    --muted: #a1aba5;
    --line: #2e3531;
    --basil: #8cc5af;
    --basil-ink: #10201a;
    --danger: #ef8a83;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #141816; --surface: #1c211e; --ink: #e7ebe8; --muted: #a1aba5; --line: #2e3531;
  --basil: #8cc5af; --basil-ink: #10201a; --danger: #ef8a83;
  color-scheme: dark;
}

/* Each recipe carries its colour from the printed book (--book), plus
   darker/lighter versions the server checked for readable contrast. */
.tinted {
  --book: #76a5af;
  --accent-text: var(--ink-l, #2e5e64);
  --accent-wash: color-mix(in srgb, var(--book) 24%, var(--paper));
  --accent-soft: color-mix(in srgb, var(--book) 12%, transparent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tinted {
    --accent-text: var(--ink-d, #a2c4c9);
    --accent-wash: color-mix(in srgb, var(--book) 16%, var(--paper));
  }
}
:root[data-theme="dark"] .tinted {
  --accent-text: var(--ink-d, #a2c4c9);
  --accent-wash: color-mix(in srgb, var(--book) 16%, var(--paper));
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex; flex-direction: column;
}
main { flex: 1; outline: none; }
img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.12; margin: 0; letter-spacing: -0.005em; }
p { margin: 0; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--basil); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer;
  font-weight: 700; font-size: 0.9375rem; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--basil); color: var(--basil-ink); border-color: var(--basil); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--basil); }
.btn-quiet { background: transparent; }
.btn-danger { color: var(--danger); background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn[disabled] { opacity: .55; cursor: progress; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) var(--gutter) 10px;
  max-width: var(--max); width: 100%; margin: 0 auto;
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.125rem; text-decoration: none; padding: 8px 0; }
body[data-view="home"] .brand { visibility: hidden; }

/* ---------- home: masthead ---------- */
.home { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter) 64px; }
.masthead { padding: clamp(8px, 3vw, 32px) 0 clamp(20px, 3vw, 28px); }
.masthead h1 {
  font-size: clamp(2.6rem, 8.5vw, 5.25rem);
  line-height: 0.98;
  letter-spacing: -0.02em;
  max-width: 12ch;
}
.masthead .count { margin-top: 14px; color: var(--muted); font-size: 1.0625rem; }

/* ---------- search + filters ---------- */
.controls {
  position: sticky; top: 0; z-index: 5;
  background: var(--paper);
  margin: 0 calc(var(--gutter) * -1); padding: 12px var(--gutter) 10px;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.controls.stuck { border-bottom-color: var(--line); }
.search { position: relative; max-width: 640px; }
.search svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 52px; padding: 0 48px 0 48px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  font-size: 1.0625rem;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--basil); box-shadow: 0 0 0 3px color-mix(in srgb, var(--basil) 25%, transparent); }
.search .clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: var(--muted);
}
.search input::-webkit-search-cancel-button { display: none; }

.chip-row {
  display: flex; gap: 8px; margin-top: 10px;
  overflow-x: auto; scrollbar-width: none;
  margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter);
  scroll-padding-inline: var(--gutter);
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-row .sep { flex: 0 0 1px; background: var(--line); margin: 6px 4px; }
.chip {
  flex: 0 0 auto; min-height: 40px; padding: 0 15px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 0.9375rem; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip .n { color: var(--muted); font-size: 0.8125rem; }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .7; }
.chip-fav[aria-pressed="true"] { background: #b5892a; border-color: #b5892a; color: #fff; }
.chip svg { flex: none; }

.result-line { display: flex; align-items: baseline; gap: 12px; margin: 14px 0 0; color: var(--muted); font-size: 0.9375rem; }
.result-line:empty { display: none; }
.linkish { background: none; border: 0; padding: 4px 0; color: var(--basil); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- chapters + grid ---------- */
.chapter { margin-top: clamp(24px, 3.5vw, 40px); }
.chapter-head {
  display: flex; align-items: baseline; gap: 12px;
  padding-bottom: 12px; margin-bottom: 18px; border-bottom: 1px solid var(--line);
}
.chapter-head h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
.chapter-head .n { color: var(--muted); }

.grid {
  display: grid; gap: 28px 20px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
}
@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 22px 14px; }
}

.card { position: relative; }
.card-link { text-decoration: none; display: block; }
.card-photo {
  aspect-ratio: 4 / 5; border-radius: var(--radius); overflow: hidden;
  background: var(--accent-wash);
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s ease; }
.card-link:hover .card-photo img { transform: scale(1.03); }
.card-noimg {
  height: 100%; display: flex; align-items: flex-end; padding: 18px;
  background: var(--accent-wash);
  color: var(--accent-text);
  font-family: var(--serif); font-style: italic; font-weight: 400;
  font-size: clamp(1.4rem, 3vw, 1.9rem); line-height: 1.08;
}
.card h3 {
  margin-top: 12px;
  font-size: clamp(1.0625rem, 2vw, 1.25rem);
  color: var(--accent-text);
}
.card-meta { margin-top: 4px; color: var(--muted); font-size: 0.875rem; line-height: 1.4; }
.card-link:focus-visible { outline: none; }
.card-link:focus-visible .card-photo { outline: 3px solid var(--basil); outline-offset: 3px; }

.fav {
  position: absolute; top: 8px; right: 8px;
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: rgb(255 255 255 / .82); color: #3a3f3c;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.fav[aria-pressed="true"] { background: #fff; color: #b5892a; }
.fav svg { width: 22px; height: 22px; }
.fav[aria-pressed="true"] svg path { fill: currentColor; }
.fav.pop svg { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(1.35); } }

.empty { padding: 56px 0; max-width: 46ch; }
.empty h2 { font-size: 1.75rem; margin-bottom: 8px; }
.empty .btn { margin-top: 18px; }

/* ---------- recipe page ---------- */
.recipe { --pad: var(--gutter); }
.recipe-wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--pad); }
.back {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  text-decoration: none; color: var(--muted); font-weight: 700; font-size: 0.9375rem;
}
.back:hover { color: var(--ink); }

.recipe-layout {
  display: grid; gap: 0 clamp(32px, 5vw, 72px);
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  align-items: start;
}
.recipe-side { position: sticky; top: 16px; padding-bottom: 32px; }
.recipe-main { padding: 8px 0 72px; }

.recipe-cat { color: var(--muted); font-size: 0.9375rem; margin-top: 4px; }
.recipe h1 {
  color: var(--accent-text);
  font-size: clamp(2.2rem, 4.6vw, 3.5rem);
  line-height: 1.02; letter-spacing: -0.015em;
  margin: 6px 0 0;
  text-wrap: balance;
}
.recipe-from { font-family: var(--serif); font-style: italic; font-size: 1.1875rem; margin-top: 10px; }
.recipe-photo { margin-top: 22px; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 5; background: var(--surface); }
.recipe-photo img { width: 100%; height: 100%; object-fit: cover; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 20px 0 0; }
.facts div { min-width: 0; }
.facts dt { color: var(--muted); font-size: 0.8125rem; }
.facts dd { margin: 0; font-weight: 700; }
.recipe-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.recipe-actions .btn[aria-pressed="true"] { background: #b5892a; color: #fff; border-color: #b5892a; }
.recipe-actions .btn[aria-pressed="true"] svg path { fill: currentColor; }

.recipe-main h2 {
  font-size: 1.625rem; color: var(--accent-text);
  margin: 0 0 14px;
}
.recipe-main section + section { margin-top: 40px; }
.group-name { font-family: var(--sans); font-weight: 700; font-size: 0.9375rem; color: var(--muted); margin: 18px 0 4px; }

.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li { border-bottom: 1px solid var(--line); }
.ingredients label {
  display: flex; gap: 14px; align-items: flex-start; cursor: pointer;
  padding: 11px 0; min-height: 44px;
}
.ingredients input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 22px; height: 22px; margin: 2px 0 0; border-radius: 6px;
  border: 1.5px solid color-mix(in srgb, var(--muted) 70%, transparent); background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
}
.ingredients input::after {
  content: ""; width: 11px; height: 6px; border: solid var(--basil-ink); border-width: 0 0 2.5px 2.5px;
  transform: rotate(-45deg) translate(1px, -1px); opacity: 0;
}
.ingredients input:checked { background: var(--basil); border-color: var(--basil); }
.ingredients input:checked::after { opacity: 1; }
.ingredients input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  counter-increment: step;
  display: grid; grid-template-columns: 2.4rem 1fr; gap: 0 12px;
  padding: 14px 12px 14px 0; margin: 0 -12px; padding-left: 12px;
  border-radius: 12px; cursor: pointer;
  font-size: 1.125rem; line-height: 1.65;
  max-width: 66ch;
}
.steps li::before {
  content: counter(step);
  font-family: var(--serif); font-weight: 700; font-size: 1.5rem; line-height: 1.2;
  color: var(--accent-text);
}
.steps li:hover { background: var(--accent-soft); }
.steps li.current { background: var(--accent-wash); }
.steps li.done { color: var(--muted); }
.steps li.done::before { opacity: .5; }
.hint { color: var(--muted); font-size: 0.875rem; margin: -6px 0 10px; }

.tips {
  background: var(--accent-wash); border-radius: var(--radius);
  padding: 20px 22px;
}
.tips h2 { font-size: 1.375rem; margin-bottom: 8px; }
.tips ul { margin: 0; padding-left: 1.1em; }
.tips li + li { margin-top: 6px; }
.missing { color: var(--muted); font-style: italic; }

@media (max-width: 899px) {
  .recipe-layout { grid-template-columns: 1fr; }
  .recipe-side { position: static; padding-bottom: 28px; }
  .recipe-head-grid { display: grid; gap: 0 28px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: end; }
  .recipe-head-grid .recipe-photo { order: 2; margin-top: 18px; aspect-ratio: 1; }
  .recipe-main { padding-top: 28px; }
}
@media (min-width: 620px) and (max-width: 899px) {
  .recipe-main .cols { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 32px; }
  .recipe-main .cols section + section { margin-top: 0; }
}
@media (max-width: 619px) {
  .recipe-head-grid { display: block; }
  .recipe-head-grid .recipe-photo { aspect-ratio: 4 / 3; margin-top: 18px; }
  .recipe h1 { font-size: clamp(2rem, 9vw, 2.6rem); }
  .steps li { font-size: 1.0625rem; }
}
@media (min-width: 900px) {
  .recipe-side {
    background: var(--accent-wash); border-radius: 22px;
    padding: 14px 28px 28px; margin-top: 8px;
    max-height: calc(100vh - 32px); overflow-y: auto; scrollbar-width: thin;
  }
  .recipe-main { padding-top: 22px; }
  .recipe-head-grid { display: flex; flex-direction: column; }
  .recipe-head-grid .recipe-photo { order: -1; aspect-ratio: 4 / 3; margin: 6px 0 22px; }
}
@media (max-width: 899px) {
  .recipe-side { background: var(--accent-wash); margin: 0 calc(var(--pad) * -1); padding: 4px var(--pad) 28px; }
}

/* ---------- editor ---------- */
.editor { max-width: 820px; margin: 0 auto; padding: 0 var(--gutter) 80px; }
.editor h1 { font-size: clamp(2rem, 5vw, 2.75rem); margin: 8px 0 24px; }
.field { display: grid; gap: 6px; margin-bottom: 20px; }
.field label, .field .label { font-weight: 700; font-size: 0.9375rem; }
.field .help { color: var(--muted); font-size: 0.875rem; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  padding: 12px 14px; font-size: 1rem; line-height: 1.5;
}
.field textarea { min-height: 180px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--basil); box-shadow: 0 0 0 3px color-mix(in srgb, var(--basil) 25%, transparent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 560px) { .row2 { grid-template-columns: 1fr; } }
.photo-edit { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.photo-edit .thumb { width: 112px; aspect-ratio: 4/5; border-radius: 10px; overflow: hidden; background: var(--accent-wash); flex: none; }
.photo-edit .thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-edit .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-btn:focus-within { outline: 3px solid var(--basil); outline-offset: 2px; }
.editor-actions {
  position: sticky; bottom: 0; display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 14px 0 max(14px, env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--line); margin-top: 12px;
}
.editor-actions .spacer { flex: 1; }
.form-error { color: var(--danger); font-size: 0.9375rem; min-height: 1.4em; }

/* ---------- dialog / toast / footer ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 24px; width: min(380px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(15 20 18 / .45); }
dialog h2 { font-size: 1.5rem; margin-bottom: 8px; }
dialog p { font-size: 0.9375rem; }
#pin-input {
  width: 100%; margin-top: 16px; height: 56px; text-align: center; letter-spacing: .4em;
  font-size: 1.5rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
}
#pin-input:focus { outline: none; border-color: var(--basil); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 12px 20px; border-radius: 999px;
  font-weight: 700; font-size: 0.9375rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot {
  max-width: var(--max); width: 100%; margin: 0 auto;
  padding: 20px var(--gutter) max(24px, env(safe-area-inset-bottom));
  color: var(--muted); font-size: 0.875rem; display: flex; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid var(--line);
}
.foot button, .foot a { background: none; border: 0; padding: 6px 0; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: inherit; }

.loading { padding: 80px var(--gutter); text-align: center; color: var(--muted); }

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

/* ---------- print a recipe ---------- */
@media print {
  .topbar, .foot, .back, .recipe-actions, .hint, .fav, .controls, .toast { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .recipe-side { background: none !important; }
  .recipe-layout { grid-template-columns: 4fr 8fr; }
  .recipe-side { position: static; }
  .recipe-photo { aspect-ratio: 1; }
  .steps li { font-size: 11pt; padding: 6px 0; }
  .ingredients input { display: none; }
  .ingredients label { padding: 4px 0; min-height: 0; }
  .tips { background: none; border: 1px solid #ccc; }
}

/* colour swatches in the editor */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches label { position: relative; cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches span {
  display: block; width: 36px; height: 36px; border-radius: 50%;
  background: var(--sw); border: 2px solid var(--paper); box-shadow: 0 0 0 1px var(--line);
}
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.swatches input:focus-visible + span { outline: 3px solid var(--basil); outline-offset: 3px; }
