/* ============ TOKENS ============ */
: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 (4px base) */
  --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;

  /* Content widths */
  --content-narrow: 640px;
  --content-default: 900px;
  --content-wide: 1120px;

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

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

  /* Fonts */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
}

/* ============ LIGHT MODE — Warm therapy palette ============ */
:root,
[data-theme='light'] {
  --color-bg: #f5efe6;
  --color-surface: #fbf7ef;
  --color-surface-2: #ffffff;
  --color-surface-offset: #ede4d3;
  --color-surface-offset-2: #e5d9c3;
  --color-divider: #d9cdb6;
  --color-border: #c9bca3;

  --color-text: #2b241a;
  --color-text-muted: #6d5f4c;
  --color-text-faint: #a89b83;
  --color-text-inverse: #fbf7ef;

  /* Primary — deep forest green */
  --color-primary: #324a3f;
  --color-primary-hover: #253730;
  --color-primary-active: #1a2822;
  --color-primary-highlight: #c9d3ca;

  /* Accent — terracotta */
  --color-accent: #b04a2a;
  --color-accent-hover: #8f3a1f;

  /* Semantics */
  --color-warning: #b17415;
  --color-warning-highlight: #f0e2c2;
  --color-error: #a12e2e;
  --color-error-highlight: #eecfcf;
  --color-success: #4d7a3a;
  --color-success-highlight: #d5e2c8;

  --shadow-sm: 0 1px 2px rgba(43, 36, 26, 0.06);
  --shadow-md: 0 4px 12px rgba(43, 36, 26, 0.08);
  --shadow-lg: 0 12px 32px rgba(43, 36, 26, 0.12);
}

/* ============ DARK MODE ============ */
[data-theme='dark'] {
  --color-bg: #1a1815;
  --color-surface: #22201c;
  --color-surface-2: #2a2723;
  --color-surface-offset: #2e2b26;
  --color-surface-offset-2: #35322c;
  --color-divider: #3a362f;
  --color-border: #4a463d;

  --color-text: #e8dcc8;
  --color-text-muted: #a89b83;
  --color-text-faint: #7a705d;
  --color-text-inverse: #22201c;

  --color-primary: #8ab29a;
  --color-primary-hover: #a2c3ae;
  --color-primary-active: #b8d3c2;
  --color-primary-highlight: #2e3d33;

  --color-accent: #d67650;
  --color-accent-hover: #e08e6b;

  --color-warning: #d9a445;
  --color-warning-highlight: #4a3d1e;
  --color-error: #d97070;
  --color-error-highlight: #4a2828;
  --color-success: #8bb26f;
  --color-success-highlight: #2f3d24;

  --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);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #1a1815;
    --color-surface: #22201c;
    --color-surface-2: #2a2723;
    --color-surface-offset: #2e2b26;
    --color-surface-offset-2: #35322c;
    --color-divider: #3a362f;
    --color-border: #4a463d;
    --color-text: #e8dcc8;
    --color-text-muted: #a89b83;
    --color-text-faint: #7a705d;
    --color-text-inverse: #22201c;
    --color-primary: #8ab29a;
    --color-primary-hover: #a2c3ae;
    --color-primary-highlight: #2e3d33;
    --color-accent: #d67650;
    --color-warning: #d9a445;
    --color-warning-highlight: #4a3d1e;
    --color-error: #d97070;
    --color-error-highlight: #4a2828;
    --color-success: #8bb26f;
    --color-success-highlight: #2f3d24;
  }
}

/* ============ BASE ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
}

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, svg { display: block; max-width: 100%; height: auto; }

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

button {
  cursor: pointer;
  background: none;
  border: none;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  color: var(--color-text);
  letter-spacing: -0.01em;
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

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

a { color: var(--color-primary); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--color-primary-hover); }

::selection {
  background: var(--color-primary-highlight);
  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;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

a, button, input, textarea, select {
  transition:
    color var(--transition-interactive),
    background var(--transition-interactive),
    border-color var(--transition-interactive),
    box-shadow var(--transition-interactive),
    transform var(--transition-interactive);
}

.container {
  width: min(100% - 2rem, var(--content-default));
  margin-inline: auto;
}
.container.wide {
  max-width: var(--content-wide);
}
