:root {
  color-scheme: dark;
  --page-bg: #020817;
  --page-bg-alt: #0f172a;
  --surface: rgba(15, 23, 42, 0.78);
  --surface-strong: rgba(15, 23, 42, 0.94);
  --surface-soft: rgba(30, 41, 59, 0.82);
  --text: #e2e8f0;
  --text-muted: #cbd5e1;
  --text-soft: #94a3b8;
  --border: rgba(255, 255, 255, 0.10);
  --brand: #f4c400;
  --brand-soft: rgba(244, 196, 0, 0.14);
}

html.theme-light,
body.theme-light {
  color-scheme: light;
  --page-bg: #f8fafc;
  --page-bg-alt: #e2e8f0;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-strong: rgba(255, 255, 255, 0.96);
  --surface-soft: rgba(241, 245, 249, 0.92);
  --text: #0f172a;
  --text-muted: #334155;
  --text-soft: #64748b;
  --border: rgba(15, 23, 42, 0.12);
  --brand: #eab308;
  --brand-soft: rgba(234, 179, 8, 0.18);
}

body {
  background-color: var(--page-bg);
  color: var(--text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

body.theme-light,
body.theme-light header,
body.theme-light main,
body.theme-light section,
body.theme-light footer {
  background-color: transparent;
}

body.theme-light header {
  background: rgba(255, 255, 255, 0.70);
  border-color: var(--border);
  backdrop-filter: blur(12px);
}

body.theme-light [class*="bg-slate-950"] { background-color: var(--page-bg) !important; }
body.theme-light [class*="bg-slate-900"] { background-color: var(--surface-strong) !important; }
body.theme-light [class*="bg-slate-800"] { background-color: var(--surface-soft) !important; }
body.theme-light [class*="bg-slate-700"] { background-color: var(--surface-soft) !important; }
body.theme-light [class*="bg-slate-600"] { background-color: var(--surface-soft) !important; }
body.theme-light [class*="bg-slate-950/60"] { background-color: rgba(241, 245, 249, 0.9) !important; }
body.theme-light [class*="bg-slate-900/70"],
body.theme-light [class*="bg-slate-900/90"] { background-color: rgba(255, 255, 255, 0.82) !important; }
body.theme-light [class*="bg-slate-800/40"],
body.theme-light [class*="bg-slate-800/50"],
body.theme-light [class*="bg-slate-800/60"] { background-color: rgba(241, 245, 249, 0.9) !important; }

body.theme-light [class*="border-white/10"],
body.theme-light [class*="border-white/20"],
body.theme-light [class*="border-white/30"],
body.theme-light [class*="border-white/40"] {
  border-color: var(--border) !important;
}

body.theme-light [class*="text-"] {
  color: var(--text) !important;
}

body.theme-light [class*="text-slate-100"],
body.theme-light header .text-white,
body.theme-light .text-slate-200,
body.theme-light [class*="text-white"] {
  color: var(--text) !important;
}
body.theme-light [class*="text-slate-300"] { color: var(--text-muted) !important; }
body.theme-light [class*="text-slate-400"],
body.theme-light [class*="text-slate-500"],
body.theme-light [class*="text-slate-600"] { color: var(--text-soft) !important; }
body.theme-light [class*="text-slate-700"] { color: var(--text-muted) !important; }

body.theme-light .text-indigo-300,
body.theme-light .text-indigo-400,
body.theme-light .text-indigo-500 {
  color: var(--brand) !important;
}
body.theme-light .bg-indigo-500,
body.theme-light .bg-indigo-400,
body.theme-light .hover\:bg-indigo-400:hover,
body.theme-light .hover\:bg-indigo-400\/10:hover {
  background-color: var(--brand) !important;
  color: #111827 !important;
}
body.theme-light .bg-indigo-500\/20,
body.theme-light .hover\:bg-indigo-400\/10:hover {
  background-color: var(--brand-soft) !important;
}
body.theme-light .border-indigo-400,
body.theme-light .border-indigo-400\/40,
body.theme-light .focus\:ring-indigo-400:focus {
  border-color: rgba(234, 179, 8, 0.45) !important;
  --tw-ring-color: rgba(234, 179, 8, 0.45) !important;
}

body.theme-light .bg-white,
body.theme-light .bg-white\/10 {
  background-color: rgba(255, 255, 255, 0.85) !important;
}
body.theme-light .text-white {
  color: var(--text) !important;
}
body.theme-light .bg-indigo-500.text-white,
body.theme-light .bg-indigo-400.text-white,
body.theme-light .bg-indigo-500.text-slate-900,
body.theme-light .bg-indigo-400.text-slate-900 {
  color: #111827 !important;
}
body.theme-light .shadow,
body.theme-light .shadow-lg,
body.theme-light .shadow-xl {
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08) !important;
}

body.theme-light input,
body.theme-light select,
body.theme-light textarea {
  background-color: rgba(255, 255, 255, 0.9) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

body.theme-light ::placeholder {
  color: var(--text-soft) !important;
}

body.theme-light a {
  color: inherit;
}

/* Strong overrides for known problematic utility classes in light mode */
body.theme-light [class*="text-white"],
body.theme-light [class*="text-slate-100"],
body.theme-light [class*="text-slate-200"],
body.theme-light [class*="text-slate-50"] {
  color: var(--text) !important;
}

/* Hover/text variants (Tailwind escapes) */
body.theme-light .hover\:text-white:hover,
body.theme-light [class*="hover\:text-white"]:hover {
  color: var(--text) !important;
}

/* Make sure muted small text remains readable */
body.theme-light .text-slate-300 { color: var(--text-muted) !important; }
body.theme-light .text-slate-400 { color: var(--text-soft) !important; }

/* Catch bg-white variants that may produce low contrast when text stays light */
body.theme-light .bg-white,
body.theme-light .bg-white\/10,
body.theme-light .bg-white\/20 {
  background-color: rgba(255,255,255,0.95) !important;
}

/* Ensure border-white utilities become visible on light backgrounds */
body.theme-light .border-white,
body.theme-light [class*="border-white/"] {
  border-color: var(--border) !important;
}

/* Ensure brand/background buttons show dark text on light theme */
body.theme-light .bg-indigo-500,
body.theme-light .bg-indigo-400,
body.theme-light .bg-indigo-500\/20,
body.theme-light .hover\:bg-indigo-400:hover {
  color: #111827 !important;
}

/* Inputs and controls */
body.theme-light input,
body.theme-light textarea,
body.theme-light select,
body.theme-light button {
  color: var(--text) !important;
}

/* Special-case: links and buttons that were intentionally styled white-on-dark should keep contrast on light */
body.theme-light .btn,
body.theme-light .github-link,
body.theme-light .github-link__icon,
body.theme-light .github-link__text {
  color: var(--text) !important;
}

/* Semantic helper classes added by migration */
.hn-text { color: var(--text) !important; }
.hn-muted { color: var(--text-muted) !important; }
.hn-soft { color: var(--text-soft) !important; }
.hn-link { color: var(--text) !important; text-decoration: none; }
.hn-btn { color: #111827 !important; background-color: var(--brand) !important; }
.hn-btn-text { color: var(--text) !important; }
body.theme-light .hn-btn-text { color: #111827 !important; }
.hn-border { border-color: var(--border) !important; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 3rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.theme-toggle .theme-icon {
  font-size: 1rem;
  line-height: 1;
}

.theme-toggle .theme-label {
  font-size: 0.75rem;
  font-weight: 600;
}

/* Ensure interactive elements remain readable in light theme */
body.theme-light a,
body.theme-light button,
body.theme-light [role="button"] {
  color: var(--text) !important;
}

/* Buttons/links that rely on border-white utilities should get darker borders in light mode */
body.theme-light [class*="border-white"],
body.theme-light [class*="border-white/"] {
  border-color: var(--border) !important;
}

/* Ensure brand-background buttons show dark text on light theme */
body.theme-light .bg-indigo-500,
body.theme-light .bg-indigo-400,
body.theme-light .bg-indigo-500\/20 {
  color: #111827 !important;
}

/* Specific: 'Issues & roadmap' uses border and no text color - ensure contrast */
body.theme-light a[ href*="codeberg" ],
body.theme-light a[ href*="/issues" ] {
  color: var(--text) !important;
}
