/* nichfoster.com — hand-crafted, no build step.
   Editorial design system (lane W1): Source Serif 4 for display, Inter for
   body, dark default with a designed light mode, and spacing / type / motion
   tokens on custom properties. Palette: dark navy, reaction-teal accent,
   bond-blue secondary; light mode is a warm paper counterpart, not an
   inversion of the dark values. */

:root {
  color-scheme: dark;

  /* --- colour · dark default ---
     The light blocks below override every colour token; these dark values
     are the source of truth for the default theme. Tints of the accents
     (borders, glows, note fills) are derived inline with color-mix() so a
     theme change restyles them without duplicate rules. */
  --bg: #0a0e14;
  --surface: #111826;
  --ink: #e8eef7;
  --muted: #93a1b5;
  --accent: #34e0c4;
  --accent-2: #6c8cff;
  --edge: #1f2b3d;
  --nav-bg: rgba(10, 14, 20, 0.72);

  /* --- rhythm --- */
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 3rem;
  --space-5: 6rem;

  /* --- type --- */
  --font-display: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-lg: clamp(1.02rem, 2.2vw, 1.25rem);
  --text-2xl: clamp(1.55rem, 3.5vw, 2.15rem);
  --text-3xl: clamp(2.5rem, 7vw, 4.4rem);

  /* --- motion ---
     Every animation reads these; both durations collapse to zero under
     prefers-reduced-motion (guard at the bottom of this file). */
  --dur-quick: 160ms;
  --dur-scene: 700ms;
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* --- light mode ---
   A designed warm-paper palette: deep navy ink, darkened reaction-teal and
   bond-blue accents for text contrast, white surfaces. Keep this palette
   byte-identical in both blocks — the media query follows the OS setting,
   and the [data-theme] attribute is the manual hook a future toggle sets
   (no toggle button in this lane). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f7f5f0;
    --surface: #ffffff;
    --ink: #1b2534;
    --muted: #5d6a7d;
    --accent: #0f766e;
    --accent-2: #4338ca;
    --edge: rgba(27, 37, 52, 0.16);
    --nav-bg: rgba(247, 245, 240, 0.82);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f5f0;
  --surface: #ffffff;
  --ink: #1b2534;
  --muted: #5d6a7d;
  --accent: #0f766e;
  --accent-2: #4338ca;
  --edge: rgba(27, 37, 52, 0.16);
  --nav-bg: rgba(247, 245, 240, 0.82);
}

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

html {
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* --- molecular canvas backdrop --- */
#molecule-field {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  display: block;
}

/* --- shared --- */
a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.container {
  max-width: 62rem;
  margin-inline: auto;
}

.kicker {
  margin: 0 0 0.75rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-2xl);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 1.1rem;
}

.lead {
  color: var(--muted);
  max-width: 42rem;
  font-size: 1.05rem;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: var(--space-1);
  z-index: 20;
  background: var(--surface);
  color: var(--ink);
  padding: var(--space-1) var(--space-2);
  border-radius: 8px;
  border: 1px solid var(--edge);
}

.skip-link:focus {
  left: var(--space-1);
}

/* --- nav --- */
.nav {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem clamp(1.1rem, 4vw, 2.25rem);
  background: var(--nav-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--edge);
}

.nav-brand {
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.nav-brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.nav-links {
  display: flex;
  gap: clamp(0.85rem, 3vw, 1.5rem);
}

.nav-links a {
  color: var(--muted);
  font-size: 0.9rem;
  /* 44px tap target: block padding + line box ≈ 44.9px at the 0.875rem
     small-viewport size and ≈ 45.5px at the 0.9rem desktop size (measured
     in Chrome for Testing 154; the nominal 0.65rem lands just under 44px
     at 0.875rem, so this is tuned to the measured height). */
  padding: 0.68rem 0.25rem;
}

.nav-links a:hover {
  color: var(--ink);
  text-decoration: none;
}

/* First width breakpoint: brand + four links crowd at 320-360px. */
@media (max-width: 480px) {
  .nav {
    padding-inline: 1rem;
    /* Baseline (not center): when the links wrap, the brand stays on the
       first link row's baseline instead of floating mid-nav. The gap is a
       guaranteed separator: a wrapped .nav-links fills all remaining width,
       so space-between alone leaves the brand touching the first link. */
    align-items: baseline;
    gap: 0.75rem;
  }

  .nav-links {
    gap: 0.75rem;
    flex-wrap: wrap;
  }

  .nav-links a {
    font-size: 0.875rem;
  }
}

/* --- hero --- */
#hero {
  /* Anchors the ambient drift pseudo-layer; hidden clips the glow to the hero. */
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--space-5) 1.25rem var(--space-4);
}

/* Display face on every h1 — index scopes its hero h1 below, and the 404
   page's page-scoped h1 borrows the same editorial treatment. */
h1 {
  font-family: var(--font-display);
  font-weight: 600;
}

#hero h1 {
  font-size: var(--text-3xl);
  line-height: 1.04;
  letter-spacing: -0.02em;
  margin: 0 0 1.1rem;
}

.grad {
  background: linear-gradient(92deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-tagline {
  color: var(--muted);
  font-size: var(--text-lg);
  max-width: 36rem;
  margin: 0 auto 1.9rem;
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 44px tap-target floor; with the 1.65 line-height this renders ≈ 46.9px. */
  min-height: 44px;
  padding: 0.62rem 1.25rem;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.95rem;
  transition: border-color var(--dur-quick) var(--ease-out),
    transform var(--dur-quick) var(--ease-out);
}

.btn:hover {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  text-decoration: none;
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(
    92deg,
    color-mix(in srgb, var(--accent) 14%, transparent),
    color-mix(in srgb, var(--accent-2) 14%, transparent)
  );
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
}

/* --- sections --- */
section {
  padding: clamp(3.5rem, 9vh, 6.5rem) clamp(1.25rem, 6vw, 2rem);
}

#research,
#projects,
#contact {
  border-top: 1px solid var(--edge);
}

/* --- research note / placeholders --- */
.note {
  margin-top: 1.6rem;
  padding: 1rem 1.25rem 1.1rem;
  border: 1px dashed color-mix(in srgb, var(--accent-2) 50%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  color: var(--muted);
  max-width: 42rem;
}

.note p {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
}

.chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-2);
  border: 1px solid color-mix(in srgb, var(--accent-2) 45%, transparent);
  border-radius: 999px;
  padding: 0.14rem 0.6rem;
}

/* --- projects --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.2rem;
  margin-top: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 1.5rem 1.4rem 1.6rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.7rem;
  transition: border-color var(--dur-quick) var(--ease-out),
    transform var(--dur-quick) var(--ease-out);
}

.card:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  transform: translateY(-2px);
}

.card h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  font-size: 1.12rem;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  flex: 1;
}

.card-link {
  font-size: 0.92rem;
}

.muted-note {
  font-size: 0.88rem;
  color: var(--muted);
}

.card.placeholder {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--accent-2) 50%, transparent);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

/* --- footer --- */
footer {
  border-top: 1px solid var(--edge);
  padding: 2.2rem 1.25rem 3rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- motion: hero entrance + scroll reveals ---
   The default branch is always-visible content: hiding and animation only
   apply when the user allows motion (no-preference). The `.js` class gate
   (set inline in index.html) keeps reveals visible without JavaScript. */
@media (prefers-reduced-motion: no-preference) {
  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(14px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  #hero .container > * {
    animation: rise var(--dur-scene) ease both;
  }

  #hero .container > :nth-child(2) {
    animation-delay: 0.08s;
  }

  #hero .container > :nth-child(3) {
    animation-delay: 0.16s;
  }

  #hero .container > :nth-child(4) {
    animation-delay: 0.24s;
  }

  .js [data-reveal] {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity var(--dur-scene) var(--ease-out),
      transform var(--dur-scene) var(--ease-out);
  }

  .js [data-reveal].is-visible {
    opacity: 1;
    transform: none;
  }

  .js .card-grid .card:nth-child(2) {
    transition-delay: 0.08s;
  }

  .js .card-grid .card:nth-child(3) {
    transition-delay: 0.16s;
  }

  /* Ambient: the legacy site's slow gradient-drift glow, ported to a
     hero-scoped pseudo layer (no markup change) using the site's own
     accent tokens at legacy alphas. Transform-only, 22s alternate cycle. */
  #hero::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
      radial-gradient(
        60vw 60vw at 12% 18%,
        color-mix(in srgb, var(--accent) 10%, transparent),
        transparent 60%
      ),
      radial-gradient(
        55vw 55vw at 88% 42%,
        color-mix(in srgb, var(--accent-2) 9%, transparent),
        transparent 60%
      );
    animation: drift 22s ease-in-out infinite alternate;
  }

  @keyframes drift {
    from {
      transform: scale(1) translateY(0);
    }
    to {
      transform: scale(1.15) translateY(-2%);
    }
  }
}

/* Second guard: reduced motion still gets instant, still content. */
@media (prefers-reduced-motion: reduce) {
  :root {
    /* Motion off: the duration tokens collapse, so anything reading them
       is still even before the hard stop below. */
    --dur-quick: 0ms;
    --dur-scene: 0ms;
  }

  html {
    scroll-behavior: auto;
  }

  /* Motion off: entrance and reveals resolve instantly. */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }

  .js [data-reveal] {
    opacity: 1;
    transform: none;
  }
}
