/* =============================================================
   base.css — CSS reset, design tokens, typography, utilities
   A Love Letter to the Web
   ============================================================= */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Colors (oklch) */
  --color-base:    oklch(8% 0.01 265);
  --color-surface: oklch(12% 0.015 265);
  --color-border:  oklch(22% 0.03 265);
  --color-primary: oklch(60% 0.18 265);
  --color-accent:  oklch(68% 0.14 295);
  --color-text:    oklch(88% 0.01 265);
  --color-muted:   oklch(58% 0.03 265);

  /* Brand gradient (used by era-2026 H2, portal CTA, accents) */
  --color-gradient-start: oklch(0.65 0.22 290);
  --color-gradient-mid:   oklch(0.62 0.20 270);
  --color-gradient-end:   oklch(0.70 0.18 200);

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-heading: var(--font-sans);
  --font-code:    var(--font-mono);

  /* Type scale (clamp: min, preferred, max) */
  --text-xs:   clamp(0.6875rem, 0.65rem + 0.19vw, 0.75rem);
  --text-sm:   clamp(0.8125rem, 0.78rem + 0.16vw, 0.875rem);
  --text-base: clamp(1rem,      0.96rem + 0.2vw,  1.0625rem);
  --text-md:   clamp(1.125rem,  1.05rem + 0.38vw, 1.25rem);
  --text-lg:   clamp(1.25rem,   1.1rem  + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,    1.25rem + 1.25vw, 2rem);
  --text-2xl:  clamp(2rem,      1.5rem  + 2.5vw,  3rem);
  --text-3xl:  clamp(2.5rem,    1.75rem + 3.75vw, 4.5rem);

  /* Spacing */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2.5rem;
  --space-2xl: 8rem;

  /* Easing */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in:     cubic-bezier(0.7, 0, 0.84, 0);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  /* Transitions */
  --duration-fast:   150ms;
  --duration-base:   250ms;
  --duration-normal: 250ms;
  --duration-slow:   400ms;
  --duration-xslow:  700ms;

  /* Layout */
  --content-width:   72rem;
  --content-padding: clamp(1rem, 5vw, 3rem);

  /* Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  20px;
  --radius-pill: 9999px;

  /* Z-index scale */
  --z-base:    0;
  --z-raised:  10;
  --z-overlay: 100;
  --z-modal:   1000;
  --z-toast:   10000;

  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
}

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

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

p,
h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

ul,
ol {
  list-style: none;
}

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

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

hr {
  border: none;
  border-top: 1px solid var(--color-border);
}

/* ── Typography ─────────────────────────────────────────────── */
h1 {
  font-family: var(--font-sans);
  font-size: var(--text-3xl);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--color-text);
}

h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

h3 {
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--color-text);
}

h4 {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.4;
  color: var(--color-text);
}

h5 {
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.5;
  color: var(--color-text);
}

h6 {
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.5;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.subtitle {
  font-size: var(--text-lg);
  font-weight: 300;
  color: var(--color-muted);
  line-height: 1.5;
}

.label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
}

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

.visually-hidden:focus,
.visually-hidden:active {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100000;
  width: auto;
  height: auto;
  padding: 0.75rem 1.5rem;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--color-primary);
  color: white;
  font-weight: 600;
  border-radius: var(--radius-md);
  text-decoration: none;
  box-shadow: 0 4px 16px oklch(0% 0 0 / 0.4);
}

.content-width {
  max-width: var(--content-width);
  width: 100%;
  margin-inline: auto;
  padding-inline: var(--content-padding);
}

/* ── Focus Styles ───────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* ── Mobile Touch Targets & Typography ─────────────────────── */
@media (max-width: 768px) {
  /* Prevent iOS auto-zoom on input focus — ensure 16px minimum */
  input,
  textarea,
  select {
    font-size: max(1rem, inherit);
  }
}

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

/* ── Per-zone selection + rainbow hue (Layer 1 / Task 16) ────────── */

::selection { background: oklch(0.7 0.25 290 / 0.35); color: inherit; }
[data-zone="scroll"] ::selection,     body[data-zone="scroll"] ::selection     { background: oklch(0.7 0.22 265 / 0.4); }
[data-zone="popover"] ::selection,    body[data-zone="popover"] ::selection    { background: oklch(0.7 0.22 305 / 0.4); }
[data-zone="art"] ::selection,        body[data-zone="art"] ::selection        { background: oklch(0.75 0.2 340 / 0.4); }
[data-zone="container"] ::selection,  body[data-zone="container"] ::selection  { background: oklch(0.75 0.17 160 / 0.4); }
[data-zone="transitions"] ::selection,body[data-zone="transitions"] ::selection{ background: oklch(0.8 0.17 80 / 0.4); }
[data-zone="houdini"] ::selection,    body[data-zone="houdini"] ::selection    { background: oklch(0.7 0.18 240 / 0.4); }
[data-zone="has"] ::selection,        body[data-zone="has"] ::selection        { background: oklch(0.75 0.18 40 / 0.4); }
[data-zone="layers"] ::selection,     body[data-zone="layers"] ::selection     { background: oklch(0.7 0.24 320 / 0.4); }

html:not([data-theme="light"]) body { background-color: oklch(0.15 0.02 var(--hue, 280)); transition: background-color 200ms linear; }

/* ── Site-wide focus + interaction baseline (Layer 1 / Task 24) ────────── */

:where(a, button, [role="button"], input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus, oklch(0.75 0.2 290));
  outline-offset: 2px;
  border-radius: 4px;
}
:where(button, [role="button"]):hover:not(:disabled):not([aria-disabled="true"]) { cursor: pointer; }
:where(button, [role="button"]):disabled, :where(button, [role="button"])[aria-disabled="true"] {
  cursor: not-allowed; opacity: 0.5;
}

html { scroll-behavior: smooth; }
:target { scroll-margin-top: 80px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
