:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #2b2622;
  --muted: #8c8278;
  --accent: #c8553d;
  --accent-soft: #f2e0da;
  --line: #ece4d9;
  --shadow: 0 1px 2px rgba(43, 38, 34, .06), 0 12px 28px rgba(43, 38, 34, .10);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgba(250, 247, 242, .85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-mark { color: var(--accent); font-size: 22px; }

.search-wrap { flex: 1; display: flex; justify-content: flex-end; }

#search {
  width: min(440px, 100%);
  padding: 11px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

/* ---------- layout ---------- */
main { padding: clamp(24px, 4vw, 48px); max-width: 1180px; margin: 0 auto; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.empty { color: var(--muted); font-size: 16px; text-align: center; padding: 80px 0; }

/* ---------- shelf ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: clamp(18px, 3vw, 34px);
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.cover {
  display: block;
  width: 100%;
  height: auto;               /* keep each cover's true proportions - never crop */
  border-radius: 10px;
  box-shadow: var(--shadow);
  background: var(--surface);
  transition: transform .18s ease, box-shadow .18s ease;
}
.card:hover .cover { transform: translateY(-4px); box-shadow: 0 6px 10px rgba(43,38,34,.10), 0 20px 40px rgba(43,38,34,.16); }

/* uniform-height slot so covers sit on a common baseline (a "shelf") and captions line up */
.cover-slot {
  aspect-ratio: 2 / 3;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.cover-slot .cover {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;   /* fit fully within the slot, never crop */
}
.cover-slot .cover-fallback { width: 100%; height: 100%; }

.cover-fallback {
  aspect-ratio: 2 / 3;        /* no image to size the box, so give the placeholder a book shape */
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px;
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  color: #6f4a3d;
  background: linear-gradient(150deg, #f3e7dd, #e7d3c6);
}

.card-meta { display: flex; flex-direction: column; gap: 2px; }
.card-title { font-family: "Fraunces", serif; font-weight: 600; font-size: 15px; line-height: 1.25; }
.card-sub { font-size: 13px; color: var(--muted); }
.card-count { font-size: 12px; color: var(--accent); margin-top: 2px; }

/* ---------- search results ---------- */
.results-head {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 18px;
}
.result-list { display: flex; flex-direction: column; gap: 8px; }

.result {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: border-color .15s, transform .12s;
}
.result:hover { border-color: var(--accent); transform: translateX(2px); }

.result .thumb {
  width: 40px;
  height: auto;
  align-self: center;
  border-radius: 5px;
  flex: 0 0 auto;
  box-shadow: none;
}
.result .thumb.cover-fallback { font-size: 9px; padding: 4px; }

.result-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.result-title { font-family: "Fraunces", serif; font-weight: 600; font-size: 16px; }
.result-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-page {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- book view ---------- */
.back {
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0 0 20px;
}
.back:hover { color: var(--accent); }

.book-header {
  display: flex;
  gap: clamp(20px, 4vw, 40px);
  align-items: flex-start;
  margin-bottom: 32px;
}
.book-header .cover.big { width: 180px; flex: 0 0 auto; }
.book-meta { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; }
.book-meta h2 { font-family: "Fraunces", serif; font-weight: 700; font-size: 30px; margin: 0; }
.book-meta .author { color: var(--muted); font-size: 16px; margin: 0; }
.book-meta .count { color: var(--accent); font-size: 13px; margin: 0 0 8px; }

.book-filter {
  margin-top: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
  max-width: 300px;
}
.book-filter:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.recipe-list {
  columns: 2;
  column-gap: 40px;
}
@media (max-width: 640px) { .recipe-list { columns: 1; } }

.recipe {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  break-inside: avoid;
}
.recipe-title { font-size: 15px; }
.recipe-cat {
  font-size: 11px;
  color: var(--muted);
  background: var(--line);
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 6px;
}
.recipe-page { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.recipe.hit { background: var(--accent-soft); border-radius: 8px; padding-left: 10px; padding-right: 10px; }
.recipe.hit .recipe-page { color: var(--accent); }
