/* =============================================================
   maths.xueai.pro — Design System v2
   Clean academic + warm trustworthy
   Light / Dark theme with toggle
   ============================================================= */

/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Noto+Sans+SC:wght@400;500;700&display=swap');

/* ── Light tokens (default) ── */
:root {
  --c-primary: oklch(48% 0.16 255);
  --c-primary-light: oklch(92% 0.04 255);
  --c-primary-hover: oklch(42% 0.18 255);
  --c-accent: oklch(45% 0.18 310);
  --c-accent-light: oklch(92% 0.05 310);

  --c-bg: oklch(97.5% 0.005 255);
  --c-surface: oklch(99% 0.003 255);
  --c-surface-raised: oklch(100% 0.002 255);
  --c-border: oklch(88% 0.01 255);
  --c-border-subtle: oklch(92% 0.008 255);
  --c-text: oklch(22% 0.015 255);
  --c-text-secondary: oklch(45% 0.01 255);
  --c-text-tertiary: oklch(58% 0.008 255);

  --c-success: oklch(55% 0.15 145);
  --c-error: oklch(55% 0.2 25);
  --c-warning: oklch(65% 0.15 75);

  /* Type scale — major third */
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.125rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.875rem;
  --fs-3xl: 2.25rem;
  --fs-4xl: 3rem;

  /* Spacing — 4px base */
  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-5: 1.25rem; --sp-6: 1.5rem; --sp-8: 2rem; --sp-10: 2.5rem;
  --sp-12: 3rem; --sp-16: 4rem; --sp-20: 5rem; --sp-24: 6rem;

  --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-xl: 24px;

  --shadow-sm: 0 1px 2px oklch(22% 0.01 255 / 0.06);
  --shadow-md: 0 2px 8px oklch(22% 0.01 255 / 0.08), 0 1px 2px oklch(22% 0.01 255 / 0.04);
  --shadow-lg: 0 4px 16px oklch(22% 0.01 255 / 0.1), 0 2px 4px oklch(22% 0.01 255 / 0.05);

  --ff-display: 'DM Sans', 'Noto Sans SC', system-ui, sans-serif;
  --ff-body: 'DM Sans', 'Noto Sans SC', system-ui, sans-serif;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-normal: 250ms;

  /* Icon color */
  --c-icon: oklch(45% 0.01 255);
}

/* ── Dark tokens ── */
[data-theme="dark"] {
  --c-bg: oklch(14% 0.015 255);
  --c-surface: oklch(18% 0.02 255);
  --c-surface-raised: oklch(22% 0.02 255);
  --c-border: oklch(28% 0.02 255);
  --c-border-subtle: oklch(24% 0.015 255);
  --c-text: oklch(92% 0.005 255);
  --c-text-secondary: oklch(68% 0.01 255);
  --c-text-tertiary: oklch(52% 0.01 255);
  --c-primary: oklch(62% 0.14 255);
  --c-primary-light: oklch(22% 0.06 255);
  --c-primary-hover: oklch(68% 0.16 255);
  --c-accent: oklch(62% 0.16 310);
  --c-accent-light: oklch(22% 0.06 310);
  --c-icon: oklch(68% 0.01 255);
  --shadow-sm: 0 1px 2px oklch(5% 0.01 255 / 0.3);
  --shadow-md: 0 2px 8px oklch(5% 0.01 255 / 0.3);
  --shadow-lg: 0 4px 16px oklch(5% 0.01 255 / 0.3);
}

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Base ── */
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--ff-body);
  font-size: var(--fs-base);
  line-height: 1.65;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--dur-normal), color var(--dur-normal);
}

/* ── Typography ── */
h1, h2, h3, h4 {
  font-family: var(--ff-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--c-text);
  letter-spacing: -0.015em;
}
h1 { font-size: var(--fs-3xl); margin-bottom: var(--sp-4); }
h2 { font-size: var(--fs-xl); margin-bottom: var(--sp-3); }
h3 { font-size: var(--fs-lg); margin-bottom: var(--sp-2); }
h4 { font-size: var(--fs-md); margin-bottom: var(--sp-2); }

p { margin-bottom: var(--sp-4); max-width: 65ch; }
p:last-child { margin-bottom: 0; }

a { color: var(--c-primary); text-decoration: none; transition: color var(--dur-fast) var(--ease-out); }
a:hover { color: var(--c-primary-hover); }
strong { font-weight: 600; }

/* ── SVG Icons ── */
.icon-svg {
  width: 20px; height: 20px;
  fill: none; stroke: var(--c-icon);
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.icon-svg-lg { width: 24px; height: 24px; }
.icon-svg-sm { width: 16px; height: 16px; }

/* ── Theme toggle ── */
.theme-toggle {
  position: fixed;
  bottom: var(--sp-4);
  right: var(--sp-4);
  z-index: 999;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all var(--dur-fast) var(--ease-out);
}
.theme-toggle:hover { border-color: var(--c-primary); box-shadow: var(--shadow-lg); }
.theme-toggle svg { width: 18px; height: 18px; stroke: var(--c-icon); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-6);
  font-family: var(--ff-body); font-size: var(--fs-sm); font-weight: 600; line-height: 1;
  border: none; border-radius: var(--r-md); cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out); text-decoration: none;
}
.btn-primary { background: var(--c-primary); color: white; }
.btn-primary:hover { background: var(--c-primary-hover); color: white; transform: translateY(-1px); }
.btn-secondary { background: var(--c-primary-light); color: var(--c-primary); }
.btn-secondary:hover { background: oklch(88% 0.06 255); }
.btn-accent { background: var(--c-accent); color: white; }
.btn-accent:hover { background: oklch(40% 0.2 310); color: white; }
.btn-ghost { background: transparent; color: var(--c-text-secondary); border: 1px solid var(--c-border); }
.btn-ghost:hover { background: var(--c-surface); border-color: var(--c-primary); color: var(--c-primary); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-lg { padding: var(--sp-4) var(--sp-8); font-size: var(--fs-base); }

/* ── Cards ── */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border-subtle);
  border-radius: var(--r-lg); padding: var(--sp-6);
  transition: all var(--dur-normal) var(--ease-out);
}
.card-interactive:hover { border-color: var(--c-primary); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-interactive { cursor: pointer; text-decoration: none; color: inherit; display: block; }

/* ── Inputs ── */
.input {
  width: 100%; padding: var(--sp-3) var(--sp-4);
  font-family: var(--ff-body); font-size: var(--fs-base);
  color: var(--c-text); background: var(--c-bg);
  border: 1.5px solid var(--c-border); border-radius: var(--r-md); outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px oklch(48% 0.16 255 / 0.12); }
.input::placeholder { color: var(--c-text-tertiary); }
label { display: block; font-size: var(--fs-sm); font-weight: 500; color: var(--c-text-secondary); margin-bottom: var(--sp-1); }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 700;
  padding: 1px 8px; border-radius: 99px;
  line-height: 1.8; vertical-align: middle; white-space: nowrap;
}
.badge-live { background: oklch(90% 0.08 145); color: oklch(35% 0.12 145); }
.badge-soon { background: oklch(90% 0.06 255); color: oklch(40% 0.12 255); }
.badge-wip { background: oklch(90% 0.06 75); color: oklch(42% 0.12 75); }
.badge-new { background: oklch(90% 0.06 310); color: oklch(40% 0.14 310); }
[data-theme="dark"] .badge-live { background: oklch(25% 0.06 145); color: oklch(72% 0.1 145); }
[data-theme="dark"] .badge-soon { background: oklch(25% 0.05 255); color: oklch(68% 0.08 255); }
[data-theme="dark"] .badge-wip { background: oklch(25% 0.05 75); color: oklch(68% 0.08 75); }
[data-theme="dark"] .badge-new { background: oklch(25% 0.05 310); color: oklch(68% 0.1 310); }

/* ── Layout ── */
.container { max-width: 960px; margin: 0 auto; padding: 0 var(--sp-6); }
.container-narrow { max-width: 640px; margin: 0 auto; padding: 0 var(--sp-6); }
.container-wide { max-width: 1120px; margin: 0 auto; padding: 0 var(--sp-6); }

.flex { display: flex; } .flex-col { flex-direction: column; } .flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; } .justify-center { justify-content: center; }
.gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); } .gap-6 { gap: var(--sp-6); }
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.text-center { text-align: center; }
.text-sm { font-size: var(--fs-sm); } .text-xs { font-size: var(--fs-xs); }
.text-secondary { color: var(--c-text-secondary); } .text-tertiary { color: var(--c-text-tertiary); }

.mt-2 { margin-top: var(--sp-2); } .mt-4 { margin-top: var(--sp-4); } .mt-6 { margin-top: var(--sp-6); } .mt-8 { margin-top: var(--sp-8); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-4 { margin-bottom: var(--sp-4); } .mb-6 { margin-bottom: var(--sp-6); } .mb-8 { margin-bottom: var(--sp-8); }
.py-8 { padding-top: var(--sp-8); padding-bottom: var(--sp-8); }
.py-12 { padding-top: var(--sp-12); padding-bottom: var(--sp-12); }

/* ── KaTeX ── */
.katex { font-size: 1.05em !important; }

/* ── Back to home link ── */
.back-home {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm); font-weight: 500; color: var(--c-text-tertiary);
  text-decoration: none; padding: var(--sp-2) 0;
  transition: color var(--dur-fast);
}
.back-home:hover { color: var(--c-primary); }
.back-home::before { content: '\2190'; }

/* ── Footer ── */
.site-footer {
  text-align: center; padding: var(--sp-10) 0 var(--sp-6);
  font-size: var(--fs-xs); color: var(--c-text-tertiary);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  h1 { font-size: var(--fs-2xl); }
  h2 { font-size: var(--fs-lg); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .container, .container-narrow, .container-wide { padding: 0 var(--sp-4); }
  .hide-mobile { display: none; }
}
@media (max-width: 480px) {
  h1 { font-size: var(--fs-xl); }
  :root { --fs-base: 0.9375rem; }
}

/* ── AIMO lecture colored boxes ─ dark mode overrides ── */
[data-theme="dark"] .trick { background: oklch(22% 0.04 25); }
[data-theme="dark"] .trick .tag { color: oklch(70% 0.15 25); }
[data-theme="dark"] .strategy { background: oklch(22% 0.04 200); }
[data-theme="dark"] .strategy .tag { color: oklch(70% 0.12 200); }
[data-theme="dark"] .review { background: oklch(22% 0.04 145); }
[data-theme="dark"] .review .tag { color: oklch(70% 0.12 145); }
[data-theme="dark"] .thm .tag { color: oklch(70% 0.12 145); }
[data-theme="dark"] .defn { background: oklch(22% 0.04 255); }
[data-theme="dark"] .exm { background: oklch(22% 0.04 75); }

/* ── Motion ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Page load fade */
body { animation: fadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1); }

/* Staggered card/item entrance */
.nav-card, .lesson, .slide-link, .mod-card, .card, .project-card, .stat-box {
  opacity: 0;
  animation: fadeUp 500ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: calc(var(--i, 0) * 60ms);
}

/* Auto-assign stagger index via nth-child */
.nav-card:nth-child(1), .lesson:nth-child(1), .mod-card:nth-child(1), .slide-link:nth-child(1) { --i: 0; }
.nav-card:nth-child(2), .lesson:nth-child(2), .mod-card:nth-child(2), .slide-link:nth-child(2) { --i: 1; }
.nav-card:nth-child(3), .lesson:nth-child(3), .mod-card:nth-child(3), .slide-link:nth-child(3) { --i: 2; }
.nav-card:nth-child(4), .lesson:nth-child(4), .mod-card:nth-child(4), .slide-link:nth-child(4) { --i: 3; }
.nav-card:nth-child(5), .lesson:nth-child(5), .mod-card:nth-child(5), .slide-link:nth-child(5) { --i: 4; }
.nav-card:nth-child(6), .lesson:nth-child(6), .mod-card:nth-child(6), .slide-link:nth-child(6) { --i: 5; }
.nav-card:nth-child(7), .lesson:nth-child(7), .mod-card:nth-child(7), .slide-link:nth-child(7) { --i: 6; }
.nav-card:nth-child(8), .lesson:nth-child(8), .mod-card:nth-child(8), .slide-link:nth-child(8) { --i: 7; }
.lesson:nth-child(9) { --i: 8; }
.lesson:nth-child(10) { --i: 9; }
.lesson:nth-child(11) { --i: 10; }
.lesson:nth-child(12) { --i: 11; }

/* Section headers fade in */
.section-title, .chapter-title, .section-header, h1, h2 {
  animation: fadeIn 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Print ── */
@media print {
  body { background: white; color: black; }
  .no-print, .theme-toggle { display: none !important; }
}

/* ── Dark mode overrides for legacy inline styles ──
   These target common hardcoded colors in pages that haven't been
   fully migrated to CSS variables yet. */
[data-theme="dark"] body { background-color: var(--c-bg) !important; color: var(--c-text) !important; }
[data-theme="dark"] h1, [data-theme="dark"] h2, [data-theme="dark"] h3, [data-theme="dark"] h4 { color: var(--c-text) !important; }
[data-theme="dark"] p, [data-theme="dark"] li, [data-theme="dark"] td, [data-theme="dark"] th, [data-theme="dark"] span, [data-theme="dark"] div { color: inherit; }
[data-theme="dark"] a { color: var(--c-primary); }

/* Backgrounds */
[data-theme="dark"] section,
[data-theme="dark"] .box,
[data-theme="dark"] .card,
[data-theme="dark"] .sol,
[data-theme="dark"] .lesson,
[data-theme="dark"] .overview-card,
[data-theme="dark"] .answer-cell {
  background-color: var(--c-surface) !important;
  border-color: var(--c-border) !important;
}

/* Common white backgrounds */
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#ffffff"],
[data-theme="dark"] [style*="background-color:#fff"],
[data-theme="dark"] [style*="background-color: #fff"],
[data-theme="dark"] [style*="background-color: white"],
[data-theme="dark"] [style*="background:#f8f9fa"],
[data-theme="dark"] [style*="background: #f8f9fa"],
[data-theme="dark"] [style*="background:#fafafa"],
[data-theme="dark"] [style*="background: #fafafa"] {
  background-color: var(--c-surface) !important;
}

/* Info/highlight boxes */
[data-theme="dark"] .box.info { background-color: var(--c-primary-light) !important; }
[data-theme="dark"] .pr { background-color: var(--c-accent-light) !important; }

/* Borders */
[data-theme="dark"] [style*="border"] { border-color: var(--c-border) !important; }
[data-theme="dark"] hr { border-color: var(--c-border) !important; opacity: 0.5; }
[data-theme="dark"] table, [data-theme="dark"] tr, [data-theme="dark"] td, [data-theme="dark"] th {
  border-color: var(--c-border) !important;
}

/* Input fields */
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background-color: var(--c-bg) !important;
  color: var(--c-text) !important;
  border-color: var(--c-border) !important;
}

/* Code blocks */
[data-theme="dark"] pre, [data-theme="dark"] code {
  background-color: var(--c-surface-raised) !important;
  color: var(--c-text) !important;
}

/* Print bar / sticky headers */
[data-theme="dark"] .print-bar {
  background: var(--c-bg) !important;
  border-color: var(--c-border) !important;
}
[data-theme="dark"] .print-bar button,
[data-theme="dark"] .print-bar a {
  background: var(--c-surface) !important;
  color: var(--c-text-secondary) !important;
  border-color: var(--c-border) !important;
}

/* Slides - common reveal.js / custom slide overrides */
[data-theme="dark"] .slide,
[data-theme="dark"] .reveal .slides section {
  background-color: var(--c-bg) !important;
  color: var(--c-text) !important;
}

/* Legacy text colors */
[data-theme="dark"] [style*="color:#333"],
[data-theme="dark"] [style*="color: #333"],
[data-theme="dark"] [style*="color:#1a1a1a"],
[data-theme="dark"] [style*="color: #1a1a1a"],
[data-theme="dark"] [style*="color:black"],
[data-theme="dark"] [style*="color: black"] {
  color: var(--c-text) !important;
}
[data-theme="dark"] [style*="color:#666"],
[data-theme="dark"] [style*="color: #666"],
[data-theme="dark"] [style*="color:#64748b"],
[data-theme="dark"] [style*="color: #64748b"],
[data-theme="dark"] [style*="color:#888"],
[data-theme="dark"] [style*="color: #888"],
[data-theme="dark"] [style*="color:#999"],
[data-theme="dark"] [style*="color: #999"],
[data-theme="dark"] [style*="color:#94a3b8"],
[data-theme="dark"] [style*="color: #94a3b8"] {
  color: var(--c-text-secondary) !important;
}
