/* ==========================================================================
   Base Reset, Typography, Accessibility Focus, Grain Texture & Reveals
   ========================================================================== */

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

html {
  scroll-behavior: smooth;
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  background-color: var(--color-surface-base);
  color: var(--color-text-primary);
  font-family: var(--font-primary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-base);
  line-height: var(--font-line-height-base);
  overflow-x: hidden;
  transition: background-color var(--motion-duration-fast) var(--ease-fluid),
              color var(--motion-duration-fast) var(--ease-fluid);
}

/* Tactile grain overlay fixed to viewport to eliminate flat digital sheen without scroll repaints */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.032;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

[data-theme="light"] body::after {
  opacity: 0.02;
}

img,
picture,
svg,
video {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

/* Typography Hierarchy */
h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  color: var(--color-text-primary);
  letter-spacing: -0.025em;
  text-wrap: balance;
}

h1 {
  font-size: var(--text-h1);
  line-height: 1.06;
  font-weight: 800;
}

h2 {
  font-size: var(--text-h2);
  line-height: 1.12;
  font-weight: 700;
}

h3 {
  font-size: var(--text-h3);
  line-height: 1.25;
  font-weight: 700;
}

p {
  max-width: 65ch;
  text-wrap: pretty;
}

.mono-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.accent-highlight {
  color: var(--color-text-tertiary);
}

/* Focus-Visible Accessibility Rules (WCAG 2.2 AA) */
:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: var(--space-12);
  z-index: var(--z-skip);
  padding: var(--space-8) var(--space-16);
  background: var(--color-surface-strong);
  color: var(--color-text-inverse);
  font-weight: 700;
  font-size: var(--font-size-2xl);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-1);
  transition: top var(--motion-duration-instant) var(--ease-fluid);
}

.skip-link:focus {
  top: var(--space-12);
}

/* Global [hidden] Guard & Screen Reader Utility */
[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Icon Uniformity (Phosphor 1.5 stroke normalized) */
.ph-icon {
  width: 1.15em;
  height: 1.15em;
  fill: currentColor;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* Scroll Progress Bar (CSS Scroll-Driven Animation, zero JS scroll listener) */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: var(--z-header);
  background: linear-gradient(90deg, var(--color-surface-strong), var(--color-text-tertiary));
  transform-origin: left center;
  transform: scaleX(0);
  pointer-events: none;
}

@supports (animation-timeline: scroll()) {
  .scroll-progress {
    animation: progressScale linear both;
    animation-timeline: scroll(root block);
  }
}

@keyframes progressScale {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

/* Scroll Reveal Choreography (IntersectionObserver Driven, Directional) */
[data-reveal] {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 720ms var(--ease-spring),
              transform 720ms var(--ease-spring);
  transition-delay: var(--delay, 0ms);
  will-change: opacity, transform;
}

[data-reveal="left"] {
  transform: translateX(-30px);
}

[data-reveal="right"] {
  transform: translateX(30px);
}

[data-reveal="zoom"] {
  transform: scale(0.94);
}

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

/* Reduced Motion Mandate */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

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