/* shared editorial system — tokens, fonts, theme, cursor, reveals */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Geist:wght@300;400;500;600;700&family=Geist+Mono:wght@400;500&display=swap');

:root {
  /* dark default */
  --bg: #0e0d0c;
  --bg-2: #161513;
  --ink: #f5f2ec;
  --ink-2: #d6d2c8;
  --muted: #8a8378;
  --line: rgba(245, 242, 236, 0.12);
  --line-strong: rgba(245, 242, 236, 0.22);
  --accent: #c084fc;
  --accent-soft: rgba(192, 132, 252, 0.16);

  --font-display: "Instrument Serif", "Times New Roman", serif;
  --font-body: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Fluid editorial type scale (theme-independent sizes) ── */
  --step-0: clamp(0.92rem, 0.88rem + 0.2vw, 1rem);     /* small mono / body */
  --step-1: clamp(1.15rem, 1.05rem + 0.5vw, 1.4rem);   /* sub-labels, small ledes */
  --step-2: clamp(1.6rem, 1.3rem + 1.4vw, 2.4rem);     /* project titles, quotes */
  --step-3: clamp(2.2rem, 1.6rem + 3vw, 3.4rem);       /* about lede, cat h4, edu degree */
  --step-4: clamp(3rem, 2rem + 5vw, 5.25rem);          /* testimonials h3, mid headings */
  --step-5: clamp(3.75rem, 2.2rem + 7.5vw, 7rem);      /* section h2 */
  --step-6: clamp(2.75rem, 1.6rem + 5.4vw, 7rem);      /* big single-line titles (contact, project hero, next) */

  /* ── Atmosphere: film grain + cursor light source (dark) ── */
  --grain-opacity: 0.05;
  --glow-color: var(--accent-soft);
  --glow-size: 60vmax;
  --clip-accent-from: var(--accent);
  --clip-accent-to: var(--ink);

  /* ── Interaction tier ── */
  --magnetic-strength: 0.28;
  --vfx-wght-base: 500;
  --vfx-wght-max: 620;
}

html[data-theme="light"] {
  --bg: #f5f2ec;
  --bg-2: #ebe7df;
  --ink: #15130f;
  --ink-2: #2a2722;
  --muted: #6d6760;
  --line: rgba(21, 19, 15, 0.12);
  --line-strong: rgba(21, 19, 15, 0.22);
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.10);

  /* lighter grain + glow on light theme to protect contrast */
  --grain-opacity: 0.035;
  --glow-color: rgba(124, 58, 237, 0.07);
  --clip-accent-from: var(--accent);
  --clip-accent-to: var(--ink);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
  font-weight: 400;
  letter-spacing: -0.005em;
  transition: background 0.5s var(--ease), color 0.5s var(--ease);
  cursor: none;
  overflow-x: hidden;
  position: relative;
}

/* ─── Atmosphere: cursor light source + film grain ──
   Both fixed, pointer-events:none, behind real content.
   Page content must sit at z-index >= 1 (it already paints over
   these because they're the first painted layers on body). */
body::after {
  /* soft accent glow that lags the cursor via --mx / --my (set in shared.js) */
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    var(--glow-size) circle at var(--mx, 50%) var(--my, 50%),
    var(--glow-color),
    transparent 70%
  );
  opacity: 0;
  transition: opacity 0.8s var(--ease);
}
body.glow-on::after { opacity: 1; }

body::before {
  /* static SVG feTurbulence film grain — no animation, rides over via soft-light */
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  mix-blend-mode: soft-light;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

/* keep real page chrome above the atmosphere layers */
.topbar, .dock, .footer-bar { position: relative; z-index: 2; }

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: none; cursor: none; }

::selection { background: var(--accent); color: var(--bg); }

/* ─── Custom cursor ──────────────────────────────── */
.cursor-dot,
.cursor-ring {
  position: fixed;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 9999;
  transform: translate3d(-100px, -100px, 0);
  will-change: transform;
  mix-blend-mode: difference;
}
.cursor-dot {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  transition: width 0.25s var(--ease-out), height 0.25s var(--ease-out), background 0.2s;
}
.cursor-ring {
  width: 28px; height: 28px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  opacity: 0.6;
  transition: width 0.3s var(--ease-out), height 0.3s var(--ease-out), opacity 0.3s, border-color 0.3s;
}
.cursor-dot.is-hover { width: 0; height: 0; }
.cursor-ring.is-hover { width: 68px; height: 68px; opacity: 0.9; }
.cursor-ring.is-text { width: 4px; height: 22px; border-radius: 1px; background: var(--accent); border-color: transparent; opacity: 0.8; }

/* hide cursor on touch */
@media (hover: none) {
  body { cursor: auto; }
  button, a { cursor: pointer; }
  .cursor-dot, .cursor-ring { display: none; }
  /* no cursor to follow on touch — disable the glow, keep the grain */
  body::after { display: none; }
}

/* ─── Reduced motion: snap reveals/curtain, keep content visible ── */
@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;
  }
  .reveal { opacity: 1; transform: none; animation: none !important; }
  .split-line .ch { transform: none; }
  .curtain { display: none; }
  .status-dot::after { animation: none; opacity: 0; }
  /* pin the light source to centre — no cursor follow */
  body::after {
    background: radial-gradient(var(--glow-size) circle at 50% 50%, var(--glow-color), transparent 70%);
    transition: none;
  }
  /* freeze mono-label weight at base */
  [data-vfx] { font-variation-settings: "wght" var(--vfx-wght-base) !important; }
  /* park the marquee readable at its start position (explicit, not just duration:0) */
  .marquee-inner { animation: none !important; transform: none !important; }
}

/* ─── Reveal animations ──────────────────────────── */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 1.1s var(--ease-out), transform 1.1s var(--ease-out);
}
.reveal.in {
  opacity: 1;
  transform: translateY(0);
}
.reveal-delay-1 { transition-delay: 0.08s; }
.reveal-delay-2 { transition-delay: 0.16s; }
.reveal-delay-3 { transition-delay: 0.24s; }

/* Native scroll-timeline reveals — additive layer over the IntersectionObserver
   fallback. Where supported, ties the reveal to the element entering the view,
   so it tracks scroll precisely. The IO `.in` path keeps working everywhere. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .reveal {
      animation: reveal-in linear forwards;
      animation-timeline: view();
      animation-range: entry 0% entry 42%;
    }
  }
}
@keyframes reveal-in {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* split-letter reveal */
.split-line {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
}
.split-line .ch {
  display: inline-block;
  transform: translateY(110%);
  transition: transform 0.9s var(--ease-out);
}
.split-line .ch.space { width: 0.28em; }
.in .split-line .ch,
.split-line.in .ch {
  transform: translateY(0);
}

/* ─── Hover image preview (for project lists) ────── */
.preview-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 320px; height: 200px;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
  overflow: hidden;
  transform: translate3d(0, 0, 0);
}
.preview-canvas.is-on { opacity: 1; }
.preview-canvas .frame {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.4s var(--ease);
  background-size: cover;
  background-position: center;
}
.preview-canvas .frame.is-on { opacity: 1; }

/* ─── Page transition curtain ────────────────────── */
.curtain {
  position: fixed;
  inset: 0;
  background: var(--accent);
  z-index: 9000;
  transform: translateY(100%);
  pointer-events: none;
}
.curtain.is-in {
  animation: curtain-in 0.7s var(--ease-out) forwards;
}
.curtain.is-out {
  animation: curtain-out 0.7s var(--ease-out) forwards;
}
@keyframes curtain-in {
  0% { transform: translateY(100%); }
  100% { transform: translateY(0); }
}
@keyframes curtain-out {
  0% { transform: translateY(0); }
  100% { transform: translateY(-100%); }
}

/* ─── Common helpers ─────────────────────────────── */
.mono { font-family: var(--font-mono); font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; font-weight: 500; }
.serif { font-family: var(--font-display); font-style: italic; }

/* serif display headline helper — art-directed leading/tracking */
.display {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  line-height: 0.92;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

/* single-word gradient-clip accent — solid fallback first */
.clip-accent { color: var(--clip-accent-from); }
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .clip-accent {
    background: linear-gradient(120deg, var(--clip-accent-from), var(--clip-accent-to));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

/* data-vfx mono-label weight breathe — base state; shared.js drives wght */
[data-vfx] {
  font-variation-settings: "wght" var(--vfx-wght-base);
  will-change: font-variation-settings;
}
.muted { color: var(--muted); }
.rule { border: none; border-top: 1px solid var(--line); }
.rule-strong { border: none; border-top: 1px solid var(--line-strong); }

/* magnetic / hovered link underline */
.link-u {
  position: relative;
  display: inline-block;
}
.link-u::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 1px;
  background: currentColor;
  transform: scaleX(1);
  transform-origin: right;
  transition: transform 0.5s var(--ease-out);
}
.link-u:hover::after {
  transform: scaleX(0);
  transform-origin: left;
}

/* shared status dot */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #6ee7b7;
  margin-right: 8px;
  vertical-align: middle;
  position: relative;
}
.status-dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: #6ee7b7;
  opacity: 0.35;
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(0.6); opacity: 0.6; }
  100% { transform: scale(2); opacity: 0; }
}

/* theme toggle button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  transition: border-color 0.3s, color 0.3s, background 0.3s;
}
.theme-toggle:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}
.theme-toggle .sun,
.theme-toggle .moon { width: 12px; height: 12px; }
html[data-theme="light"] .theme-toggle .moon { display: none; }
html[data-theme="dark"] .theme-toggle .sun,
html:not([data-theme="light"]) .theme-toggle .sun { display: none; }
