/* Reset and base styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #4a4a4a;
  --color-primary-light: #666666;
  --color-primary-dark: #333333;
  --color-accent: #a0a0a0;
  --color-accent-light: #e8e8e8;
  --color-background: #faf9f8;
  --color-surface: #ffffff;
  --color-text: #333333;
  --color-text-light: #666666;
  --color-border: #e0e0e0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #9a9a9a;
    --color-primary-light: #b0b0b0;
    --color-primary-dark: #e0e0e0;
    --color-accent: #707070;
    --color-accent-light: #3a3a3a;
    --color-background: #1a1a1a;
    --color-surface: #252525;
    --color-text: #e8e8e8;
    --color-text-light: #a0a0a0;
    --color-border: #404040;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--color-background);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  color: white;
  padding: 2.5rem 1.5rem;
  text-align: center;
}

.header-content h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.5px;
}

.tagline {
  opacity: 0.9;
  font-size: 1.1rem;
}

/* Main content */
main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
}

/* Search section */
.search-section {
  margin-bottom: 1.5rem;
}

.search-container {
  position: relative;
  max-width: 500px;
  margin: 0 auto;
}

#search-input {
  width: 100%;
  padding: 1rem 1.25rem;
  padding-right: 3rem;
  font-size: 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(74, 74, 74, 0.15);
}

#search-input::placeholder {
  color: #999;
}

.clear-btn {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #999;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.clear-btn:hover {
  color: var(--color-text);
}

/* Filters section */
.filters-section {
  margin-bottom: 2rem;
}

.filter-group {
  text-align: center;
}

.filter-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--color-text-light);
  margin-bottom: 0.75rem;
}

.category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.category-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.2s;
}

.category-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.category-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

/* Results section */
.results-section {
  margin-bottom: 2rem;
}

.results-header {
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  color: var(--color-text-light);
}

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

/* Recipe card */
.recipe-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid var(--color-border);
}

.recipe-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.recipe-card h3 {
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
  color: var(--color-primary-dark);
}

.recipe-card .categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.recipe-card .category-tag {
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.recipe-card .ingredient-preview {
  font-size: 0.875rem;
  color: var(--color-text-light);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-light);
}

.empty-state h3 {
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  overflow-y: auto;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: sticky;
  top: 0;
  float: right;
  margin: 1rem;
  background: var(--color-background);
  border: none;
  font-size: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  cursor: pointer;
  color: var(--color-text-light);
  transition: background 0.2s;
  z-index: 10;
}

.modal-close:hover {
  background: var(--color-border);
  color: var(--color-text);
}

#recipe-detail {
  padding: 2rem;
  padding-top: 0;
}

#recipe-detail h2 {
  font-size: 1.75rem;
  color: var(--color-primary-dark);
  margin-bottom: 0.5rem;
  padding-right: 2rem;
}

#recipe-detail .source {
  margin-bottom: 1.5rem;
}

#recipe-detail .source a {
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.9rem;
}

#recipe-detail .source a:hover {
  text-decoration: underline;
}

#recipe-detail .recipe-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

#recipe-detail .category-tag {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#recipe-detail h3 {
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.375rem;
  border-bottom: 2px solid var(--color-accent-light);
}

#recipe-detail ul,
#recipe-detail ol {
  padding-left: 1.25rem;
}

#recipe-detail li {
  margin-bottom: 0.5rem;
}

#recipe-detail .ingredients li {
  list-style-type: disc;
}

#recipe-detail .instructions li {
  list-style-type: decimal;
  padding-left: 0.25rem;
}

#recipe-detail .notes {
  background: var(--color-background);
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin-top: 1rem;
}

#recipe-detail .notes ul {
  list-style-type: none;
  padding-left: 0;
}

#recipe-detail .notes li {
  position: relative;
  padding-left: 1.25rem;
}

#recipe-detail .notes li::before {
  content: "\2022";
  position: absolute;
  left: 0;
  color: var(--color-accent);
}

/* Footer */
footer {
  background: var(--color-primary-dark);
  color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 1.5rem;
  font-size: 0.875rem;
}

/* Dark mode header/footer overrides */
@media (prefers-color-scheme: dark) {
  header {
    background: linear-gradient(135deg, #1a1a1a 0%, #252525 100%);
  }

  footer {
    background: #1a1a1a;
  }
}

/* Responsive adjustments */
@media (max-width: 640px) {
  header {
    padding: 2rem 1rem;
  }

  .header-content h1 {
    font-size: 1.75rem;
  }

  main {
    padding: 1.5rem 1rem;
  }

  .recipe-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    max-height: 95vh;
    border-radius: var(--radius-md);
  }

  #recipe-detail {
    padding: 1.5rem;
    padding-top: 0;
  }

  #recipe-detail h2 {
    font-size: 1.5rem;
  }
}
