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

/* ----- Design tokens ----- */
:root {
  --line-length: 68ch;

  /* Typography — single-serif look inspired by danielwyb.com
     (Source Serif 4 is the closest open-source match to Poynter Oldstyle Text) */
  --font-serif: "Source Serif 4", "Source Serif Pro", ui-serif, Georgia,
    "Times New Roman", serif;
  --font-sans: var(--font-serif);
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  /* Motion */
  --ease-out-soft: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --dur-1: 120ms;
  --dur-2: 200ms;
  --dur-3: 320ms;
  --dur-4: 520ms;

  /* Shape */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-pill: 999px;

  /* Surfaces — overridden by data-theme below */
  color-scheme: light;
}

/* ---------------------------------------------------------------
   Shared green accent — deep pine / evergreen.
   Intentionally more saturated and cooler than the old washed-out
   sage (#7ea06b) so it reads as a confident green, not a beige-green.
   --------------------------------------------------------------- */

/* ---------- Light (default, clean white) ----------
   Flat aesthetic: borders do the work, shadows nearly absent. */
:root,
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-tint: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-glass: rgba(255, 255, 255, 0.75);
  --surface-glass-border: rgba(15, 17, 19, 0.09);

  --text: #0a0c0e;
  --text-muted: #4d5159;
  --text-faint: #868991;

  --accent: #1f5a40;
  --accent-ink: #ffffff;
  --accent-soft: #e4ede7;

  --border: rgba(15, 17, 19, 0.1);
  --border-strong: rgba(15, 17, 19, 0.18);

  --shadow-sm: 0 0 0 0 rgba(0, 0, 0, 0);
  --shadow-md: 0 1px 0 rgba(15, 17, 19, 0.03);
  --shadow-lg: 0 2px 0 rgba(15, 17, 19, 0.04),
    0 12px 28px rgba(15, 17, 19, 0.06);

  /* Legacy token compatibility */
  --bg-color: var(--bg);
  --text-color: var(--text);
  --link-color: var(--accent);
  --brand-color-primary: var(--accent);
  --brand-color-secondary: #2a5b6a;
  --hover-color-primary: #143f2d;
  --hover-color-secondary: #1b3f49;
  --bg-color-semitransparent: rgba(255, 255, 255, 0.75);
  --bg-color-secondary: var(--surface-2);
  --text-color-secondary: var(--text-muted);
  --border-color: var(--border);
  --brand-color-primary-offset: #cfdfd5;
}

/* ---------- Dark — new emerald (no more pale sage) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0f1012;
  --bg-tint: #17181b;
  --surface: #1a1b1e;
  --surface-2: #222327;
  --surface-glass: rgba(26, 27, 30, 0.55);
  --surface-glass-border: rgba(255, 255, 255, 0.08);

  --text: #efece5;
  --text-muted: #958d84;
  --text-faint: #625c55;

  /* Brighter than light-mode pine so links / “Read essay” read clearly on dark. */
  --accent: #3f946e;
  --accent-ink: #ffffff;   /* white on accent fills */
  --accent-soft: #1a2f27;  /* deep tint of the dark accent */

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35),
    0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.45),
    0 30px 80px rgba(0, 0, 0, 0.5);

  --bg-color: var(--bg);
  --text-color: var(--text);
  --link-color: var(--accent);
  --brand-color-primary: var(--accent);
  --brand-color-secondary: #7fb6b0;
  --hover-color-primary: #2a4a36;
  --hover-color-secondary: #1e3b3a;
  --bg-color-semitransparent: rgba(15, 16, 18, 0.72);
  --bg-color-secondary: var(--surface-2);
  --text-color-secondary: var(--text-muted);
  --border-color: var(--border);
  --brand-color-primary-offset: #8fd6b6;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color var(--dur-3) var(--ease-out-soft),
    color var(--dur-3) var(--ease-out-soft);
}

/* ----- Typography ----- */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.15;
  margin: 0 0 0.5em 0;
}

h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(2.5rem, 5vw, 4rem);
  letter-spacing: -0.01em;
  line-height: 1.1;
  margin: 0 0 0.6em 0;
}

h2 { font-size: clamp(1.5rem, 2.4vw, 2rem); margin: 1.6em 0 0.4em; }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.2rem; }
h5 { font-size: 1.1rem; }
h6 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }

p,
ul,
ol {
  font-size: 1.125rem;
  line-height: 1.7;
  margin: 1.1em 0;
}

ol,
ul {
  padding-left: 1.5rem;
}

li {
  margin: 0.5rem 0;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--dur-2) var(--ease-out-soft),
    opacity var(--dur-2) var(--ease-out-soft);
}

a:hover {
  color: var(--accent);
}

/* External inline prose links: subtle underline at rest,
   expands to fully cover the text on hover. Internal links
   (relative hrefs) are intentionally left plain. */
.prose a[href^="http"],
article a[href^="http"],
.container p a[href^="http"],
blockquote a[href^="http"] {
  color: var(--text);
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-size: 100% 1px;
  background-position: 0 100%;
  /* Vertical padding expands the inline background-painting area so
     100%×100% on hover actually covers ascenders + descenders. */
  padding: 0.12em 0.05em 0.04em;
  margin: 0 -0.05em;
  border-radius: 2px;
  transition: background-size var(--dur-3) var(--ease-out-soft),
    color var(--dur-2) var(--ease-out-soft);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  box-shadow: none;
}

.prose a[href^="http"]:hover,
article a[href^="http"]:hover,
.container p a[href^="http"]:hover,
blockquote a[href^="http"]:hover {
  background-size: 100% 100%;
  color: var(--accent-ink);
}

img {
  max-width: 100%;
  display: block;
}

hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 3rem auto;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--text);
  background: var(--surface-2);
  padding: 0.15em 0.4em;
  border-radius: 6px;
  border: 1px solid var(--border);
}

pre {
  border-radius: var(--radius-md) !important;
  margin: 1.4em 0 !important;
  box-shadow: var(--shadow-sm);
}

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

blockquote {
  border-left: 2px solid var(--accent);
  font-style: italic;
  font-size: 1.2em;
  color: var(--text-muted);
  margin: 2rem 0;
  padding: 0.2rem 1.5rem;
}

blockquote p {
  margin: 0.4em 0;
}

figure {
  margin: 0 0 2em;
}

table {
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 1rem;
  margin: 2em 0;
  width: 100%;
}

th,
td {
  padding: 0.6em 0.8em;
  text-align: left;
}

th {
  border-bottom: 1px solid var(--border-strong);
  font-weight: 600;
}

td {
  border-bottom: 1px solid var(--border);
}

/* ----- Utilities ----- */
.container {
  margin: 0 auto;
  max-width: 42rem;
  width: 100%;
  padding: 0 1rem;
}

.content h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0.4em 0 0.6em;
}

/* Reusable card surface */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-3) var(--ease-out-soft),
    box-shadow var(--dur-3) var(--ease-out-soft),
    border-color var(--dur-2) var(--ease-out-soft);
}

a.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

/* Pill element (nav chips, buttons) */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: transform var(--dur-2) var(--ease-out-soft),
    box-shadow var(--dur-2) var(--ease-out-soft),
    background var(--dur-2) var(--ease-out-soft),
    border-color var(--dur-2) var(--ease-out-soft);
  cursor: pointer;
}

.pill:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
  color: var(--text);
}

.pill[aria-current="page"],
.pill.is-active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* Focus ring used across interactive elements */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ----- Motion — gentle entrance ----- */
@keyframes tay-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.rise {
  animation: tay-rise var(--dur-4) var(--ease-out-soft) both;
}

.rise-stagger > * {
  animation: tay-rise var(--dur-4) var(--ease-out-soft) both;
}
.rise-stagger > *:nth-child(1) { animation-delay: 0ms; }
.rise-stagger > *:nth-child(2) { animation-delay: 60ms; }
.rise-stagger > *:nth-child(3) { animation-delay: 120ms; }
.rise-stagger > *:nth-child(4) { animation-delay: 180ms; }
.rise-stagger > *:nth-child(5) { animation-delay: 240ms; }
.rise-stagger > *:nth-child(6) { animation-delay: 300ms; }
.rise-stagger > *:nth-child(7) { animation-delay: 360ms; }
.rise-stagger > *:nth-child(8) { animation-delay: 420ms; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ----- Responsive ----- */
@media (max-width: 720px) {
  body {
    font-size: 15px;
  }

  p,
  ul,
  ol {
    font-size: 1.05rem;
  }
}
