:root {
  --bg: #fafafa;
  --bg-secondary: #f0f0f0;
  --text: #1a1a1a;
  --text-secondary: #666;
  --accent: #2563eb;
  --border: #e5e5e5;
  --code-bg: #f5f5f5;
  --max-width: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --bg-secondary: #141414;
    --text: #e5e5e5;
    --text-secondary: #999;
    --accent: #60a5fa;
    --border: #2a2a2a;
    --code-bg: #1a1a1a;
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Hide scrollbars but keep functionality */
::-webkit-scrollbar {
  display: none;
}

html {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

h1 {
  font-size: 2rem;
  margin-top: 0;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.2rem;
  color: var(--text-secondary);
}

p {
  margin-bottom: 1.25rem;
}

/* Links */
a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Navigation */
nav {
  padding: 0.5rem 0;
  margin-bottom: 1rem;
}

nav .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0;
  padding-bottom: 0;
}

nav .nav-right {
  justify-content: flex-end;
}

.logo {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  list-style: none;
}

.nav-links a {
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 0.35rem 0.7rem;
  border-radius: 4px;
  transition: all 0.15s ease;
  letter-spacing: 0.01em;
}

.nav-links a:hover {
  color: var(--text);
  background: var(--bg-secondary);
  text-decoration: none;
}

.nav-links a.active {
  color: var(--text);
  background: var(--bg-secondary);
}

/* Math blocks */
.math-block {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: 8px;
  margin: 1.5rem 0;
  overflow-x: auto;
  text-align: center;
}

.math-inline {
  padding: 0 0.2rem;
}

/* Blockquotes - for key insights */
blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1.25rem;
  margin: 1.5rem 0;
  color: var(--text-secondary);
  font-style: italic;
}

blockquote strong {
  color: var(--text);
  font-style: normal;
}

/* Lists */
ul, ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.5rem;
}

/* Code */
code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.5rem 0;
}

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

/* Cards for lesson links */
.lesson-card {
  display: block;
  padding: 1.25rem;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.lesson-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.lesson-card h3 {
  margin: 0 0 0.5rem 0;
  color: var(--text);
  font-size: 1.1rem;
}

.lesson-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.lesson-number {
  font-size: 0.75rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

/* Derivation steps */
.derivation {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: 8px;
  margin: 1.5rem 0;
}

.derivation-step {
  margin-bottom: 1rem;
  padding-left: 1rem;
  border-left: 2px solid var(--border);
}

.derivation-step:last-child {
  margin-bottom: 0;
}

.step-number {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.85rem;
}

/* Key concept highlight */
.key-concept {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg) 100%);
  border: 1px solid var(--border);
  padding: 1.25rem;
  border-radius: 8px;
  margin: 1.5rem 0;
}

.key-concept h4 {
  margin-top: 0;
  color: var(--accent);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Question boxes */
.question {
  background: var(--bg-secondary);
  border-left: 3px solid #f59e0b;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-radius: 0 8px 8px 0;
}

.question h4 {
  margin-top: 0;
  font-size: 0.9rem;
  color: #f59e0b;
}

/* Connection to other topics */
.connection {
  background: var(--bg-secondary);
  border-left: 3px solid #10b981;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-radius: 0 8px 8px 0;
}

.connection h4 {
  margin-top: 0;
  font-size: 0.9rem;
  color: #10b981;
}

/* Footer */
footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* Lesson navigation */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.lesson-nav a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

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

/* Progress indicator */
.progress-bar {
  height: 2px;
  background: var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.1s;
}

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

  .container {
    padding: 1.5rem 1rem;
  }

  h1 {
    font-size: 1.75rem;
  }

  .nav-links {
    gap: 1rem;
  }
}

/* Tree view */
.tree {
  margin: 2rem 0;
}

.tree-node {
  margin: 0;
}

.tree-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.25rem;
  cursor: pointer;
  border-radius: 4px;
  user-select: none;
}

.tree-label:hover {
  background: var(--bg-secondary);
}

.tree-toggle {
  font-size: 0.6rem;
  color: var(--text-secondary);
  width: 1rem;
  flex-shrink: 0;
}

.tree-title {
  font-weight: 600;
  color: var(--text);
}

.tree-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.tree-number {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
}

.tree-children {
  display: none;
  padding-left: 1.25rem;
  border-left: 1px solid var(--border);
  margin-left: 0.5rem;
}

.tree-children.open {
  display: block;
}

.tree-leaf {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.25rem;
  color: var(--text);
  border-radius: 4px;
  font-size: 0.9rem;
}

.tree-leaf:hover {
  background: var(--bg-secondary);
  text-decoration: none;
}

.tree-leaf.active {
  background: var(--bg-secondary);
  color: var(--accent);
}

/* Sidebar layout for lessons */
.with-sidebar {
  margin-left: 280px;
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: center;
}

.sidebar {
  position: fixed;
  top: 3rem;
  left: 0;
  width: 260px;
  height: calc(100vh - 3rem);
  overflow-y: auto;
  padding: 1rem 1rem 2rem 1.5rem;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.sidebar .tree {
  margin: 0;
}

.sidebar .tree-label {
  padding: 0.35rem 0.25rem;
  font-size: 0.85rem;
}

.sidebar .tree-leaf {
  padding: 0.3rem 0.25rem;
  font-size: 0.8rem;
}

.sidebar .tree-desc {
  display: none;
}

.lesson-content {
  max-width: var(--max-width);
  width: 100%;
}

@media (max-width: 900px) {
  .with-sidebar {
    margin-left: 0;
    padding: 1.5rem 1rem;
  }

  .sidebar {
    display: none;
  }

  /* Mobile menu button */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
  }

  .mobile-menu-btn svg {
    width: 20px;
    height: 20px;
  }

  /* Hide desktop nav on mobile */
  .nav-links {
    display: none;
  }

  nav .container {
    justify-content: flex-end;
  }

  /* Mobile menu overlay */
  .mobile-menu {
    position: fixed;
    top: 0;
    right: -100%;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    background: var(--bg);
    border-left: 1px solid var(--border);
    z-index: 1000;
    transition: right 0.3s ease;
    overflow-y: auto;
    padding: 1rem;
  }

  .mobile-menu.open {
    right: 0;
  }

  .mobile-menu-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
  }

  .mobile-menu-backdrop.open {
    opacity: 1;
    visibility: visible;
  }

  .mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
  }

  .mobile-menu-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 0.5rem;
  }

  .mobile-nav-links {
    list-style: none;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
  }

  .mobile-nav-links a {
    display: block;
    padding: 0.6rem 0;
    color: var(--text);
    font-size: 0.9rem;
  }

  .mobile-nav-links a.active {
    color: var(--accent);
  }

  .mobile-menu .tree {
    margin: 0;
  }
}

@media (min-width: 901px) {
  .mobile-menu-btn,
  .mobile-menu,
  .mobile-menu-backdrop {
    display: none !important;
  }
}

/* Print styles */
@media print {
  nav, .lesson-nav, .progress-bar, .sidebar {
    display: none;
  }

  .container, .with-sidebar {
    max-width: 100%;
    display: block;
  }
}
