@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
  --primary: #0d9488;
  --primary-light: #2dd4bf;
  --primary-dark: #0f766e;
  --accent: #f59e0b;
  --accent-light: #fcd34d;
  
  /* Light Theme Mesh/Gradient */
  --bg-app: #f8fafc;
  --bg: #f8fafc;
  --bg-gradient: radial-gradient(circle at 0% 0%, #f0fdfa 0%, #f8fafc 50%, #e2e8f0 100%);
  --surface: rgba(255, 255, 255, 0.75);
  --surface-solid: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  
  --glass-border: 1px solid rgba(255, 255, 255, 0.8);
  --glass-shadow: 0 8px 32px 0 rgba(15, 23, 42, 0.05);
  --border: rgba(100, 116, 139, 0.2);
  
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
}

[data-theme="dark"] {
  /* Dark Theme Mesh/Gradient */
  --bg-app: #0f172a;
  --bg: #0f172a;
  --bg-gradient: radial-gradient(circle at 100% 0%, #134e4a 0%, #0f172a 40%, #020617 100%);
  --surface: rgba(30, 41, 59, 0.6);
  --surface-solid: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.4);
  --border: rgba(255, 255, 255, 0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Outfit', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg-app);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.4s ease, color 0.4s ease;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* App Screens & Transitions */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95) translateY(20px);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  z-index: 10;
  padding-bottom: 80px; /* Space for banner ads */
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: scale(1) translateY(0);
  z-index: 20;
}

/* Glassmorphism Utilities */
.glass-card {
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 28px;
  overflow: hidden;
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 20px;
  padding: 18px 24px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 25px -5px rgba(13, 148, 136, 0.4);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}
.btn-primary:active { transform: scale(0.94); box-shadow: 0 4px 10px -5px rgba(13, 148, 136, 0.5); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.icon-btn {
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: var(--glass-border);
  color: var(--text-main);
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  box-shadow: var(--glass-shadow);
  transition: all 0.2s;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.9); }

/* Splash */
#splash {
  background: linear-gradient(135deg, #020617, var(--primary-dark));
  color: white;
  justify-content: center;
  align-items: center;
}
.logo-icon {
  font-size: 4.5rem;
  background: linear-gradient(135deg, #ffffff, #f1f5f9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 10px 15px rgba(0,0,0,0.3));
  animation: float 3s ease-in-out infinite;
}
.logo-text { font-size: 2.8rem; font-weight: 800; letter-spacing: -1.5px; margin-top: 12px; }

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-15px); }
  100% { transform: translateY(0px); }
}

/* Premium Crown Glow */
@keyframes goldGlow {
  0% { filter: drop-shadow(0 0 2px rgba(251, 191, 36, 0.4)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.8)); transform: scale(1.1); }
  100% { filter: drop-shadow(0 0 2px rgba(251, 191, 36, 0.4)); transform: scale(1); }
}
.premium-crown {
  color: #fbbf24;
  margin-left: 6px;
  display: inline-block;
  animation: goldGlow 3s infinite ease-in-out;
}

/* AI Radar Loader */
.radar-loader {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid rgba(45, 212, 191, 0.2);
  position: relative;
  overflow: hidden;
  margin-bottom: 24px;
}
.radar-loader::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50%;
  height: 50%;
  background: linear-gradient(45deg, rgba(45, 212, 191, 0.8) 0%, transparent 70%);
  transform-origin: 0 0;
  animation: radarScan 1.5s linear infinite;
}
@keyframes radarScan {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Onboarding */
#onboarding { justify-content: space-between; padding: 40px 24px; }
.ob-image { flex: 1; display: flex; align-items: center; justify-content: center; }
.ob-image i { font-size: 8rem; color: var(--primary); text-shadow: 0 20px 30px rgba(13, 148, 136, 0.3); }
.ob-content { padding: 32px 24px; text-align: center; }
.ob-content h2 { font-size: 2.2rem; font-weight: 800; margin-bottom: 12px; }
.ob-content p { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 32px; line-height: 1.6; }

/* Main Screen */
#main { padding: 24px; padding-top: 40px; }
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; }
.user-greeting h1 { font-size: 1.8rem; font-weight: 800; }
.user-greeting p { font-size: 1rem; color: var(--text-muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.plan-badge-small { background: rgba(245, 158, 11, 0.15); color: var(--warning); padding: 4px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }

.scan-card {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.8) 0%, rgba(4, 47, 46, 0.9) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 32px;
  padding: 32px 24px 48px 24px;
  color: white;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 40px -10px rgba(15, 118, 110, 0.4);
  margin-bottom: 32px;
  flex-shrink: 0;
  min-height: 440px;
}
.scan-card::after {
  content: ''; position: absolute; top: -50%; right: -50%; width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  border-radius: 50%;
}
.scan-count { font-size: 4rem; font-weight: 800; line-height: 1; margin: 8px 0; color: #fff; }
.scan-label { font-size: 1.1rem; opacity: 0.9; font-weight: 500; }

.section-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 16px; color: var(--text-main); }

/* History Cards Premium */
.history-card {
  padding: 16px 20px;
  margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.03);
  transition: transform 0.2s, box-shadow 0.2s;
}
.history-card:active { transform: scale(0.96); box-shadow: 0 2px 8px rgba(0,0,0,0.02); }
.history-icon { width: 48px; height: 48px; border-radius: 16px; background: rgba(13, 148, 136, 0.1); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
.history-text h4 { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.history-text p { font-size: 0.85rem; color: var(--text-muted); }
.history-score { font-size: 1.4rem; font-weight: 800; }

/* Ad Banners Removed */

/* Interstitial Ad Overlay */
#ad-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: white;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
#ad-overlay.active { opacity: 1; pointer-events: all; }
.ad-content-box { width: 300px; height: 250px; background: #1e293b; border-radius: 16px; display: flex; align-items: center; justify-content: center; margin-bottom: 24px; position: relative;}
.ad-content-box::before { content: 'SPONSORED'; position: absolute; top: 10px; left: 10px; font-size: 0.7rem; opacity: 0.5; }
.ad-timer { background: rgba(255,255,255,0.2); padding: 8px 16px; border-radius: 20px; font-weight: 700; margin-bottom: 24px; }
.ad-skip-btn { background: transparent; color: white; border: 1px solid rgba(255,255,255,0.5); padding: 10px 24px; border-radius: 20px; display: none; }

/* Premium Screen */
.premium-bg {
  position: absolute; top: 0; left: 0; width: 100%; height: 350px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  z-index: -1;
  border-radius: 0 0 40px 40px;
}
.premium-header { padding: 60px 24px 40px; text-align: center; color: white; }
.premium-header i { font-size: 3rem; margin-bottom: 16px; display: block; animation: float 3s infinite;}
.premium-header h2 { font-size: 2.2rem; font-weight: 800; margin-bottom: 8px; }
.plans-container { padding: 0 24px 40px; margin-top: -20px;}
.plan-card {
  background: var(--surface-solid);
  border: 2px solid transparent;
  border-radius: 24px;
  padding: 24px;
  margin-bottom: 16px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: var(--glass-shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.plan-card.active { border-color: var(--accent); transform: scale(1.02); box-shadow: 0 20px 40px rgba(245, 158, 11, 0.2); }
.plan-price { font-size: 1.8rem; font-weight: 800; color: var(--text-main); }

/* Scan Screen */
#scan .upload-area {
  min-height: 350px;
  border: 2px dashed rgba(13, 148, 136, 0.4);
  background: rgba(13, 148, 136, 0.03);
  transition: all 0.3s;
}
#scan .upload-area:active { background: rgba(13, 148, 136, 0.08); }
.upload-actions-container i { font-size: 4rem; color: var(--primary); margin-bottom: 16px; display: block; }
.upload-actions-container p { color: var(--text-main); font-weight: 600; font-size: 1.2rem; }
.focus-frame { border: 2px solid var(--primary-light); background: rgba(45, 212, 191, 0.1); box-shadow: 0 0 0 9999px rgba(0,0,0,0.6); }

/* Settings */
.setting-item { padding: 24px; margin-bottom: 16px; }
select.setting-select, input.setting-input { background: var(--bg-app); border: 1px solid var(--border-color); padding: 14px 16px; border-radius: 12px; color: var(--text-main); font-weight: 600; }

/* Loading UI (Premium) */
#loading {
  background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(10px);
}
.loader-premium {
  width: 80px; height: 80px; position: relative; margin-bottom: 32px;
}
.loader-premium::before, .loader-premium::after {
  content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  border-radius: 50%; border: 4px solid transparent;
}
.loader-premium::before { border-top-color: var(--primary-light); border-bottom-color: var(--primary-light); animation: spin 2s linear infinite; }
.loader-premium::after { border-left-color: var(--accent); border-right-color: var(--accent); animation: spin 1.5s linear infinite reverse; }

/* Result Screen */
.score-circle {
  width: 160px; height: 160px;
  background: var(--surface-solid);
  border-radius: 50%;
  box-shadow: 0 20px 40px rgba(0,0,0,0.1);
  bottom: -80px;
}
.score-value { font-size: 4rem; }
.risk-category { padding: 20px; border-radius: 20px; background: var(--surface-solid); border: none; box-shadow: var(--glass-shadow); margin-bottom: 16px;}
.ingredient-pill { background: var(--bg-app); border: none; padding: 8px 16px; font-weight: 600; }

/* Premium Splash Loader */
.classic-loader {
  width: 56px;
  height: 56px;
  border: 4px solid transparent;
  border-radius: 50%;
  animation: spin-pulse 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
  box-shadow: 0 0 20px rgba(255,255,255,0.15);
  position: relative;
}

.classic-loader::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 4px solid transparent;
  border-top-color: #fff;
  border-bottom-color: #fff;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes spin-pulse {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}


/* TOAST NOTIFICATIONS */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.recent-scans {
  background: var(--surface);
  border-radius: 32px 32px 0 0;
  padding: 32px 24px 48px 24px;
  flex: 1;
}

.toast {
  background: var(--surface-solid);
  color: var(--text-main);
  padding: 14px 20px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  pointer-events: all;
  border-left: 4px solid var(--primary);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { border-left-color: var(--success); }
.toast.success i { color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.error i { color: var(--danger); }
.toast.info { border-left-color: var(--primary); }
.toast.info i { color: var(--primary); }

/* CROPPER MODAL */
#cropper-modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#cropper-modal.active {
  opacity: 1;
  pointer-events: all;
}

.cropper-header {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0,0,0,0.8);
  color: white;
}

.cropper-header h3 {
  font-size: 1.2rem;
  font-weight: 600;
}

.cropper-container-wrapper {
  flex: 1;
  width: 100%;
  background: #111;
  overflow: hidden;
  position: relative;
}

.cropper-container-wrapper img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.cropper-footer {
  padding: 24px;
  background: rgba(0,0,0,0.9);
  display: flex;
  gap: 16px;
  padding-bottom: 40px;
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: white;
  border: none;
  padding: 16px 24px;
  border-radius: 20px;
  font-weight: 600;
  flex: 1;
  font-size: 1.05rem;
}

/* Select Chips (Pills / Bubbles) */
.select-chip {
  padding: 8px 16px;
  border-radius: 30px;
  border: 1px solid rgba(100, 116, 139, 0.3);
  background: transparent;
  color: var(--text-main);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.select-chip:hover {
  background: rgba(13, 148, 136, 0.05);
  border-color: rgba(13, 148, 136, 0.3);
}

.select-chip:active {
  transform: scale(0.95);
}
