:root {
  --canvas: #f1f3fa;
  --sheet: #fff;
  --ink: #192857;
  --muted: #53607b;
  --blue: #2143c2;
  --line: #d8deee;
  --lime: #e1f07a;
  font-family: "Avenir Next", Avenir, system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}
* { box-sizing: border-box }
[hidden] { display: none !important }
body { margin: 0; line-height: 1.5 }
button, input, select, textarea { font: inherit }
button { cursor: pointer }
a { color: var(--blue); text-underline-offset: 0.2em }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px }
img { display: block; max-width: 100%; height: auto }
h1, h2, h3, p { margin-top: 0 }
h1, h2 { letter-spacing: -0.045em; line-height: 1.04 }
h1 { font-size: clamp(2.85rem, 7vw, 6rem) }
h2 { font-size: clamp(1.85rem, 4vw, 3rem) }
h3 { line-height: 1.2 }
.topbar, footer, main { max-width: 1320px; margin-inline: auto }
.topbar, footer { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.15rem clamp(1rem, 4vw, 3.5rem) }
.brand { color: var(--ink); font-weight: 800; line-height: 1.2; text-decoration: none }
.brand span { display: block; color: var(--blue); font-weight: 650 }
nav { display: flex; align-items: center; gap: clamp(0.75rem, 3vw, 2rem) }
nav a { color: var(--ink); font-weight: 650; text-decoration: none }
nav a[aria-current], nav a:hover { color: var(--blue); text-decoration: underline }
.hero {
  display: grid;
  grid-template-columns: 1.08fr 1fr;
  align-items: stretch;
  margin-inline: clamp(1rem, 4vw, 3.5rem);
  background: var(--ink);
  color: white;
  border-radius: 14px;
  overflow: hidden;
}
.hero-copy { padding: clamp(1.75rem, 5vw, 4.5rem) }
.hero h1 { font-size: clamp(2.65rem, 5.9vw, 5.2rem); margin-bottom: 1.2rem }
.hero h1 em { color: var(--lime); font-style: normal }
.hero p { max-width: 33ch; color: #e0e5fc; margin-bottom: 1.5rem }
.hero-image { width: 100%; height: 100%; min-height: 350px; object-fit: cover; object-position: center }
.primary, .secondary, .text-button {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  background: var(--blue); color: white; border: 1px solid transparent; border-radius: 7px;
  font-weight: 650; line-height: 1.25; padding: 0.68rem 0.95rem;
}
.primary:hover { background: var(--ink) }
.hero .primary { background: var(--lime); color: var(--ink) }
.hero .primary:hover { background: white }
.hero :focus-visible { outline-color: var(--lime) }
.secondary { background: var(--sheet); color: var(--ink); border-color: var(--line) }
.secondary:hover { background: #e7ecff }
.secondary:disabled { opacity: 0.5; cursor: default }
.text-button { background: transparent; color: var(--blue); padding-inline: 0.3rem }
.text-button:hover { text-decoration: underline }
.danger { color: #92223c }
.collection { padding: clamp(2rem, 6vw, 4.5rem) clamp(1rem, 4vw, 3.5rem); scroll-margin-top: 0.75rem }
.section-top { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 1.35rem }
.section-top h2 { margin-bottom: 0.25rem }
.section-top p { color: var(--muted); margin: 0 }
.tools { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 0.8rem; align-items: end }
label { display: grid; gap: 0.3rem; font-weight: 650; font-size: 0.9rem }
input, select, textarea {
  color: var(--ink); background: var(--sheet); border: 1px solid #bac5df;
  border-radius: 6px; padding: 0.65rem; min-width: 0; max-width: 100%; width: 100%;
}
textarea { resize: vertical }
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1rem 0 1.25rem }
.filters button { border: 1px solid var(--line); border-radius: 6px; background: var(--sheet); color: var(--ink); padding: 0.45rem 0.7rem; font-size: 0.9rem }
.filters button[aria-pressed="true"] { background: var(--lime); border-color: var(--lime); font-weight: 750 }
.recipe-layout { display: grid; grid-template-columns: minmax(235px, 0.78fr) minmax(0, 1.5fr); align-items: start; gap: 1rem }
.index-panel, .reader-panel { border: 1px solid var(--line); border-radius: 10px; background: var(--sheet); overflow: hidden }
.index-heading, .reader-bar { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; min-height: 3rem; padding: 0.7rem 1rem; background: #e8edff; color: var(--ink); font-size: 0.9rem }
.index-heading span { color: var(--muted) }
.chapter-heading { margin: 0; padding: 0.95rem 1rem 0.4rem; text-transform: uppercase; letter-spacing: 0.09em; font-size: 0.78rem; color: var(--muted) }
.recipe-row {
  display: flex; width: 100%; align-items: center; gap: 0.75rem; justify-content: space-between;
  border: 0; border-bottom: 1px solid var(--line); border-left: 4px solid transparent;
  padding: 0.7rem 0.9rem 0.7rem 0.75rem; background: white; text-align: left; color: var(--ink);
}
.recipe-row:hover { background: #f3f5ff }
.recipe-row[aria-current="true"] { border-left-color: var(--blue); background: #edf1ff; color: var(--blue); font-weight: 750 }
.recipe-row:focus-visible { outline-offset: -4px }
.recipe-row small { white-space: nowrap; color: var(--muted) }
.more { margin: 1rem }
.empty, #reader-empty { padding: 1rem }
.reader-panel { scroll-margin-top: 0.75rem }
#recipe-detail { padding: clamp(1rem, 3vw, 2.2rem) }
#recipe-detail:focus { outline: none }
#recipe-detail h2 { margin: 0.35rem 0 1rem }
.detail-meta { font-size: 0.9rem; font-weight: 650; color: var(--blue) }
.detail-actions { display: flex; gap: 0.55rem; padding: 0.85rem clamp(1rem, 3vw, 2.2rem); border-top: 1px solid var(--line) }
.recipe-art { display: block; width: 100%; max-height: 330px; object-fit: contain; background: var(--canvas); border-radius: 7px }
.source-scan { position: relative; width: 100%; margin: 1rem 0; border: 1px solid var(--line); border-radius: 5px; overflow: hidden }
.source-scan img { width: 100% }
.source-scan.top-half, .source-scan.bottom-half { aspect-ratio: 1192 / 750 }
.source-scan.top-half img, .source-scan.bottom-half img { position: absolute; left: 0; top: 0 }
.source-scan.bottom-half img { top: -100% }
summary { cursor: pointer; color: var(--blue); font-weight: 650 }
.cookbook-text, .notes { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 0.65rem }
.back-to-index { display: none }
footer { flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); border-top: 1px solid var(--line) }
dialog { width: min(95vw, 720px); max-height: 90dvh; padding: clamp(1rem, 3vw, 2rem); border: 1px solid var(--line); border-radius: 12px; color: var(--ink) }
dialog::backdrop { background: #151e41aa }
.dialog-head, .form-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem }
.form-actions { justify-content: flex-end }
#recipe-form { display: grid; gap: 0.8rem }
.dialog-head h2, .form-help { margin: 0 }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 0.75rem }
.icon-button { border: 0; background: transparent; font-size: 1.6rem; color: var(--ink) }
#toast { position: fixed; z-index: 2; bottom: 1rem; left: 50%; width: max-content; max-width: calc(100% - 2rem); transform: translateX(-50%); padding: 0.75rem 1rem; border-radius: 7px; background: var(--ink); color: white; visibility: hidden }
#toast.visible { visibility: visible }
.about-page, .gallery, .reader { padding: clamp(1.5rem, 5vw, 4rem) clamp(1rem, 4vw, 3.5rem); }
.about-page h1, .gallery h1, .reader h1 { margin-bottom: 1.5rem }
.about-letter { max-width: 960px; margin-inline: auto }
.about-letter h1 em { font-style: normal; color: var(--blue) }
.letter-body { display: flow-root; font-size: 1.15rem }
.about-photo { width: min(100%, 420px); float: right; margin: 0 0 1rem 1.5rem }
.about-photo img { border-radius: 10px }
.letter-signature { font-weight: 700 }
.about-links, .reader-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem; margin-block: 1rem }
.reader { max-width: 920px }
.reader-tools select { width: auto }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 215px), 1fr)); gap: 1rem }
.photo-grid figure { margin: 0; overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 8px }
.photo-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover }
.photo-grid figcaption { padding: 0.75rem }
@media (max-width: 780px) {
  .recipe-layout { display: block }
  .reader-panel { display: none }
  .reading .reader-panel { display: block }
  .reading .index-panel { display: none }
  .back-to-index { display: inline-flex }
  .hero-image { min-height: 270px }
}
@media (max-width: 560px) {
  .hero { grid-template-columns: 1fr }
  .hero-image { height: auto; min-height: 0; aspect-ratio: 1.75 }
  .tools { grid-template-columns: repeat(2, minmax(0, 1fr)) }
  .tools label:first-child { grid-column: 1 / -1 }
  .section-top { align-items: flex-start }
  .about-photo { float: none; margin: 0 0 1rem }
  .topbar { gap: 0.6rem }
  nav { gap: 0.6rem; font-size: 0.9rem }
}
@media print {
  :root { background: white; color: black }
  .topbar, footer, .hero, .section-top, .tools, .filters, .index-panel, .reader-bar, .detail-actions, #reader-empty, .recipe-art { display: none !important }
  .recipe-layout, .reader-panel { display: block !important }
  .collection, #recipe-detail { padding: 0 }
  .reader-panel { border: 0 }
  .source-scan { break-inside: avoid; max-width: 160mm }
}
@media (min-width: 781px) {
  .index-panel { max-height: 730px; overflow: auto; scrollbar-gutter: stable }
  .index-heading { position: sticky; top: 0; z-index: 1 }
}
.recipe-ingredients, .recipe-method { margin-top: 1.4rem }
.ingredient-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem }
.ingredient-toolbar h3, .recipe-method h3 { margin: 0 }
.ingredient-toolbar label { display: flex; align-items: center; gap: 0.5rem }
.ingredient-toolbar select { width: auto }
#ingredient-list { padding-left: 1.25rem; margin-top: 0.75rem }
#ingredient-list li, .recipe-method li { padding-block: 0.22rem }
.ingredient-heading { list-style: none; font-weight: 750; margin: 0.55rem 0 0 -1.25rem }
#scaled-yield { margin: 0.5rem 0 0; color: var(--muted) }
.recipe-method p, .recipe-method ol { margin-top: 0.65rem }
.recipe-art { max-height: 220px }
.topbar { justify-content: flex-end }
@media print { .ingredient-toolbar label { display: none } }
