/* Modern CSS for Recursion Book */

/* CSS Custom Properties for consistent theming */
:root {
  /* Color palette */
  --primary-color: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;
  --secondary-color: #14b8a6;
  --accent-color: #f59e0b;

  /* Text colors */
  --text-primary: #000000;
  --text-secondary: #000000;
  --text-muted: #000000;
  --text-inverse: #ffffff;

  /* Background colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-code: #1e293b;
  --bg-code-inline: #f1f5f9;

  /* Border colors */
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;

  /* Spacing scale */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Courier New', monospace;

  /* Other properties */
  --max-width: 45rem;
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
}

/* Reset and base styles */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: var(--space-lg);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Main content container */
main, article, .container, .content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: var(--space-md);
  font-weight: 600;
  line-height: 1.25;
  color: var(--text-primary);
}

h1 {
  font-size: 2.75rem;
  font-weight: 700;
  margin-bottom: var(--space-xl);
  letter-spacing: -0.03em;
}

h2 {
  font-size: 2rem;
  margin-top: var(--space-3xl);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--border-light);
  letter-spacing: -0.02em;
}

h3 {
  font-size: 1.5rem;
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-md);
}

h4 {
  font-size: 1.25rem;
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
}

p {
  margin-top: 0;
  margin-bottom: var(--space-lg);
}

/* Links */
a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-base), box-shadow var(--transition-base);
  border-bottom: 1px solid transparent;
}

a:hover {
  color: var(--primary-dark);
  border-bottom-color: var(--primary-light);
}

a:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

a:visited {
  color: var(--primary-dark);
}

/* Lists */
ul, ol {
  margin-top: 0;
  margin-bottom: var(--space-lg);
  padding-left: var(--space-xl);
}

li {
  margin-bottom: var(--space-sm);
}

/* Code styling */
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  font-weight: 500;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  margin: var(--space-xl) 0;
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}

pre code {
  color: inherit;
  padding: 0;
  white-space: pre;
  font-weight: 400;
}

/* Syntax highlighting for code blocks - using subtle font variations instead of colors */
pre .keyword { font-weight: 700; }
pre .string { font-style: italic; }
pre .number { font-weight: 600; }
pre .comment { opacity: 0.7; font-style: italic; }
pre .function { font-weight: 600; }

/* Blockquotes */
blockquote {
  margin: var(--space-xl) 0;
  padding: var(--space-lg);
  background: var(--bg-secondary);
  border-left: 4px solid var(--primary-color);
  border-radius: var(--radius-md);
  font-style: italic;
}

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

/* Images and figures */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: var(--space-xl) auto;
}

figure {
  margin: var(--space-2xl) 0;
  padding: 0;
  text-align: center;
}

figure img {
  margin-bottom: var(--space-md);
}

figcaption {
  font-size: 0.9rem;
  font-style: italic;
  margin-top: var(--space-sm);
  opacity: 0.8;
}

/* Tables */
table {
  width: 100%;
  margin: var(--space-xl) 0;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

thead {
  background: var(--bg-tertiary);
}

th {
  padding: var(--space-md) var(--space-lg);
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-light);
}

tbody tr:hover {
  background: var(--bg-secondary);
  transition: background var(--transition-fast);
}

/* Horizontal rule */
hr {
  border: none;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border-medium), transparent);
  margin: var(--space-3xl) 0;
}

/* Callout boxes */
.note, .warning, .info, .callout {
  margin: var(--space-xl) 0;
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.note {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-left: 4px solid #0284c7;
}

.warning {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-left: 4px solid var(--accent-color);
}

.info {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  border-left: 4px solid var(--primary-color);
}

/* Interactive elements */
button, .button {
  display: inline-block;
  padding: var(--space-sm) var(--space-lg);
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

button:hover, .button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

button:active, .button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Form elements */
input, textarea, select {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  font-size: 1rem;
  border: 2px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Utility classes */
.text-center { text-align: center; }
.mt-lg { margin-top: var(--space-lg); }
.mb-lg { margin-bottom: var(--space-lg); }

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

  body {
    font-size: 1rem;
  }

  main, article, .container, .content {
    padding: var(--space-lg) var(--space-md);
  }

  h1 {
    font-size: 2rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  h3 {
    font-size: 1.25rem;
  }

  pre {
    padding: var(--space-md);
    font-size: 0.85rem;
  }
}

/* Print styles */
@media print {
  body {
    color: #000;
    background: #fff;
  }

  a {
    color: #000;
    text-decoration: underline;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --text-muted: #ffffff;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-code: #1e293b;
    --bg-code-inline: #334155;
    --border-light: #334155;
    --border-medium: #475569;
    --primary-color: #60a5fa;
    --primary-dark: #3b82f6;
    --primary-light: #93c5fd;
  }

  img {
    opacity: 0.9;
  }

  table {
    background: var(--bg-secondary);
  }

  .note {
    background: linear-gradient(135deg, #0c4a6e 0%, #075985 100%);
  }

  .warning {
    background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
  }

  .info {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
  }
}

/* Smooth transitions for theme switching */
* {
  transition: background-color 200ms ease, border-color 200ms ease;
}

/* Selection styling */
::selection {
  background: var(--primary-light);
  color: var(--bg-primary);
}

::-moz-selection {
  background: var(--primary-light);
  color: var(--bg-primary);
}

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-md);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}