/* ──────────────────────────────────────────────────
   IngredSense — Stylesheet
   ────────────────────────────────────────────────── */

:root {
  /* Dark theme (default) */
  --bg: #0b0f14;
  --bg-2: #11171f;
  --surface: #151d27;
  --surface-2: #1c2632;
  --border: #25313f;
  --text: #e8eef5;
  --text-dim: #9aa8b8;
  --text-faint: #6b7785;
  --accent: #d4ff3a;
  --accent-ink: #0b0f14;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --danger: #ef4444;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, .6);
  --blur: saturate(180%) blur(20px);
}

:root[data-theme="light"] {
  --bg: #faf7f2;
  --bg-2: #f1ede5;
  --surface: #ffffff;
  --surface-2: #f5f1ea;
  --border: #e5ddd0;
  --text: #1a1614;
  --text-dim: #6b6359;
  --text-faint: #9a9287;
  --accent: #1a1614;
  --accent-ink: #faf7f2;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --danger: #b91c1c;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, .15);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  -webkit-overflow-scrolling: touch;
  font-family: 'Fraunces', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  transition: background .3s ease, color .3s ease;
  -webkit-font-smoothing: antialiased;
}
body[data-lang="bn"],
body[data-lang="bn"] button,
body[data-lang="bn"] input {
  font-family: 'Hind Siliguri', sans-serif;
}

/* ── App shell ── */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
  padding: 14px 14px calc(14px + env(safe-area-inset-top)) 14px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
}
.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  font-size: 17px;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}
.logo-text {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.5px;
  line-height: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logo-text small {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--text-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 3px;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease;
  flex-shrink: 0;
  position: relative;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.lang-toggle {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  height: 34px;
  flex-shrink: 0;
}
.lang-toggle button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all .2s ease;
  min-width: 28px;
}
.lang-toggle button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

@media (max-width: 380px) {
  .logo-text { font-size: 16px; }
  .logo-text small { display: none; }
  .logo-mark { width: 30px; height: 30px; font-size: 15px; }
  header { padding-left: 12px; padding-right: 12px; gap: 6px; }
  .icon-btn { width: 32px; height: 32px; }
  .lang-toggle { height: 32px; }
  .lang-toggle button { font-size: 10px; padding: 0 6px; min-width: 24px; }
  .controls { gap: 4px; }
}

/* ── Main ── */
main {
  flex: 1;
  padding: 24px 18px 120px 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.hero h1 {
  font-size: clamp(32px, 9vw, 44px);
  line-height: 1.0;
  letter-spacing: -0.02em;
  margin: 0 0 10px 0;
  font-weight: 600;
  font-variation-settings: "opsz" 144;
}
.hero h1 em {
  font-style: italic;
  color: var(--text-dim);
  font-weight: 400;
}
.hero p {
  margin: 0;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.5;
}
body[data-lang="bn"] .hero h1 { font-size: clamp(26px, 7.5vw, 36px); line-height: 1.2; }

/* ── Scan card ── */
.scan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.scan-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .4;
}

/* Age selector */
.age-selector {
  padding: 16px 18px;
  background: var(--surface-2);
  border-radius: 16px;
  border: 1px solid var(--border);
}
.age-selector-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 12px;
}
.age-selector-label svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }
.age-chips {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.age-chip {
  padding: 10px 4px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  text-align: center;
  transition: all .15s ease;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}
.age-chip small {
  display: block;
  font-size: 9px;
  opacity: 0.7;
  margin-top: 2px;
  font-weight: 400;
}
body[data-lang="bn"] .age-chip { font-family: 'Hind Siliguri', sans-serif; font-size: 13px; }
.age-chip.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  transform: scale(1.02);
}
.age-chip:active { transform: scale(0.96); }

.camera-wrap {
  position: relative;
  aspect-ratio: 3/4;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg-2);
  border: 1px dashed var(--border);
  display: grid;
  place-items: center;
}
#video, #preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
#video.active, #preview.active { display: block; }

.camera-placeholder {
  text-align: center;
  padding: 20px;
  color: var(--text-faint);
}
.camera-placeholder svg {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  stroke: var(--text-faint);
  fill: none;
  stroke-width: 1.5;
}
.camera-placeholder p { margin: 0; font-size: 14px; line-height: 1.5; }

.viewfinder {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
}
.viewfinder.active { display: block; }
.viewfinder::before, .viewfinder::after,
.viewfinder > span:nth-child(1), .viewfinder > span:nth-child(2) {
  content: "";
  position: absolute;
  width: 28px;
  height: 28px;
  border: 2px solid var(--accent);
}
.viewfinder::before { top: 18px; left: 18px; border-right: none; border-bottom: none; border-top-left-radius: 6px; }
.viewfinder::after { top: 18px; right: 18px; border-left: none; border-bottom: none; border-top-right-radius: 6px; }
.viewfinder > span:nth-child(1) { bottom: 18px; left: 18px; border-right: none; border-top: none; border-bottom-left-radius: 6px; }
.viewfinder > span:nth-child(2) { bottom: 18px; right: 18px; border-left: none; border-top: none; border-bottom-right-radius: 6px; }
.viewfinder-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, .7);
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.05em;
  white-space: nowrap;
  backdrop-filter: blur(10px);
}

/* ── Buttons ── */
.actions { margin-top: 16px; display: flex; gap: 10px; }
.btn {
  flex: 1;
  height: 52px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .15s ease, background .2s ease, opacity .2s ease;
}
body[data-lang="bn"] .btn { font-family: 'Hind Siliguri', sans-serif; font-weight: 600; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.primary:disabled { background: var(--surface-2); color: var(--text-dim); border-color: var(--border); }
.big-capture { width: 100%; height: 64px; font-size: 17px; border-radius: 18px; }
.file-input { display: none; }

/* ── Result card ── */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0;
  overflow: hidden;
  display: none;
}
.result-card.visible { display: block; animation: slideUp .4s cubic-bezier(.16, 1, .3, 1); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.alert-banner {
  padding: 22px 22px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.alert-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(135deg, transparent 0 14px, rgba(255, 255, 255, .06) 14px 16px);
  pointer-events: none;
}
.alert-banner.good { background: #16a34a; }
.alert-banner.warn { background: #d97706; }
.alert-banner.bad  { background: #dc2626; }

.alert-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, .35);
  backdrop-filter: blur(6px);
}
.alert-icon svg { width: 32px; height: 32px; stroke: #fff; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.alert-text { flex: 1; min-width: 0; }
.alert-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 4px;
}
.alert-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.05;
  font-variation-settings: "opsz" 144;
}
body[data-lang="bn"] .alert-value { font-size: 22px; line-height: 1.25; }

.score-badge {
  width: 60px; height: 60px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  background: rgba(255, 255, 255, .2);
  border: 2px solid rgba(255, 255, 255, .4);
  color: #fff;
  flex-shrink: 0;
  backdrop-filter: blur(6px);
}
.score-badge small {
  font-size: 9px;
  display: block;
  line-height: 1;
  margin-top: 1px;
  opacity: 0.85;
}

.section {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.section:last-child { border-bottom: none; }
.section h3 {
  margin: 0 0 10px 0;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.section h3 svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }
.section p {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}
body[data-lang="bn"] .section p { font-size: 15px; line-height: 1.7; }

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.flag {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid;
  font-family: 'JetBrains Mono', monospace;
}
.flag.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); background: color-mix(in srgb, var(--good) 8%, transparent); }
.flag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.flag.bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 40%, transparent);  background: color-mix(in srgb, var(--bad) 8%, transparent); }

.age-warning {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bad) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
  color: var(--bad);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}
.age-warning.warn {
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--warn);
}
.age-warning.good {
  background: color-mix(in srgb, var(--good) 10%, transparent);
  border-color: color-mix(in srgb, var(--good) 30%, transparent);
  color: var(--good);
}
.age-warning svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.5; flex-shrink: 0; margin-top: 1px; }

.details-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all .2s;
}
body[data-lang="bn"] .details-toggle { font-family: 'Hind Siliguri', sans-serif; font-size: 13px; }
.details-toggle:active { transform: scale(0.97); }
.details-toggle svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  transition: transform .3s;
}
.details-toggle.open svg { transform: rotate(180deg); }

.details-full {
  max-height: 0;
  overflow: hidden;
  transition: max-height .4s cubic-bezier(.4, 0, .2, 1), margin-top .3s;
  margin-top: 0;
}
.details-full.open { max-height: 1200px; margin-top: 14px; }
.details-full p {
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: 12px;
  border-left: 3px solid var(--accent);
  margin: 0;
  font-size: 14px !important;
  line-height: 1.7 !important;
}
body[data-lang="bn"] .details-full p { line-height: 1.8 !important; }

/* ── Loading ── */
.loading { display: none; padding: 40px 20px; text-align: center; }
.loading.active { display: block; }
.spinner {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  margin: 0 auto 16px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.05em;
}

.disclaimer {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  padding: 0 20px;
  line-height: 1.5;
  font-style: italic;
}

@media (max-width: 360px) {
  main { padding: 18px 14px 120px; }
}

/* ── Modals ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.active { display: flex; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 22px;
  position: relative;
  box-shadow: var(--shadow);
}
.modal h2 {
  margin: 0 0 6px 0;
  font-size: 24px;
  letter-spacing: -0.02em;
  font-weight: 600;
}
.modal-sub {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 20px 0;
  line-height: 1.5;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
