/* ============================================================
   MaggieMix — hand-written styles ("Dastarkhwan" look)
   Layout utilities come from css/tailwind.css (static build).
   Everything component-ish or animated lives here.
   ============================================================ */

:root {
  --cream: #FBF5E6;
  --paper: #FFFDF7;
  --ink: #1C1A17;
  --ink-700: #3D352C;
  --ink-500: #6B5E4F;
  --green: #11402A;
  --zafran: #D98B0B;
  --zafran-300: #F2B64A;
  --zafran-800: #8A5607;
  --rani: #B3245E;
  --rani-700: #8E1C4A;
  --rani-900: #7A1740;
  --mehndi: #2E7D4F;
  --mehndi-700: #205C39;

  /* Measured at runtime from the sticky filter bar (js/app.js). */
  --filters-h: 180px;
}

body { font-family: Manrope, system-ui, sans-serif; background: var(--cream); color: var(--ink); }
.font-display { font-family: 'DM Serif Display', Georgia, serif; font-weight: 400; }
.urdu { font-family: 'Noto Nastaliq Urdu', serif; line-height: 1.9; }
body.sheet-open { overflow: hidden; }
svg { width: 1em; height: 1em; }
/* The hidden attribute always wins over component display rules below. */
[hidden] { display: none !important; }

.eyebrow { font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase; font-weight: 800; }

/* ── Header & footer ──────────────────────────────────────── */
.site-header { background: var(--green); color: var(--cream); border-bottom: 6px solid var(--zafran); }
.site-footer { margin-top: 24px; background: var(--green); color: var(--zafran-300); text-align: center; padding: 18px; font-size: 13px; letter-spacing: 0.12em; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 22px; border: 0; border-radius: 999px;
  background: var(--green); color: var(--cream);
  font: inherit; font-weight: 700; font-size: 15px; cursor: pointer;
}
.btn-primary:hover { background: #17533A; }
.btn-outline {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 18px; border: 2px solid var(--green); border-radius: 999px;
  background: transparent; color: var(--green);
  font: inherit; font-weight: 700; font-size: 15px; cursor: pointer;
}
.btn-outline:hover { background: rgba(17, 64, 42, 0.06); }
.btn-primary:focus-visible, .btn-outline:focus-visible, .pick-button:focus-visible,
.filter-pill:focus-visible, .fav-btn:focus-visible, .sheet-close-btn:focus-visible, .search-clear:focus-visible {
  outline: 3px solid var(--rani); outline-offset: 2px;
}

/* Pick For Me */
.pick-button {
  display: inline-flex; align-items: center; gap: 10px;
  height: 46px; padding: 0 20px; border: 0; border-radius: 999px;
  background: var(--rani); color: var(--cream);
  font: inherit; font-weight: 800; font-size: 15px; letter-spacing: 0.01em; cursor: pointer;
  box-shadow: 0 3px 0 var(--rani-900);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.pick-button svg { width: 20px; height: 20px; }
.pick-button:hover { transform: translateY(-1px); box-shadow: 0 4px 0 var(--rani-900); }
.pick-button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--rani-900); }
.dice-wobble { animation: diceWobble 2.4s ease-in-out infinite; transform-origin: center; }
.pick-button:hover .dice-wobble { animation-duration: 0.6s; }
@keyframes diceWobble {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  25% { transform: rotate(8deg) scale(1.05); }
  50% { transform: rotate(-4deg) scale(1); }
  75% { transform: rotate(4deg) scale(1.05); }
}

/* ── Search box ───────────────────────────────────────────── */
.search-box { position: relative; }
.search-box .search-icon {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--green); pointer-events: none;
}
.search-input {
  width: 100%; height: 48px; box-sizing: border-box;
  padding: 0 44px 0 44px;
  border: 3px solid var(--zafran); border-radius: 999px;
  background: var(--cream); color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 500;
}
.search-input::placeholder { color: var(--ink-500); }
.search-input:focus { outline: none; border-color: var(--zafran-300); box-shadow: 0 0 0 4px rgba(242, 182, 74, 0.35); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-clear {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: var(--green); color: var(--cream); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.search-clear svg { width: 12px; height: 12px; }

/* ── Filter bar ───────────────────────────────────────────── */
.filter-bar { background: rgba(251, 245, 230, 0.94); backdrop-filter: blur(10px); border-bottom: 2px solid var(--green); }
.filter-label { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; font-weight: 800; color: var(--ink-500); width: 60px; flex-shrink: 0; }
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 999px;
  border: 2px solid var(--green); background: transparent; color: var(--green);
  font: inherit; font-weight: 700; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.filter-pill:hover { background: rgba(17, 64, 42, 0.07); }
.filter-pill.pill-chicken { border-color: var(--zafran); color: var(--zafran-800); }
.filter-pill.pill-meat { border-color: var(--rani); color: var(--rani-700); }
.filter-pill.pill-veg { border-color: var(--mehndi); color: var(--mehndi-700); }
.filter-pill.pill-chicken:hover { background: rgba(217, 139, 11, 0.12); }
.filter-pill.pill-meat:hover { background: rgba(179, 36, 94, 0.1); }
.filter-pill.pill-veg:hover { background: rgba(46, 125, 79, 0.1); }
/* Active states (class names are set by js/app.js) */
.filter-pill.active-all, .filter-pill.active-rice, .filter-pill.active-saalan, .filter-pill.active-sides,
.filter-pill.active-snacks, .filter-pill.active-quick, .filter-pill.active-medium, .filter-pill.active-elaborate {
  background: var(--green); border-color: var(--green); color: var(--cream);
}
.filter-pill.active-chicken { background: var(--zafran); border-color: var(--zafran); color: var(--ink); }
.filter-pill.active-meat { background: var(--rani); border-color: var(--rani); color: var(--cream); }
.filter-pill.active-veg { background: var(--mehndi); border-color: var(--mehndi); color: var(--cream); }

.filter-pill.favorites-filter { border-color: var(--zafran); color: var(--zafran-800); background: var(--paper); }
.filter-pill.favorites-filter .star { width: 15px; height: 15px; color: var(--zafran); }
.filter-pill.favorites-filter .star path { fill: var(--zafran); }
.filter-pill.favorites-filter.active { background: var(--zafran); color: var(--ink); }
.filter-pill.favorites-filter.active .star { color: var(--ink); }
.filter-pill.favorites-filter.active .star path { fill: var(--ink); }

.counter-badge { color: var(--rani); font-weight: 800; font-size: 1.2em; }

/* Right-hand column (desktop): one continuous rule down the filter bar and the detail panel */
.fourth-column { border-left: 2px solid var(--green); }

/* ── Mobile bottom bar ────────────────────────────────────── */
.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(251, 245, 230, 0.96); backdrop-filter: blur(10px);
  border-top: 2px solid var(--green);
}
.mobile-bar .pick-button { height: 48px; font-size: 16px; }
.mobile-bar .filter-pill.favorites-filter { height: 40px; }
@media (min-width: 1024px) { .mobile-bar { display: none; } }

/* ── Recipe cards ─────────────────────────────────────────── */
.recipe-card {
  --accent: var(--green); --accent-ink: var(--cream);
  position: relative;
  background: var(--paper);
  border: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--accent);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  /* Skip layout/paint for cards far off-screen: 188 cards render much faster on phones. */
  content-visibility: auto;
  contain-intrinsic-size: auto 360px;
  scroll-margin-top: calc(var(--filters-h) + 16px);
}
.recipe-card.card-chicken { --accent: var(--zafran); --accent-ink: var(--ink); }
.recipe-card.card-meat { --accent: var(--rani); --accent-ink: var(--cream); }
.recipe-card.card-veg { --accent: var(--mehndi); --accent-ink: var(--cream); }
.recipe-card:hover { transform: translate(-2px, -2px); box-shadow: 7px 7px 0 var(--accent); }
.recipe-card:focus-within { outline: 3px solid var(--rani); outline-offset: 3px; }
.recipe-card.selected { transform: translate(-2px, -2px); box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--green), 7px 7px 0 var(--accent); }
.recipe-card.highlighted { animation: pickPulse 1.6s ease-in-out 2; }
@keyframes pickPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--rani), 7px 7px 0 var(--accent); }
  50% { box-shadow: 0 0 0 6px var(--paper), 0 0 0 10px var(--rani), 7px 7px 0 var(--accent); }
}

/* The card title is the one real keyboard/screen-reader control; the rest of the card is a click target. */
.card-title-btn { all: unset; display: inline; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.card-title-btn::after { content: ''; position: absolute; inset: 0; }

/* Illustration block: the Urdu name in Nastaliq on the protein colour */
.card-illo {
  background: var(--accent); color: var(--accent-ink);
  padding: 14px 16px 8px; min-height: 76px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-illo .urdu { font-size: 28px; font-weight: 700; line-height: 1.7; flex: 1; min-width: 0; }
.illo-emoji {
  font-size: 44px; line-height: 1; flex-shrink: 0;
  filter: drop-shadow(0 3px 6px rgba(28, 26, 23, 0.25));
  transition: transform 0.2s ease;
}
.recipe-card:hover .illo-emoji { transform: scale(1.12) rotate(-4deg); }
.card-illo .chip {
  font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 800;
  background: var(--cream); color: var(--accent); padding: 4px 8px; border-radius: 4px; flex-shrink: 0;
}
.recipe-card.card-chicken .card-illo .chip { color: var(--zafran-800); }
.recipe-card.card-meat .card-illo .chip { color: var(--rani-700); }
.recipe-card.card-veg .card-illo .chip { color: var(--mehndi-700); }
.fav-indicator {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  width: 22px; height: 22px; color: var(--zafran-300);
  animation: favPop 0.35s ease both;
}
.recipe-card.card-chicken .fav-indicator { color: var(--rani); }
.fav-indicator path { fill: currentColor; }
@keyframes favPop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.card-title { font-family: 'DM Serif Display', Georgia, serif; font-weight: 400; font-size: 22px; line-height: 1.15; color: var(--ink); }
.card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; font-weight: 700; color: var(--ink-500); }
.card-desc { font-size: 14px; line-height: 1.5; color: var(--ink-700); }
.card-desc-ur { font-size: 13.5px; color: var(--ink-500); }
.card-hint { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); font-weight: 800; text-align: right; }

/* Effort meter: filled squares in the accent colour */
.effort { display: inline-flex; gap: 3px; color: var(--accent); }
.effort i { width: 9px; height: 9px; display: inline-block; box-sizing: border-box; border: 1.5px solid currentColor; }
.effort i.on { background: currentColor; }

/* Staggered fade-in for the first row or two of cards */
.card-enter { animation: cardFadeIn 0.35s ease both; }
.card-enter:nth-child(2)  { animation-delay: 40ms; }
.card-enter:nth-child(3)  { animation-delay: 80ms; }
.card-enter:nth-child(4)  { animation-delay: 120ms; }
.card-enter:nth-child(5)  { animation-delay: 160ms; }
.card-enter:nth-child(6)  { animation-delay: 200ms; }
.card-enter:nth-child(7)  { animation-delay: 240ms; }
.card-enter:nth-child(8)  { animation-delay: 280ms; }
.card-enter:nth-child(9)  { animation-delay: 320ms; }
.card-enter:nth-child(n+10) { animation-delay: 360ms; }
@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Detail panel (desktop) & sheet content ───────────────── */
.detail-panel {
  position: sticky;
  top: calc(var(--filters-h) + 1.5rem);
  max-height: calc(100vh - var(--filters-h) - 3rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--zafran) transparent;
}
.detail-panel::-webkit-scrollbar { width: 6px; }
.detail-panel::-webkit-scrollbar-thumb { background: var(--zafran); border-radius: 3px; }
.detail-empty {
  background: var(--paper); border: 3px dashed var(--zafran); border-radius: 10px;
  padding: 40px 24px; text-align: center;
}
.detail-card {
  --accent: var(--green); --accent-ink: var(--cream);
  background: var(--paper); border: 4px double var(--green); border-radius: 10px; overflow: hidden;
  animation: detailFadeIn 0.35s ease both;
}
.detail-card.card-chicken { --accent: var(--zafran); --accent-ink: var(--ink); }
.detail-card.card-meat { --accent: var(--rani); --accent-ink: var(--cream); }
.detail-card.card-veg { --accent: var(--mehndi); --accent-ink: var(--cream); }
.sheet-panel .detail-card { border: 0; border-radius: 0; animation: none; }
@keyframes detailFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.detail-head {
  background: var(--accent); color: var(--accent-ink);
  padding: 20px 22px 14px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.detail-head .eyebrow { opacity: 0.85; margin-bottom: 4px; }
.detail-emoji { font-size: 52px; line-height: 1; flex-shrink: 0; filter: drop-shadow(0 3px 6px rgba(28, 26, 23, 0.25)); align-self: center; }
.detail-title { font-family: 'DM Serif Display', Georgia, serif; font-weight: 400; font-size: 30px; line-height: 1.05; }
.detail-body { padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 14px; }
.detail-urdu { font-size: 21px; color: var(--green); }
.detail-urdu-desc { font-size: 14.5px; color: var(--ink-500); }
.detail-desc { font-size: 15px; line-height: 1.55; color: var(--ink-700); }
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 6px 10px; border: 2px solid var(--green); color: var(--green); border-radius: 4px;
}
.tag.tag-accent { border-color: var(--accent); color: var(--accent); }
.detail-card.card-chicken .tag.tag-accent { color: var(--zafran-800); }
.detail-card.card-meat .tag.tag-accent { color: var(--rani-700); }
.detail-card.card-veg .tag.tag-accent { color: var(--mehndi-700); }
.section-title { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; font-weight: 800; color: var(--ink-500); margin-bottom: 10px; }
.ingredients { border-top: 2px solid var(--green); padding-top: 14px; }
.ingredients ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.ingredients li { display: flex; gap: 10px; font-size: 14.5px; color: var(--ink-700); line-height: 1.45; }
.ingredients li::before { content: '✦'; color: var(--rani); font-weight: 700; flex-shrink: 0; }
.note { background: var(--cream); border: 2px dashed var(--zafran); border-radius: 6px; padding: 12px 14px; }
.note .section-title { color: var(--zafran-800); margin-bottom: 6px; }
.note p { font-size: 14.5px; line-height: 1.55; color: var(--ink-700); font-style: italic; }
.detail-actions { display: flex; gap: 10px; }
.detail-actions .btn-primary { flex: 1; }
.detail-actions svg { width: 18px; height: 18px; }

/* Save star (detail head) */
.fav-btn {
  width: 44px; height: 44px; border-radius: 999px; flex-shrink: 0;
  border: 2px solid var(--accent-ink); background: transparent; color: var(--accent-ink);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.fav-btn svg { width: 20px; height: 20px; }
.fav-btn:hover { transform: scale(1.08); background: rgba(255, 255, 255, 0.15); }
.fav-btn.is-fav { background: var(--cream); color: var(--zafran); border-color: var(--cream); }
.detail-card.card-chicken .fav-btn.is-fav { color: var(--rani); }
.fav-btn.is-fav svg path { fill: currentColor; }

/* ── Mobile bottom sheet ──────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(28, 26, 23, 0.5);
  z-index: 90;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet-panel {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 90vh;
  z-index: 91;
  background: var(--paper);
  border-top: 3px solid var(--green);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px rgba(28, 26, 23, 0.25);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-panel.open { transform: translateY(0); }
.sheet-close {
  position: sticky; top: 0; z-index: 2;
  background: var(--paper);
  padding: 0 16px 6px;
  display: flex; justify-content: center; align-items: center;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--zafran); margin: 10px auto 0; }
.sheet-close-btn {
  position: absolute; right: 12px; top: 8px;
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--green);
  background: var(--paper); color: var(--green); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sheet-close-btn svg { width: 14px; height: 14px; }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--ink); color: var(--cream);
  padding: 10px 16px; border-radius: 999px; border: 2px solid var(--zafran);
  font-size: 14px; font-weight: 600; max-width: calc(100vw - 32px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
}
@media (min-width: 1024px) { .toast { bottom: 28px; } }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Responsive tweaks ────────────────────────────────────── */
@media (min-width: 768px) {
  .filter-pill { height: 40px; padding: 0 16px; font-size: 14px; }
}
@media (max-width: 767px) {
  .filter-label { display: none; }
  .card-illo .urdu { font-size: 24px; }
  .illo-emoji { font-size: 36px; }
  .detail-emoji { font-size: 44px; }
  .card-title { font-size: 20px; }
  .card-body { padding: 12px 14px 14px; }
  .detail-head { padding: 18px 18px 12px; }
  .detail-body { padding: 16px 18px 20px; }
  .detail-title { font-size: 26px; }
}
@media (max-width: 380px) {
  .filter-pill { height: 34px; padding: 0 11px; font-size: 12.5px; }
}

/* ── Reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .dice-wobble, .pick-button:hover .dice-wobble, .card-enter, .detail-card, .fav-indicator, .recipe-card.highlighted { animation: none; }
  .recipe-card:hover .illo-emoji { transform: none; }
  .recipe-card, .pick-button, .fav-btn, .filter-pill, .sheet-panel, .sheet-backdrop, .toast { transition: none; }
  .recipe-card:hover { transform: none; }
}

/* ── Print: just the open recipe ──────────────────────────── */
@media print {
  @page { margin: 1.5cm; }
  body { background: white; }
  header, #filters, footer, #recipeGrid, #emptyState, #detailEmpty, .mobile-bar,
  .sheet-backdrop, .sheet-close, .toast, .detail-actions, .fav-btn { display: none !important; }
  main, main > div, .fourth-column {
    display: block !important; width: auto !important; max-width: none !important;
    padding: 0 !important; border: 0 !important; background: white !important;
  }
  .detail-panel { position: static !important; max-height: none !important; overflow: visible !important; }
  .detail-card { animation: none !important; border-color: #1C1A17; }
  .detail-head { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-panel { position: static !important; transform: none !important; max-height: none !important; box-shadow: none !important; overflow: visible !important; border: 0 !important; }
  .sheet-panel:not(.open) { display: none !important; }
  .recipe-card { content-visibility: visible; }
}
