/* ============================================
   Beads of Brilliance — User Theme System
   Dark / Light mode via CSS custom properties
   ============================================ */

/* ── Light theme (default) ── */
:root {
  --theme-bg: #f0f2f5;
  --theme-surface: #ffffff;
  --theme-surface-2: #f8f9fa;
  --theme-border: #e0e0e0;
  --theme-text: #2c3e50;
  --theme-text-muted: #666666;
  --theme-text-light: #999999;
  --theme-primary: #4a90e2;
  --theme-primary-dark: #357abd;
  --theme-shadow: rgba(0, 0, 0, 0.07);
  --theme-shadow-md: rgba(0, 0, 0, 0.12);
  --theme-card-hover: rgba(74, 144, 226, 0.06);
  --theme-input-bg: #ffffff;
  --theme-input-border: #dde3ec;
  --theme-toggle-bg: #1a1a2e;
  --theme-toggle-icon: "🌙";
  --theme-transition:
    background 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ── Dark theme ── */
[data-theme="dark"] {
  --theme-bg: #0f1117;
  --theme-surface: #1a1d2e;
  --theme-surface-2: #242840;
  --theme-border: #2e3250;
  --theme-text: #e8eaf0;
  --theme-text-muted: #c8ccd8;
  --brand-text: #c8ccd8;
  --theme-text-light: #6b7280;
  --theme-primary: #5ba3f5;
  --theme-primary-dark: #4a90e2;
  --theme-shadow: rgba(0, 0, 0, 0.3);
  --theme-shadow-md: rgba(0, 0, 0, 0.5);
  --theme-card-hover: rgba(91, 163, 245, 0.08);
  --theme-input-bg: #1a1d2e;
  --theme-input-border: #2e3250;
  --theme-toggle-bg: #ffd700;
  --theme-toggle-icon: "☀️";
  /* Override brand colors so all var(--brand-*) references adapt automatically */
  --brand-blue-dark: #a8b8e8;
  --brand-text: #e8eaf0;
}

/* ── Apply theme to base elements ── */
body {
  background-color: var(--theme-bg);
  color: var(--theme-text);
  transition: var(--theme-transition);
}

/* Cards & surfaces */
[data-theme="dark"] .paper-card,
[data-theme="dark"] .ws-card,
[data-theme="dark"] .tool-card,
[data-theme="dark"] .arith-card,
[data-theme="dark"] .col-add-card,
[data-theme="dark"] .paper-sheet,
[data-theme="dark"] .pp-container,
[data-theme="dark"] .dash-container > div,
[data-theme="dark"] .program-section {
  background-color: var(--theme-surface) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

[data-theme="dark"] .paper-card:hover,
[data-theme="dark"] .tool-card:hover {
  border-color: var(--theme-primary) !important;
  box-shadow: 0 8px 24px var(--theme-shadow-md) !important;
}

/* Text */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] .paper-card-title,
[data-theme="dark"] .tool-card-title {
  color: var(--theme-text) !important;
}

/* Override all specific .class h3 rules from styles.css in dark mode */
[data-theme="dark"] h3,
[data-theme="dark"] * h3,
[data-theme="dark"] .benefit-card h3,
[data-theme="dark"] .approach-step h3,
[data-theme="dark"] .certification-card h3,
[data-theme="dark"] .age-path-card h3,
[data-theme="dark"] .course-card h3,
[data-theme="dark"] .benefit-item h3,
[data-theme="dark"] .mission-card h3,
[data-theme="dark"] .vision-card h3,
[data-theme="dark"] .legacy-text h3,
[data-theme="dark"] .research-card h3,
[data-theme="dark"] .approach-item h3,
[data-theme="dark"] .contact-option-small h3,
[data-theme="dark"] .contact-info h3,
[data-theme="dark"] .course-features-section h3,
[data-theme="dark"] .excellence-card h3,
[data-theme="dark"] .excellence-benefits h3,
[data-theme="dark"] .step-content h3,
[data-theme="dark"] .cert-content h3,
[data-theme="dark"] .benefit-item-compact h3,
[data-theme="dark"] .highlight-card h3,
[data-theme="dark"] .error-suggestions h3,
[data-theme="dark"] .legal-content h3,
[data-theme="dark"] .feature-item h3,
[data-theme="dark"] .section-title,
[data-theme="dark"] .program-highlights h4,
[data-theme="dark"] .footer-col-heading {
  color: #153bba !important;
}

[data-theme="dark"] .paper-card-sub,
[data-theme="dark"] .tool-card-sub,
[data-theme="dark"] p,
[data-theme="dark"] body p,
[data-theme="dark"] main p,
[data-theme="dark"] section p,
[data-theme="dark"] div p,
[data-theme="dark"] article p {
  color: #2e3340 !important;
}

/* Controls / inputs */
[data-theme="dark"] select,
[data-theme="dark"] input,
[data-theme="dark"] textarea {
  background-color: var(--theme-input-bg) !important;
  border-color: var(--theme-input-border) !important;
  color: var(--theme-text) !important;
}

[data-theme="dark"] .pp-controls {
  background: var(--theme-surface-2) !important;
  border-color: var(--theme-border) !important;
}

/* Practice paper output */
[data-theme="dark"] #paperOutput {
  background: var(--theme-bg) !important;
}

[data-theme="dark"] .paper-header,
[data-theme="dark"] .paper-meta {
  background: var(--theme-surface) !important;
  border-color: var(--theme-border) !important;
}

/* Section headers */
[data-theme="dark"] .program-section-header {
  border-bottom-color: var(--theme-border) !important;
}

[data-theme="dark"] .program-section-header h2,
[data-theme="dark"] .program-section-header p {
  color: var(--theme-text) !important;
}

/* Footer */
[data-theme="dark"] .site-footer {
  background: #0a0c18 !important;
}

[data-theme="dark"] .footer-bottom {
  background: #060810 !important;
  border-color: #1a1d2e !important;
}

[data-theme="dark"] .footer-col-heading,
[data-theme="dark"] .footer-brand-name {
  color: #e8eaf0 !important;
}

[data-theme="dark"] .footer-link-list a,
[data-theme="dark"] .footer-contact-info a {
  color: var(--theme-text-muted) !important;
}

[data-theme="dark"] .footer-link-list a:hover,
[data-theme="dark"] .footer-contact-info a:hover {
  color: var(--theme-primary) !important;
}

/* Back to practice bar */
[data-theme="dark"] div[style*="background:#fff"][style*="border-bottom"] {
  background: var(--theme-surface) !important;
  border-color: var(--theme-border) !important;
}

[data-theme="dark"] div[style*="background:#fff"][style*="border-bottom"] a {
  color: var(--theme-primary) !important;
}

/* Scroll to top button */
[data-theme="dark"] .scroll-to-top {
  background: var(--theme-surface-2) !important;
  color: var(--theme-text) !important;
  border-color: var(--theme-border) !important;
}

/* ── Theme toggle button ── */
#theme-toggle {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  background: var(--theme-toggle-bg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.3s ease;
  outline: none;
}
#theme-toggle:hover {
  transform: scale(1.12);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
#theme-toggle:active {
  transform: scale(0.95);
}

/* Tooltip */
#theme-toggle::after {
  content: attr(aria-label);
  position: absolute;
  left: 54px;
  top: 50%;
  transform: translateY(-50%);
  background: #1a1a2e;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
#theme-toggle:hover::after {
  opacity: 1;
}

/* Hide on print */
@media print {
  #theme-toggle {
    display: none !important;
  }
}

/* ── Protect colored hero/banner sections from dark mode text override ── */
/* Any section with a gradient or solid colored background keeps its own text color */
[data-theme="dark"] .school-math-hero h1,
[data-theme="dark"] .school-math-hero h2,
[data-theme="dark"] .school-math-hero h3,
[data-theme="dark"] .school-math-hero p,
[data-theme="dark"] .school-math-hero span,
[data-theme="dark"] .abacus-hero h1,
[data-theme="dark"] .abacus-hero h2,
[data-theme="dark"] .abacus-hero h3,
[data-theme="dark"] .abacus-hero p,
[data-theme="dark"] .abacus-hero span,
[data-theme="dark"] .educator-hero-section h1,
[data-theme="dark"] .educator-hero-section h2,
[data-theme="dark"] .educator-hero-section h3,
[data-theme="dark"] .educator-hero-section p,
[data-theme="dark"] .pp-hero h1,
[data-theme="dark"] .pp-hero p,
[data-theme="dark"] .dash-hero h1,
[data-theme="dark"] .dash-hero p,
[data-theme="dark"] .rule-banner,
[data-theme="dark"] .rule-banner *,
[data-theme="dark"] [style*="background:linear-gradient"] h1,
[data-theme="dark"] [style*="background:linear-gradient"] h2,
[data-theme="dark"] [style*="background:linear-gradient"] p {
  color: inherit !important;
}
