/* ================================================================
   Gram Scan — Styles
   Matches the Gram app design system:
     Fonts: Quicksand (headers/body), Rubik (numbers)
     Colors: teal/mint palette
   ================================================================ */

:root {
  --brand: #8ddbc5;
  --brand-dark: #336b62;
  --brand-darker: #1b594e;
  --primary-700: #336b62;
  --primary-800: #1b594e;
  --success: #00d865;
  --error: #ff4000;
  --warning: #ff9500;

  --bg: #ffffff;
  --bg-subtle: #f7f7f7;
  --bg-card: #ffffff;

  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --text-on-dark: #ffffff;

  --font-body: 'Quicksand', system-ui, -apple-system, sans-serif;
  --font-number: 'Rubik', system-ui, -apple-system, sans-serif;

  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --bg-subtle: #1e1e1e;
    --bg-card: #1e1e1e;

    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --text-tertiary: #707070;
    --text-on-dark: #ffffff;
  }
}

/* ---- Reset ---- */

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

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

a {
  text-decoration: none;
  color: inherit;
}

.hidden { display: none !important; }

/* ---- Screen system ---- */

#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  opacity: 1;
  visibility: visible;
}

/* ================================================================
   STATE 1: Landing
   ================================================================ */

#screen-landing {
  background: var(--bg);
  justify-content: space-between;
  padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 16px);
}

.landing-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 32px;
}

.logo-container {
  margin-bottom: 8px;
}

.logo {
  height: 64px;
  width: auto;
}

.hero-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 320px;
}

.hero-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
  border-radius: 20px;
  margin-bottom: 8px;
}

h1 {
  font-family: var(--font-body);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-secondary);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  padding: 16px 32px;
  background: var(--primary-700);
  color: var(--text-on-dark);
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 700;
  border-radius: var(--radius-full);
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-primary:active {
  transform: scale(0.97);
  background: var(--primary-800);
}

.btn-small {
  padding: 12px 24px;
  font-size: 16px;
  max-width: 240px;
}

.hint {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
}

.landing-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  padding-top: 16px;
}

.landing-footer .footer-logo {
  height: 28px;
  width: auto;
  opacity: 0.5;
}

/* ================================================================
   STATE 2: Camera
   ================================================================ */

#screen-camera {
  background: #000;
}

.camera-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#camera-feed {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 24px);
}

.camera-close {
  align-self: flex-start;
}

.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-full);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn-icon:active {
  background: rgba(0, 0, 0, 0.5);
}

.btn-icon-placeholder {
  width: 44px;
  height: 44px;
}

/* Viewfinder corners */

.viewfinder {
  position: relative;
  width: 75%;
  max-width: 300px;
  aspect-ratio: 1;
  margin: 0 auto;
}

.vf-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: rgba(255, 255, 255, 0.8);
  border-style: solid;
  border-width: 0;
}

.vf-tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 12px; }
.vf-tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 12px; }
.vf-bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 12px; }
.vf-br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 12px; }

.camera-hint {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  margin-top: -12px;
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.btn-capture {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.1s ease;
}

.btn-capture:active {
  transform: scale(0.92);
}

.capture-ring {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  display: block;
}

/* ================================================================
   STATE 3: Processing
   ================================================================ */

#screen-processing {
  background: var(--bg);
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.processing-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.processing-image-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.captured-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-subtle);
  border-top-color: var(--primary-700);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.processing-text {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.processing-subtext {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-tertiary);
}

/* ================================================================
   STATE 4: Results
   ================================================================ */

#screen-results {
  background: var(--bg-subtle);
  overflow-y: auto;
}

.results-content {
  min-height: 100%;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.results-header {
  display: flex;
  align-items: center;
}

.btn-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary-700);
  padding: 8px 4px;
}

.btn-text:active {
  opacity: 0.7;
}

.meal-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  padding: 0 4px;
}

/* Summary card */

.results-summary {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.summary-calories {
  text-align: center;
  margin-bottom: 20px;
}

.summary-calories .cal-number {
  font-family: var(--font-number);
  font-size: 42px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
}

.summary-calories .cal-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 4px;
}

.macro-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}

.macro-bar-carbs { background: #14b8a6; }
.macro-bar-protein { background: #eab308; }
.macro-bar-fat { background: #f97316; }

.macro-legend {
  display: flex;
  justify-content: space-around;
}

.macro-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.macro-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.macro-dot-carbs { background: #14b8a6; }
.macro-dot-protein { background: #eab308; }
.macro-dot-fat { background: #f97316; }

.macro-value {
  font-family: var(--font-number);
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
}

.macro-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
}

/* Food list */

.food-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.food-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.food-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.food-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.food-calories {
  font-family: var(--font-number);
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  margin-left: 12px;
}

.food-macros {
  display: flex;
  gap: 16px;
}

.food-macro {
  display: flex;
  align-items: center;
  gap: 6px;
}

.food-macro-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.food-macro-value {
  font-family: var(--font-number);
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
}

/* Serving info */

.food-serving {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* Download CTA */

.download-cta {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  border: 1.5px solid var(--brand);
  margin-top: 8px;
}

.cta-text h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.cta-text p {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.cta-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.store-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--primary-700);
  color: var(--text-on-dark);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-full);
  transition: background 0.2s ease, transform 0.1s ease;
}

.store-badge:active {
  transform: scale(0.97);
  background: var(--primary-800);
}

.store-badge svg {
  flex-shrink: 0;
}

/* ================================================================
   Error overlay
   ================================================================ */

.error-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.error-card {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 32px 24px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.error-message {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
}

/* ================================================================
   Utilities and animations
   ================================================================ */

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in-up {
  animation: fadeInUp 0.4s ease forwards;
}

/* Stagger children in results */
.food-card:nth-child(1) { animation-delay: 0s; }
.food-card:nth-child(2) { animation-delay: 0.05s; }
.food-card:nth-child(3) { animation-delay: 0.1s; }
.food-card:nth-child(4) { animation-delay: 0.15s; }
.food-card:nth-child(5) { animation-delay: 0.2s; }

/* ================================================================
   Dark mode overrides
   ================================================================ */

@media (prefers-color-scheme: dark) {
  .hero-icon svg rect { stroke: #8ddbc5; }
  .hero-icon svg circle[stroke] { stroke: #8ddbc5; }

  .processing-overlay {
    background: rgba(0, 0, 0, 0.4);
  }

  .results-summary,
  .food-card,
  .download-cta {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }

  .download-cta {
    border-color: var(--primary-700);
  }

  .error-card {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  }
}
