/* ============================================
   GLOBAL STYLES
   ============================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-1);
  color: var(--fg-0);
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: clip;
}

body {
  min-height: 100vh;
  position: relative;
}

/* Grain overlay on body */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: var(--grain);
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* Retro scanlines */
:root[data-retro="on"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.15) 0px,
    rgba(0,0,0,0.15) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}

a { color: inherit; text-decoration: none; }

button { font-family: inherit; }

::selection { background: var(--accent-soft); color: var(--fg-0); }

/* ============================================
   TYPE SCALE — utility classes
   ============================================ */

.t-display {
  font-size: clamp(48px, 8vw, 112px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 0.96;
}
.t-h1 {
  font-size: clamp(36px, 5vw, 64px);
  font-weight: 500;
  letter-spacing: -0.025em;
  line-height: 1.02;
}
.t-h2 {
  font-size: clamp(28px, 3.5vw, 42px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.t-h3 {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.012em;
  line-height: 1.25;
}
.t-lede {
  font-size: clamp(17px, 1.5vw, 20px);
  color: var(--fg-1);
  line-height: 1.55;
  letter-spacing: -0.01em;
  font-weight: 400;
}
.t-body { font-size: 16px; line-height: 1.62; color: var(--fg-1); }
.t-small { font-size: 13px; line-height: 1.5; color: var(--fg-2); }
.t-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-2);
  font-weight: 500;
}
.t-mono { font-family: var(--font-mono); }

:root[data-type="serif"] .t-display,
:root[data-type="serif"] .t-h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  letter-spacing: -0.015em;
}

/* ============================================
   LAYOUT
   ============================================ */

.container {
  max-width: var(--container);
  width: 100%;
  margin: 0 auto;
  padding: 0 calc(var(--s-6) * var(--density));
}
.container-reading {
  max-width: var(--container-reading);
  margin: 0 auto;
  padding: 0 calc(var(--s-5) * var(--density));
}
.section {
  padding: calc(var(--s-10) * var(--density)) 0;
}
.section-sm {
  padding: calc(var(--s-8) * var(--density)) 0;
}

/* ============================================
   HELPERS
   ============================================ */

.divider {
  height: 1px;
  background: var(--line-1);
  width: 100%;
}

.gradient-border {
  position: relative;
  border-radius: var(--r-4);
  background: var(--bg-2);
}
.gradient-border::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.02) 50%, rgba(255,255,255,0.06));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}

.fade-in {
  animation: fadeIn 0.6s var(--ease-out) both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in-up {
  opacity: 0;
  transform: translateY(16px);
  animation: fadeInUp 0.8s var(--ease-out) forwards;
}
@keyframes fadeInUp {
  to { opacity: 1; transform: translateY(0); }
}

/* stagger children */
[data-stagger] > * { opacity: 0; transform: translateY(12px); animation: fadeInUp 0.7s var(--ease-out) forwards; }
[data-stagger] > *:nth-child(1) { animation-delay: 0.05s; }
[data-stagger] > *:nth-child(2) { animation-delay: 0.12s; }
[data-stagger] > *:nth-child(3) { animation-delay: 0.19s; }
[data-stagger] > *:nth-child(4) { animation-delay: 0.26s; }
[data-stagger] > *:nth-child(5) { animation-delay: 0.33s; }
[data-stagger] > *:nth-child(6) { animation-delay: 0.40s; }
[data-stagger] > *:nth-child(7) { animation-delay: 0.47s; }
[data-stagger] > *:nth-child(8) { animation-delay: 0.54s; }

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 5px; border: 2px solid var(--bg-1); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-3); }

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

/* Pixel character anchored bottom-right */
.pixel-buddy {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  z-index: 50;
  cursor: pointer;
  image-rendering: pixelated;
  transition: transform 0.2s var(--ease-spring);
}
.pixel-buddy:hover { transform: translateY(-4px) scale(1.08); }
