@layer reset, tokens, base, layout, components, motion, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { color-scheme: light; overflow-x: hidden; }
  body { margin: 0; min-width: 0; }
  img, svg { max-width: 100%; }
}

@layer tokens {
  @font-face {
    font-family: "Desk Variable";
    src: local("SF Pro Display"), local("Segoe UI Variable"), local("Helvetica Neue");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
  }
  @font-face {
    font-family: "Desk Mono";
    src: local("JetBrains Mono Variable"), local("JetBrains Mono"), local("SFMono-Regular");
    font-weight: 100 800;
    font-style: normal;
    font-display: swap;
  }
  :root {
    --paper: #ffffff;
    --ink: #333333;
    --navy: #2e3b8f;
    --amber: #fbaf18;
    --pink: #ec1c5f;
    --cyan: #00aeef;
    --purple: #6556df;
    --line: #d9deed;
    --mist: #f5f7fc;
    --shadow: 0 2px 12px rgb(46 59 143 / 0.08);
    --radius: 12px;
    --spring-stiffness: 120;
    --spring-damping: 20;
    --accent: var(--navy);
    --accent-text: var(--navy);
  }
  body[data-topic="start"] { --accent: var(--navy); --accent-text: var(--navy); }
  body[data-topic="questions"] { --accent: var(--cyan); --accent-text: #006987; }
  body[data-topic="money"] { --accent: #b87900; --accent-text: #765000; }
  body[data-topic="evidence"] { --accent: var(--purple); --accent-text: #5142c4; }
  body[data-topic="safety"] { --accent: var(--pink); --accent-text: #a80f40; }
}

@layer base {
  body {
    background: var(--paper);
    color: var(--ink);
    font-family: "Desk Variable", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.6;
  }
  h1, h2, h3, p, ul, ol, figure { margin-top: 0; }
  h1, h2, h3, strong { color: var(--ink); }
  h1 {
    max-width: 15ch;
    margin-bottom: 1.5rem;
    font-size: clamp(2.5rem, 5vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.045em;
    line-height: 1.02;
  }
  h2 {
    margin-bottom: 1rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
  }
  h3 { font-size: 1.125rem; }
  p, li, a, summary, figcaption { font-size: 1rem; }
  p, article > section > ul { max-width: 72ch; }
  a { color: var(--navy); text-underline-offset: 0.2em; text-decoration-thickness: 0.1em; }
  a:hover { color: var(--purple); }
  :focus-visible { outline: 3px solid var(--amber); outline-offset: 4px; }
  small, .meta {
    font-family: "Desk Mono", ui-monospace, "SFMono-Regular", monospace;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.07em;
    line-height: 1.35;
    text-transform: uppercase;
  }
}

@layer layout {
  .shell { width: min(100% - 3rem, 1280px); margin-inline: auto; }
  body > header { border-bottom: 1px solid var(--line); background: var(--paper); }
  body > header > .shell { display: flex; align-items: center; justify-content: space-between; gap: 2rem; min-height: 88px; }
  main { overflow: clip; }
  main article { max-width: 1100px; padding-block: clamp(3rem, 6vw, 6rem); }
  article > header[data-hero] {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(360px, 1.1fr);
    align-items: center;
    gap: clamp(2rem, 5vw, 5rem);
    min-height: min(680px, 75vh);
  }
  article > section {
    display: grid;
    grid-template-columns: minmax(200px, 0.4fr) minmax(0, 0.8fr);
    column-gap: clamp(2rem, 8vw, 7rem);
    padding-block: clamp(3rem, 6vw, 6rem);
    border-top: 1px solid var(--line);
  }
  article > section:nth-of-type(even) { grid-template-columns: minmax(0, 0.8fr) minmax(200px, 0.4fr); }
  article > section:nth-of-type(even) h2 { grid-column: 2; }
  article > section:nth-of-type(even) > :not(h2) { grid-column: 1; grid-row: auto; }
  article > section h2 { grid-row: 1 / span 8; padding-left: 1rem; border-left: 5px solid var(--accent); }
  article > section p, article > section ul, article > section details, article > section [data-cards] { grid-column: 2; }
  article > section > ul { padding-left: 1.25rem; }
  article > section > ul li { margin-bottom: 0.65rem; padding-left: 0.4rem; }
  footer { border-top: 1px solid var(--line); background: var(--ink); color: var(--paper); }
  footer .shell { display: flex; align-items: center; justify-content: space-between; gap: 2rem; min-height: 112px; padding-block: 1.5rem; }
  footer p { max-width: 62ch; margin: 0; color: var(--paper); }
}

@layer components {
  .skip { position: fixed; z-index: 20; top: 0.5rem; left: 0.5rem; min-height: 44px; padding: 0.65rem 1rem; background: var(--ink); color: var(--paper); transform: translateY(-150%); }
  .skip:focus { transform: none; }
  .brand { display: inline-flex; min-height: 52px; align-items: center; gap: 0.8rem; color: var(--ink); font-size: 1rem; font-weight: 700; line-height: 1.15; text-decoration: none; }
  .brand small { display: block; margin-bottom: 0.25rem; color: var(--navy); font-size: 0.75rem; }
  [data-mark] { width: 34px; height: 34px; flex: 0 0 auto; border: 7px solid var(--navy); border-right-color: var(--cyan); border-bottom-color: var(--pink); border-radius: 50%; transform: rotate(-20deg); }
  nav > ul { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem 1rem; margin: 0; padding: 0; list-style: none; }
  nav li { display: grid; grid-template-columns: repeat(2, auto); align-items: center; }
  nav li > span { grid-column: 1 / -1; color: #5c6272; font-family: "Desk Mono", ui-monospace, monospace; font-size: 0.75rem; font-weight: 500; letter-spacing: 0.06em; line-height: 1; text-transform: uppercase; }
  nav a, footer a { display: inline-flex; min-width: 44px; min-height: 44px; align-items: center; padding-inline: 0.55rem; font-weight: 600; text-decoration: none; }
  footer a { color: var(--paper); }
  .meta { margin-bottom: 1.25rem; color: var(--accent-text); }
  .lede { max-width: 60ch; margin-bottom: 0; font-size: 1.125rem; }
  .timeline { min-width: 0; margin: 0; padding: 1rem 0 0; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-color: var(--accent) var(--mist); }
  .timeline ol { position: relative; display: grid; grid-template-columns: 0.85fr 1.2fr 0.95fr; gap: 1rem; min-width: 620px; margin: 0; padding: 2.25rem 0 1rem; list-style: none; }
  .timeline ol::before { position: absolute; top: 0.95rem; right: 4%; left: 4%; height: 4px; background: var(--navy); content: ""; transform-origin: left; }
  .timeline li { position: relative; min-height: 176px; padding: 1.5rem; border: 1px solid var(--line); border-top: 6px solid var(--accent); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
  .timeline li::before { position: absolute; top: -2.45rem; left: 1.5rem; width: 18px; height: 18px; border: 4px solid var(--paper); border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--accent); content: ""; }
  .timeline li:nth-child(2) { border-top-color: var(--purple); }
  .timeline li:nth-child(2)::before { background: var(--purple); box-shadow: 0 0 0 2px var(--purple); }
  .timeline li:nth-child(3) { border-top-color: var(--pink); }
  .timeline li:nth-child(3)::before { background: var(--pink); box-shadow: 0 0 0 2px var(--pink); }
  .timeline small, .timeline strong, .timeline span { display: block; }
  .timeline small { margin-bottom: 1.25rem; color: #555d6f; }
  .timeline strong { margin-bottom: 0.4rem; font-size: 1.05rem; }
  .timeline figcaption { max-width: 60ch; padding: 0.75rem 0 0.25rem; color: #565c6a; }
  [data-cards] { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 1rem; }
  [data-cards] a { display: flex; min-height: 128px; flex-direction: column; justify-content: space-between; gap: 1rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); text-decoration: none; }
  [data-cards] a strong, [data-cards] a span { display: block; }
  [data-cards] a span { color: var(--ink); }
  details { max-width: 72ch; margin-bottom: 0.75rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
  summary { min-height: 56px; padding: 0.9rem 3rem 0.9rem 1rem; color: var(--ink); font-weight: 700; cursor: pointer; }
  details p { padding: 0 1rem 1rem; }
  .sources { margin-block: clamp(3rem, 6vw, 6rem); padding: clamp(1.5rem, 4vw, 3rem); border: 1px solid var(--line); border-left: 8px solid var(--accent); border-radius: var(--radius); background: var(--mist); box-shadow: var(--shadow); }
  .sources h2 { max-width: 24ch; }
  .sources ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); gap: 1rem; margin: 1.5rem 0 0; padding: 0; list-style: none; }
  .sources li { display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem; min-width: 0; }
  .sources li > span { color: var(--ink); }
  .sources ul + p { margin: 1.25rem 0 0; }
  .sources a { display: inline-flex; max-width: 100%; min-height: 48px; align-items: center; padding: 0.7rem 1rem; border: 1px solid #b7bfd5; border-radius: var(--radius); background: var(--paper); font-weight: 600; text-decoration: none; }
  .next { display: flex; min-height: 88px; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 2rem; padding: 1rem 1.25rem; border-radius: var(--radius); background: var(--navy); color: var(--paper); text-decoration: none; }
  .next span, .next strong { color: var(--paper); }
  .next span { font-family: "Desk Mono", ui-monospace, monospace; font-size: 0.875rem; letter-spacing: 0.06em; text-transform: uppercase; }
}

@layer motion {
  @keyframes rail-draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
  @keyframes milestone-pop { from { opacity: 0; transform: translateY(16px) scale(0.94); } to { opacity: 1; transform: none; } }
  @keyframes page-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
  @keyframes page-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-16px); } }
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: 300ms ease both page-out; }
  ::view-transition-new(root) { animation: 300ms ease both page-in; }
  .timeline ol::before { animation: rail-draw 480ms ease-out both; }
  .timeline li { animation: milestone-pop 480ms cubic-bezier(0.34, 1.56, 0.64, 1) both; }
  .timeline li:nth-child(2) { animation-delay: 100ms; }
  .timeline li:nth-child(3) { animation-delay: 200ms; }
  .timeline li, [data-cards] a, .sources a, .next { transition: transform 220ms ease, border-color 220ms ease, background-color 220ms ease; }
  .timeline li:hover, [data-cards] a:hover, .sources a:hover { transform: scale(1.03); }
  @supports (animation-timeline: view()) {
    article > section, .sources {
      animation: page-in 480ms ease both;
      animation-timeline: view();
      animation-range: entry 0% cover 24%;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  }
}

@layer utilities {
  @media (max-width: 1040px) {
    body > header > .shell { align-items: flex-start; flex-direction: column; gap: 0.75rem; padding-block: 1rem; }
    nav { width: 100%; }
    nav > ul { justify-content: flex-start; }
  }
  @media (max-width: 767px) {
    .shell { width: min(100% - 2rem, 1280px); }
    nav > ul { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
    nav li { min-width: 0; }
    nav a { padding-inline: 0.35rem; }
    article > header[data-hero] { grid-template-columns: 1fr; min-height: auto; padding-bottom: 3rem; }
    article > section, article > section:nth-of-type(even) { display: block; padding-block: 3.25rem; }
    article > section h2 { margin-bottom: 1.5rem; }
    [data-cards] { grid-template-columns: 1fr; }
    .timeline { overflow-x: visible; }
    .timeline ol { grid-template-columns: 1fr; gap: 1.25rem; min-width: 0; padding: 0 0 0 1.75rem; }
    .timeline ol::before { top: 0; bottom: 0; right: auto; left: 0.45rem; width: 4px; height: auto; animation: none; }
    .timeline li { min-height: 0; }
    .timeline li::before { top: 1.5rem; left: calc(-1.3rem - 8px); }
    .timeline li:hover { transform: none; }
    footer .shell { align-items: flex-start; flex-direction: column; gap: 0.75rem; }
  }
  @media (max-width: 430px) {
    nav > ul { grid-template-columns: 1fr; }
    nav li { grid-template-columns: 1fr 1fr; }
    h1 { font-size: 2.5rem; }
    .sources { padding: 1.25rem; }
  }
}
