* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --green: #22c55e;
  --green-light: #dcfce7;
  --green-dark: #16a34a;
  --yellow: #eab308;
  --yellow-light: #fef9c3;
  --red: #ef4444;
  --red-light: #fee2e2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  background: #fff;
}

/* Page transitions */
.page { 
  animation: fadeIn 0.3s ease; 
  padding: 0 20px 100px;
  padding-top: calc(var(--safe-top) + 16px);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  margin-bottom: 8px;
}
.header h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.header .logo-accent { color: var(--green); }
.header-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.header-icon:active { background: var(--gray-200); }

/* Scan Button */
.scan-hero {
  background: linear-gradient(135deg, var(--green) 0%, #16a34a 100%);
  border-radius: 24px;
  padding: 36px 28px;
  text-align: center;
  color: #fff;
  margin: 16px 0;
  box-shadow: 0 8px 32px rgba(34,197,94,0.3);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.scan-hero::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
  animation: shimmer 3s ease-in-out infinite;
}
@keyframes shimmer { 0%, 100% { transform: translate(-10%, -10%); } 50% { transform: translate(10%, 10%); } }
.scan-hero:active { transform: scale(0.97); }
.scan-hero .scan-icon { font-size: 48px; margin-bottom: 12px; }
.scan-hero h2 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.scan-hero p { font-size: 14px; opacity: 0.9; }

/* Cards */
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  border: 1px solid var(--gray-100);
  transition: transform 0.2s;
}
.card:active { transform: scale(0.98); }

/* Section */
.section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 24px 0 12px;
  color: var(--gray-800);
}

/* History items */
.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  cursor: pointer;
  border: 1px solid var(--gray-100);
  transition: transform 0.15s;
}
.history-item:active { transform: scale(0.98); }
.delete-scan { background: none; border: none; font-size: 18px; cursor: pointer; padding: 6px; margin-left: auto; opacity: 0.4; transition: opacity 0.2s; }
.delete-scan:hover { opacity: 1; }
.history-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-sm);
  background: var(--green-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.history-info { flex: 1; min-width: 0; }
.history-info h4 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-info p { font-size: 13px; color: var(--gray-400); margin-top: 2px; }
.history-score {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* Result card */
.result-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  border: 1px solid var(--gray-100);
  position: relative;
  overflow: hidden;
}
.result-card.top-pick {
  border: 2px solid var(--green);
  box-shadow: 0 4px 24px rgba(34,197,94,0.15);
}
.top-badge {
  position: absolute;
  top: 0; right: 0;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px 4px 16px;
  border-radius: 0 0 0 16px;
  letter-spacing: 0.5px;
}
.result-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.score-circle {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: #fff;
  flex-shrink: 0;
  position: relative;
}
.score-circle svg {
  position: absolute;
  top: -3px; left: -3px;
  width: 58px; height: 58px;
  transform: rotate(-90deg);
}
.score-circle svg circle {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}
.score-circle svg .bg { stroke: rgba(255,255,255,0.3); }
.score-circle svg .fg { stroke: #fff; transition: stroke-dashoffset 1s ease; }
.result-name { font-size: 16px; font-weight: 700; }
.result-cals { font-size: 13px; color: var(--gray-400); margin-top: 2px; }
.macros {
  display: flex; gap: 8px; margin: 12px 0;
}
.macro {
  flex: 1;
  background: var(--gray-50);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}
.macro-val { font-size: 16px; font-weight: 700; }
.macro-label { font-size: 11px; color: var(--gray-400); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }
.result-reason {
  font-size: 14px;
  color: var(--gray-600);
  line-height: 1.5;
  padding-top: 12px;
  border-top: 1px solid var(--gray-100);
}
.result-reason summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--gray-700);
  font-size: 13px;
  padding: 4px 0;
}
.result-reason p { margin-top: 8px; }
.warnings {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.warning-tag {
  background: var(--red-light);
  color: var(--red);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 24px;
  border-radius: 14px;
  font-size: 15px; font-weight: 600;
  border: none; cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--green); color: #fff; box-shadow: 0 4px 16px rgba(34,197,94,0.3); }
.btn-primary:active { background: var(--green-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-outline { background: transparent; border: 2px solid var(--gray-200); color: var(--gray-700); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 14px; font-weight: 500;
  border: 2px solid var(--gray-200);
  background: #fff;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.chip.active { border-color: var(--green); background: var(--green-light); color: var(--green-dark); font-weight: 600; }
.chip:active { transform: scale(0.95); }

/* Loading */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.95);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.loading-spinner {
  width: 56px; height: 56px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 20px; font-size: 16px; font-weight: 600; color: var(--gray-700); }
.loading-sub { margin-top: 6px; font-size: 13px; color: var(--gray-400); }

/* Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--gray-100);
  display: flex;
  padding: 8px 0;
  padding-bottom: calc(8px + var(--safe-bottom));
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 2px;
  padding: 6px;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 10px; font-weight: 600;
  transition: color 0.2s;
  text-decoration: none;
}
.nav-item.active { color: var(--green); }
.nav-item .nav-icon { font-size: 24px; }

/* Onboarding */
.onboarding {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: 60px 28px 40px;
  animation: fadeIn 0.4s ease;
}
.onboarding-step { flex: 1; display: flex; flex-direction: column; }
.onboarding h2 {
  font-size: 28px; font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}
.onboarding p {
  font-size: 15px; color: var(--gray-500);
  margin-bottom: 28px;
  line-height: 1.5;
}
.onboarding .emoji-big { font-size: 64px; margin-bottom: 20px; }
.onboarding .chips { margin-bottom: 24px; }
.onboarding .btn { margin-top: auto; }

/* Upload area */
.upload-area {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin: 16px 0;
}
.upload-area:active, .upload-area.dragover {
  border-color: var(--green);
  background: var(--green-light);
}
.upload-area .upload-icon { font-size: 40px; margin-bottom: 12px; }
.upload-area p { font-size: 14px; color: var(--gray-500); }

/* Camera preview */
.camera-preview {
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin: 16px 0;
  position: relative;
}
.camera-preview video { width: 100%; height: 100%; object-fit: cover; }
.camera-preview img { width: 100%; height: 100%; object-fit: contain; background: var(--gray-100); }

/* Settings */
.settings-group {
  margin-bottom: 24px;
}
.settings-group label {
  font-size: 14px; font-weight: 600; color: var(--gray-600);
  display: block; margin-bottom: 8px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
}
.empty-state .empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.empty-state p { font-size: 14px; color: var(--gray-400); line-height: 1.5; }

/* Share button */
.share-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px;
  background: var(--gray-100);
  border-radius: 12px;
  font-size: 14px; font-weight: 600;
  color: var(--gray-600);
  border: none; cursor: pointer;
  margin-top: 8px;
}

/* Back button */
.back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: none;
  font-size: 15px; font-weight: 600;
  color: var(--gray-600); cursor: pointer;
  padding: 8px 0; margin-bottom: 8px;
  font-family: inherit;
}

/* Color helpers */
.bg-green { background: var(--green); }
.bg-yellow { background: var(--yellow); }
.bg-red { background: var(--red); }
.text-green { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-red { color: var(--red); }

/* Install banner */
.install-banner {
  background: linear-gradient(135deg, var(--gray-800), var(--gray-900));
  color: #fff;
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex; align-items: center; gap: 14px;
  margin: 16px 0;
  cursor: pointer;
}
.install-banner .install-icon { font-size: 28px; }
.install-banner h4 { font-size: 14px; font-weight: 700; }
.install-banner p { font-size: 12px; opacity: 0.7; margin-top: 2px; }
.install-banner .install-close {
  margin-left: auto; background: rgba(255,255,255,0.2);
  border: none; color: #fff; width: 28px; height: 28px;
  border-radius: 50%; cursor: pointer; font-size: 14px;
}

/* Goal badge on home */
.goal-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: var(--green-light);
  color: var(--green-dark);
  border-radius: 20px;
  font-size: 13px; font-weight: 600;
  margin-bottom: 8px;
}
