:root {
  --paper: #fbf6ee;
  --card: #fffdf9;
  --ink: #2b2420;
  --muted: #6f625a;
  --line: #e7ddd0;
  --accent: #b5462f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3dc;
  --ok: #2f6b3a;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4d00;
  --err-bg: #fde5e1;
  --err-ink: #8a2414;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 14px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[data-book="lupita"] { --accent: #b5462f; --accent-soft: #f6e3dc; }
:root[data-book="emma"] { --accent: #4f6b2c; --accent-soft: #e6eed8; }
:root[data-book="lola"] { --accent: #7a3b69; --accent-soft: #f0e0ec; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1d1916; --card: #27221e; --ink: #f1e9df; --muted: #b5a89c; --line: #3b342e;
    --accent-soft: #3d2a24; --warn-bg: #3a3016; --warn-ink: #f3d98b; --err-bg: #43211b; --err-ink: #f7b4a6;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
  :root[data-book="lupita"]:not([data-theme="light"]) { --accent: #e07a5f; --accent-soft: #3d2a24; }
  :root[data-book="emma"]:not([data-theme="light"]) { --accent: #9fbf6e; --accent-soft: #2c3420; --accent-ink: #1d1916; }
  :root[data-book="lola"]:not([data-theme="light"]) { --accent: #d390c2; --accent-soft: #3a2535; --accent-ink: #1d1916; }
  :root:not([data-book]):not([data-theme="light"]) { --accent: #e07a5f; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 18px/1.55 var(--sans);
}
a { color: var(--accent); }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); }
h2 { font-size: 1.35rem; margin-top: 1.4em; }
h3 { font-size: 1.05rem; font-family: var(--sans); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--paper); /* fallback for browsers without color-mix (Safari < 16.2) */
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; white-space: nowrap; }
.account { display: flex; align-items: center; gap: 8px; font-size: .95rem; color: var(--muted); min-width: 0; }
.account .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

main { max-width: 820px; margin: 0 auto; padding: 20px 16px 80px; outline: none; }
.loading { color: var(--muted); text-align: center; padding: 40px 0; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 999px; border: 1.5px solid var(--accent);
  background: var(--card); color: var(--accent); font: 600 1rem var(--sans); cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.big { min-height: 60px; font-size: 1.15rem; padding: 14px 26px; width: 100%; }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: .92rem; }
.btn.ghost { border-color: var(--line); color: var(--ink); }
.btn.danger { border-color: var(--err-ink); color: var(--err-ink); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .chip:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent); outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 2px;
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }

input[type="search"], input[type="text"], input[type="number"], textarea, select {
  width: 100%; font: 1.05rem var(--sans); color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
label { display: block; font-weight: 600; margin: 18px 0 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: .92rem; display: block; margin-top: 2px; }

/* home */
.intro { color: var(--muted); margin-bottom: 20px; }
.books { display: grid; gap: 16px; margin: 20px 0 28px; }
@media (min-width: 700px) { .books { grid-template-columns: repeat(3, 1fr); } }
.book-card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  padding: 22px 20px 18px; border-radius: var(--radius); text-decoration: none; color: var(--ink);
  background: var(--card); box-shadow: var(--shadow); border-left: 8px solid var(--c);
  min-height: 160px;
}
.book-card h2 { margin: 0; font-size: 1.3rem; }
.book-card p { margin: 0; color: var(--muted); font-size: .97rem; }
.byline { font-style: italic; color: var(--ink) !important; margin: 0 0 4px; }
.book-card .count { margin-top: auto; font-weight: 600; color: var(--c); }
.book-card[data-book="lupita"] { --c: #b5462f; }
.book-card[data-book="emma"] { --c: #4f6b2c; }
.book-card[data-book="lola"] { --c: #7a3b69; }
@media (prefers-color-scheme: dark) {
  .book-card[data-book="lupita"] { --c: #e07a5f; }
  .book-card[data-book="emma"] { --c: #9fbf6e; }
  .book-card[data-book="lola"] { --c: #d390c2; }
}

/* lists */
.toolbar { display: grid; gap: 10px; margin: 16px 0 8px; }
@media (min-width: 640px) { .toolbar { grid-template-columns: 1fr 200px; } }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chip {
  flex: 0 0 auto; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font: 600 .92rem var(--sans); cursor: pointer; min-height: 38px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.result-count { color: var(--muted); font-size: .95rem; margin: 4px 0 8px; }
.recipe-list { list-style: none; padding: 0; margin: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.recipe-list li + li { border-top: 1px solid var(--line); }
.recipe-list a { display: flex; gap: 14px; align-items: center; padding: 14px 16px; color: var(--ink); text-decoration: none; min-height: 64px; }
.recipe-list a:hover { background: var(--accent-soft); }
.recipe-list .thumb { flex: 0 0 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--accent-soft); }
.recipe-list .t { font-weight: 600; font-size: 1.05rem; }
.recipe-list .m { color: var(--muted); font-size: .9rem; }
.recipe-list .body { min-width: 0; flex: 1; }
.recipe-list .badges { margin-left: auto; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.group-letter { font-family: var(--serif); color: var(--accent); margin: 18px 4px 6px; font-size: 1.2rem; }

/* recipe */
.crumbs { font-size: .95rem; margin-bottom: 14px; }
.crumbs a { text-decoration: none; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.pill { background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 3px 12px; font-size: .9rem; }
.credit { font-style: italic; color: var(--muted); font-size: 1.05rem; margin: 0 0 6px; }
.sheet { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 20px 8px; margin: 16px 0; }
.ingredients { margin: 0 0 12px; padding-left: 1.2em; }
.ingredients li { margin: 4px 0; }
.ingredients li::marker { color: var(--accent); }
.sub { list-style: none; margin: 14px 0 4px -1.2em !important; font-weight: 700; color: var(--accent); }
.instructions p { margin: 0 0 14px; }
.notes { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 12px 16px; margin: 0 0 16px; }
details.original summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
details.original pre { white-space: pre-wrap; font: .95rem/1.5 var(--sans); background: var(--paper); padding: 12px; border-radius: 10px; }

.banner { border-radius: 12px; padding: 14px 16px; margin: 12px 0; display: flex; gap: 12px; align-items: flex-start; }
.banner.info { background: var(--accent-soft); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.err { background: var(--err-bg); color: var(--err-ink); }
.spinner { flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; margin-top: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 10px 0; }
.gallery button { padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: 10px; overflow: hidden; aspect-ratio: 1; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }

.comments { list-style: none; padding: 0; margin: 0; }
.comment { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 10px 0; }
.comment .head { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .9rem; }
.comment .head strong { color: var(--ink); }
.comment p { margin: 6px 0; white-space: pre-wrap; }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; padding: 4px; }
.comment-form { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 16px 16px; margin-top: 14px; }

/* photo picker */
.picker { display: grid; gap: 12px; margin: 18px 0; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.preview { position: relative; border-radius: 12px; overflow: hidden; aspect-ratio: 3/4; background: var(--line); }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview .n { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; border-radius: 999px; padding: 0 9px; font-weight: 700; }
.preview button { position: absolute; right: 6px; top: 6px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 1rem; cursor: pointer; }
.steps { padding-left: 1.2em; color: var(--muted); }

.lightbox { padding: 0; border: 0; background: transparent; max-width: 100vw; max-height: 100vh; }
.lightbox::backdrop { background: rgba(0, 0, 0, .85); }
.lightbox img { max-width: 96vw; max-height: 92vh; display: block; margin: auto; border-radius: 6px; }
.lightbox .close { position: fixed; top: 12px; right: 12px; width: 48px; height: 48px; border-radius: 50%; border: 0; font-size: 1.3rem; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(150%); background: var(--ink); color: var(--paper);
  padding: 12px 20px; border-radius: 999px; transition: transform .25s, opacity .25s, visibility .25s; max-width: calc(100vw - 32px); z-index: 50;
  opacity: 0; visibility: hidden; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

@media print {
  .topbar, .actions, .crumbs, .comment-form, .no-print, .banner { display: none !important; }
  body { background: #fff; font-size: 12pt; }
  .sheet { box-shadow: none; padding: 0; }
}
