* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ==== Body & Gradient ==== */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #fce7f3 0%, #f3e8ff 25%, #fdf2f8 50%, #fce7f3 75%, #f3e8ff 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  min-height: 100vh;
  padding: 20px;
}

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ==== Container ==== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(236, 72, 153, 0.15);
  overflow: hidden;
  border: 1px solid rgba(236, 72, 153, 0.1);
}

/* ==== Header ==== */
.header {
  background: linear-gradient(135deg, #ec4899, #be185d);
  color: white;
  padding: 30px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.9), rgba(190, 24, 93, 0.9));
  z-index: 1;
}

.header-content { position: relative; z-index: 2; flex: 1; }

.magda-image {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  height: 200px;
  opacity: 0.9;
  z-index: 1;
  filter: drop-shadow(0 0 25px rgba(255,255,255,0.4));
  border-radius: 20px;
}

.header h1 {
  font-size: 2.8rem;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
  font-weight: 900;
}

.header-subtitle {
  font-size: 1.3rem;
  opacity: 0.95;
  margin-bottom: 20px;
  font-style: italic;
  font-weight: bold;
  color: #fce7f3;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

/* ==== Stats ==== */
.stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.stat {
  text-align: center;
  background: rgba(255,255,255,0.1);
  padding: 15px 20px;
  border-radius: 15px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
}

.stat-number {
  font-size: 2rem;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* ==== Controls ==== */
.controls {
  padding: 20px 30px;
  background: rgba(252, 231, 243, 0.3);
  border-bottom: 1px solid rgba(236, 72, 153, 0.1);
  position: sticky;
  top: 0;
  z-index: 99;
  backdrop-filter: blur(10px);
}

.search-box {
  width: 100%;
  padding: 15px;
  border: 2px solid rgba(236, 72, 153, 0.2);
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 15px;
  background: rgba(255, 255, 255, 0.9);
  transition: border-color 0.3s;
}
.search-box:focus {
  outline: none;
  border-color: #ec4899;
  box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.1);
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  overflow-x: auto;
  padding-bottom: 5px;
}

.filter-btn {
  padding: 8px 16px;
  border: 2px solid rgba(236, 72, 153, 0.2);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
  flex-shrink: 0;
}
.filter-btn:hover {
  border-color: #ec4899;
  transform: translateY(-1px);
  background: rgba(236, 72, 153, 0.1);
}
.filter-btn.active {
  background: #ec4899;
  color: #fff;
  border-color: #ec4899;
  box-shadow: 0 4px 12px rgba(236, 72, 153, 0.3);
}

/* ==== Recipes Grid ==== */
.recipes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  padding: 30px;
  min-height: 200px;
}

/* ==== Card ==== */
.recipe-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 15px;
  box-shadow: 0 4px 15px rgba(236, 72, 153, 0.1);
  overflow: hidden;
  transition: transform 0.3s, box-shadow 0.3s;
  cursor: pointer;
  opacity: 0;
  animation: fadeInUp 0.6s ease forwards;
  border: 1px solid rgba(236, 72, 153, 0.1);
}
.recipe-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(236, 72, 153, 0.2);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==== Recipe Image ==== */
.recipe-image {
  width: 100%;
  height: 200px;
  background: linear-gradient(45deg, #fce7f3, #f3e8ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: #ec4899;
  position: relative;
  overflow: hidden;
}
.recipe-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s ease;
}
.recipe-image .placeholder {
  position: absolute;
  inset: 0;
  background: linear-gradient(45deg, #fce7f3, #f3e8ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: #ec4899;
}
.recipe-image .loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid #fce7f3;
  border-top: 3px solid #ec4899;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ==== Content ==== */
.recipe-content { padding: 20px; }
.recipe-title {
  font-size: 1.3rem;
  font-weight: bold;
  margin-bottom: 10px;
  color: #1f2937;
}
.recipe-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  font-size: 0.9rem;
  color: #6b7280;
}
.recipe-categories {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}
.category-tag {
  background: rgba(236, 72, 153, 0.1);
  color: #be185d;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  border: 1px solid rgba(236, 72, 153, 0.2);
}
.recipe-macros {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 15px;
}
.macro {
  text-align: center;
  padding: 6px;
  background: rgba(252, 231, 243, 0.3);
  border-radius: 8px;
  border: 1px solid rgba(236, 72, 153, 0.1);
}
.macro-value {
  font-weight: bold;
  color: #ec4899;
  font-size: 0.95rem;
  margin-bottom: 2px;
}
.macro-label {
  font-size: 0.75rem;
  color: #6b7280;
  line-height: 1;
}

/* ==== Loaders & Messages ==== */
.loading-spinner,
.end-message {
  text-align: center;
  padding: 40px;
  color: #6b7280;
  display: none;
}
.loading-spinner.show { display: block; }
.end-message.show     { display: block; }

/* ==== Modal ==== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 1000;
  overflow-y: auto;
}
.modal-content {
  background: #fff;
  margin: 50px auto;
  border-radius: 20px;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  background: linear-gradient(135deg, #ec4899, #be185d);
  color: #fff;
  padding: 60px 30px 30px;
  position: relative;
}
.modal-header h2 {
  margin: 0;
  margin-top: 10px;
}
.close {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 2rem;
  cursor: pointer;
  transition: transform 0.3s;
}
.close:hover { transform: scale(1.1); }

.modal-actions {
  position: absolute;
  top: 20px;
  right: 80px;
  display: flex;
  gap: 10px;
  z-index: 2;
}
.action-btn {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s;
  backdrop-filter: blur(10px);
}
.action-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: translateY(-1px);
}

.modal-body { padding: 30px; }
.ingredients-list {
  list-style: none;
  margin: 20px 0;
}
.ingredients-list li {
  padding: 15px;
  border-bottom: 1px solid rgba(236, 72, 153, 0.1);
  background: rgba(252, 231, 243, 0.2);
  margin-bottom: 8px;
  border-radius: 8px;
}
.ingredient-name {
  font-weight: bold;
  color: #1f2937;
  margin-bottom: 5px;
  font-size: 1.1rem;
}
.ingredient-amount {
  color: #6b7280;
  font-size: 0.9rem;
  margin-bottom: 5px;
}
.ingredient-macros {
  font-size: 0.85rem;
  color: #4b5563;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.ingredient-macros span { font-weight: 500; }

/* ==== Steps ==== */
.recipe-steps {
  list-style: none;
  counter-reset: step-counter;
}
.recipe-steps li {
  counter-increment: step-counter;
  margin: 15px 0;
  padding: 15px;
  background: rgba(252, 231, 243, 0.2);
  border-radius: 10px;
  position: relative;
  padding-left: 60px;
}
.recipe-steps li::before {
  content: counter(step-counter);
  position: absolute;
  left: 20px;
  top: 15px;
  background: #ec4899;
  color: #fff;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9rem;
}

/* ==== Calculator Modal ==== */
.calculator-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 1001;
  overflow-y: auto;
}
.calculator-content {
  background: #fff;
  margin: 50px auto;
  border-radius: 20px;
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
}
.calculator-header {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  padding: 30px;
  position: relative;
}
.calculator-close {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 2rem;
  cursor: pointer;
  transition: transform 0.3s;
}
.calculator-close:hover { transform: scale(1.1); }

.calculator-body { padding: 30px; }
.calculator-ingredients { margin-bottom: 30px; }
.calc-ingredient {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 15px;
  padding: 15px;
  background: rgba(252,231,243,0.2);
  border-radius: 10px;
  margin-bottom: 16px;
  border: 2px solid transparent;
  transition: border-color 0.3s;
}
.calc-ingredient:hover { border-color: #10b981; }
.calc-ingredient-name {
  flex: 1;
  font-weight: bold;
  color: #1f2937;
}
.calc-amount-input {
  width: 80px;
  padding: 8px;
  border: 2px solid rgba(236, 72, 153, 0.2);
  border-radius: 5px;
  text-align: center;
  font-weight: bold;
}
.calc-amount-input:focus {
  outline: none;
  border-color: #10b981;
}
.calc-macros {
  display: flex;
  gap: 15px;
  font-size: 0.85rem;
  color: #6b7280;
}
.calc-macro { white-space: nowrap; }
.calc-macro-value {
  color: #10b981;
  font-weight: bold;
}
.calculator-summary {
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  padding: 20px;
  border-radius: 15px;
  border: 2px solid #10b981;
}
.calc-summary-title {
  font-size: 1.2rem;
  font-weight: bold;
  color: #065f46;
  margin-bottom: 15px;
  text-align: center;
}
.calc-summary-macros {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}
.calc-summary-macro {
  text-align: center;
  background: #fff;
  padding: 15px;
  border-radius: 10px;
  border: 1px solid #10b981;
}
.calc-summary-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: #10b981;
}
.calc-summary-label {
  font-size: 0.9rem;
  color: #065f46;
  margin-top: 5px;
}

/* ==== Responsive ==== */
@media (max-width: 768px) {
  .recipes-grid { grid-template-columns: 1fr; padding: 20px; }
  .stats       { gap: 15px; }
  .filters     { justify-content: flex-start; }
  .header      { padding: 20px; min-height: 180px; }
  .header h1   { font-size: 2.2rem; }
  .magda-image { height: 160px; right: 10px; }
  .stat        { padding: 10px 15px; }
  .ingredient-macros { gap: 8px; }
  .calc-summary-macros { grid-template-columns: repeat(2, 1fr); }
  .modal-actions { position: static; margin-top: 15px; justify-content: center; }
}

@media (max-width: 480px) {
  .magda-image     { display: none; }
  .header          { min-height: 140px; }
  .header h1       { font-size: 1.8rem; }
  .calc-summary-macros { grid-template-columns: 1fr; }
}

/* ==== Substitutions UI ==== */
.substitute-select {
  width: 100%;
  padding: 8px 12px;
  padding-right: 36px;
  margin-top: 8px;
  font-size: 0.9rem;
  border: 2px solid rgba(16,184,129,0.3);
  border-radius: 8px;
  background-color: #fff;
  background-image: url("data:image/svg+xml,...");
  background-repeat: no-repeat;
  background-position: right 12px center;
  appearance: none;
  cursor: pointer;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}
.remove-btn {
  background-color: #ff3b30;
  color: #fff;
  border: none;
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  margin-left: 8px;
  transition: background-color 0.2s;
}
.remove-btn:hover { background-color: #e03128; }

.substitute-input {
  width: 100%;
  min-width: 200px;
  padding: 8px 12px;
  padding-right: 36px;
  margin-top: 8px;
  font-size: 0.9rem;
  border: 2px solid rgba(16,184,129,0.3);
  border-radius: 8px;
  background-color: #fff;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
  background-image: url("data:image/svg+xml,...");
  background-repeat: no-repeat;
  background-position: right 12px center;
  appearance: none;
  cursor: pointer;
}
.substitute-input:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16,184,129,0.15);
}

.subs-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-height: 200px;
  overflow-y: auto;
  z-index: 500;
}
.subs-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.9rem;
}
.subs-item:hover { background: rgba(16,184,129,0.1); }