/* ---------- design tokens ---------- */
:root,
[data-preset="fresh"] {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-alt: #f3f1ed;
  --text: #201c1a;
  --text-muted: #6b6560;
  --border: #e7e2db;
  --accent: #ff6b4a;
  --accent-contrast: #ffffff;
  --danger: #d6483f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 16, 12, 0.05), 0 10px 28px rgba(20, 16, 12, 0.07);
  --font-heading: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --heading-weight: 800;
}

[data-preset="midnight"] {
  --bg: #17151a;
  --surface: #211f26;
  --surface-alt: #1b1920;
  --text: #f2efe9;
  --text-muted: #a39d9a;
  --border: #322f38;
  --accent: #ff7a5c;
  --accent-contrast: #1a1720;
  --danger: #ff6b61;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.45);
}

[data-preset="warm"] {
  --bg: #fbf3e6;
  --surface: #fffaf0;
  --surface-alt: #f5e8d2;
  --text: #3a2c1e;
  --text-muted: #8a7358;
  --border: #e7d6b5;
  --accent: #c1602e;
  --accent-contrast: #fffaf0;
  --danger: #b0392f;
  --radius: 10px;
  --font-heading: "Playfair Display", Georgia, serif;
  --heading-weight: 700;
}

[data-preset="sage"] {
  --bg: #f4f7f1;
  --surface: #ffffff;
  --surface-alt: #e8efe1;
  --text: #232a1f;
  --text-muted: #6c7863;
  --border: #d6e0cb;
  --accent: #5c8a54;
  --accent-contrast: #ffffff;
  --danger: #c1503f;
}

[data-preset="berry"] {
  --bg: #faf4f6;
  --surface: #ffffff;
  --surface-alt: #f2e3ea;
  --text: #2c1a22;
  --text-muted: #7a5f68;
  --border: #ecd5dd;
  --accent: #9c3b5e;
  --accent-contrast: #ffffff;
  --danger: #c1372f;
  --radius: 18px;
  --font-heading: "Playfair Display", Georgia, serif;
  --heading-weight: 700;
}

[data-preset="slate"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #e8ebf0;
  --text: #1e2530;
  --text-muted: #62707e;
  --border: #dce1e7;
  --accent: #3b6ea5;
  --accent-contrast: #ffffff;
  --danger: #c1443a;
  --radius: 8px;
}

[data-preset="charcoal"] {
  --bg: #1a1a18;
  --surface: #232220;
  --surface-alt: #1e1d1b;
  --text: #f0ede6;
  --text-muted: #9c968c;
  --border: #35332f;
  --accent: #d4a13d;
  --accent-contrast: #1a1a18;
  --danger: #e2645a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.45);
}

[data-preset="citrus"] {
  --bg: #fdfbef;
  --surface: #ffffff;
  --surface-alt: #f5efc9;
  --text: #2a2410;
  --text-muted: #7d7458;
  --border: #ece0a8;
  --accent: #dba500;
  --accent-contrast: #2a2410;
  --danger: #c1443a;
  --radius: 18px;
}

* { box-sizing: border-box; }

/* Consistent, visible keyboard-focus indicator everywhere — many buttons in this app
   reset default browser chrome (background/border: none), which can otherwise leave
   keyboard users with little or no visible focus ring on custom-styled controls. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hidden { display: none !important; }

html, body { height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  transition: background 0.2s ease, color 0.2s ease;
  overscroll-behavior-x: none;
  /* Stops the double-tap-to-zoom gesture from firing during quick swipe/tap
     interaction (e.g. flipping book pages) — "manipulation" still allows
     normal scrolling AND pinch-zoom, so this doesn't take away the
     accessibility zoom low-vision users may rely on, unlike disabling zoom
     entirely via the viewport meta tag would. */
  touch-action: manipulation;
}

button, input, textarea, select { font-family: inherit; }

h1, h2, h3 { font-family: var(--font-heading); font-weight: var(--heading-weight); margin: 0; }

/* ---------- app shell ---------- */
#appShell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(14px + env(safe-area-inset-left));
  z-index: 60;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.45);
  z-index: 45;
}

#sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--surface-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(22px + env(safe-area-inset-top)) 16px calc(22px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

.sidebar-brand h1 {
  font-size: 1.25rem;
  line-height: 1.25;
}
.sidebar-subtitle {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.92rem;
  cursor: pointer;
}
.sidebar-nav-item:hover { background: var(--surface); }
.sidebar-nav-item.active { background: var(--accent); color: var(--accent-contrast); font-weight: 700; }
.sidebar-nav-count {
  margin-left: auto;
  font-size: 0.76rem;
  opacity: 0.75;
}
.sidebar-nav-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 4px;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.sidebar-footer-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.88rem;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.sidebar-footer-btn:hover { background: var(--surface); }

#main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}

#mainContent {
  max-width: 980px;
  margin: 0 auto;
  padding: 40px clamp(20px, 4vw, 56px) 100px;
}

@media (max-width: 800px) {
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .sidebar-scrim:not(.hidden) { display: block; }
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  #sidebar.open { transform: translateX(0); }
  #mainContent { padding-top: 72px; }
}

/* ---------- view header + cards ---------- */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.view-header h2 { font-size: 1.7rem; }
.view-header p {
  margin: 6px 0 0;
  color: var(--text-muted);
  max-width: 540px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  text-align: left;
  color: var(--text);
}
.card:hover { transform: translateY(-2px); }
.card h3 { font-size: 1.02rem; }
.card p { margin: 0; color: var(--text-muted); font-size: 0.85rem; }

.card-photo {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: calc(var(--radius) - 4px);
  background: var(--surface-alt);
  margin-bottom: 2px;
}
.card-photo-placeholder {
  width: 100%;
  height: 130px;
  border-radius: calc(var(--radius) - 4px);
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
  padding: 20px 0;
}

/* ---------- recipe detail ---------- */
.recipe-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}
.recipe-photo {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: var(--radius);
  margin: 0 0 20px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.recipe-title { font-size: 1.6rem; margin: 0 0 4px; }
.recipe-meta { color: var(--text-muted); font-style: italic; margin: 0 0 22px; font-size: 0.95rem; }
.recipe-section { margin-top: 22px; }
.recipe-section h3 {
  font-size: 1.05rem;
  color: var(--accent);
  border-bottom: 2px solid var(--border);
  display: inline-block;
  padding-bottom: 4px;
  margin: 0 0 10px;
}
.recipe-section ul, .recipe-section ol { margin: 0; padding-left: 22px; }
.recipe-section li { margin-bottom: 8px; line-height: 1.55; }
.recipe-notes { line-height: 1.55; }
.recipe-actions { margin-top: 30px; display: flex; gap: 10px; }

/* ---------- tips ---------- */
.tip-category { margin-bottom: 24px; }
.tip-category h3 { color: var(--accent); margin: 0 0 8px; font-size: 1.05rem; }
.tip-category ul { margin: 0; padding-left: 20px; }
.tip-category li { margin-bottom: 6px; line-height: 1.55; }

/* ---------- nutrition ---------- */
.nutrition-sub { font-size: 0.8rem; font-weight: 400; color: var(--text-muted); font-style: italic; }
.nutrition-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  max-width: 420px;
  margin-top: 8px;
}
.nutrition-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  padding: 9px 14px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.nutrition-row:last-child { border-bottom: none; }
.nutrition-row.nutrition-head {
  background: var(--surface-alt);
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.nutrition-val { text-align: right; }
.nutrition-note { margin-top: 8px; font-size: 0.8rem; color: var(--text-muted); font-style: italic; max-width: 420px; }

/* ---------- meal planner ---------- */
.meal-plan-nav { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.meal-plan-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}
.meal-plan-day {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 160px;
}
.meal-plan-day-header {
  font-weight: 700;
  font-size: 0.85rem;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  width: 100%;
  padding: 4px 6px;
  margin: -4px -6px 0;
  cursor: pointer;
  border-radius: 6px;
}
.meal-plan-day-header:hover { color: var(--accent); background: var(--surface-alt); }
.meal-plan-day-header.active { color: var(--accent-contrast); background: var(--accent); text-decoration: none; }
.meal-plan-nutrition-toggle { display: flex; gap: 8px; margin-bottom: 10px; }
.meal-plan-entries { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.meal-plan-entries .empty-state { font-size: 0.78rem; padding: 8px 0; }
.meal-plan-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.82rem;
}
.meal-plan-remove {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  padding: 2px;
}
.meal-plan-remove:hover { color: var(--danger); }
.meal-plan-add { font-size: 0.8rem; padding: 6px 8px; }
.meal-plan-day-total { font-size: 0.78rem; color: var(--text-muted); text-align: right; }
.meal-plan-week-total { max-width: 480px; }

.shopping-list-checks { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.modal label.shopping-list-check { flex-direction: row; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 400; }
.modal label.auth-terms-check { flex-direction: row; align-items: flex-start; gap: 8px; font-size: 0.82rem; font-weight: 400; color: var(--text-muted); }
.auth-terms-check input { margin-top: 3px; }
.shopping-list-result { margin-top: 16px; }
.shopping-list-category { margin-bottom: 16px; }
.shopping-list-category:last-child { margin-bottom: 0; }
.shopping-list-category h4 {
  margin: 0 0 6px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.shopping-list-items { margin: 0; padding-left: 20px; }
.shopping-list-items li { margin-bottom: 6px; line-height: 1.5; }

.shopping-list-save-form { display: flex; gap: 8px; margin-top: 16px; }
.shopping-list-save-form input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.shopping-list-card { position: relative; padding-right: 34px; }
.shopping-list-card-open {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.shopping-list-card-delete {
  position: absolute;
  top: 14px;
  right: 12px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
  line-height: 1;
}
.shopping-list-card-delete:hover { color: var(--danger); }

.shopping-list-name-input {
  font-family: var(--font-heading);
  font-weight: var(--heading-weight);
  font-size: 1.7rem;
  border: none;
  background: none;
  color: var(--text);
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 6px;
  width: 100%;
  max-width: 480px;
}
.shopping-list-name-input:hover, .shopping-list-name-input:focus { background: var(--surface-alt); }

.shopping-list-detail-items { max-width: 560px; margin-bottom: 20px; }
.shopping-list-item-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.shopping-list-item-row.checked .shopping-list-item-input { color: var(--text-muted); text-decoration: line-through; }
.shopping-list-item-input {
  flex: 1;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.92rem;
  padding: 4px 6px;
  margin: 0 -6px;
  border-radius: 6px;
}
.shopping-list-item-input:hover, .shopping-list-item-input:focus { background: var(--surface-alt); }

.shopping-list-add-item-form { display: flex; gap: 8px; max-width: 400px; }
.shopping-list-add-item-form input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .meal-plan-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .meal-plan-grid { grid-template-columns: 1fr; }
}

/* ---------- buttons ---------- */
.btn {
  font-size: 0.9rem;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-add { background: var(--accent); color: var(--accent-contrast); margin-top: 6px; }
.btn-add:hover { filter: brightness(0.92); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 0.9rem;
  max-width: 480px;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal {
  background: var(--surface);
  color: var(--text);
  width: min(90vw, 560px);
  max-height: 86vh;
  overflow-y: auto;
  border-radius: var(--radius);
  padding: 28px 30px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.modal h2 { margin-bottom: 4px; }
.modal form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; color: var(--text); font-weight: 600; }
.modal .hint { font-weight: 400; color: var(--text-muted); font-size: 0.8rem; }
.modal input, .modal textarea, .modal select {
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.preset-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.preset-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.preset-chip:hover { background: var(--surface-alt); }
.preset-chip.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

.color-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.color-grid input[type="color"] { width: 100%; min-height: 42px; padding: 4px; }

.form-divider {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--text);
  font-size: 1rem;
}
.form-divider .hint { display: block; font-family: var(--font-body); font-weight: 400; margin-top: 2px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.ai-generate-row { display: flex; gap: 8px; }
.ai-generate-row input { flex: 1; }

.photo-preview-wrap { display: flex; align-items: center; gap: 12px; margin-top: -6px; }
.photo-preview { width: 92px; height: 92px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }

.shared-recipe-preview {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.shared-recipe-preview h3 { margin: 0 0 4px; font-size: 1.05rem; }
.shared-recipe-preview .hint { margin: 0; }

.page-manager-list-wrap { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.page-manager-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.page-manager-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.page-manager-name { font-weight: 700; }
.page-manager-desc { font-size: 0.9rem; color: var(--text-muted); margin-top: 3px; }
.page-manager-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.page-manager-actions button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.page-manager-actions .btn-danger { color: var(--danger); border-color: var(--danger); }

.account-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 220px;
  z-index: 20;
}
.account-email { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 10px; word-break: break-all; }
.account-ai-status { font-size: 0.82rem; color: var(--text-muted); margin: -4px 0 10px; }
.account-panel .btn { width: 100%; }
.account-panel .btn + .btn { margin-top: 6px; }

/* ---------- auth ---------- */
.auth-shell { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.auth-card { width: min(92vw, 420px); padding: 32px 30px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 6px; color: var(--text); }
.auth-card .auth-subtitle { color: var(--text-muted); margin: 0 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.auth-switch { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
.auth-status { margin-top: 14px; color: var(--accent); font-weight: 600; font-size: 0.9rem; }

.ad-gate-slot {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0;
  overflow: hidden;
}

.sidebar-ad-slot {
  margin: 10px 16px;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 90px;
}

/* Sits below the content area (whichever view/layout is showing), out of the
   way of the actual reading flow rather than pushed above it — appears on
   every page since it's rendered by renderMain() itself, not per-view. */
.content-ad-slot {
  max-width: 728px;
  margin: 24px auto 12px;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 90px;
}

.cookie-consent {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  z-index: 200;
}
.cookie-consent p { margin: 0 0 12px; font-size: 0.88rem; color: var(--text-muted); }
.cookie-consent-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- book layout ---------- */
.book-frame {
  position: relative;
  padding: 0 56px;
  touch-action: pan-y;
}

.book-page {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    6px 8px 0 0 var(--surface-alt),
    6px 8px 0 1px var(--border),
    12px 16px 0 0 var(--bg),
    12px 16px 0 1px var(--border),
    var(--shadow);
  height: min(70vh, 720px);
  transform-origin: left center;
  backface-visibility: hidden;
  overflow: hidden;
}
.book-page::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 22px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.12), transparent);
  pointer-events: none;
  z-index: 1;
}
.book-page-inner {
  height: 100%;
  overflow-y: auto;
  padding: clamp(28px, 5vw, 52px);
}
.book-page.enter-right { animation: bookFlipRight 0.38s ease forwards; }
.book-page.enter-left { animation: bookFlipLeft 0.38s ease forwards; }

.book-page-count {
  text-align: center;
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

@keyframes bookFlipRight {
  from { transform: rotateY(-6deg) translateX(10px); opacity: 0.5; }
  to { transform: rotateY(0deg) translateX(0); opacity: 1; }
}
@keyframes bookFlipLeft {
  from { transform: rotateY(6deg) translateX(-10px); opacity: 0.5; }
  to { transform: rotateY(0deg) translateX(0); opacity: 1; }
}

.book-frame .nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.book-frame .nav-arrow:hover { background: var(--surface-alt); }
.book-frame .nav-arrow:disabled { opacity: 0.25; pointer-events: none; }
.book-frame .nav-prev { left: 0; }
.book-frame .nav-next { right: 0; }

/* inside book pages, present recipe/section lists like a page of text rather than a card grid */
[data-layout="book"] .card-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}
[data-layout="book"] .card {
  flex-direction: row;
  align-items: center;
  gap: 14px;
  background: none;
  border: none;
  border-bottom: 1px dotted var(--border);
  border-radius: 0;
  box-shadow: none;
  padding: 14px 2px;
}
[data-layout="book"] .card:hover { transform: none; color: var(--accent); }
[data-layout="book"] .card-photo,
[data-layout="book"] .card-photo-placeholder {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  margin-bottom: 0;
}
[data-layout="book"] .view-header h2 { font-family: "Playfair Display", Georgia, serif; }

@media (max-width: 700px) {
  .book-frame { padding: 0; }
  .book-frame .nav-arrow { display: none; }
  .book-page { height: min(78vh, 640px); box-shadow: var(--shadow); }
  .book-page-inner { padding: 24px 20px; }
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
  .preset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
