/* ============================================================
   BASE STYLES — Reset, Typography, Focus, Grain
   ============================================================ */

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

html {
  font-size: 16px;
  scroll-behavior: auto; /* Lenis handles smooth scroll */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--lh-normal);
  background-color: var(--c-dark);
  color: var(--c-light-text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: default;
}

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

ul, ol {
  list-style: none;
}

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

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

pre, code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

/* ── Typography ────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
}

em {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: var(--weight-medium);
}

.font-hand {
  font-family: var(--font-hand);
  font-weight: 600;
}

.hand-note {
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: clamp(1.05rem, 1.4vw, 1.3rem);
  color: var(--c-accent-light);
  display: inline-block;
  transform: rotate(-1.2deg);
  line-height: 1.3;
}

p {
  line-height: var(--lh-normal);
}

blockquote {
  quotes: none;
}

blockquote p::before,
blockquote p::after {
  content: '';
}

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

:focus:not(:focus-visible) {
  outline: none;
}

.chapter-nav__item:focus-visible {
  outline: none;
}

.chapter-nav__item:focus-visible .chapter-nav__dot {
  outline: 2px solid var(--c-accent);
  outline-offset: 3px;
}

/* ── Skip Link ────────────────────────────────────────────── */
.skip-link {
  position: fixed;
  top: var(--space-4);
  left: var(--space-4);
  z-index: 999;
  padding: var(--space-2) var(--space-4);
  background: var(--c-accent);
  color: var(--c-dark);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease-out);
}

.skip-link:focus {
  transform: translateY(0);
}

/* ── Grain Overlay ────────────────────────────────────────── */
.grain {
  position: fixed;
  inset: -50%;
  width: 200%;
  height: 200%;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.035;
  will-change: transform;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
  animation: grain-move 0.5s steps(1) infinite;
}

@keyframes grain-move {
  0%   { transform: translate(0, 0); }
  10%  { transform: translate(-4%, -4%); }
  20%  { transform: translate(-8%, 4%); }
  30%  { transform: translate(4%, -8%); }
  40%  { transform: translate(-4%, 12%); }
  50%  { transform: translate(-8%, 4%); }
  60%  { transform: translate(4%, 0); }
  70%  { transform: translate(0, 8%); }
  80%  { transform: translate(-4%, 4%); }
  90%  { transform: translate(8%, -4%); }
  100% { transform: translate(4%, 4%); }
}

/* ── Progress Bar ─────────────────────────────────────────── */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--c-accent);
  z-index: var(--z-progress);
  transform-origin: left;
  transition: width 0.1s linear;
  pointer-events: none;
}

/* ── Reduced Motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .grain {
    animation: none;
  }
}

/* ── Selection ────────────────────────────────────────────── */
::selection {
  background: var(--c-accent);
  color: var(--c-dark);
}

/* ── Scrollbar (minimal) ──────────────────────────────────── */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: var(--c-dark);
}
::-webkit-scrollbar-thumb {
  background: var(--c-rule-dark);
  border-radius: 2px;
}

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