/* ============================================================
   BASE — Custom properties, reset, typography, global styles
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&display=swap');

/* --- Custom Properties (Option A: Navy + Amber) --- */
:root {
  /* Colors */
  --color-primary:       #1E3A5F;
  --color-primary-light: #2E5A8F;
  --color-primary-pale:  #EEF2F8;
  --color-accent:        #F59E0B;
  --color-accent-dark:   #D97706;
  --color-text:          #1A2332;
  --color-text-muted:    #5A6A7E;
  --color-bg:            #FAFBFD;
  --color-bg-alt:        #EEF2F8;
  --color-border:        #D8E2EE;
  --color-success:       #059669;
  --color-error:         #DC2626;
  --color-white:         #FFFFFF;

  /* Typography */
  --font-heading: 'DM Serif Display', Georgia, 'Times New Roman', serif;
  --font-body:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono:    ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, monospace;

  /* Fluid type scale */
  --text-xs:   clamp(0.75rem,  0.72rem + 0.15vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.84rem + 0.2vw,  1rem);
  --text-base: clamp(1rem,     0.96rem + 0.2vw,  1.125rem);
  --text-lg:   clamp(1.125rem, 1.05rem + 0.4vw,  1.375rem);
  --text-xl:   clamp(1.25rem,  1.1rem  + 0.75vw, 1.75rem);
  --text-2xl:  clamp(1.5rem,   1.25rem + 1.25vw, 2.25rem);
  --text-3xl:  clamp(1.875rem, 1.5rem  + 1.875vw,2.875rem);
  --text-4xl:  clamp(2.25rem,  1.75rem + 2.5vw,  3.75rem);

  /* Spacing (8px 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;

  /* Layout */
  --container-max:  1240px;
  --content-max:    68ch;
  --sidebar-width:  300px;
  --gap:            clamp(1rem, 3vw, 2rem);

  /* Borders & Radius */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(30, 58, 95, 0.08), 0 1px 2px rgba(30, 58, 95, 0.05);
  --shadow-md: 0 4px 8px rgba(30, 58, 95, 0.08), 0 2px 4px rgba(30, 58, 95, 0.05);
  --shadow-lg: 0 10px 24px rgba(30, 58, 95, 0.1), 0 4px 8px rgba(30, 58, 95, 0.06);

  /* Animation */
  --transition-fast: 150ms ease;
  --transition:      220ms ease;
  --transition-slow: 350ms ease;
}

/* --- Dark Mode --- */
@media (prefers-color-scheme: dark) {
  :root {
    --color-primary:       #5B8AC5;
    --color-primary-light: #7AAAD9;
    --color-primary-pale:  #162336;
    --color-accent:        #F59E0B;
    --color-accent-dark:   #FBBF24;
    --color-text:          #E4EAF4;
    --color-text-muted:    #7A93B0;
    --color-bg:            #0D1B2A;
    --color-bg-alt:        #162336;
    --color-border:        #253D57;
    --color-success:       #34D399;
    --color-error:         #F87171;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 24px rgba(0,0,0,0.4);
  }
}

/* Dark mode via JS toggle */
[data-theme="dark"] {
  --color-primary:       #5B8AC5;
  --color-primary-light: #7AAAD9;
  --color-primary-pale:  #162336;
  --color-accent:        #F59E0B;
  --color-accent-dark:   #FBBF24;
  --color-text:          #E4EAF4;
  --color-text-muted:    #7A93B0;
  --color-bg:            #0D1B2A;
  --color-bg-alt:        #162336;
  --color-border:        #253D57;
  --color-success:       #34D399;
  --color-error:         #F87171;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 24px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --color-primary:       #1E3A5F;
  --color-primary-light: #2E5A8F;
  --color-primary-pale:  #EEF2F8;
  --color-accent:        #F59E0B;
  --color-accent-dark:   #D97706;
  --color-text:          #1A2332;
  --color-text-muted:    #5A6A7E;
  --color-bg:            #FAFBFD;
  --color-bg-alt:        #EEF2F8;
  --color-border:        #D8E2EE;
  --color-success:       #059669;
  --color-error:         #DC2626;
  --shadow-sm: 0 1px 3px rgba(30, 58, 95, 0.08), 0 1px 2px rgba(30, 58, 95, 0.05);
  --shadow-md: 0 4px 8px rgba(30, 58, 95, 0.08), 0 2px 4px rgba(30, 58, 95, 0.05);
  --shadow-lg: 0 10px 24px rgba(30, 58, 95, 0.1), 0 4px 8px rgba(30, 58, 95, 0.06);
}

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

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition), color var(--transition);
}

img, video { max-width: 100%; height: auto; display: block; }
svg { display: inline; vertical-align: middle; }
input, button, textarea, select { font: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--color-primary); text-decoration: underline; text-underline-offset: 3px; }
a:hover { color: var(--color-primary-light); }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }
hr { border: none; border-top: 1px solid var(--color-border); }

/* --- Focus Styles (WCAG AA) --- */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 400;
  line-height: 1.2;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); font-family: var(--font-body); font-weight: 600; }

p { margin-bottom: var(--space-4); max-width: 72ch; }
p:last-child { margin-bottom: 0; }

strong, b { font-weight: 600; }
em, i { font-style: italic; }

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

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-bg-alt);
  padding: 0.1em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

pre {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
}

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

blockquote {
  border-left: 4px solid var(--color-accent);
  padding: var(--space-3) var(--space-6);
  margin: var(--space-6) 0;
  background: var(--color-bg-alt);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
  color: var(--color-text-muted);
}

blockquote p { max-width: none; }

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

.text-muted { color: var(--color-text-muted); }
.text-sm    { font-size: var(--text-sm); }
.text-xs    { font-size: var(--text-xs); }
.text-center { text-align: center; }

/* --- Skip Link (accessibility) --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 9999;
  background: var(--color-accent);
  color: var(--color-text);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: var(--space-4); }
