/* ===== Fonts ===== */

@font-face {
  font-family: "Literata";
  src:
    url("/fonts/literata-latin-opsz-normal.woff2") format("woff2"),
    url("/fonts/literata-latin-ext-opsz-normal.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Literata";
  src:
    url("/fonts/literata-latin-opsz-italic.woff2") format("woff2"),
    url("/fonts/literata-latin-ext-opsz-italic.woff2") format("woff2");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0000-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Inter";
  src:
    url("/fonts/inter-latin-opsz-normal.woff2") format("woff2"),
    url("/fonts/inter-latin-ext-opsz-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Inter";
  src:
    url("/fonts/inter-latin-opsz-italic.woff2") format("woff2"),
    url("/fonts/inter-latin-ext-opsz-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0000-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "JetBrains Mono";
  src:
    url("/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2"),
    url("/fonts/jetbrains-mono-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ===== Tokens ===== */

:root {
  /* Font stacks */
  --font-body: "Literata", Georgia, "Times New Roman", serif;
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "Cascadia Code", "Fira Code", monospace;

  /* Modular scale — minor third (1.2) with fluid clamp */
  --text-sm: clamp(0.833rem, 0.75rem + 0.2vw, 0.875rem);
  --text-base: clamp(1rem, 0.9rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.2rem, 1.05rem + 0.4vw, 1.35rem);
  --text-xl: clamp(1.44rem, 1.2rem + 0.6vw, 1.62rem);
  --text-2xl: clamp(1.728rem, 1.4rem + 0.8vw, 1.944rem);
  --text-3xl: clamp(2.074rem, 1.6rem + 1.2vw, 2.488rem);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Measure */
  --measure: 65ch;

  /* Line heights */
  --leading-tight: 1.2;
  --leading-body: 1.6;
  --leading-loose: 1.8;
}

/* ===== Colors — light (default) ===== */

:root {
  --color-bg: #faf6f0;
  --color-text: #3d3530;
  --color-muted: #6b5f55;
  --color-accent: #8b4513;
  --color-border: #d4cdc5;
  --color-code-bg: #f0ece6;
  --color-highlight: #fff3cd;
}

/* ===== Colors — dark ===== */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #1e1a17;
    --color-text: #e8e0d6;
    --color-muted: #a89888;
    --color-accent: #d4945a;
    --color-border: #4a4038;
    --color-code-bg: #2a2420;
    --color-highlight: #3d3020;
  }
}

[data-theme="dark"] {
  --color-bg: #1e1a17;
  --color-text: #e8e0d6;
  --color-muted: #a89888;
  --color-accent: #d4945a;
  --color-border: #4a4038;
  --color-code-bg: #2a2420;
  --color-highlight: #3d3020;
}

/* ===== High contrast ===== */

@media (prefers-contrast: more) {
  :root {
    --color-bg: #ffffff;
    --color-text: #000000;
    --color-muted: #3d3530;
    --color-accent: #6b2f00;
    --color-border: #000000;
    --color-code-bg: #f0ece6;
    --color-highlight: #fff3cd;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --color-bg: #000000;
      --color-text: #ffffff;
      --color-muted: #d4cdc5;
      --color-accent: #f0b070;
      --color-border: #ffffff;
      --color-code-bg: #1a1410;
      --color-highlight: #3d3020;
    }
  }

  [data-theme="dark"] {
    --color-bg: #000000;
    --color-text: #ffffff;
    --color-muted: #d4cdc5;
    --color-accent: #f0b070;
    --color-border: #ffffff;
    --color-code-bg: #1a1410;
    --color-highlight: #3d3020;
  }
}

/* ===== Reset ===== */

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

/* ===== Body ===== */

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--color-text);
  background-color: var(--color-bg);
}

/* ===== Headings ===== */

h1, h2, h3, h4 {
  font-family: var(--font-ui);
  line-height: var(--leading-tight);
  margin-block: var(--space-xl) var(--space-md);
}

h1 { font-size: var(--text-3xl); font-weight: 700; }
h2 { font-size: var(--text-2xl); font-weight: 650; }
h3 { font-size: var(--text-xl); font-weight: 600; }
h4 { font-size: var(--text-lg); font-weight: 600; }

/* ===== Prose ===== */

p, ul, ol {
  margin-block-end: var(--space-md);
}

ul, ol {
  padding-inline-start: var(--space-xl);
}

blockquote {
  margin-block: var(--space-lg);
  padding-inline-start: var(--space-lg);
  border-inline-start: 0.2em solid var(--color-border);
  font-style: italic;
  color: var(--color-muted);
}

/* ===== Code ===== */

code {
  font-family: var(--font-code);
  font-size: 0.875em;
}

pre {
  margin-block: var(--space-lg);
  padding: var(--space-md);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: var(--leading-loose);
  background-color: var(--color-code-bg);
  border-radius: 0.25rem;

  & code {
    font-size: inherit;
  }
}

code:not(pre code) {
  background-color: var(--color-code-bg);
  padding: 0.1em 0.3em;
  border-radius: 0.2em;
}

/* ===== Links ===== */

a {
  color: var(--color-accent);
  text-underline-offset: 0.15em;
}

/* ===== Page header ===== */

.site-header {
  font-family: var(--font-ui);
  padding-block: var(--space-lg);
  margin-block-end: var(--space-xl);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-sm) var(--space-lg);
}

.site-title {
  font-size: var(--text-lg);
  font-weight: 700;
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  list-style: none;
  font-size: var(--text-sm);
}

/* ===== Theme toggle ===== */

.theme-toggle {
  margin-inline-start: auto;
  background: none;
  border: 0.0625rem solid var(--color-border);
  border-radius: 0.25rem;
  padding: 0.35em 0.6em;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-muted);
  cursor: pointer;
  line-height: 1;
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;

  &:hover {
    color: var(--color-text);
    border-color: var(--color-text);
  }
}

/* ===== Page footer ===== */

.site-footer {
  margin-block-start: auto;
  padding-block: var(--space-xl);
  border-block-start: 0.0625rem solid var(--color-border);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-muted);
}

/* ===== Focus ===== */

:focus-visible {
  outline: 0.125rem solid var(--color-accent);
  outline-offset: 0.125rem;
}

/* ===== Reduced motion ===== */

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