/* ═══════════════════════════════════════════════════════════════════
   base.css — reset, body, typography utilities, cursor, nav, footer,
              grain overlay, scroll progress rail.
   ═══════════════════════════════════════════════════════════════════ */

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

html { scroll-behavior: auto; }
html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-weight: var(--w-regular);
  font-feature-settings: "ss01", "cv11";
  background: var(--bg);
  color: var(--text);
  line-height: var(--lead-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

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

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

/* ─── Layout ─── */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--container-px);
  position: relative;
}

.chapter {
  position: relative;
  padding: var(--chapter-py) 0;
  isolation: isolate;
}
.chapter--paper {
  background: var(--bg-paper);
  color: var(--text-paper);
}

/* ─── Grain overlay — site-wide texture ─── */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 240px;
  will-change: transform;
}

/* ─── Typography utilities ─── */
.t-label {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: var(--w-medium);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-mute);
}
.t-label--accent { color: var(--accent); }
.t-label--paper { color: var(--text-paper-dim); }
.t-label-dot {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.t-label-dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: currentColor;
  opacity: 0.7;
}

.t-eyebrow {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: var(--w-medium);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 14px;
}
.t-eyebrow::before {
  content: "";
  width: 32px;
  height: 1px;
  background: currentColor;
  opacity: 0.6;
}
.t-eyebrow--accent { color: var(--accent); }

.t-italic {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: var(--w-light);
  letter-spacing: -0.015em;
  color: var(--accent-soft);
}

.t-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.t-rule {
  display: block;
  height: 1px;
  background: var(--rule);
  border: none;
  margin: 0;
}
.chapter--paper .t-rule { background: var(--rule-paper); }

/* ─── Nav ─── */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 90;
  padding: 20px 0;
  color: var(--text);
  transition: transform 0.5s var(--ease-out), background 0.3s var(--ease-out), backdrop-filter 0.3s var(--ease-out);
}
.nav.is-scrolled {
  background: color-mix(in srgb, var(--ink-950) 72%, transparent);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}
.nav.is-hidden { transform: translateY(-100%); }

.nav-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--container-px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}

.nav-brand {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: var(--w-semibold);
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.nav-brand::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: var(--r-full);
  background: var(--accent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 60%, transparent);
}

.nav-links {
  display: inline-flex;
  gap: 28px;
  font-size: 0.875rem;
  font-weight: var(--w-medium);
  color: var(--text-dim);
}
.nav-links a {
  position: relative;
  padding: 4px 0;
  transition: color var(--dur-fast) var(--ease-out);
}
.nav-links a:hover { color: var(--text); }
.nav-links a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s var(--ease-out);
}
.nav-links a:hover::after,
.nav-links a.is-active::after { transform: scaleX(1); }

.nav-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  font-weight: var(--w-medium);
  padding: 10px 18px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--ink-950);
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.nav-cta:hover { background: var(--accent-soft); transform: translateY(-1px); }

/* ─── Mobile nav — hide links, keep brand + CTA ─── */
@media (max-width: 768px) {
  .nav { padding: 14px 0; }
  .nav-inner { gap: 12px; }
  .nav-links { display: none; }
  .nav-cta { padding: 9px 14px; font-size: 0.8125rem; }
  .nav-brand { font-size: 0.875rem; }
  .nav-brand::before { width: 8px; height: 8px; }
}

/* ─── Custom cursor ─── */
.cursor {
  position: fixed;
  top: 0; left: 0;
  width: 12px;
  height: 12px;
  border-radius: var(--r-full);
  background: var(--accent);
  pointer-events: none;
  z-index: 200;
  mix-blend-mode: difference;
  transform: translate(-50%, -50%);
  will-change: transform, width, height;
  transition:
    width 0.3s var(--ease-out),
    height 0.3s var(--ease-out),
    background 0.3s var(--ease-out);
}
.cursor.is-hover {
  width: 56px;
  height: 56px;
  background: var(--mauve-200);
}
.cursor.is-label {
  width: 92px;
  height: 92px;
  background: var(--mauve-200);
}
.cursor-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: var(--w-semibold);
  letter-spacing: var(--track-label-tight);
  text-transform: uppercase;
  color: var(--ink-950);
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
  pointer-events: none;
  white-space: nowrap;
}
.cursor.is-label .cursor-label { opacity: 1; }
.cursor.is-out { opacity: 0; }

@media (hover: none), (prefers-reduced-motion: reduce) {
  .cursor { display: none; }
}

/* ─── Scroll progress — vertical side rail ─── */
.scroll-rail {
  position: fixed;
  top: 0;
  right: clamp(14px, 2vw, 24px);
  bottom: 0;
  width: 1px;
  background: var(--rule);
  z-index: 80;
  pointer-events: none;
}
.scroll-rail::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--progress, 0%);
  background: var(--accent);
  transition: height 0.1s linear;
}

@media (max-width: 900px) { .scroll-rail { display: none; } }
@media (prefers-reduced-motion: reduce) { .scroll-rail { display: none; } }

/* ─── Magnetic button ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: var(--w-medium);
  letter-spacing: -0.005em;
  padding: 18px 28px;
  border-radius: var(--r-full);
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  will-change: transform;
}
.btn--primary {
  background: var(--accent);
  color: var(--ink-950);
}
.btn--primary:hover { background: var(--mauve-300); }
.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--rule);
}
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn--xl {
  padding: 22px 36px;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.btn-arrow {
  display: inline-block;
  transition: transform var(--dur-fast) var(--ease-out);
}
.btn:hover .btn-arrow { transform: translateX(4px); }

/* ─── Footer ─── */
.foot {
  background: var(--ink-900);
  color: var(--text-dim);
  padding: clamp(56px, 8vw, 96px) 0 24px;
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
}
.foot-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: clamp(32px, 5vw, 72px);
  align-items: start;
}
.foot-brand-line {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: var(--w-light);
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  color: var(--text);
  line-height: var(--lead-tight);
  max-width: 22ch;
  margin-top: 12px;
}
.foot-col h4 {
  font-size: 0.6875rem;
  font-weight: var(--w-medium);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 16px;
}
.foot-col ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.foot-col a { transition: color var(--dur-fast); }
.foot-col a:hover { color: var(--accent); }
.foot-bottom {
  margin-top: clamp(40px, 6vw, 72px);
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 24px;
  font-size: 0.75rem;
  color: var(--text-mute);
}

@media (max-width: 900px) {
  .foot-grid { grid-template-columns: 1fr 1fr; gap: 32px; }
  .foot-grid .foot-brand { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .foot-grid { grid-template-columns: 1fr; }
  .foot-bottom { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ─── Reduced motion ─── */
@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;
  }
}
