/* ---------------------------------------------------------------
   base.css — reset, design tokens, type scale, grid, themes
--------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
}

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

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

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

ul {
  list-style: none;
}

/* ---- Tokens ---- */
:root {
  /* Palette — light (default) */
  --color-bg: #f2f0eb;
  --color-ink: #111111;
  --color-ink-muted: #6b6b66;
  --color-line: rgba(17, 17, 17, 0.14);
  --color-accent: #ff3b00;
  --color-accent-ink: #ffffff;
  --color-surface: #e9e6de;

  /* Fonts */
  --font-display: 'Inter Tight', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

  /* Fluid type scale */
  --size-hero: clamp(3.2rem, 13vw, 12rem);
  --size-xxl: clamp(2.4rem, 7vw, 5.5rem);
  --size-xl: clamp(1.8rem, 4vw, 3rem);
  --size-lg: clamp(1.3rem, 2.4vw, 1.8rem);
  --size-md: 1.05rem;
  --size-base: 0.95rem;
  --size-sm: 0.8rem;
  --size-xs: 0.7rem;

  /* Grid */
  --gutter: 16px;
  --margin: 20px;
  --max-width: 1440px;
  --header-height: 76px;

  /* Motion */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 0.25s;
  --dur-med: 0.6s;
  --dur-slow: 1.1s;

  color-scheme: light;
}

@media (min-width: 768px) {
  :root {
    --gutter: 24px;
    --margin: 48px;
  }
}

/* Dark mode via system preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-bg: #111111;
    --color-ink: #f2f0eb;
    --color-ink-muted: #9a9a94;
    --color-line: rgba(242, 240, 235, 0.16);
    --color-accent: #ff5222;
    --color-accent-ink: #111111;
    --color-surface: #1b1b1a;
    color-scheme: dark;
  }
}

/* Dark mode via manual toggle */
:root[data-theme='dark'] {
  --color-bg: #111111;
  --color-ink: #f2f0eb;
  --color-ink-muted: #9a9a94;
  --color-line: rgba(242, 240, 235, 0.16);
  --color-accent: #ff5222;
  --color-accent-ink: #111111;
  --color-surface: #1b1b1a;
  color-scheme: dark;
}

:root[data-theme='light'] {
  --color-bg: #f2f0eb;
  --color-ink: #111111;
  --color-ink-muted: #6b6b66;
  --color-line: rgba(17, 17, 17, 0.14);
  --color-accent: #ff3b00;
  --color-accent-ink: #ffffff;
  --color-surface: #e9e6de;
  color-scheme: light;
}

/* ---- Base elements ---- */
html {
  scroll-behavior: smooth;
}

body {
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-display);
  font-size: var(--size-base);
  line-height: 1.5;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
  overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 0.98;
}

.mono {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- Layout helpers ---- */
.wrap {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--margin);
}

.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--gutter);
}

.hairline {
  border: none;
  border-top: 1px solid var(--color-line);
}

.section {
  position: relative;
  padding-block: clamp(64px, 12vw, 140px);
  border-top: 1px solid var(--color-line);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gutter);
  margin-bottom: clamp(32px, 6vw, 72px);
}

.section-index {
  font-family: var(--font-mono);
  font-size: var(--size-sm);
  letter-spacing: 0.08em;
  color: var(--color-ink-muted);
}

.section-title {
  font-size: var(--size-xxl);
  text-transform: uppercase;
}

/* ---- Grid-line background (easter egg, toggled with 'G') ---- */
.grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-fast) ease;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--gutter);
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--margin);
}

.grid-overlay.is-visible {
  opacity: 1;
}

.grid-overlay span {
  height: 100%;
  border-left: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
}

/* ---- Focus states ---- */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

/* ---- Screen-reader only ---- */
.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;
}

/* ---- Skip link ---- */
.skip-link {
  position: fixed;
  top: -100px;
  left: var(--margin);
  z-index: 2000;
  background: var(--color-accent);
  color: var(--color-accent-ink);
  padding: 10px 18px;
  font-family: var(--font-mono);
  font-size: var(--size-sm);
  transition: top var(--dur-fast) ease;
}

.skip-link:focus {
  top: 16px;
}

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