/* Global dark theme. It only changes presentation; existing markup and content stay untouched. */
html[data-bs-theme="dark"] { color-scheme: dark; }

html[data-bs-theme="dark"] body {
  background: radial-gradient(circle at 50% -20%, #063c2e 0, transparent 37%), #050606 !important;
  color: #f1fff8 !important;
}

html[data-bs-theme="dark"] body::before {
  opacity: .18 !important;
}

.bs-theme-toggle {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 2147480000;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 1px solid #cfe5f0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .94);
  color: #1e5a6f;
  font: 700 22px/1 Arial, sans-serif;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
  transition: background .2s ease, border-color .2s ease, color .2s ease, transform .2s ease;
}

.bs-theme-toggle:hover { transform: translateY(-2px); }
.bs-theme-toggle:focus-visible { outline: 3px solid #19d982; outline-offset: 3px; }

html[data-bs-theme="dark"] .bs-theme-toggle {
  border-color: #294338;
  background: #101512;
  color: #eafff1;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .48);
}

html[data-bs-theme="dark"] :is(
  .main-header, .nav-mobile-panel, .search-section, .search-box, .card,
  .card-info, .creator-card, .featured-creators-section, .footer-note,
  .modal-container, .modal-content, .rank-modal-container, .vip-modal-container,
  .post-modal-shell, .post-panel-content, .notification-modal-container,
  .notification-modal-footer, .floating-video-ad, .live-toast, .toast,
  .auth-input, .filter-badge, .tag-btn, .member-badge, .page-btn,
  .profile-card, .profile-content, .stat-box, .bio-section, .profile-build-tabs,
  .purchases-modal-container, .purchases-modal-shell, .purchase-item,
  .analytics-panel, .metric-card, .custom-modal, .content-box,
  .mybuilds-modal-container, .buy-coins-container, .confirm-modal-container
) {
  background-color: #101512 !important;
  color: #f1fff8 !important;
  border-color: #294338 !important;
}

html[data-bs-theme="dark"] :is(
  input, textarea, select, .search-box input, .post-field, .modal-input,
  .quick-up-input, .mybuilds-search-input, .page-jump-input
) {
  background-color: #0b100d !important;
  color: #f1fff8 !important;
  border-color: #294338 !important;
}

html[data-bs-theme="dark"] :is(
  input, textarea, select, .search-box input, .post-field, .modal-input,
  .quick-up-input, .mybuilds-search-input, .page-jump-input
)::placeholder {
  color: #9fb3a6 !important;
}

html[data-bs-theme="dark"] :is(
  p, .card-desc, .modal-desc, .footer-note, .creator-tagline, .member-since,
  .purchase-detail, .stat-label, .bio-text, .featured-subtitle, .forgot-note,
  .notification-mensagem, .post-help-text, .post-panel-subtitle
) {
  color: #a8b7af !important;
}

html[data-bs-theme="dark"] :is(
  h1, h2, h3, h4, .card-title, .modal-title, .profile-name, .creator-name,
  .section-title, .rank-title, .post-modal-title, .purchases-modal-title
) {
  color: #f3fff7 !important;
}

html[data-bs-theme="dark"] :is(
  .card-link, .auth-submit, .post-submit-btn, .modal-buy-btn, .btn-upgrade,
  .promo-spotlight-cta, .profile-edit-btn, .follow-btn, .feature-btn,
  .purchase-download-btn, .save-capa-btn, .modal-save, .quick-up-btn
) {
  background: #19c979 !important;
  color: #041b0e !important;
  border-color: #19c979 !important;
}

html[data-bs-theme="dark"] :is(
  .hero, .promo-hero-banner, .promo-spotlight-banner, .tags-chicks-shell
) {
  background-color: transparent !important;
}

html[data-bs-theme="dark"] :is(.card, .creator-card, .profile-card):hover {
  border-color: #19d982 !important;
  box-shadow: 0 18px 36px rgba(0, 0, 0, .52) !important;
}

html[data-bs-theme="dark"] :is(.social-links, .footer-note, .main-header) {
  border-color: #294338 !important;
}

/* Home header: its action shell has its own light gradient in index.html. */
html[data-bs-theme="dark"] :is(
  .header-actions-shell, .nav-actions, .auth-btn, .user-name,
  .notification-btn, .post-btn, .logout-btn, .nav-mobile-toggle
) {
  background: #101512 !important;
  color: #f1fff8 !important;
  border-color: #294338 !important;
  box-shadow: none !important;
}

/* Profile page: preserve its layout while replacing only the light surfaces. */
html[data-bs-theme="dark"] :is(
  .bio-text, .social-link, .profile-build-tab, .back-btn,
  .purchase-toast, .top-row, .profile-info
) {
  background: #101512 !important;
  color: #edf9f2 !important;
  border-color: #294338 !important;
}

html[data-bs-theme="dark"] :is(.bio-text, .social-link, .profile-build-tab) {
  color: #dcebe2 !important;
}

/* About page: these panels use page-specific white backgrounds. */
html[data-bs-theme="dark"] :is(
  .back-link, .hero-about, .section, .feature-card, .feature-card-body,
  .profile-preview, .stat-card
) {
  background: #101512 !important;
  color: #edf9f2 !important;
  border-color: #294338 !important;
}

html[data-bs-theme="dark"] :is(
  .hero-about h1, .hero-about p, .section h2, .section p,
  .feature-card-body, .feature-card-body p, .profile-preview p
) {
  color: #edf9f2 !important;
  -webkit-text-fill-color: currentColor;
}

/* Product pages are generated by server.js and use their own component names. */
html[data-bs-theme="dark"] :is(
  .topbar, .product-page, .summary, .content, .description, .info,
  .creator, .stat, .tag, .recommended-builds, .recommended-build-card,
  .report-modal-card, .report-cancel, .report-build-btn
) {
  background: #101512 !important;
  color: #edf9f2 !important;
  border-color: #294338 !important;
  box-shadow: none !important;
}

html[data-bs-theme="dark"] :is(
  .brand, .back-link, h1, h1.free-build-title, .section h2, .info h2,
  .description, .description-line strong, .description-line b,
  .info-row strong, .recommended-build-body strong, .recommended-builds-header h2
) {
  color: #f3fff7 !important;
}

html[data-bs-theme="dark"] :is(
  .creator span, .stat span, .action-note, .info-row span, .recommended-build-meta span,
  .favorite-note, .report-modal-card p
) {
  color: #a8b7af !important;
}

html[data-bs-theme="dark"] :is(.info-row, .recommended-builds) {
  border-color: #294338 !important;
}

html[data-bs-theme="dark"] :is(.primary-action, .report-submit) {
  background: #19c979 !important;
  color: #041b0e !important;
  box-shadow: none !important;
}

/* Home result counter: clearer interactive outline in dark mode. */
html[data-bs-theme="dark"] :is(#resultsCounter, .filter-badge) {
  background: #0d1711 !important;
  color: #f1fff8 !important;
  border: 1px solid #19c979 !important;
  box-shadow: inset 0 0 0 1px rgba(25, 217, 130, .12), 0 0 0 1px rgba(0, 0, 0, .28) !important;
}

/* Legal pages: their layout is shared by Contact, DMCA, Terms and Privacy. */
html[data-bs-theme="dark"] :is(
  .legal-hero, .legal-card, .legal-footer, .contact-highlight, .contact-grid div,
  .notice, .warning, .legal-kicker, .legal-meta span, .back-link
) {
  background: #101512 !important;
  color: #edf9f2 !important;
  border-color: #294338 !important;
  box-shadow: none !important;
}

html[data-bs-theme="dark"] :is(
  .legal-hero h1, .legal-card h1, .legal-card h2, .legal-card h3,
  .legal-card p, .legal-card li, .legal-card strong, .legal-footer,
  .contact-highlight span, .contact-highlight p
) {
  color: #dcebe2 !important;
  -webkit-text-fill-color: currentColor;
}

html[data-bs-theme="dark"] .legal-hero h1,
html[data-bs-theme="dark"] .legal-card h2,
html[data-bs-theme="dark"] .legal-card h3,
html[data-bs-theme="dark"] .legal-card strong {
  color: #f3fff7 !important;
}

html[data-bs-theme="dark"] :is(.legal-kicker, .legal-meta span, .contact-highlight a, .legal-footer a) {
  color: #68d998 !important;
}

html[data-bs-theme="dark"] .legal-nav a.active {
  background: #101512 !important;
  color: #f3fff7 !important;
  border-color: #19c979 !important;
}

/* Post Build modal: fields, editor and gallery keep readable dark surfaces. */
html[data-bs-theme="dark"] :is(
  .post-tabs-bar, .post-tab-btn, .post-panel-content, .post-field,
  .post-textarea-field, .post-rich-editor-wrap, .post-editor-toolbar,
  .post-editor-btn, .post-editor-color, .post-rich-editor, .post-image-box,
  .post-tag-radio, .post-delivery-switch, .post-delivery-switch-btn,
  .post-delivery-card, .post-delivery-option, .post-file-card,
  .post-file-display, .post-file-button
) {
  background: #101512 !important;
  color: #edf9f2 !important;
  border-color: #294338 !important;
  box-shadow: none !important;
}

html[data-bs-theme="dark"] :is(
  .post-panel-title, .post-section-label, .post-field-group label,
  .post-rich-editor, .post-delivery-title, .post-delivery-copy strong,
  .post-file-name
) {
  color: #f3fff7 !important;
}

html[data-bs-theme="dark"] :is(
  .post-panel-subtitle, .post-help-text, .post-delivery-copy span,
  .post-image-box .placeholder, .post-field::placeholder,
  .post-rich-editor:empty::before
) {
  color: #a8b7af !important;
}

html[data-bs-theme="dark"] :is(.post-tab-btn.active, .post-delivery-switch-btn.active) {
  background: #19c979 !important;
  color: #041b0e !important;
  border-color: #19c979 !important;
}

/* Small tags inside marketplace cards. */
html[data-bs-theme="dark"] :is(.mini-tag, .card-tags .tag) {
  background: #0d1711 !important;
  color: #eafff1 !important;
  border: 1px solid #19c979 !important;
  box-shadow: none !important;
}

html[data-bs-theme="dark"] .view-counter {
  background: transparent !important;
  color: #a8b7af !important;
  border: 0 !important;
  box-shadow: none !important;
}

html[data-bs-theme="dark"] .view-counter .view-number {
  color: #ffffff !important;
}

/* Home header: keep only the action capsule dark, never the full header row. */
html[data-bs-theme="dark"] .main-header {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

/* Home search: preserve the original rounded layout without the flat dark rectangle. */
html[data-bs-theme="dark"] .search-section {
  background: linear-gradient(135deg, rgba(14, 28, 20, .92), rgba(10, 18, 14, .88)) !important;
  border: 1px solid #315840 !important;
  border-radius: 60px !important;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .34), inset 0 1px 0 rgba(185, 255, 214, .05) !important;
}

html[data-bs-theme="dark"] .search-box {
  background: #0a110e !important;
  border: 1px solid #315f45 !important;
  border-radius: 48px !important;
  box-shadow: inset 0 0 16px rgba(25, 217, 130, .035) !important;
}

html[data-bs-theme="dark"] .search-box:focus-within {
  border-color: #19c979 !important;
  box-shadow: 0 0 0 3px rgba(25, 201, 121, .12), inset 0 0 16px rgba(25, 217, 130, .06) !important;
}

html[data-bs-theme="dark"] .search-box :is(input, input::placeholder, i) {
  color: #c7d9ce !important;
}

/* Hero typography: brighter hierarchy with a restrained emerald accent. */
html[data-bs-theme="dark"] .hero h1 {
  background: linear-gradient(135deg, #ffffff 0%, #edfff4 55%, #68d998 100%) !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  color: transparent !important;
  text-shadow: 0 0 24px rgba(25, 217, 130, .10) !important;
}

html[data-bs-theme="dark"] .hero p {
  background: rgba(25, 217, 130, .11) !important;
  border: 1px solid rgba(104, 217, 152, .28) !important;
  color: #c7d9ce !important;
}

@media (max-width: 640px) {
  .bs-theme-toggle { width: 40px; height: 40px; font-size: 20px; }
}
