/* Math4Humans - Clean, Accessible Design */

:root {
  /* Core colors - Warm Academic */
  --color-bg: #fffcf8;
  --color-bg-alt: #faf7f2;
  --color-bg-warm: #fff8f0;
  --color-text: #3d3935;
  --color-text-muted: #6b6560;
  --color-heading: #2a2724;

  /* Header colors (dark theme - Luminous Precision) */
  /* Progressive dark-to-light: darkest at top, lighter toward content */
  --header-bg: #0f1114;           /* Tier 1: Brand - darkest, anchors page */
  --header-bg-nav: #15181c;       /* Tier 2: Primary nav - slightly lighter */
  --header-bg-subjects: #1a1d22;  /* Tier 3: Subjects - medium */
  --header-bg-chapters: #22262d;  /* Tier 4: Chapters - lightest, closest to content */
  --header-text: #e8eaed;
  --header-text-muted: #7d838c;
  --header-accent: #f0b954;
  --header-accent-glow: rgba(240, 185, 84, 0.3);
  --header-highlight: #c9d1db;
  --header-highlight-muted: rgba(201, 209, 219, 0.12);

  /* Accent colors - bolder primary, refined secondary */
  --color-primary: #d4873f;
  --color-primary-dark: #b8702f;
  --color-primary-light: rgba(212, 135, 63, 0.12);
  --color-secondary: #6d5acd;
  --color-secondary-light: rgba(109, 90, 205, 0.12);

  /* Borders & shadows */
  --color-border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);

  /* Typography - Warm Academic */
  --font-body: "Source Serif 4", Georgia, serif;
  --font-ui: "DM Sans", system-ui, sans-serif;
  --font-display: "Playfair Display", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, monospace;

  /* Spacing - more generous */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2.5rem;
  --spacing-2xl: 3rem;
  --spacing-section: 4rem;

  /* Container */
  --container-max: 1100px;
  --content-max: 750px;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  color: var(--color-heading);
  font-weight: 600;
  line-height: 1.3;
  margin-top: var(--spacing-xl);
  margin-bottom: var(--spacing-md);
  scroll-margin-top: 300px; /* Offset for sticky header when navigating to anchors */
  position: relative;
}

/* Anchor link on headings */
.heading-anchor {
  position: absolute;
  left: -1.25em;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  width: 1em;
  height: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-border);
  text-decoration: none;
  transition: opacity 0.15s ease, color 0.15s ease, transform 0.15s ease;
  cursor: pointer;
}

.heading-anchor svg {
  width: 0.55em;
  height: 0.55em;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.heading-anchor:hover {
  color: var(--color-primary);
  text-decoration: none;
  transform: translateY(-50%) scale(1.1);
}

h1:hover .heading-anchor,
h2:hover .heading-anchor,
h3:hover .heading-anchor,
h4:hover .heading-anchor,
h5:hover .heading-anchor,
h6:hover .heading-anchor {
  opacity: 1;
}

/* Copied state */
.heading-anchor.copied {
  color: var(--color-primary);
}

.heading-anchor.copied svg {
  display: none;
}

.heading-anchor.copied::before {
  content: '✓';
  font-size: 0.7em;
  font-weight: 600;
}

/* Anchor offset for any element with an ID */
[id] {
  scroll-margin-top: 300px;
}

h1 { font-size: 2.25rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.375rem; }
h4 { font-size: 1.125rem; }

p {
  margin: 0 0 var(--spacing-md);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

/* Layout */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--spacing-lg);
}

.content-wrapper {
  max-width: var(--content-max);
}

/* ========================================
   Header - Luminous Precision Design
   ======================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  user-select: none;
  -webkit-user-select: none;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.03),
    0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Tier 1: Branding + Search */
.header-brand {
  background: var(--header-bg);
  padding: 1.25rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.brand-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-xl);
}

.site-branding {
  display: flex;
  align-items: center;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.logo-link:hover {
  text-decoration: none;
  opacity: 0.9;
}

.logo-icon {
  display: flex;
  align-items: center;
  transition: opacity 0.3s ease;
}

.logo-link:hover .logo-icon {
  opacity: 0.9;
}

.logo-icon img {
  width: 48px;
  height: 48px;
  display: block;
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.site-title {
  font-family: var(--font-display);
  font-size: 1.875rem;
  font-weight: 500;
  color: var(--header-text);
  margin: 0;
  line-height: 1;
  letter-spacing: -0.01em;
}

.site-tagline {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--header-text-muted);
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Search */
.header-search {
  flex-shrink: 0;
}

.search-form {
  display: flex;
  align-items: stretch;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: all 0.25s ease;
}

.search-form:focus-within {
  border-color: var(--header-highlight);
  box-shadow: 0 0 0 3px var(--header-highlight-muted);
}

.search-form input {
  background: transparent;
  border: none;
  padding: 0.625rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.875rem;
  width: 200px;
  color: var(--header-text);
  outline: none;
}

.search-form input::placeholder {
  color: var(--header-text-muted);
  font-weight: 400;
}

.search-form button {
  background: rgba(255, 255, 255, 0.04);
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  padding: 0.625rem 1rem;
  cursor: pointer;
  color: var(--header-text-muted);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: all 0.2s ease;
}

.search-form button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--header-text);
}

/* Tier 2: Primary navigation */
.header-nav {
  background: var(--header-bg-nav);
  padding: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.main-nav ul {
  display: flex;
  justify-content: center;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
}

.main-nav li {
  position: relative;
}

.main-nav a {
  display: block;
  color: var(--header-text-muted);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.875rem 1.75rem;
  transition: all 0.2s ease;
  position: relative;
}

.main-nav a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 2px;
  background: var(--header-accent);
  transition: width 0.25s ease;
  box-shadow: 0 0 8px var(--header-accent-glow);
}

.main-nav a:hover {
  color: var(--header-text);
  text-decoration: none;
}

.main-nav a:hover::after {
  width: 24px;
}

.main-nav a.active {
  color: var(--header-text);
  text-decoration: none;
}

.main-nav a.active::after {
  width: 24px;
}

/* Tier 3: Subject navigation (scrollable) */
.header-subjects {
  background: var(--header-bg-subjects);
  display: flex;
  align-items: center;
  position: relative;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.subject-scroll-btn {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 48px;
  background: linear-gradient(90deg, var(--header-bg-subjects) 50%, transparent);
  border: none;
  color: var(--header-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.subject-scroll-left {
  left: 0;
}

.subject-scroll-right {
  right: 0;
  background: linear-gradient(-90deg, var(--header-bg-subjects) 50%, transparent);
}

.subject-scroll-btn svg {
  transition: transform 0.2s ease;
}

.subject-scroll-btn:hover {
  color: var(--header-text);
}

.subject-scroll-btn:hover svg {
  transform: scale(1.1);
}

.subject-scroll-btn:active svg {
  transform: scale(0.95);
}


.subject-scroll-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

.subject-nav {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: smooth;
}

.subject-nav::-webkit-scrollbar {
  display: none;
}

.subject-categories {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  white-space: nowrap;
  width: max-content;
}

.subject-categories li {
  flex-shrink: 0;
}

.subject-categories a {
  display: block;
  color: var(--header-text-muted);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  transition: all 0.2s ease;
  border-radius: 6px;
  position: relative;
}

.subject-categories a:hover {
  color: var(--header-text);
  background: rgba(255, 255, 255, 0.04);
  text-decoration: none;
}

.subject-categories a.active {
  color: var(--header-bg);
  background: var(--header-accent);
  text-decoration: none;
  box-shadow: 0 2px 8px var(--header-accent-glow);
}

/* Tier 4: Chapter navigation (scrollable) */
.header-chapters {
  background: var(--header-bg-chapters);
  display: flex;
  align-items: center;
  position: relative;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.chapter-scroll-btn {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 48px;
  background: linear-gradient(90deg, var(--header-bg-chapters) 50%, transparent);
  border: none;
  color: var(--header-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.chapter-scroll-left {
  left: 0;
}

.chapter-scroll-right {
  right: 0;
  background: linear-gradient(-90deg, var(--header-bg-chapters) 50%, transparent);
}

.chapter-scroll-btn svg {
  transition: transform 0.2s ease;
}

.chapter-scroll-btn:hover {
  color: var(--header-text);
}

.chapter-scroll-btn:hover svg {
  transform: scale(1.1);
}

.chapter-scroll-btn:active svg {
  transform: scale(0.95);
}

.chapter-scroll-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

.chapter-nav {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: smooth;
}

.chapter-nav::-webkit-scrollbar {
  display: none;
}

.chapter-list {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  list-style: none;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  white-space: nowrap;
  width: max-content;
}

.chapter-list li {
  flex-shrink: 0;
}

.chapter-list a {
  display: block;
  color: var(--header-text-muted);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 400;
  padding: 0.4rem 0.875rem;
  transition: all 0.2s ease;
  border-radius: 4px;
  border: 1px solid transparent;
}

.chapter-list a:hover {
  color: var(--header-text);
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

.chapter-list a.active {
  color: var(--header-accent);
  background: rgba(240, 185, 84, 0.12);
  border-color: var(--header-accent);
  font-weight: 500;
  text-decoration: none;
}

/* Hero Section */
.hero {
  background: linear-gradient(135deg, var(--color-bg-alt) 0%, #eef2ff 100%);
  padding: var(--spacing-2xl) 0;
  text-align: center;
  border-bottom: 1px solid var(--color-border);
}

.hero h1 {
  font-size: 2.5rem;
  margin-top: 0;
  margin-bottom: var(--spacing-md);
}

.hero .lead {
  font-size: 1.25rem;
  color: var(--color-text-muted);
  max-width: 600px;
  margin: 0 auto var(--spacing-xl);
}

/* Main Content */
main {
  padding: var(--spacing-2xl) 0;
  min-height: 60vh;
}

/* Cards for Subjects */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--spacing-lg);
  margin: var(--spacing-xl) 0;
}

.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--spacing-lg);
  transition: all 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.card h3 {
  margin-top: 0;
  color: var(--color-primary);
}

.card p {
  color: var(--color-text-muted);
  margin-bottom: 0;
}

/* Subject List */
.subject-list {
  list-style: none;
  padding: 0;
  margin: var(--spacing-xl) 0;
}

.subject-list li {
  border-bottom: 1px solid var(--color-border);
}

.subject-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md) 0;
  color: var(--color-text);
}

.subject-list a:hover {
  color: var(--color-primary);
  text-decoration: none;
}

.subject-list .arrow {
  color: var(--color-text-muted);
  transition: transform 0.2s ease;
}

.subject-list a:hover .arrow {
  transform: translateX(4px);
  color: var(--color-primary);
}

/* Buttons */
.btn {
  display: inline-block;
  font-family: var(--font-ui);
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  color: white;
  text-decoration: none;
}

.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
}

.btn-secondary:hover {
  background: var(--color-primary);
  color: white;
  text-decoration: none;
}

/* Animation Keyframes */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Article/Content Styling */
article {
  max-width: var(--content-max);
}

article h1 {
  margin-top: 0;
}

/* Page load animations - staggered */
article > h1 {
  animation: fadeInUp 0.4s ease-out backwards;
  animation-delay: 0s;
}

article > .lead {
  animation: fadeInUp 0.4s ease-out backwards;
  animation-delay: 0.05s;
}

article > .toc-inline {
  animation: fadeInUp 0.4s ease-out backwards;
  animation-delay: 0.1s;
}

article > .content {
  animation: fadeInUp 0.4s ease-out backwards;
  animation-delay: 0.15s;
}

article img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: var(--spacing-lg) 0;
}

/* Section headers with visual weight */
article h2 {
  margin-top: var(--spacing-section);
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
  position: relative;
}

article h2::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  width: 3rem;
  height: 3px;
  background: var(--color-primary);
}

/* Math content styling - Elevated Design */
.math-example {
  background: linear-gradient(135deg, var(--color-bg-warm) 0%, #fff8f0 100%);
  border-radius: 16px;
  padding: 2rem 2.5rem;
  margin: 2.5rem 0;
  box-shadow:
    0 1px 3px rgba(0,0,0,0.04),
    0 8px 24px rgba(180, 130, 60, 0.08);
  position: relative;
  border: none;
  border-left: 4px solid var(--color-primary);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.math-example:hover {
  transform: translateY(-2px);
  box-shadow:
    0 2px 4px rgba(0,0,0,0.04),
    0 12px 32px rgba(180, 130, 60, 0.12);
}

/* Difficulty badges (top-right corner) */
.math-example.difficulty-easy::before {
  content: 'Easy';
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.25rem 0.75rem;
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.math-example.difficulty-easy {
  border-left-color: #10b981;
}

.math-example.difficulty-medium::before {
  content: 'Medium';
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.25rem 0.75rem;
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.math-example.difficulty-medium {
  border-left-color: #f59e0b;
}

.math-example.difficulty-hard::before {
  content: 'Hard';
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.25rem 0.75rem;
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.math-example.difficulty-hard {
  border-left-color: #ef4444;
}

/* Self-test problems - Interactive Cards */
.self-test {
  background: linear-gradient(135deg, #f8f5ff 0%, #f3eeff 100%);
  border: 1px solid rgba(109, 90, 205, 0.15);
  border-radius: 16px;
  padding: 2rem;
  margin: 2.5rem 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.self-test:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(109, 90, 205, 0.12);
}

.self-test h4 {
  color: var(--color-secondary);
  margin-top: 0;
  font-family: var(--font-ui);
}

/* Styled reveal button */
.self-test details summary {
  cursor: pointer;
  padding: 0.75rem 1.25rem;
  background: rgba(109, 90, 205, 0.08);
  border-radius: 8px;
  font-family: var(--font-ui);
  font-weight: 500;
  transition: all 0.2s ease;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.self-test details summary::-webkit-details-marker {
  display: none;
}

.self-test details summary::after {
  content: '▸';
  transition: transform 0.2s ease;
}

.self-test details[open] summary::after {
  transform: rotate(90deg);
}

.self-test details summary:hover {
  background: rgba(109, 90, 205, 0.15);
}

.self-test details[open] > *:not(summary) {
  animation: fadeInUp 0.3s ease-out;
}

/* Code blocks */
pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: var(--spacing-lg);
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-bg-alt);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}

pre code {
  background: none;
  padding: 0;
}

/* Tables - Warm Academic Style */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 12px;
  overflow: hidden;
  margin: 2rem 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

th {
  background: var(--color-bg-alt);
  font-family: var(--font-ui);
  font-weight: 600;
  text-align: left;
  padding: 1rem 1.25rem;
  color: var(--color-heading);
}

td {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
}

tr:nth-child(even) td {
  background: rgba(250, 247, 242, 0.5);
}

/* Blockquotes - Definition Callouts */
blockquote {
  background: linear-gradient(90deg, var(--color-primary-light) 0%, transparent 100%);
  border-left: 4px solid var(--color-primary);
  border-radius: 0 12px 12px 0;
  padding: 1.5rem 2rem;
  margin: 2rem 0;
  font-style: normal;
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* Footer */
.site-footer {
  background: var(--color-bg-alt);
  border-top: 1px solid var(--color-border);
  padding: var(--spacing-2xl) 0 var(--spacing-lg);
  margin-top: var(--spacing-2xl);
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: var(--spacing-xl);
}

.footer-section h4 {
  margin-top: 0;
  color: var(--color-heading);
  font-size: 1rem;
}

.footer-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.footer-section li {
  margin-bottom: var(--spacing-xs);
}

/* Multi-column subjects list in footer */
.footer-subjects ul {
  column-count: 3;
  column-gap: var(--spacing-xl);
}

.footer-subjects li {
  break-inside: avoid;
}

.footer-section a {
  color: var(--color-text-muted);
}

.footer-section a:hover {
  color: var(--color-primary);
}

.footer-bottom {
  margin-top: var(--spacing-xl);
  padding-top: var(--spacing-lg);
  border-top: 1px solid var(--color-border);
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Breadcrumbs */
.breadcrumbs {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: var(--spacing-lg);
}

.breadcrumbs a {
  color: var(--color-text-muted);
}

.breadcrumbs a:hover {
  color: var(--color-primary);
}

.breadcrumbs span {
  margin: 0 var(--spacing-sm);
}

/* Article Layout - Grid for sidebar TOC */
.article-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

/* Post navigation */
.post-navigation {
  display: flex;
  justify-content: space-between;
  margin-top: var(--spacing-2xl);
  padding-top: var(--spacing-lg);
  border-top: 1px solid var(--color-border);
}

/* Table of Contents */
.toc {
  font-family: var(--font-ui);
  background: var(--color-bg-alt);
  border-radius: 8px;
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
}

.toc h4 {
  margin-top: 0;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.toc ul {
  list-style: none;
  padding-left: var(--spacing-md);
  margin: 0;
}

.toc li {
  margin-bottom: var(--spacing-xs);
}

/* Hide sidebar TOC by default (mobile) */
.toc-sidebar {
  display: none;
}

/* Wide screen: sidebar TOC */
@media (min-width: 1100px) {
  .article-layout {
    grid-template-columns: 1fr 240px;
  }

  /* Hide inline TOC on wide screens */
  .toc-inline {
    display: none;
  }

  /* Show sidebar TOC */
  .toc-sidebar {
    display: block;
    position: relative;
  }

  .toc-sidebar .toc {
    position: sticky;
    top: 305px;
    background: transparent;
    border-left: 2px solid var(--color-border);
    border-radius: 0;
    padding: 0 0 0 1.5rem;
    margin-bottom: 0;
  }

  .toc-sidebar .toc h4 {
    font-size: 0.75rem;
  }

  .toc-sidebar .toc ul {
    padding-left: 0;
  }

  .toc-sidebar .toc a {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    transition: color 0.2s ease, border-color 0.2s ease;
    display: block;
    padding: 0.25rem 0;
    border-left: 2px solid transparent;
    margin-left: -1.5rem;
    padding-left: calc(1.5rem - 2px);
  }

  .toc-sidebar .toc a:hover {
    color: var(--color-primary);
    text-decoration: none;
  }

  .toc-sidebar .toc a.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    font-weight: 500;
  }
}

/* Responsive */
@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  /* Header responsive - Luminous Precision */
  /* On mobile, only the brand/logo is sticky, not search or nav */
  .site-header {
    position: relative;
  }

  /* Split header-brand: logo stays sticky, search scrolls away */
  .header-brand {
    padding: 0;
  }

  .header-brand .brand-inner {
    flex-direction: column;
    gap: 0;
  }

  /* Pin branding (logo + title) to top of viewport on mobile */
  .site-branding {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--header-bg);
    padding: 0.75rem var(--spacing-lg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }

  /* Add padding to header-brand to account for fixed branding height */
  .header-brand {
    padding-top: 60px;
  }

  /* Search is not sticky - scrolls with page */
  .header-brand .header-search {
    padding: 0.75rem var(--spacing-lg);
    margin: 0 calc(-1 * var(--spacing-lg));
    width: calc(100% + 2 * var(--spacing-lg));
    background: var(--header-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
  }

  .logo-link {
    flex-direction: row;
    text-align: left;
    gap: 0.75rem;
  }

  .logo-icon img {
    width: 36px;
    height: 36px;
  }

  .site-title {
    font-size: 1.5rem;
  }

  .site-tagline {
    font-size: 0.6875rem;
  }

  .header-search {
    width: 100%;
  }

  .search-form {
    width: 100%;
  }

  .search-form input {
    flex: 1;
    width: auto;
  }

  .main-nav a {
    padding: 0.75rem 1.25rem;
    font-size: 0.75rem;
  }

  .subject-scroll-btn {
    width: 36px;
    min-height: 40px;
  }

  .subject-categories a {
    font-size: 0.75rem;
    padding: 0.4375rem 0.75rem;
  }

  .subtopic-nav a {
    font-size: 0.6875rem;
    padding: 0.3125rem 0.625rem;
  }

  .main-nav ul {
    gap: var(--spacing-md);
  }

  /* Scrollable subject nav on mobile */
  .subject-scroll-btn {
    width: 32px;
  }

  .subject-categories a {
    font-size: 0.8rem;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .subtopic-nav ul {
    gap: var(--spacing-sm);
  }

  .hero h1 {
    font-size: 2rem;
  }

  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.5rem; }

  .card-grid {
    grid-template-columns: 1fr;
  }

  /* Footer - stack on mobile */
  .footer-inner {
    flex-direction: column;
  }

  /* Footer subjects - 2 columns on tablet */
  .footer-subjects ul {
    column-count: 2;
  }
}

@media (max-width: 480px) {
  .footer-subjects ul {
    column-count: 1;
  }
}

/* Utility classes */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-0 { margin-bottom: 0; }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }

/* Search Page */
.search-page {
  padding: var(--spacing-2xl) 0;
  min-height: 60vh;
}

.search-page h1 {
  margin-top: 0;
  margin-bottom: var(--spacing-xl);
}

#search {
  max-width: 800px;
}

/* Pagefind UI Customization */
.pagefind-ui {
  --pagefind-ui-scale: 1;
  --pagefind-ui-primary: var(--color-primary);
  --pagefind-ui-text: var(--color-text);
  --pagefind-ui-background: var(--color-bg);
  --pagefind-ui-border: var(--color-border);
  --pagefind-ui-tag: var(--color-bg-alt);
  --pagefind-ui-border-width: 2px;
  --pagefind-ui-border-radius: 8px;
  --pagefind-ui-font: var(--font-sans);
}

/* Pagefind UI is used as-is with CSS variable customization above */

.pagefind-ui__results-area {
  margin-top: 0;
}

.pagefind-ui__result {
  padding: var(--spacing-lg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: var(--spacing-md);
  background: var(--color-bg);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pagefind-ui__result:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.pagefind-ui__result-link {
  color: var(--color-heading);
  font-weight: 600;
  font-size: 1.125rem;
  text-decoration: none;
}

.pagefind-ui__result-link:hover {
  color: var(--color-primary);
}

.pagefind-ui__result-excerpt {
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-top: var(--spacing-sm);
}

.pagefind-ui__result-excerpt mark {
  background: rgba(240, 185, 84, 0.3);
  color: var(--color-text);
  padding: 0.1em 0.2em;
  border-radius: 2px;
}

.pagefind-ui__message {
  color: var(--color-text-muted);
  font-size: 1rem;
}

.pagefind-ui__button {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
}

.pagefind-ui__button:hover {
  background: var(--color-primary-dark);
}

/* ========================================
   Dark Mode Support
   ======================================== */
@media (prefers-color-scheme: dark) {
  :root {
    /* Core colors - dark mode */
    --color-bg: #1a1d23;
    --color-bg-alt: #22262d;
    --color-bg-warm: #252a30;
    --color-text: #e0e4ea;
    --color-text-muted: #9ca3af;
    --color-heading: #f3f4f6;

    /* Borders & shadows - dark mode */
    --color-border: #374151;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);

    /* Accent colors - slightly brighter for dark mode */
    --color-primary: #e9a04a;
    --color-primary-dark: #d4873f;
    --color-primary-light: rgba(233, 160, 74, 0.15);
    --color-secondary: #8b7ddf;
    --color-secondary-light: rgba(139, 125, 223, 0.15);
  }

  /* Hero section - dark mode */
  .hero {
    background: linear-gradient(135deg, #1e2128 0%, #252a33 100%);
    border-bottom-color: var(--color-border);
  }

  /* Cards - dark mode */
  .card {
    background: var(--color-bg-alt);
    border-color: var(--color-border);
  }

  .card:hover {
    border-color: var(--color-primary);
  }

  /* Math examples - dark mode */
  .math-example {
    background: linear-gradient(135deg, #252a30 0%, #2a2f36 100%);
    box-shadow:
      0 1px 3px rgba(0,0,0,0.2),
      0 8px 24px rgba(0, 0, 0, 0.3);
  }

  .math-example:hover {
    box-shadow:
      0 2px 4px rgba(0,0,0,0.2),
      0 12px 32px rgba(0, 0, 0, 0.4);
  }

  /* Difficulty badges - dark mode */
  .math-example.difficulty-easy::before {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
  }

  .math-example.difficulty-medium::before {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
  }

  .math-example.difficulty-hard::before {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
  }

  /* Self-test problems - dark mode */
  .self-test {
    background: linear-gradient(135deg, #1e1b2e 0%, #252236 100%);
    border-color: rgba(139, 125, 223, 0.2);
  }

  .self-test:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  }

  .self-test h4 {
    color: #a89eff;
  }

  .self-test details summary {
    background: rgba(139, 125, 223, 0.12);
  }

  .self-test details summary:hover {
    background: rgba(139, 125, 223, 0.2);
  }

  /* Code blocks already have dark bg, just ensure consistency */
  code {
    background: #2d3139;
  }

  /* Tables - dark mode */
  table {
    background: var(--color-bg-alt);
    border-color: var(--color-border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }

  th {
    background: #2a2f36;
  }

  td {
    border-top-color: var(--color-border);
  }

  tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
  }

  /* Blockquotes - dark mode */
  blockquote {
    background: linear-gradient(90deg, var(--color-primary-light) 0%, transparent 100%);
  }

  /* TOC - dark mode */
  .toc {
    background: var(--color-bg-alt);
  }

  .toc-sidebar .toc {
    border-left-color: var(--color-border);
  }

  /* Footer - dark mode */
  .site-footer {
    background: var(--color-bg-alt);
    border-top-color: var(--color-border);
  }

  /* Pagefind - dark mode */
  .pagefind-ui {
    --pagefind-ui-text: var(--color-text);
    --pagefind-ui-background: var(--color-bg);
    --pagefind-ui-border: var(--color-border);
    --pagefind-ui-tag: var(--color-bg-alt);
  }

  .pagefind-ui__result {
    background: var(--color-bg-alt);
    border-color: var(--color-border);
  }

  .pagefind-ui__result-excerpt mark {
    background: rgba(240, 185, 84, 0.25);
    color: var(--color-text);
  }

  /* Details/summary - dark mode */
  details {
    background: var(--color-bg-alt);
    border-color: var(--color-border);
  }

  summary {
    background: rgba(255, 255, 255, 0.05);
  }

  summary:hover {
    background: rgba(255, 255, 255, 0.08);
  }
}
