/**
 * brand.css — shared design system for mission.megabyte.space (all 88 pages).
 *
 * Single source of brand truth: tokens + section-surface rhythm + fluid type &
 * spacing scales + AA contrast utilities. Loaded by every page so styling is
 * cohesive instead of 88 inline <style> blocks with ad-hoc hex. Per-page inline
 * styles may override locally, but pull from these tokens — never new raw hex.
 *
 * Brand: dark-first. #060610 canvas · #00E5FF cyan · #50AAE3 blue · #7C3AED violet.
 * Fonts: Sora (display) · Space Grotesk (UI) · JetBrains Mono (mono/eyebrow).
 */

@layer tokens, base, surfaces, type, components, utilities;

/* ---------------------------------------------------------------- tokens -- */
@layer tokens {
  :root {
    color-scheme: dark;

    /* Brand */
    --bg: #060610;
    --cyan: #00e5ff;
    --blue: #50aae3;
    --violet: #7c3aed;
    --danger: #ff5d5d;

    /* Surfaces — section-rhythm bands (each step a touch lighter than --bg) */
    --surface-0: #060610;
    --surface-1: #0a0a16;
    --surface-2: #0e1326;
    --surface-3: #141a30;
    --card: #0a0a14;
    --hairline: rgba(255, 255, 255, 0.07);
    --hairline-strong: rgba(0, 229, 255, 0.16);

    /* Ink — AA-contrast on dark (per text-contrast.md) */
    --ink: #f4f4ff;
    --ink-muted: #aeb6c8; /* ~5.3:1 on --bg — body copy */
    --ink-faint: #8893a8; /* ~3.6:1 — captions/meta only, never body */
    --ink-cyan: color-mix(in oklch, var(--cyan) 72%, var(--ink) 28%);

    /* Fluid type scale (clamp: min @360px → max @1280px) */
    --step--1: clamp(0.83rem, 0.79rem + 0.18vw, 0.94rem);
    --step-0: clamp(1rem, 0.95rem + 0.22vw, 1.13rem);
    --step-1: clamp(1.2rem, 1.1rem + 0.5vw, 1.5rem);
    --step-2: clamp(1.44rem, 1.25rem + 0.95vw, 2rem);
    --step-3: clamp(1.73rem, 1.4rem + 1.6vw, 2.7rem);
    --step-4: clamp(2.07rem, 1.55rem + 2.6vw, 3.6rem);
    --step-5: clamp(2.49rem, 1.6rem + 4.4vw, 5rem);

    /* 8pt spacing scale */
    --space-2xs: 0.5rem;
    --space-xs: 0.75rem;
    --space-sm: 1rem;
    --space-md: 1.5rem;
    --space-lg: 2.5rem;
    --space-xl: 4rem;
    --space-2xl: 6rem;
    --section-y: clamp(3.5rem, 2rem + 6vw, 7rem);

    /* Radius / shadow / motion */
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 22px;
    --radius-pill: 999px;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 14px 40px rgba(0, 0, 0, 0.45);
    --glow-cyan: 0 0 0 1px rgba(0, 229, 255, 0.25), 0 10px 40px rgba(0, 229, 255, 0.12);
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --dur: 0.333s;

    --measure: 68ch; /* readable line length */
    --container: 1200px;

    --font-display: 'Sora', system-ui, sans-serif;
    --font-ui: 'Space Grotesk', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
  }
}

/* ------------------------------------------------------------------ base -- */
@layer base {
  *,
  *::before,
  *::after { box-sizing: border-box; }

  html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  }

  /* Opt-in body baseline — add class="brand" to <body> to adopt without
     fighting existing per-page resets. */
  body.brand {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: var(--step-0);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  :where(a):focus-visible,
  :where(button):focus-visible,
  :where([tabindex]):focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
  }
}

/* -------------------------------------------------------------- surfaces -- */
/* The fix for "16,000px of flat void": alternating bands + real padding so
   every section reads as a distinct, intentional surface. */
@layer surfaces {
  .section { padding-block: var(--section-y); position: relative; }
  .section--0 { background: var(--surface-0); }
  .section--1 { background: var(--surface-1); }
  .section--2 { background: var(--surface-2); }
  .section--3 {
    background:
      radial-gradient(1200px 400px at 50% -10%, rgba(0, 229, 255, 0.06), transparent 60%),
      var(--surface-1);
  }
  /* Hairline divider between adjacent same-color bands. */
  .section + .section { border-top: 1px solid var(--hairline); }

  .container {
    width: min(100% - 2 * var(--space-md), var(--container));
    margin-inline: auto;
  }
  .container--narrow { width: min(100% - 2 * var(--space-md), 760px); margin-inline: auto; }
}

/* ------------------------------------------------------------------ type -- */
@layer type {
  .eyebrow {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--cyan);
    font-weight: 700;
    margin: 0 0 var(--space-xs);
  }
  .display {
    font-family: var(--font-display);
    font-size: var(--step-5);
    line-height: 1.05;
    letter-spacing: -0.02em;
    font-weight: 800;
    margin: 0 0 var(--space-md);
    text-wrap: balance;
    color: var(--ink);
  }
  .h2 {
    font-family: var(--font-display);
    font-size: var(--step-3);
    line-height: 1.15;
    letter-spacing: -0.01em;
    font-weight: 700;
    margin: 0 0 var(--space-sm);
    text-wrap: balance;
    color: var(--ink);
  }
  .h3 { font-family: var(--font-display); font-size: var(--step-2); line-height: 1.2; margin: 0 0 var(--space-xs); color: var(--ink); }
  .lead { font-size: var(--step-1); color: var(--ink-muted); max-width: var(--measure); text-wrap: pretty; margin: 0 0 var(--space-md); }
  .prose { color: var(--ink-muted); max-width: var(--measure); text-wrap: pretty; }
  .prose p { margin: 0 0 var(--space-sm); }
  .text-cyan { color: var(--ink-cyan); }
  .text-gradient {
    background: linear-gradient(100deg, var(--cyan), var(--blue) 55%, var(--violet));
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }
}

/* ------------------------------------------------------------ components -- */
@layer components {
  /* Pills — enumerable values render as pills, never CSV (gorgeous-by-default). */
  .pill {
    display: inline-flex; align-items: center; gap: 0.4em;
    padding: 0.32em 0.85em; border-radius: var(--radius-pill);
    background: rgba(0, 229, 255, 0.1); border: 1px solid var(--hairline-strong);
    color: var(--ink-cyan); font-size: var(--step--1); font-weight: 600;
    transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .pill:hover { transform: translateY(-1px); background: rgba(0, 229, 255, 0.16); }
  .pill--violet { background: rgba(124, 58, 237, 0.16); border-color: rgba(124, 58, 237, 0.45); color: #c4b5fd; }
  .pill--good { background: rgba(52, 211, 153, 0.14); border-color: rgba(52, 211, 153, 0.4); color: #6ee7b7; }

  /* Card */
  .card {
    background: var(--card); border: 1px solid var(--hairline);
    border-radius: var(--radius); padding: var(--space-md);
    transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  }
  .card:hover { transform: translateY(-3px); border-color: var(--hairline-strong); box-shadow: var(--shadow-2); }

  /* Buttons */
  .btn {
    display: inline-flex; align-items: center; gap: 0.5em;
    padding: 0.85em 1.6em; border-radius: var(--radius-sm);
    font-family: var(--font-ui); font-weight: 700; font-size: var(--step-0);
    text-decoration: none; cursor: pointer; border: 1px solid transparent;
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .btn--primary { background: linear-gradient(135deg, var(--cyan), var(--blue)); color: var(--bg); }
  .btn--primary:hover { transform: translateY(-2px); box-shadow: var(--glow-cyan); }
  .btn--ghost { background: transparent; border-color: var(--hairline-strong); color: var(--ink); }
  .btn--ghost:hover { background: rgba(0, 229, 255, 0.08); transform: translateY(-2px); }

  /* Auto-fit responsive grid — kills the dead vertical space by filling rows. */
  .grid { display: grid; gap: var(--space-md); }
  .grid--cards { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
  .grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }

  /* Stat block */
  .stat { text-align: center; }
  .stat__num { font-family: var(--font-display); font-size: var(--step-4); font-weight: 800; color: var(--cyan); font-variant-numeric: tabular-nums; line-height: 1; }
  .stat__label { margin-top: var(--space-2xs); font-size: var(--step--1); color: var(--ink-faint); letter-spacing: 0.06em; text-transform: uppercase; }
}

/* ------------------------------------------------------------- utilities -- */
@layer utilities {
  .stack > * + * { margin-top: var(--space-md); }
  .stack-sm > * + * { margin-top: var(--space-sm); }
  .center { text-align: center; }
  .measure { max-width: var(--measure); }
  .mx-auto { margin-inline: auto; }

  /* Reveal — fade + 16px rise on first paint / scroll (reduced-motion safe). */
  .reveal { opacity: 0; transform: translateY(16px); }
  @media (prefers-reduced-motion: no-preference) {
    .reveal { animation: brand-reveal 0.6s var(--ease) both; }
    .reveal[data-delay='1'] { animation-delay: 0.08s; }
    .reveal[data-delay='2'] { animation-delay: 0.16s; }
    .reveal[data-delay='3'] { animation-delay: 0.24s; }
  }
  @keyframes brand-reveal { to { opacity: 1; transform: none; } }
  @media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; } }
}

/* ----------------------------------------------- GEO: quotable + FAQ -- */
/* AI-search quotable answer block (LLMs cite these) + accessible FAQ. */
@layer components {
  .ai-quotable { padding: 2.5rem 0 0.5rem; }
  .ai-quotable .container, .ai-quotable .cin-container { max-width: 820px; margin-inline: auto; }
  .ai-quotable-label { font-family: 'Sora', system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; color: var(--cyan); margin: 0 0 0.6rem; }
  .ai-quotable-body { font-size: clamp(1.05rem, 2vw, 1.25rem); line-height: 1.6; color: var(--ink); margin: 0; border-left: 3px solid var(--blue); padding-left: 1.25rem; }

  .faq { padding: 2.5rem 0; }
  .faq .container, .faq .cin-container { max-width: 820px; margin-inline: auto; }
  .faq h2 { font-family: 'Sora', system-ui, sans-serif; margin: 0 0 1.25rem; }
  .faq-item { border: 1px solid color-mix(in oklch, var(--ink) 16%, transparent); border-radius: 12px; margin: 0 0 0.75rem; background: color-mix(in oklch, var(--cyan) 4%, transparent); transition: border-color 0.333s var(--ease, ease), background 0.333s var(--ease, ease); }
  .faq-item:hover, .faq-item[open] { border-color: color-mix(in oklch, var(--cyan) 45%, transparent); }
  .faq-item summary { cursor: pointer; list-style: none; padding: 1rem 1.25rem; font-weight: 600; color: var(--ink); display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
  .faq-item summary::-webkit-details-marker { display: none; }
  .faq-item summary::after { content: '+'; color: var(--cyan); font-size: 1.4rem; line-height: 1; transition: transform 0.333s var(--ease, ease); }
  .faq-item[open] summary::after { transform: rotate(45deg); }
  .faq-item summary:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 12px; }
  .faq-item p { margin: 0; padding: 0 1.25rem 1.1rem; color: var(--ink-muted, var(--ink)); line-height: 1.65; }
  @media (prefers-reduced-motion: reduce) { .faq-item, .faq-item summary::after { transition: none; } }
}

/* --------------------------------------------- a11y: focus not obscured -- */
/* WCAG 2.4.11 (AA): keyboard focus + in-page anchor targets must not hide
   behind the sticky header (header.top, ~69px) or the donate mobile sticky-bar
   (position:fixed; bottom:0). With no scroll-padding the browser scrolled
   focused/anchored elements flush to the viewport edge, under the fixed chrome.
   Not an animation — no reduced-motion gate needed. */
html { scroll-padding-top: 5rem; scroll-padding-bottom: 5rem; }
