/* base.css — EconLib4 Documentation */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
  scroll-padding-top: 5rem;
}

:root {
  /* Type Scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);
  --text-3xl:  clamp(2.5rem,   1rem    + 4vw,    5rem);

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

  /* Fonts */
  --font-display: 'JetBrains Mono', 'Fira Code', monospace;
  --font-body: 'Source Serif 4', 'Georgia', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* Content widths */
  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;
}

/* ─── LIGHT MODE ─── */
:root, [data-theme="light"] {
  --color-bg:             #f5f4f0;
  --color-surface:        #ffffff;
  --color-surface-2:      #faf9f7;
  --color-surface-offset: #eceae5;
  --color-surface-code:   #1e1e2e;
  --color-divider:        #d8d6d0;
  --color-border:         #cccac3;

  --color-text:           #1a1a2e;
  --color-text-muted:     #5a5870;
  --color-text-faint:     #9896a8;
  --color-text-inverse:   #f5f4f0;

  /* Primary — Violet/Purple (mathematical abstraction) */
  --color-primary:        #6d28d9;
  --color-primary-hover:  #5b21b6;
  --color-primary-active: #4c1d95;
  --color-primary-light:  #ede9fe;
  --color-primary-glow:   rgba(109, 40, 217, 0.12);

  /* Accent — Slate */
  --color-accent:         #475569;
  --color-accent-hover:   #334155;

  /* Status */
  --color-success:        #059669;
  --color-success-bg:     #ecfdf5;
  --color-warning:        #d97706;
  --color-warning-bg:     #fffbeb;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(26, 26, 46, 0.06);
  --shadow-md: 0 4px 12px rgba(26, 26, 46, 0.08);
  --shadow-lg: 0 12px 32px rgba(26, 26, 46, 0.12);

  /* Architecture layers */
  --layer-0: #e8e5f0;
  --layer-1: #ddd8f0;
  --layer-2: #d2ccee;
  --layer-3: #c7c0ec;
  --layer-4: #bcb4ea;
  --layer-5: #b1a8e8;
  --layer-text: #1a1a2e;
}

/* ─── DARK MODE ─── */
[data-theme="dark"] {
  --color-bg:             #0f0f1a;
  --color-surface:        #171728;
  --color-surface-2:      #1e1e32;
  --color-surface-offset: #141425;
  --color-surface-code:   #0d0d1a;
  --color-divider:        #2a2a42;
  --color-border:         #33334d;

  --color-text:           #e2e0f0;
  --color-text-muted:     #9896b0;
  --color-text-faint:     #5e5c78;
  --color-text-inverse:   #0f0f1a;

  --color-primary:        #a78bfa;
  --color-primary-hover:  #c4b5fd;
  --color-primary-active: #8b5cf6;
  --color-primary-light:  rgba(167, 139, 250, 0.12);
  --color-primary-glow:   rgba(167, 139, 250, 0.15);

  --color-accent:         #94a3b8;
  --color-accent-hover:   #cbd5e1;

  --color-success:        #34d399;
  --color-success-bg:     rgba(52, 211, 153, 0.1);
  --color-warning:        #fbbf24;
  --color-warning-bg:     rgba(251, 191, 36, 0.1);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

  --layer-0: #1a1a30;
  --layer-1: #1e1e38;
  --layer-2: #222240;
  --layer-3: #262648;
  --layer-4: #2a2a50;
  --layer-5: #2e2e58;
  --layer-text: #e2e0f0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:             #0f0f1a;
    --color-surface:        #171728;
    --color-surface-2:      #1e1e32;
    --color-surface-offset: #141425;
    --color-surface-code:   #0d0d1a;
    --color-divider:        #2a2a42;
    --color-border:         #33334d;
    --color-text:           #e2e0f0;
    --color-text-muted:     #9896b0;
    --color-text-faint:     #5e5c78;
    --color-text-inverse:   #0f0f1a;
    --color-primary:        #a78bfa;
    --color-primary-hover:  #c4b5fd;
    --color-primary-active: #8b5cf6;
    --color-primary-light:  rgba(167, 139, 250, 0.12);
    --color-primary-glow:   rgba(167, 139, 250, 0.15);
    --color-accent:         #94a3b8;
    --color-accent-hover:   #cbd5e1;
    --color-success:        #34d399;
    --color-success-bg:     rgba(52, 211, 153, 0.1);
    --color-warning:        #fbbf24;
    --color-warning-bg:     rgba(251, 191, 36, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    --layer-0: #1a1a30;
    --layer-1: #1e1e38;
    --layer-2: #222240;
    --layer-3: #262648;
    --layer-4: #2a2a50;
    --layer-5: #2e2e58;
    --layer-text: #e2e0f0;
  }
}

/* ─── RESETS ─── */
body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
}

img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
ul[role="list"], ol[role="list"] { list-style: none; }
input, button, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
  line-height: 1.15;
  font-family: var(--font-display);
}

p, li, figcaption { text-wrap: pretty; max-width: 72ch; }

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

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

button { cursor: pointer; background: none; border: none; }
table { border-collapse: collapse; width: 100%; }

a, button, [role="button"], [role="link"], input, textarea, select {
  transition: color var(--transition-interactive),
              background var(--transition-interactive),
              border-color var(--transition-interactive),
              box-shadow var(--transition-interactive);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
}
