/* ================================================
   NutriSnap — Premium Dark UI
   Inspired by Food Scan reference design
   DM Sans + DM Mono, traffic-light colors, ring charts
   ================================================ */

/* Reset & Base */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1c1c26;
  --border: rgba(255, 255, 255, 0.06);
  --text: #f0f0f5;
  --muted: #6b6b80;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --green-glow: rgba(74, 222, 128, 0.15);
  --yellow-glow: rgba(251, 191, 36, 0.15);
  --red-glow: rgba(248, 113, 113, 0.15);
  --radius: 24px;
  --radius-sm: 20px;
  --radius-xs: 14px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  padding: 0;
}

/* App Container */
.app {
  width: 100%;
  max-width: 420px;
  min-height: 100dvh;
  padding: 16px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 0;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.header-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Main */
.main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Upload Section */
.upload-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upload-area {
  background: var(--surface);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.upload-area::before {
  content: '';
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(74, 222, 128, 0.06) 0%, transparent 70%);
  pointer-events: none;
}

.upload-content {
  pointer-events: none;
  position: relative;
}

.upload-area:active {
  transform: scale(0.98);
  border-color: var(--green);
}

.camera-icon {
  color: var(--green);
  margin-bottom: 16px;
  opacity: 0.8;
}

.upload-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.upload-hint {
  font-size: 13px;
  color: var(--muted);
}

/* Image Preview */
.preview-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: fadeSlideUp 0.4s ease;
}

.preview-image {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius);
}

.remove-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.remove-btn:active {
  transform: scale(0.9);
  background: var(--red);
}

/* Analyze Button */
.analyze-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 16px 32px;
  border: none;
  border-radius: var(--radius-xs);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: #0a0a0f;
  background: linear-gradient(135deg, var(--green), #34d399);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 24px rgba(74, 222, 128, 0.25);
  animation: fadeSlideUp 0.4s ease 0.1s both;
  position: relative;
  overflow: hidden;
}

.analyze-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255, 255, 255, 0.15) 50%, transparent 60%);
  transform: translateX(-100%);
  transition: transform 0.6s;
}

.analyze-btn:not(:disabled):active {
  transform: scale(0.97);
}

.analyze-btn:not(:disabled):hover::before {
  transform: translateX(100%);
}

.analyze-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.analyze-btn .btn-loader {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(10, 10, 15, 0.25);
  border-top-color: #0a0a0f;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Results Section */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeSlideUp 0.5s ease;
}

/* Score Card */
.score-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.score-card::before {
  content: '';
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(74, 222, 128, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

.food-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
  position: relative;
}

.food-name {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 24px;
  text-align: center;
  position: relative;
}

/* Score Ring */
.score-ring-wrap {
  position: relative;
  width: 140px;
  height: 140px;
  margin-bottom: 12px;
}

.score-ring-wrap svg {
  transform: rotate(-90deg);
}

.score-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-number {
  font-size: 42px;
  font-weight: 600;
  color: var(--green);
  line-height: 1;
  font-family: 'DM Mono', monospace;
}

.score-denom {
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
  font-family: 'DM Mono', monospace;
}

.score-status {
  font-size: 11px;
  font-weight: 500;
  color: var(--green);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

/* Suggestion */
.suggestion {
  background: rgba(74, 222, 128, 0.06);
  border: 1px solid rgba(74, 222, 128, 0.15);
  border-radius: var(--radius-xs);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: #c8c8d8;
  text-align: center;
  width: 100%;
  position: relative;
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s;
  animation: fadeSlideUp 0.5s ease both;
}

.metric-card:nth-child(1) {
  animation-delay: 0.05s;
}

.metric-card:nth-child(2) {
  animation-delay: 0.1s;
}

.metric-card:nth-child(3) {
  animation-delay: 0.15s;
}

.metric-card:nth-child(4) {
  animation-delay: 0.2s;
}

.metric-card:active {
  transform: scale(0.97);
}

.metric-card.green::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--green-glow);
  pointer-events: none;
  border-radius: var(--radius-sm);
}

.metric-card.yellow::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--yellow-glow);
  pointer-events: none;
  border-radius: var(--radius-sm);
}

.metric-card.red::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--red-glow);
  pointer-events: none;
  border-radius: var(--radius-sm);
}

/* Metric Rings */
.ring-wrap {
  position: relative;
  width: 80px;
  height: 80px;
}

.ring-wrap svg {
  transform: rotate(-90deg);
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-emoji {
  font-size: 18px;
  line-height: 1;
}

.ring-value {
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.2;
}

.ring-unit {
  font-size: 9px;
  color: var(--muted);
  font-weight: 400;
}

.metric-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}

.metric-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.green .metric-status {
  color: var(--green);
}

.yellow .metric-status {
  color: var(--yellow);
}

.red .metric-status {
  color: var(--red);
}

/* SVG Rings */
.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
}

.ring-fill {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ultra Processed Card */
.ultra-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: fadeSlideUp 0.5s ease 0.25s both;
}

.ultra-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ultra-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.ultra-value {
  font-size: 17px;
  font-weight: 600;
}

.ultra-value.low {
  color: var(--green);
}

.ultra-value.medium {
  color: var(--yellow);
}

.ultra-value.high {
  color: var(--red);
}

.ultra-pill {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.ultra-pill.low {
  background: var(--green-glow);
  color: var(--green);
  border: 1px solid rgba(74, 222, 128, 0.2);
}

.ultra-pill.medium {
  background: var(--yellow-glow);
  color: var(--yellow);
  border: 1px solid rgba(251, 191, 36, 0.2);
}

.ultra-pill.high {
  background: var(--red-glow);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

/* Breakdown Card */
.breakdown-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  animation: fadeSlideUp 0.5s ease 0.3s both;
}

.breakdown-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.breakdown-row:last-child {
  border-bottom: none;
}

.breakdown-label {
  color: var(--muted);
}

.breakdown-val {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  color: var(--text);
}

/* New Analysis Button */
.new-analysis-btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--green);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  animation: fadeSlideUp 0.5s ease 0.35s both;
}

.new-analysis-btn:active {
  transform: scale(0.97);
  background: var(--surface);
}

/* Error Toast */
.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-xs);
  font-size: 14px;
  font-weight: 500;
  z-index: 100;
  animation: toastIn 0.3s ease;
  box-shadow: 0 8px 32px rgba(248, 113, 113, 0.3);
  max-width: calc(100% - 40px);
  text-align: center;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Animations */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Responsive */
@media (min-width: 400px) {
  .upload-area {
    padding: 56px 32px;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}