/*
 * The Antipodean Mercury - Typography System
 * Based on 18th-century broadsheet aesthetics
 */

/* ============================================
   FONT LOADING
   ============================================ */

@font-face {
  font-family: 'EB Garamond';
  src: url('/fonts/EBGaramond-Variable.woff2') format('woff2');
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Libre Baskerville';
  src: url('/fonts/LibreBaskerville-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'IM Fell English SC';
  src: url('/fonts/IMFellEnglishSC.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/IBMPlexSans-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/IBMPlexMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ============================================
   CSS CUSTOM PROPERTIES
   ============================================ */

:root {
  /* ===========================================
     BREAKPOINTS (for reference - use in @media)
     These values cannot be used as CSS vars in
     media queries, but are documented here for
     consistency across the codebase.

     --bp-mobile:  640px   (max-width for mobile)
     --bp-tablet:  768px   (max-width for tablet)
     --bp-desktop: 1200px  (min-width for desktop)
     =========================================== */

  /* Color System - Light Mode (default) */
  --text: #1a1a1a;
  --background: #fffef9;
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));
  --accent: #a8322d;
  --accent-hover: #8a2924;
  --subtle: #6b6b6b;
  --border: #e0e0e0;

  /* Convenience aliases */
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));

  /* Typography Scale (Major Third - 1.250) */
  --text-xs: 0.64rem;   /* 11.52px */
  --text-sm: 0.8rem;    /* 14.4px */
  --text-base: 1rem;    /* 18px mobile, 19px desktop */
  --text-md: 1.25rem;   /* 22.5px / 23.75px */
  --text-lg: 1.563rem;  /* 28.13px / 29.7px */
  --text-xl: 1.953rem;  /* 35.15px / 37.1px */
  --text-2xl: 2.441rem; /* 43.94px / 46.38px */
  --text-3xl: 3.052rem; /* 54.94px / 57.99px */
  --text-4xl: 3.815rem; /* 68.67px / 72.49px */

  /* Line Heights */
  --leading-tight: 1.2;
  --leading-snug: 1.4;
  --leading-normal: 1.6;
  --leading-relaxed: 1.7;
  --leading-loose: 2.0;

  /* Measures (optimal reading width) */
  --measure-narrow: 70ch;
  --measure-base: 80ch;
  --measure-wide: 90ch;

  /* Layout widths */
  --content-width: 720px;
  --margin-width: 28ch;
  --gutter: 3rem;

  /* Spacing Scale */
  --space-xs: 0.25rem;   /* 4px */
  --space-sm: 0.5rem;    /* 8px */
  --space-md: 1rem;      /* 16px */
  --space-lg: 1.5rem;    /* 24px */
  --space-xl: 2rem;      /* 32px */
  --space-2xl: 3rem;     /* 48px */
  --space-3xl: 4rem;     /* 64px */

  /* Font Families */
  --font-text: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --font-head: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
  --font-display: 'IM Fell English SC', 'Libre Baskerville', Georgia, serif;
  --font-ui: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

/* Dark Mode - explicit attribute takes precedence */
[data-theme="dark"] {
  --text: #e8e6e3;
  --background: #1a1a1a;
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 8%, var(--background));
  --accent: #c94940;
  --accent-hover: #e05a50;
  --subtle: #9b9b9b;
  --border: #333333;
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));
}

/* Dark Mode - system preference (when no explicit theme set) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --text: #e8e6e3;
    --background: #1a1a1a;
    --bg: var(--background);
    --bg-secondary: color-mix(in srgb, var(--text) 8%, var(--background));
    --accent: #c94940;
    --accent-hover: #e05a50;
    --subtle: #9b9b9b;
    --border: #333333;
    --bg: var(--background);
    --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));
  }
}

/* Sepia Mode */
[data-theme="sepia"] {
  --text: #2b2b2b;
  --background: #f4f1ea;
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));
  --accent: #a8322d;
  --accent-hover: #8a2924;
  --subtle: #6b6b6b;
  --border: #d4cfbf;
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));
}

/* Light Mode - explicit (overrides system preference) */
[data-theme="light"] {
  --text: #1a1a1a;
  --background: #fffef9;
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));
  --accent: #a8322d;
  --accent-hover: #8a2924;
  --subtle: #6b6b6b;
  --border: #e0e0e0;
  --bg: var(--background);
  --bg-secondary: color-mix(in srgb, var(--text) 5%, var(--background));
}

/* ============================================
   BASE STYLES
   ============================================ */

* {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  background: var(--background);
  color: var(--text);
  color-scheme: light dark;

  /* Smooth transitions for theme changes */
  transition: background-color 0.3s ease, color 0.3s ease;
}

@media (min-width: 1200px) {
  html {
    font-size: 19px;
  }
}

body {
  margin: 0;
  font-family: var(--font-text);
  font-size: var(--text-base);
  line-height: var(--leading-normal);

  /* Typography features */
  font-variant-ligatures: common-ligatures;
  font-feature-settings: "onum" 1, "liga" 1; /* oldstyle numerals, ligatures */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (min-width: 1200px) {
  body {
    line-height: var(--leading-relaxed);
  }
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-head);
  font-weight: 400;
  line-height: var(--leading-tight);
  letter-spacing: 0.003em;
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-lg);
}

h1 {
  font-size: var(--text-3xl);
  margin-top: 0;
}

h2 {
  font-size: var(--text-2xl);
}

h3 {
  font-size: var(--text-xl);
}

h4 {
  font-size: var(--text-lg);
}

h5, h6 {
  font-size: var(--text-md);
}

p {
  margin: 0 0 var(--space-lg) 0;
  max-width: var(--measure-wide);
}

/* Drop cap for essay opening paragraphs */
.article-content > p:first-of-type::first-letter {
  font-size: 3.5em;
  line-height: 0.85;
  float: left;
  margin: 0.05em 0.1em 0 0;
  font-family: var(--font-display);
  font-weight: 400;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.2s ease, text-decoration-thickness 0.2s ease;
}

a:hover {
  text-decoration-thickness: 2px;
}

a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

strong {
  font-weight: 600;
}

em {
  font-style: italic;
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  padding: 0.125em 0.25em;
  border-radius: 3px;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.875em;
  line-height: 1.5;
  overflow-x: auto;
  background: color-mix(in srgb, var(--text) 5%, transparent);
  border: 1px solid var(--border);
  padding: var(--space-lg);
  border-radius: 4px;
  margin: var(--space-xl) 0;
}

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

blockquote {
  margin: var(--space-xl) 0;
  padding-left: var(--space-xl);
  border-left: 3px solid var(--accent);
  font-style: italic;
  color: var(--subtle);
}

/* ============================================
   LISTS
   ============================================ */

ul, ol {
  margin: var(--space-lg) 0;
  padding-left: var(--space-xl);
}

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

li::marker {
  color: var(--accent);
}

/* ============================================
   ORNAMENTS & DECORATIVE ELEMENTS
   ============================================ */

.ornament {
  display: block;
  text-align: center;
  margin: var(--space-2xl) auto;
  opacity: 0.8;
  color: var(--accent);
}

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

.fleuron {
  text-align: center;
  font-size: var(--text-lg);
  margin: var(--space-2xl) 0;
  opacity: 0.6;
}

.manicule {
  color: var(--accent);
  margin-right: var(--space-sm);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.font-display {
  font-family: var(--font-display);
}

.font-ui {
  font-family: var(--font-ui);
}

.text-center {
  text-align: center;
}

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

.text-accent {
  color: var(--accent);
}

/* Dyslexia-friendly mode */
[data-dyslexia="true"] {
  font-family: var(--font-ui);
  line-height: var(--leading-loose);
  letter-spacing: 0.03em;
  word-spacing: 0.1em;
  text-align: left; /* Override justification */
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  :root {
    --text: #000000;
    --background: #ffffff;
    --accent: #000000;
    --subtle: #666666;
  }

  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  .ornament,
  .manicule {
    display: none;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  /* Print URLs after links */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    font-family: var(--font-mono);
  }
}
