/* ---------- Tokens ---------- */
:root {
  --bg: hsl(90 10% 96%);
  --surface: hsl(80 15% 99%);
  --surface-2: hsl(90 12% 93%);
  --ink: hsl(100 10% 12%);
  --muted: hsl(90 8% 40%);
  --border: hsl(90 10% 86%);
  --accent: hsl(100 32% 30%);
  --accent-ink: hsl(90 40% 97%);
  --recipe-bg: hsl(95 28% 92%);
  --recipe-border: hsl(95 22% 78%);
  --recipe-ink: hsl(100 25% 18%);
  --shadow: 90 15% 10%;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  --font-serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: hsl(100 8% 7%);
    --surface: hsl(100 7% 10%);
    --surface-2: hsl(100 7% 14%);
    --ink: hsl(90 15% 93%);
    --muted: hsl(90 8% 62%);
    --border: hsl(100 8% 20%);
    --accent: hsl(100 40% 60%);
    --accent-ink: hsl(100 30% 8%);
    --recipe-bg: hsl(100 16% 14%);
    --recipe-border: hsl(100 16% 24%);
    --recipe-ink: hsl(95 30% 88%);
    --shadow: 0 0% 0%;
  }
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }

/* ---------- Layout ---------- */
.page { max-width: 1400px; margin: 0 auto; padding: 0 clamp(1rem, 3vw, 2.5rem) 4rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 3vw, 2.5rem);
  margin: 0 clamp(-1rem, -3vw, -2.5rem);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 0.5rem; }
.brand-mark { color: var(--accent); font-size: 0.85rem; }
.brand-name {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-tools { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.count { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

.search input {
  width: min(320px, 60vw);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
}
.search input::placeholder { color: var(--muted); }
.search input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

main { padding-top: 1.75rem; }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 4rem 1rem;
  font-size: 0.95rem;
}

/* ---------- Card ---------- */
.card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.16,1,0.3,1), box-shadow 0.2s cubic-bezier(0.16,1,0.3,1), border-color 0.2s;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--recipe-border);
  box-shadow: 0 14px 30px -18px hsl(var(--shadow) / 0.55);
}
.card:active { transform: translateY(-1px) scale(0.99); }
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-media {
  display: block;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
}
.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.05rem 1.15rem 1.2rem;
}

.card-name {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.25;
}

.card-category {
  font-size: 0.82rem;
  color: var(--muted);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.1rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.65rem;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.74rem;
  color: var(--ink);
  line-height: 1.3;
}
.chip-more {
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.card-family { display: flex; align-items: center; gap: 0.35rem; }
.card-family::before {
  content: "\25C6";
  color: var(--accent);
  font-size: 0.6rem;
}
.card-index { font-family: var(--font-mono); }

/* ---------- Overlay / Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  background: hsl(var(--shadow) / 0.6);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.overlay[hidden] { display: none; }
.overlay.is-open { opacity: 1; }

.modal {
  width: min(640px, 100%);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 30px 80px -20px hsl(var(--shadow) / 0.5);
  transform: translateY(14px) scale(0.98);
  transition: transform 0.24s cubic-bezier(0.16,1,0.3,1);
  overflow: hidden;
}
.overlay.is-open .modal { transform: translateY(0) scale(1); }

.modal-media {
  position: relative;
  background: var(--surface-2);
  flex: 0 0 auto;
}
.modal-media img {
  width: 100%;
  max-height: 34vh;
  object-fit: cover;
  object-position: top;
}

.modal-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
}
.modal-index {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-pill);
  background: hsl(var(--shadow) / 0.55);
  color: hsl(90 20% 96%);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  backdrop-filter: blur(4px);
}

.modal-scroll { padding: 1.6rem clamp(1.25rem, 4vw, 2rem) 1.6rem; }

.modal-heading { margin-bottom: 0.6rem; }
.modal-heading h2 {
  font-family: var(--font-serif);
  font-size: 1.65rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
  line-height: 1.2;
}
.modal-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.modal-description {
  font-size: 0.96rem;
  line-height: 1.55;
  color: var(--ink);
  max-width: 60ch;
  margin: 0.9rem 0 1.1rem;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1.3rem;
}

.recipe-box {
  background: var(--recipe-bg);
  border: 1px solid var(--recipe-border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem 1.1rem;
}
.recipe-label {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.recipe-label-dim {
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--muted);
}
.recipe-text {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.65;
  color: var(--recipe-ink);
  white-space: pre-wrap;
}

.modal-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding: 1rem clamp(1.25rem, 4vw, 2rem);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.btn {
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.7rem 1.2rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary.is-copied { background: var(--ink); color: var(--surface); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
  margin-left: auto;
}
.btn-ghost:hover { background: var(--surface-2); }

body.no-scroll { overflow: hidden; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .card, .overlay, .modal, .btn { transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .search input { width: 100%; }
  .modal-actions { flex-direction: column; }
  .btn-ghost { margin-left: 0; }
}
