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

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3ecf8e;
  --accent-dim: #2a9d6a;
  --warning: #f5a623;
  --danger: #e74c5c;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.gallery-section {
  max-width: 960px;
  margin: 3rem auto 0;
  padding: 0 1.25rem 2rem;
}

.header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.logo {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 1.05rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.section {
  margin-bottom: 1.75rem;
}

.section:last-of-type {
  margin-bottom: 0;
}

.section h2 {
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.8rem;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(62, 207, 142, 0.05);
}

.upload-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.upload-placeholder p {
  color: var(--text-muted);
}

.upload-placeholder strong {
  color: var(--accent);
}

.hint {
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.preview {
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  object-fit: contain;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
}

input,
select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  margin-top: 1.75rem;
  padding: 0.9rem 1.5rem;
  background: var(--accent);
  color: #0a1a12;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dim);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-banner {
  background: rgba(231, 76, 92, 0.15);
  border: 1px solid var(--danger);
  color: #f5a0a8;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.results h2 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.portion {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

.ingredients-block h3,
.results .card > h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

#ingredients {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#ingredients li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.9rem;
}

.nutrition-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.5rem;
}

.nutrition-list li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.modal-details h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.nutrient-bars {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.nutrient-row {
  display: grid;
  grid-template-columns: 120px 1fr 60px;
  align-items: center;
  gap: 0.75rem;
}

.nutrient-label {
  font-size: 0.9rem;
  font-weight: 500;
}

.bar-track {
  height: 10px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.bar-track-overflow {
  box-shadow: inset 0 0 0 1px var(--danger);
}

.bar-track-overflow::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 3px,
    rgba(231, 76, 92, 0.25) 3px,
    rgba(231, 76, 92, 0.25) 6px
  );
  pointer-events: none;
}

.bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.6s ease;
  position: relative;
  z-index: 1;
}

.bar-fill.low { background: var(--accent); }
.bar-fill.medium { background: var(--warning); }
.bar-fill.high { background: var(--danger); }

.nutrient-pct {
  text-align: right;
  font-weight: 600;
  font-size: 0.95rem;
}

.nutrient-pct-overflow {
  color: var(--danger);
}

.nutrient-detail {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: -0.5rem;
  padding-left: 0;
}

.footer {
  text-align: center;
  margin-top: 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.gallery-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.gallery-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.gallery-loading {
  text-align: center;
  padding: 2rem;
}

.gallery-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.gallery-item {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  transition: transform 0.2s, border-color 0.2s;
  position: relative;
  cursor: pointer;
}

.gallery-item::after {
  content: attr(data-label);
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.4rem 0.5rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.2s;
}

.gallery-item:hover::after {
  opacity: 1;
}

.gallery-item:hover {
  transform: scale(1.03);
  border-color: var(--accent);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  position: relative;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  margin: 0;
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

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

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-image {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 8px;
}

.modal-details h2 {
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
}

.modal-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

body.modal-open {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  .nutrient-row {
    grid-template-columns: 1fr auto;
  }

  .bar-track {
    grid-column: 1 / -1;
  }
}
