/**
 * SwiftPress Base CSS
 * Custom Properties + Modern Reset + Typography System
 * 
 * Performance notes:
 * - Custom properties enable runtime theming without JS
 * - System font stack as fallback, web font loaded async
 * - fluid() clamp()-based type scale eliminates breakpoint clutter
 * - No animations by default; respect prefers-reduced-motion
 */

/* ─── Custom Properties ─────────────────────────────────────────── */
:root {
  /* Color System */
  --color-primary:       #1a6ef5;
  --color-primary-dark:  #1458c8;
  --color-primary-light: #e8f0fe;
  --color-text:          #1c1c1e;
  --color-text-muted:    #6b6b6b;
  --color-border:        #e2e2e2;
  --color-bg:            #ffffff;
  --color-bg-alt:        #f7f7f8;
  --color-surface:       #ffffff;

  /* Typography Scale — fluid clamp() avoids media query sprawl */
  --font-sans:   'system-ui', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif:  Georgia, 'Times New Roman', serif;
  --font-mono:   'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  --text-xs:   clamp(0.694rem, 0.67rem + 0.12vw,  0.75rem);
  --text-sm:   clamp(0.833rem, 0.8rem  + 0.165vw, 0.9rem);
  --text-base: clamp(1rem,     0.96rem + 0.2vw,   1.0625rem);
  --text-md:   clamp(1.125rem, 1.07rem + 0.275vw, 1.25rem);
  --text-lg:   clamp(1.25rem,  1.18rem + 0.35vw,  1.5rem);
  --text-xl:   clamp(1.5rem,   1.35rem + 0.75vw,  2rem);
  --text-2xl:  clamp(1.875rem, 1.6rem  + 1.375vw, 2.75rem);
  --text-3xl:  clamp(2.25rem,  1.85rem + 2vw,     3.5rem);

  --leading-tight:  1.25;
  --leading-snug:   1.4;
  --leading-normal: 1.65;
  --leading-loose:  1.8;

  --font-weight-normal:    400;
  --font-weight-medium:    500;
  --font-weight-semibold:  600;
  --font-weight-bold:      700;

  /* Spacing — 4px base grid */
  --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-sm:  640px;
  --container-md:  768px;
  --container-lg:  1024px;
  --container-xl:  1200px;
  --container-2xl: 1400px;
  --container-pad: clamp(1rem, 4vw, 2rem);

  /* Borders & Radius */
  --radius-sm:   3px;
  --radius-md:   6px;
  --radius-lg:   12px;
  --radius-full: 9999px;
  --border-width: 1px;

  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --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);

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow:   400ms ease;

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgb(26 110 245 / 0.4);
}

/* Dark mode via prefers-color-scheme */
@media (prefers-color-scheme: dark) {
  :root {
    --color-text:       #f2f2f7;
    --color-text-muted: #aeaeb2;
    --color-border:     #3a3a3c;
    --color-bg:         #1c1c1e;
    --color-bg-alt:     #2c2c2e;
    --color-surface:    #2c2c2e;
    --color-primary-light: #1d3461;
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.4);
  }
}

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

html {
  font-size: 100%;               /* respects user browser preference */
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Respect user motion preferences — performance AND accessibility */
@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;
  }
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100svh;
  overflow-x: hidden;
}

/* ─── Typography ────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--leading-tight);
  color: var(--color-text);
  text-wrap: balance;        /* modern line-break improvement */
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); }

p {          /* optimal reading width */
  text-wrap: pretty;
}

a {
  color: var(--color-primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--transition-fast), opacity var(--transition-fast);
}

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

/* Accessible focus — visible for keyboard, hidden for mouse */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) { outline: none; }

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

img {
  height: auto;
  /* Native lazy loading is set per-image in PHP; this is a fallback */
}

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

/* Prevent orphaned text in headings */
h1, h2, h3 { text-wrap: balance; }

/* Code blocks */
code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

pre {
  overflow-x: auto;
  padding: var(--space-6);
  background: var(--color-bg-alt);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  line-height: var(--leading-loose);
}

code:not(pre code) {
  background: var(--color-bg-alt);
  padding: 0.125em 0.375em;
  border-radius: var(--radius-sm);
  border: var(--border-width) solid var(--color-border);
}

blockquote {
  border-left: 4px solid var(--color-primary);
  padding: var(--space-4) var(--space-6);
  background: var(--color-bg-alt);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: var(--text-md);
  color: var(--color-text-muted);
}

blockquote cite {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  font-style: normal;
}

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

ul, ol {
  padding-left: var(--space-6);
}

li + li { margin-top: var(--space-1); }

/* Table defaults */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th, td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: var(--border-width) solid var(--color-border);
}

th {
  font-weight: var(--font-weight-semibold);
  background: var(--color-bg-alt);
}

/* Screen reader only utility */
.screen-reader-text,
.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;
}

/* Skip to content link — appears on keyboard focus */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 9999;
  padding: var(--space-3) var(--space-5);
  background: var(--color-primary);
  color: #fff;
  font-weight: var(--font-weight-semibold);
  text-decoration: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 0;
  box-shadow: none;
  outline: 2px solid #fff;
  outline-offset: 2px;
}
