:root {
  --ink: #0f172a;
  --muted: #475569;
  --card: #fff;
  --border: #e2e8f0;
  --accent: #16a34a;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  font-family: "DM Sans", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, #eef6ff, #fdfdff 60%);
  color: var(--ink);
}

body.no-scroll {
  overflow: hidden;
  touch-action: none;
}

.page {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 32px 0 64px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hero h1 {
  margin: 4px 0 6px;
  font-size: clamp(30px, 4vw, 40px);
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
}

.eyebrow {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
  font-size: 12px;
}

.lede { margin: 0; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

.section-title { margin: 0 0 12px; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.hint {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 14px;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 16px; /* Prevent iOS zoom on focus */
  font-family: inherit;
  background: white;
}

textarea { resize: vertical; }

.primary, .primary-danger, .ghost {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Override hero buttons for bigger tap targets */
.hero-actions button,
.hero-actions a {
  padding: 18px 20px;
  min-height: 56px;
  width: 240px;
}

.meal-card {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.meal-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.meal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.whisper-card .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.whisper-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.whisper-meter {
  height: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.whisper-meter #whisper-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  transition: width 120ms ease;
}

.whisper-output {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meal-card {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.meal-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.meal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .hero-actions {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    width: 100%;
  }
  .hero-actions button,
  .hero-actions a {
    width: 100%;
    max-width: none;
  }
}

.primary {
  background: linear-gradient(135deg, var(--accent), #22c55e);
  color: white;
  box-shadow: 0 12px 30px rgba(22, 163, 74, 0.25);
}

.primary-danger {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: white;
  box-shadow: 0 12px 30px rgba(185, 28, 28, 0.25);
  border: none;
}

.ghost {
  background: white;
  color: var(--ink);
  border: 1px solid var(--border);
}

.small { padding: 8px 12px; font-size: 14px; }
.full { width: 100%; }
.danger {
  background: #b91c1c;
  color: white;
  border: none;
}

.manual-ingredients {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.manual-ingredients textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 16px; /* stop iOS zoom on focus */
  font-family: inherit;
  background: white;
}

.manual-entry {
  display: grid;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(22, 163, 74, 0.12);
  color: #15803d;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pill.option {
  background: white;
  border: 1px solid var(--border);
  color: var(--ink);
  cursor: pointer;
}

.pill.option.active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.12);
  color: #166534;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(22, 163, 74, 0.12);
  color: #15803d;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pill.option {
  background: white;
  border: 1px solid var(--border);
  color: var(--ink);
  cursor: pointer;
}

.pill.option.active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.12);
  color: #166534;
}

.result {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 12px;
  min-height: 140px;
  overflow: auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
}

.modal.hidden { display: none; }

.hidden { display: none !important; }

.modal-content {
  background: #fff;
  width: min(520px, 100%);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
}
.crop-wrap {
  position: relative;
}
.modal-content.wide {
  width: min(720px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.modal-content.scrollable {
  overflow-y: auto;
}

@media (max-width: 768px) {
  .modal {
    align-items: flex-start;
    overflow-y: auto;
    touch-action: auto;
  }
  .modal-content {
    margin-top: 24px;
    max-height: none;
    overflow-y: auto;
  }
}

.crop-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0f172a;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 24px;
  height: 24px;
  background: #22c55e;
  border-radius: 50%;
  border: 3px solid #0f172a;
  box-shadow: 0 0 0 2px #fff;
  pointer-events: none;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status {
  margin: 0;
  color: var(--muted);
  min-height: 20px;
}

.success-inline {
  color: #16a34a;
  font-weight: 700;
  align-self: center;
}

.step { display: grid; gap: 10px; }
.step.hidden { display: none; }
.step-title { margin: 0; font-weight: 700; }

.upload-box {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  background: #f8fafc;
  position: relative;
}

.placeholder { color: var(--muted); }
.preview { width: 100%; border-radius: 12px; display: block; }
.preview.hidden { display: none; }

.barcode-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.6);
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.barcode-overlay.active { opacity: 1; }

.overlay-spinner {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
}

.overlay-label {
  color: #fff;
  font-weight: 700;
}

.review-area {
  width: 100%;
  min-height: 180px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: monospace;
  font-size: 14px;
}

.inline-field {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: start;
}

.quagga-view {
  width: 100%;
  height: 320px;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.button-row > button {
  flex: 1;
}

.ingredients-choice {
  text-align: center;
}

.choice-col {
  display: grid;
  gap: 10px;
  align-items: center;
  justify-items: stretch;
}

.choice-btn {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 16px;
  border: 1px solid var(--border);
}

.detected-box {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.thumb-tile {
  border: 1px dashed var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  background: #f8fafc;
  min-height: 110px;
}

.thumb-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-meta {
  position: absolute;
  bottom: 6px;
  left: 8px;
  right: 38px;
  font-size: 12px;
  color: var(--ink);
  text-shadow: 0 1px 6px rgba(255, 255, 255, 0.9);
}

.thumb-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  border: none;
  background: rgba(15, 23, 42, 0.82);
  color: white;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-weight: 900;
  cursor: pointer;
}

.empty-state {
  color: var(--muted);
  font-weight: 600;
}

.meal-detected,
.meal-results {
  display: grid;
  gap: 12px;
}

.meal-card-result {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(135deg, #f8fafc, #f2f6ff);
}

.meal-card-result h4 {
  margin: 0 0 6px;
}

.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.thumb-tile {
  border: 1px dashed var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  background: #f8fafc;
  min-height: 110px;
}

.thumb-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-meta {
  position: absolute;
  bottom: 6px;
  left: 8px;
  right: 38px;
  font-size: 12px;
  color: var(--ink);
  text-shadow: 0 1px 6px rgba(255, 255, 255, 0.9);
}

.thumb-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  border: none;
  background: rgba(15, 23, 42, 0.82);
  color: white;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-weight: 900;
  cursor: pointer;
}

.empty-state {
  color: var(--muted);
  font-weight: 600;
}

.meal-detected,
.meal-results {
  display: grid;
  gap: 12px;
}

.meal-card-result {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(135deg, #f8fafc, #f2f6ff);
}

.meal-card-result h4 {
  margin: 0 0 6px;
}

.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e2e8f0;
  border-top: 3px solid #22c55e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

.spinner.small {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.btn-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

.quagga-frame-box {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.quagga-corner-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.quagga-corner-box.horizontal {
  width: 78%;
  height: 44%;
}

.quagga-corner-box.vertical {
  width: 44%;
  height: 78%;
}

.quagga-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(239, 68, 68, 0.85);
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.25);
}

.quagga-corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.quagga-corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.quagga-corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.quagga-corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }
.spinner.large {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

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

@media (max-width: 640px) {
  .hero { flex-direction: column; align-items: flex-start; }
}
