/* ==========================================================================
   OPEN TEXTBOOKS - Design System
   A warm, accessible, education-focused design
   ========================================================================== */

/* ==========================================================================
   CSS Variables (Design Tokens)
   ========================================================================== */
:root {
  /* Typography Scale */
  --font-display: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
  --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  
  --text-xs: 0.75rem;      /* 12px */
  --text-sm: 0.875rem;     /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-lg: 1.125rem;     /* 18px */
  --text-xl: 1.25rem;      /* 20px */
  --text-2xl: 1.5rem;      /* 24px */
  --text-3xl: 1.875rem;    /* 30px */
  --text-4xl: 2.25rem;     /* 36px */
  --text-5xl: 3rem;        /* 48px */
  
  --leading-tight: 1.25;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;
  
  /* Color Palette - Friendly Classroom Theme (Indigo + Warm Orange) */
  /* Primary: Indigo (trust, knowledge, focus) */
  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-200: #c7d2fe;
  --indigo-300: #a5b4fc;
  --indigo-400: #818cf8;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;
  --indigo-800: #3730a3;
  --indigo-900: #312e81;

  /* Slate - for text and neutrals */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* Accent: Warm Orange (warmth, energy, engagement) */
  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-200: #fde68a;
  --amber-300: #fcd34d;
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --amber-800: #92400e;
  --amber-900: #78350f;

  /* Success: Green (growth, correct, learning) */
  --sage-50: #f0fdf4;
  --sage-100: #dcfce7;
  --sage-200: #bbf7d0;
  --sage-300: #86efac;
  --sage-400: #4ade80;
  --sage-500: #22c55e;
  --sage-600: #16a34a;
  --sage-700: #15803d;

  /* Info: Blue */
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  /* Error/Warning */
  --rose-50: #fff1f2;
  --rose-100: #ffe4e6;
  --rose-500: #f43f5e;
  --rose-600: #e11d48;
  --rose-700: #be123c;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;

  /* Semantic Colors - Light Theme (Default) */
  --color-bg: #FFF7ED;
  --color-bg-alt: #FAFAFA;
  --color-bg-elevated: #ffffff;
  --color-surface: #F3F4F6;
  --color-text: #111827;
  --color-text-muted: #6B7280;
  --color-text-subtle: #9CA3AF;
  --color-heading: #111827;
  --color-link: var(--indigo-600);
  --color-link-hover: var(--indigo-700);
  --color-border: #E5E7EB;
  --color-border-strong: #D1D5DB;
  --color-focus: var(--indigo-500);
  --color-accent: var(--amber-500);
  --color-accent-hover: var(--amber-600);
  --color-accent-soft: var(--amber-100);
  --color-primary: var(--indigo-600);
  --color-primary-hover: var(--indigo-700);
  --color-primary-soft: var(--indigo-100);
  
  /* Spacing Scale */
  --space-0: 0;
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-20: 5rem;     /* 80px */
  --space-24: 6rem;     /* 96px */
  
  /* Layout */
  --max-width-prose: 65ch;
  --max-width-content: 1200px;
  --max-width-wide: 1400px;
  
  /* Borders & Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  
  /* Z-index scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
}

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

* {
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

main {
  flex: 1;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* ==========================================================================
   Typography
   ========================================================================== */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--color-heading);
  line-height: var(--leading-tight);
  font-weight: 700;
}

h1 {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-6);
}

h2 {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-5);
}

h3 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-4);
}

h4 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-3);
}

p {
  margin-bottom: var(--space-4);
}

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

a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-link-hover);
}

/* Focus styles for accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

strong, b {
  font-weight: 600;
}

small {
  font-size: var(--text-sm);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--slate-100);
  padding: 0.2em 0.4em;
  border-radius: var(--radius-sm);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--slate-900);
  color: var(--slate-100);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

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

blockquote {
  border-left: 4px solid var(--amber-400);
  padding-left: var(--space-4);
  margin: var(--space-6) 0;
  font-style: italic;
  color: var(--color-text-muted);
}

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-8) 0;
}

/* Lists */
ul, ol {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

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

li:last-child {
  margin-bottom: 0;
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container {
  width: 100%;
  max-width: var(--max-width-content);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.container--wide {
  max-width: var(--max-width-wide);
}

.container--prose {
  max-width: var(--max-width-prose);
}

.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

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

.btn--primary:hover {
  background: var(--amber-700);
  border-color: var(--amber-700);
  color: white;
}

.btn--secondary {
  background: transparent;
  color: var(--slate-700);
  border-color: var(--slate-300);
}

.btn--secondary:hover {
  background: var(--slate-50);
  border-color: var(--slate-400);
}

.btn--ghost {
  background: transparent;
  color: var(--slate-600);
  border-color: transparent;
}

.btn--ghost:hover {
  background: var(--slate-100);
}

.btn--sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
}

.btn--lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-lg);
}

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: box-shadow var(--transition-base);
}

.card--interactive {
  cursor: pointer;
}

.card--interactive:hover {
  box-shadow: var(--shadow-md);
}

.card--interactive:focus-within {
  box-shadow: var(--shadow-md);
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* ==========================================================================
   Form Elements
   ========================================================================== */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--color-heading);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-elevated);
  transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--color-focus);
  outline: none;
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

/* ==========================================================================
   Badge / Tag
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-full);
  background: var(--slate-100);
  color: var(--slate-700);
}

.badge--amber {
  background: var(--amber-100);
  color: var(--amber-800);
}

.badge--sage {
  background: var(--sage-100);
  color: var(--sage-700);
}

/* ==========================================================================
   Page Layout Sections
   ========================================================================== */
.section {
  padding: var(--space-12) 0;
}

.section--alt {
  background: var(--color-bg-alt);
}

.section--hero {
  padding: var(--space-16) 0;
}

/* ==========================================================================
   Responsive Breakpoints Reference
   - sm: 640px
   - md: 768px
   - lg: 1024px
   - xl: 1280px
   ========================================================================== */

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */
/* Explicit Light Theme - ensures light mode even when system prefers dark */
[data-theme="light"] {
  --color-bg: #FFF7ED;
  --color-bg-alt: #FAFAFA;
  --color-bg-elevated: #ffffff;
  --color-surface: #F3F4F6;
  --color-text: #111827;
  --color-text-muted: #6B7280;
  --color-text-subtle: #9CA3AF;
  --color-heading: #111827;
  --color-link: var(--indigo-600);
  --color-link-hover: var(--indigo-700);
  --color-border: #E5E7EB;
  --color-border-strong: #D1D5DB;
  --color-focus: var(--indigo-500);
  --color-accent: var(--amber-500);
  --color-accent-hover: var(--amber-600);
  --color-accent-soft: var(--amber-100);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --color-bg: #0f172a;
    --color-bg-alt: #1e293b;
    --color-bg-elevated: #1e293b;
    --color-text: #e2e8f0;
    --color-text-muted: #94a3b8;
    --color-text-subtle: #64748b;
    --color-heading: #f1f5f9;
    --color-link: #fbbf24;
    --color-link-hover: #fcd34d;
    --color-border: #334155;
    --color-border-strong: #475569;
    --color-focus: #fbbf24;
    --color-accent: #f59e0b;
    --color-accent-soft: #78350f;
  }
}

/* Dark Theme - High Contrast, Readable */
[data-theme="dark"] {
  --color-bg: #0f1419;
  --color-bg-alt: #1a2028;
  --color-bg-elevated: #242c38;
  --color-surface: #2d3748;
  --color-text: #f7fafc;
  --color-text-muted: #cbd5e0;
  --color-text-subtle: #a0aec0;
  --color-heading: #ffffff;
  --color-link: #90cdf4;
  --color-link-hover: #bee3f8;
  --color-border: #4a5568;
  --color-border-strong: #718096;
  --color-focus: #90cdf4;
  --color-accent: #fbbf24;
  --color-accent-hover: #fcd34d;
  --color-accent-soft: rgba(251, 191, 36, 0.15);
  --color-primary: #90cdf4;
  --color-primary-hover: #bee3f8;
  --color-primary-soft: rgba(144, 205, 244, 0.15);

  /* Override slate colors for dark mode */
  --slate-100: #2d3748;
  --slate-200: #4a5568;
  --slate-700: #e2e8f0;
  --slate-800: #f7fafc;
}

/* ==========================================================================
   Text Size Controls
   ========================================================================== */
[data-text-size="small"] {
  font-size: 14px;
}

[data-text-size="normal"] {
  font-size: 16px;
}

[data-text-size="large"] {
  font-size: 18px;
}

[data-text-size="x-large"] {
  font-size: 20px;
}

/* ==========================================================================
   Accessibility Controls Container
   ========================================================================== */
.a11y-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.a11y-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.a11y-btn:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.a11y-btn:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

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

.text-size-controls {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.text-size-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: var(--space-1);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: all var(--transition-fast);
}

.text-size-btn:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

.text-size-btn.active {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}
