/* Opt-in dark appearance. The existing cream / beige theme is the default. */
html[data-theme="dark"] {
  --app-ink: #e5ede7;
  --app-muted: #acbcb1;
  --app-canvas: #111b16;
  --app-surface: #1c2a22;
  --app-soft: #263e30;
  --app-line: #374a3e;
  --app-shadow: 0 3px 16px rgba(0, 0, 0, .16);
  --appearance-raised: #24362b;
  --appearance-link: #8bd5ad;
  color-scheme: dark;
}
html[data-theme="dark"] body { background: #0d1510; color: var(--app-ink); }
html[data-theme="dark"] .phone { background: var(--app-canvas); border-color: var(--app-line); }

/* Backgrounds are changed individually so charts, photos and status dots keep their colors. */
html[data-theme="dark"] .phone :is(
  .summary-card, .daily-tracker, .meal-item, .profile-list, .settings-row,
  .settings-link-row, .faq-item, .policy-card, .rating-card, .nutrition-target-card,
  .profile-budget-panel, .budget-stat, .detail-section-card, .weekly-day,
  .home-meal-card, .smart-product-card, .recipes-card, .pantry-cat-card,
  .pantry-ing-card, .pantry-add-box, .pantry-ai-card, .pantry-stat-card,
  .recipe-price-controls, .recipe-price-breakdown, .history-period-summary,
  .history-day-card, .history-editor-card, .history-empty-state,
  .referral-code-card, .referral-upi-card, .referral-steps-card, .cheaper-card,
  .wishlist-empty, .home-menu, .pantry-item, .shop-item, .scan-history-card,
  .manual-barcode-wrap, .notification-item, .tips-card, .tips-fact-card,
  .tip-article-body, .tip-article-sources, .tip-article-fact, .tip-article-action,
  .store-manager, .store-connect-card,
  .plan-total-row, .kitchen-suggestion-item, .recipe-library-card,
  .smart-store-cart, .item-compare-panel, .connect-strip, .single-store-note,
  .mm-chat-new, .quick-chip, .chat-bubble.bot, .chat-input-row
) {
  background: var(--app-surface) !important;
  border-color: var(--app-line) !important;
  color: var(--app-ink);
}
html[data-theme="dark"] .phone :is(
  h1, h2, h3, h4, label, .onb-title, .onb-question, .cal-value,
  .pl-label, .settings-link-label, .settings-preference-title, .goal-card p,
  .pace-title, .home-meal-copy b, .home-meal-label, .daily-tracker-heading strong,
  .macro, .macro p, .macro-value, .cooking-for-title, .cooking-for-label,
  .plan-total-row, .history-period-heading,
  .recipes-card-title, .product-info h3, .product-info p b, .pantry-cat-name,
  .pantry-ing-name, .pantry-add-title, .pantry-ai-feature-title, .pantry-detail-title,
  .pantry-section-title, .pantry-stat-num:not(.low):not(.soon), .history-stat b,
  .history-meal-copy b, .detail-method-step, .detail-nutrition-stats,
  .detail-quick-stats, .referral-step, .referral-code-text, .cart-line > span,
  .notification-title, .tips-card strong, #tips-fact-text, .tip-article-body p,
  .tip-article-body li, .tip-article-copy, .tip-article-copy p, .tip-article-copy li,
  .tip-article-action p
) { color: var(--app-ink) !important; }
html[data-theme="dark"] .phone :is(
  .desc, .subtitle, .summary-label, .cal-label, .onb-step, .pl-value, .greet-small,
  .settings-group-title, .settings-preference small, .settings-preference-note,
  .policy-updated, .policy-card p, .rating-note, .rating-caption, .home-meal-copy small,
  .home-meal-history-hint, .daily-tracker-caption, .recipes-card-meta,
  .recipes-nav-tab:not(.active), .recipes-seeall-count, .product-qty, .product-info p,
  .pantry-detail-kicker, .pantry-detail-subtitle, .pantry-stat-label,
  .pantry-section-count, .pantry-ing-submeta, .pantry-add-desc, .pantry-ai-feature-desc,
  .pantry-disclaimer-note, .budget-of, .budget-recipe-note, .budget-recipe-empty,
  .weekly-day > summary small, .weekly-recipe small, .weekly-plan-note,
  .history-stat span, .history-day-heading p, .history-day-macros,
  .history-meal-copy small, .history-summary-caption, .history-editor-note,
  .history-no-meals, .history-period-btn:not(.active), .detail-nutrition-note, .detail-estimated-label,
  .referral-code-label, .referral-disclaimer, .referral-upi-status, .cheaper-label,
  .scan-history-time, .scan-history-macros, .mm-chat-brand p,
  .mm-chat-welcome > p, .quick-chip small, .mm-chat-composer-meta,
  .mm-chat-message-meta time, .mm-chat-copy, .mm-chat-estimate,
  .connect-strip small, .manager-heading p, .store-connect-card small,
  .smart-store-cart header small, .cart-line small, .smart-empty, .notification-message
) { color: var(--app-muted) !important; }

/* Forms, option cards and secondary controls. */
html[data-theme="dark"] .phone :is(
  input:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  select, textarea
) {
  background: var(--appearance-raised) !important;
  color: var(--app-ink) !important;
  border-color: var(--app-line) !important;
}
html[data-theme="dark"] .phone :is(input, textarea)::placeholder { color: #a2b4a8 !important; }
html[data-theme="dark"] .phone :is(
  .btn-outline, .btn-social, .manage-btn, .unit-btn, .method-card,
  .goal-card, .pace-card, .gender-card, .chip:not(.selected),
  .preset-btn:not(.active), .cooking-for-card, .detail-cooking-option,
  .recipes-pill:not(.active), .storage-tab:not(.active), .pantry-tag:not(.selected),
  .pantry-subcat-btn:not(.active), .pantry-cube-btn, .pantry-btn-chip,
  .history-period-tabs, .history-period-btn.active, .history-stat,
  .history-meal-row, .history-meal-actions button, .history-add-meal,
  .history-editor-heading button, .home-meal-recipe, .pantry-detail-shell,
  .pantry-ai-feature, .pantry-cat-img-wrap, .pantry-cat-no-img,
  .recipe-price-controls button, .smart-category-row button, .add-smart-product,
  .store-connect-card button, .smart-refresh, .smart-location-cta,
  .cart-quantity button, .smart-store-cart header, .meal-regen-btn,
  .history-open-button, .detail-tag-chip, .recipes-icon-btn,
  .recipes-close-btn, .recipes-back-circle-btn
) {
  background: var(--appearance-raised) !important;
  color: var(--app-ink) !important;
  border-color: var(--app-line) !important;
}
html[data-theme="dark"] .phone :is(
  .goal-card.selected, .method-card.selected, .pace-card.selected,
  .gender-card.selected, .cooking-for-card.selected, .detail-cooking-option.selected,
  .recipes-pill.active, .storage-tab.active, .smart-category-row button.active
) { background: var(--app-soft) !important; border-color: #62af87 !important; color: #b4efd0 !important; }
html[data-theme="dark"] .phone :is(
  .btn-primary, .pantry-submit-btn, .pantry-ai-action-btn, .chat-send-btn,
  .chat-bubble.user, .chip.selected:not(.dislike-chip), .pantry-subcat-btn.active,
  .pantry-tag.selected, .preset-btn.active
) { color: #fff; }
html[data-theme="dark"] .phone :is(
  .green, .login-link, .onb-back-label, .meal-kcal, .pantry-cat-action,
  .pantry-ai-header, .pantry-field-label, .pantry-subcat-label, .shop-category,
  .nutrition-target-row b, .budget-percent, .savings-line, .weekly-recipe,
  .history-edit-activity, .budget-text-button, .settings-link-row .pl-arrow,
  .mm-chat-speaker, .mm-chat-starters button, .mm-chat-followups button,
  .smart-location, .smart-section-title button, .tip-article-sources a,
  .daily-tracker-actions button, .steps-entry-row button, .steps-quick-add,
  .already-have-items, .cal-percent, .cooking-for-title-accent
) { color: var(--appearance-link) !important; }
html[data-theme="dark"] .phone :is(.recipes-see-all-btn, .mm-chat-brand h1 span, .mm-chat-context span) { color: var(--appearance-link) !important; }
html[data-theme="dark"] :is(.price-footnote, .price-connection-status, .price-nearby-store small) { color: var(--app-muted) !important; }
html[data-theme="dark"] .phone input.error:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]) { border-color: #ef8b9b !important; }
html[data-theme="dark"] .phone :is(.pantry-btn-chip.danger, .pantry-ing-status.out-of-stock, .pantry-stock-badge.out-of-stock, .pantry-validation-hint.error, .field-error) { color: #ff9aab !important; }
html[data-theme="dark"] .phone :is(.pantry-ing-status.in-stock, .pantry-stock-badge.in-stock, .pantry-validation-hint.success) { color: #8bd5ad !important; }
html[data-theme="dark"] .phone :is(.pantry-ing-status.low-stock, .pantry-stock-badge.low-stock, .pantry-stat-num.low, .pantry-ing-status.expiring, .pantry-ing-status.use-soon, .pantry-stock-badge.expiring, .pantry-stock-badge.use-soon, .pantry-stat-num.soon) { color: #f0c26f !important; }
html[data-theme="dark"] .phone :is(.profile-list-item, .menu-item, .settings-link-row):hover { background: var(--appearance-raised); }
html[data-theme="dark"] .phone :is(.premium-banner, .ai-tip-box, .referral-wallet-card) { background: #393021; border-color: #665537; color: #f2dca9; }
html[data-theme="dark"] .phone :is(.premium-sub, .referral-wallet-amount) { color: #e8ce91; }
html[data-theme="dark"] .phone :is(.already-have-card, .kitchen-suggest-card, .cheaper-savings-box, .budget-note.ok) { background: var(--app-soft); color: #b4efd0; }
html[data-theme="dark"] .phone :is(.already-have-card b, .kitchen-suggest-title, .kitchen-suggest-note) { color: #b4efd0; }
html[data-theme="dark"] .phone :is(.progress-track, .progress-bg, .onb-progress-bg, .unit-toggle) { background: #33463a; }
html[data-theme="dark"] .phone :is(.profile-list-item, .summary-row, .nutrition-target-row, .cart-line, .weekly-day-macros) { border-color: var(--app-line); }
html[data-theme="dark"] .phone .detail-nutrition-ring::before { background: var(--app-surface); }
html[data-theme="dark"] .phone :is(.bottom-nav, #scan-screen .bottom-nav) { background: #1c2a22f7; border-color: var(--app-line); }
html[data-theme="dark"] .bottom-nav .nav-item { color: #b0c1b5; }
html[data-theme="dark"] .bottom-nav .nav-item.active,
html[data-theme="dark"] .bottom-nav .nav-item.active .nav-icon { color: #a2e4c0; }

/* Standalone recipes share this theme; amounts, nutrition and images are unchanged. */
html[data-theme="dark"] .recipe-app { background: var(--app-canvas) !important; color: var(--app-ink); }
html[data-theme="dark"] .recipe-app :is(
  .section-card, .section, .ingredient-card, .method-card, .dietary-item,
  .optional-spices, .cooking-for-wrap, .recipe-household-picker,
  .cooking-for-card, .cooking-for-panel, .cooking-for-box,
  .recipe-price-controls, .recipe-price-breakdown
) { background: var(--app-surface) !important; border-color: var(--app-line) !important; }
html[data-theme="dark"] .recipe-app :is(
  .section-title, .ingredient-name, .ingredient-quantity, .nutrition-name,
  .nutrition-value, .donut-value, .donut-label, .method-text, .method-text p,
  .tips-list, .dietary-label, .dietary-note, .optional-title, .optional-spice-list, label,
  .optional-spice-list li, .optional-note, .nutrition-note, .cooking-for-label,
  .recipe-household-title, .cooking-for-title, .cooking-title
) { color: var(--app-ink) !important; }
html[data-theme="dark"] .recipe-app :is(
  .donut-inner, .ingredient-image, .method-image, .circle-btn,
  .serving-pill, .estimated-pill, .cooking-for-pill,
  .recipe-household-options button, .cooking-for-btn, .cooking-choice,
  .cooking-for-choice, .cooking-for-option, .cook-for-option, .serving-option,
  .cooking-option, .recipe-price-controls input, .recipe-price-controls select,
  .recipe-price-controls button
) { background: var(--appearance-raised) !important; border-color: var(--app-line) !important; color: #c9e8d5 !important; }
html[data-theme="dark"] .recipe-app :is(
  .recipe-household-options button.selected, .cooking-for-btn.active,
  .cooking-choice.is-selected, .cooking-for-choice.selected,
  .cooking-for-option.selected, [aria-pressed="true"]
) { background: var(--app-soft) !important; border-color: #62af87 !important; color: #b4efd0 !important; }
html[data-theme="dark"] :is(.detail-panel, .detail-description, .detail-title, .detail-quantity) { color: var(--app-ink); }
html[data-theme="dark"] .detail-panel { background: var(--app-surface); border-color: var(--app-line); }
html[data-theme="dark"] .detail-quantity { background: var(--app-soft); }

/* Respect both the explicit setting and the device accessibility preference. */
html[data-reduce-motion="true"] { scroll-behavior: auto !important; }
html[data-reduce-motion="true"] *,
html[data-reduce-motion="true"] *::before,
html[data-reduce-motion="true"] *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
  scroll-behavior: auto !important;
}
