:root {
  --cream: #FBF7EF;
  --cream-deep: #F1EADB;
  --ink: #1A140D;
  --red: #BE2523;
  --red-deep: #9C1E1C;
  --teal: #0D3745;
  --clay: #C97A2E;
  --matched: #2E7D32;
  --missing: #A8443F;
  --line: #E4DCC8;

  --font-display: "Fraunces", serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

img { max-width: 100%; display: block; }

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--cream);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--teal);
  font-size: 1.1rem;
  text-decoration: none;
}
.icon-btn:hover { background: var(--cream-deep); }

.burger, .burger::before, .burger::after {
  content: "";
  display: block;
  width: 20px;
  height: 2px;
  background: var(--teal);
  position: relative;
  transition: transform .2s ease, opacity .2s ease;
}
.burger::before { position: absolute; top: -6px; }
.burger::after { position: absolute; top: 6px; }

.brand-mark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: -.01em;
  color: var(--ink);
}
.brand-mark em { font-style: normal; color: var(--red); }

.brand-logo { height: 32px; width: auto; }

.drawer-mark { width: 44px; height: 44px; margin-bottom: 10px; }

/* ---------- Drawer menu ---------- */
.drawer {
  position: fixed;
  top: 0;
  left: 0; 
  height: 100%;
  width: min(300px, 85vw);
  background: var(--teal);
  color: var(--cream);
  z-index: 40;
  transform: translateX(-100%); 
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  
  /* منع تداخل العناصر مع نتوء الشاشة أو الحواف السفلية للهاتف */
  padding-top: env(safe-area-inset-top, 20px);
  padding-bottom: env(safe-area-inset-bottom, 20px);
  display: flex;
  flex-direction: column;
}
.drawer.open { 
  transform: translateX(0); 
}

.drawer-inner { 
  padding: 20px 24px; 
  display: flex; 
  flex-direction: column; 
  gap: 6px;
  overflow-y: auto;
  flex: 1;
}

.drawer-inner h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  margin: 0 0 14px;
  color: var(--cream);
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(251,247,239,.14);
}

.drawer-inner a {
  padding: 12px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.95rem;
  color: var(--cream);
  transition: background 0.2s ease;
  display: block;
}
.drawer-inner a:hover, .drawer-inner a:active {
  background: rgba(251,247,239,.08);
}

/* ---------- زر تثبيت التطبيق داخل القائمة الجانبية ---------- */
.menu-install-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: auto;
  padding: 14px 16px;
  background-color: var(--red) !important;
  color: #ffffff !important;
  border: none;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 14px rgba(190, 37, 35, 0.25);
}

.menu-install-link:hover {
  background-color: var(--red-deep) !important;
  box-shadow: 0 6px 18px rgba(190, 37, 35, 0.35);
}

.menu-install-link:active {
  transform: translateY(1px);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26,20,13,.4);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

/* ---------- Hero / search ---------- */
.hero {
  padding: 34px 20px 10px;
  max-width: 640px;
  margin: 0 auto;
  text-align: center;
}

.eyebrow {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--clay);
  font-weight: 600;
  margin: 0 0 10px;
}

.hero h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  line-height: 1.15;
  margin: 0 0 12px;
  color: var(--teal);
}

.hero-sub {
  font-size: .96rem;
  line-height: 1.5;
  color: #4b4335;
  margin: 0 0 26px;
}

.search-form { text-align: left; }

.chip-field {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  padding: 10px 12px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--cream-deep);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 6px 6px 12px;
  border-radius: 999px;
  font-size: .86rem;
  margin-bottom: 6px;
}
.chip button {
  background: none;
  border: none;
  color: var(--red);
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
}

#ingredient-input {
  flex: 1 1 140px;
  min-width: 140px;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: .96rem;
  padding: 8px 4px;
  background: transparent;
  margin-bottom: 6px;
}

.shelf-ledge {
  height: 10px;
  border-radius: 0 0 12px 12px;
  background: linear-gradient(180deg, #DCAE6E 0%, var(--clay) 55%, #A85F1E 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,.14);
  position: relative;
  margin-bottom: 22px;
}
.shelf-ledge::before,
.shelf-ledge::after {
  content: "";
  position: absolute;
  top: 100%;
  width: 6px;
  height: 12px;
  background: var(--clay);
  border-radius: 0 0 3px 3px;
}
.shelf-ledge::before { left: 14px; }
.shelf-ledge::after { right: 14px; }

.filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.filters select {
  width: 100%;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: var(--font-body);
  font-size: .82rem;
  color: var(--ink);
}

.search-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--red);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: .01em;
}
.search-btn:hover { background: var(--red-deep); }
.search-btn:active { transform: translateY(1px); }

/* ---------- Results ---------- */
.results {
  max-width: 900px;
  margin: 20px auto 0;
  padding: 0 20px;
  min-height: 20px;
}

.results-meta {
  font-size: .82rem;
  color: #6b6152;
  margin: 0 0 14px;
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.recipe-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--ink);
  transition: transform .15s ease, box-shadow .15s ease;
}
.recipe-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(26,20,13,.08); }

.recipe-card .thumb {
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: var(--cream-deep);
}

.recipe-card .body { padding: 14px 14px 16px; flex: 1; display: flex; flex-direction: column; }

.recipe-card h3 {
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 600;
  margin: 0 0 8px;
  line-height: 1.3;
  color: var(--teal);
}

.match-badge {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 5px;
  font-size: .74rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: #FBEFE6;
  color: var(--clay);
  margin-bottom: 8px;
}
.match-badge.high { background: #E9F5EA; color: var(--matched); }

.ingredient-line {
  font-size: .78rem;
  line-height: 1.5;
  margin: 2px 0;
}
.ingredient-line .matched { color: var(--matched); }
.ingredient-line .missing { color: var(--missing); }

.time-line { font-size: .78rem; color: #6b6152; margin-top: auto; padding-top: 8px; }

.empty-state, .error-state {
  text-align: center;
  padding: 34px 20px;
  border-radius: 12px;
  background: var(--cream-deep);
  color: #4b4335;
  font-size: .92rem;
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
  flex-wrap: wrap;
}
.pagination button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: .84rem;
}
.pagination button.current { background: var(--teal); color: #fff; border-color: var(--teal); }

/* ---------- Worth trying (random row) ---------- */
.worth-trying {
  max-width: 900px;
  margin: 46px auto 0;
  padding: 0 0 40px;
}
.worth-trying h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  margin: 0 0 4px;
  padding: 0 20px;
  color: var(--teal);
}
.section-sub {
  font-size: .84rem;
  color: #6b6152;
  margin: 0 0 14px;
  padding: 0 20px;
}

.random-row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 4px 20px 10px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.random-row::-webkit-scrollbar { height: 6px; }
.random-row::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }

.random-card {
  flex: 0 0 200px;
  scroll-snap-align: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
}
.random-card .thumb { width: 100%; height: 120px; object-fit: cover; background: var(--cream-deep); }
.random-card .body { padding: 10px 12px 14px; }
.random-card .tag {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--clay);
}
.random-card h3 {
  font-family: var(--font-display);
  font-size: .92rem;
  font-weight: 600;
  margin: 4px 0 0;
  line-height: 1.3;
  color: var(--teal);
}

/* ---------- Footer ---------- */
.app-footer {
  border-top: 1px solid var(--line);
  padding: 22px 20px 34px;
  text-align: center;
  color: #6b6152;
  font-size: .82rem;
}
.footer-links { display: flex; justify-content: center; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.footer-links a { text-decoration: none; color: var(--teal); font-weight: 600; }

/* ---------- Loading ---------- */
.loading-row {
  display: flex;
  justify-content: center;
  padding: 30px 0;
}
.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Smart Install UI Components (Tooltip Style) ---------- */
.smart-install-banner {
  position: fixed;
  top: 70px; /* موقعه مباشرة تحت الهيدر */
  left: 14px;
  right: auto;
  bottom: auto;
  width: calc(100vw - 28px);
  max-width: 320px; /* عرض مناسب للبوب-أب الخفيف */
  z-index: 99;
  background: var(--teal);
  color: var(--cream);
  padding: 14px 16px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 10px 28px rgba(13,55,69,.35);
  
  /* إعدادات الحركة والظهور */
  transform: translateY(-15px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
}

/* السهم الصغير الذي يشير لأيقونة المنيو */
.smart-install-banner::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 20px; /* ليكون تحت أيقونة البرجر (المنيو) مباشرة */
  border-width: 0 10px 10px 10px;
  border-style: solid;
  border-color: transparent transparent var(--teal) transparent;
}

.smart-install-banner.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.smart-install-banner .banner-text {
  flex: 1;
  padding-right: 12px;
}

.smart-install-banner h4 {
  margin: 0 0 2px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--cream);
}

.smart-install-banner p {
  margin: 0;
  font-size: 0.8rem;
  opacity: 0.85;
  line-height: 1.3;
}

.smart-install-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.smart-install-actions .action-btn {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.2s;
}
.smart-install-actions .action-btn:hover { background: var(--red-deep); }

.smart-install-actions .close-btn {
  background: transparent;
  border: none;
  color: var(--cream);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.smart-install-actions .close-btn:hover { opacity: 1; }



/* ---------- Cookie Consent Banner ---------- */
.cookie-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(150%);
  width: 90%;
  max-width: 500px;
  background-color: #0D3745;
  color: #ffffff;
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-family: 'Inter', sans-serif;
}
.cookie-banner.show {
  transform: translateX(-50%) translateY(0);
}
.cookie-text {
  font-size: 0.9rem;
  line-height: 1.4;
  margin: 0;
}
.cookie-text a {
  color: #a8c8f0;
  text-decoration: underline;
}
.cookie-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.cookie-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.cookie-btn.accept {
  background-color: #4a90d9;
  color: white;
}
.cookie-btn.accept:hover { background-color: #357abd; }
.cookie-btn.decline {
  background-color: transparent;
  color: #a8c8f0;
  border: 1px solid #4a90d9;
}
.cookie-btn.decline:hover { background-color: rgba(255,255,255,0.1); }

/* ---------- Accessibility ---------- */
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (min-width: 640px) {
  .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* ---------- AdSense Responsive Styling ---------- */
.ad-container {
  margin: 24px auto;
  width: 100%;
  max-width: 100%;
  text-align: center;
  box-sizing: border-box;
}

.ad-label {
  display: block;
  font-size: 0.72rem;
  color: #6b6152;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ad-wrapper {
  background: var(--cream-deep);
  border-radius: 10px;
  min-height: 90px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.ad-container + .search-btn {
  margin-top: 10px;
}

/* إشعار التثبيت داخل المنيو */
.drawer-install-notice {
  background: rgba(255, 251, 239, 0.1);
  border: 1px solid rgba(255, 251, 239, 0.2);
  padding: 12px;
  border-radius: 10px;
  margin: 10px 0;
  text-align: center;
  font-size: 0.85rem;
}