/* ─────────────────────────────────────────────────────────────────
   CHAP microsite — site styles
   Ported from the Claude Design prototype's <style> block. The design
   tokens (fonts, colours, gradients, shadows, easing) live in
   assets/ds/colors_and_type.css and are referenced via var(--bb-*).
   ───────────────────────────────────────────────────────────────── */

html { scroll-behavior: smooth; }
body { margin: 0; }

/* The design-system stylesheet underlines links by default; the site
   design wants clean links everywhere. */
a { border-bottom: none !important; text-decoration: none; }

/* ── Keyframes ───────────────────────────────────────────────────── */
@keyframes bb-lp {
  0%   { box-shadow: 0 0 0 0 rgba(31,91,57,0.5); }
  70%  { box-shadow: 0 0 0 10px rgba(31,91,57,0); }
  100% { box-shadow: 0 0 0 0 rgba(31,91,57,0); }
}
@keyframes bb-slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes bb-reveal {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}

/* ── Motion ──────────────────────────────────────────────────────────
   Scroll-driven reveals. initReveal() sets html.anim, then an
   IntersectionObserver adds .in to each .reveal wrapper as it enters
   the viewport. Everything is gated on .anim: without JS the page
   renders fully visible, and prefers-reduced-motion turns it all off. */

/* Content blocks rise in, staggered top to bottom. */
.anim .reveal > * {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity .65s var(--bb-ease-out), transform .65s var(--bb-ease-out);
}
.anim .reveal.in > * { opacity: 1; transform: none; }
.anim .reveal.in > *:nth-child(2) { transition-delay: 0.07s; }
.anim .reveal.in > *:nth-child(3) { transition-delay: 0.14s; }
.anim .reveal.in > *:nth-child(4) { transition-delay: 0.21s; }
.anim .reveal.in > *:nth-child(5) { transition-delay: 0.28s; }
.anim .reveal.in > *:nth-child(6) { transition-delay: 0.35s; }
.anim .reveal.in > *:nth-child(7) { transition-delay: 0.42s; }
.anim .reveal.in > *:nth-child(n+8) { transition-delay: .45s; }

/* Section-header accent ticks draw themselves under the title. */
.anim .reveal div[style*="height:3px"] { width: 0 !important; transition: width .55s var(--bb-ease-out) .5s; }
.anim .reveal.in div[style*="height:3px"] { width: 56px !important; }

/* Hero enters on load: copy rises line by line over a slow photo drift. */
@keyframes bb-rise {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: none; }
}
.anim #top .gx > div > * { animation: bb-rise .8s var(--bb-ease-out) backwards; }
.anim #top .gx > div > *:nth-child(1) { animation-delay: 0.08s; }
.anim #top .gx > div > *:nth-child(2) { animation-delay: 0.20s; }
.anim #top .gx > div > *:nth-child(3) { animation-delay: 0.32s; }
.anim #top .gx > div > *:nth-child(4) { animation-delay: 0.44s; }
.anim #top .gx > div > *:nth-child(5) { animation-delay: 0.56s; }
.anim #top .gx > div > *:nth-child(6) { animation-delay: 0.68s; }
.anim #top .gx > div > *:nth-child(7) { animation-delay: 0.80s; }
.anim #top .gx > div > *:nth-child(8) { animation-delay: 0.92s; }
@keyframes bb-kenburns {
  from { transform: scale(1); }
  to   { transform: scale(1.055); }
}
.anim #top > div:first-child img { animation: bb-kenburns 20s ease-in-out forwards; transform-origin: 62% 38%; }

/* Cold loads: the photo fades in when it arrives instead of popping
   over the charcoal. Cached loads never get .hero-fade (no hiding). */
.anim #top img.hero-fade { opacity: 0; }
.anim #top img.hero-fade.loaded { opacity: 1; transition: opacity .7s ease; }

/* Evidence-loop chips pop in reading order. */
.anim .reveal #evidence-flow > span {
  opacity: 0;
  transform: translateY(10px) scale(.92);
  transition: opacity .5s var(--bb-ease-out), transform .5s var(--bb-ease-out);
}
.anim .reveal.in #evidence-flow > span { opacity: 1; transform: none; }
.anim .reveal.in #evidence-flow > span:nth-child(1) { transition-delay: 0.25s; }
.anim .reveal.in #evidence-flow > span:nth-child(2) { transition-delay: 0.34s; }
.anim .reveal.in #evidence-flow > span:nth-child(3) { transition-delay: 0.43s; }
.anim .reveal.in #evidence-flow > span:nth-child(4) { transition-delay: 0.52s; }
.anim .reveal.in #evidence-flow > span:nth-child(5) { transition-delay: 0.61s; }
.anim .reveal.in #evidence-flow > span:nth-child(6) { transition-delay: 0.70s; }
.anim .reveal.in #evidence-flow > span:nth-child(7) { transition-delay: 0.79s; }

/* Protocol-stack layers drop into place, CHAP first. Keyframes with
   fill backwards so the cards' own inline hover transitions win after. */
@keyframes bb-layer-in {
  from { opacity: 0; transform: translateY(-18px); }
  to   { opacity: 1; transform: none; }
}
.anim .reveal:not(.in) #stack-diagram > div { opacity: 0; }
.anim .reveal.in #stack-diagram > div { animation: bb-layer-in .6s var(--bb-ease-out) backwards; }
.anim .reveal.in #stack-diagram > div:nth-child(1) { animation-delay: .30s; }
.anim .reveal.in #stack-diagram > div:nth-child(2) { animation-delay: .48s; }
.anim .reveal.in #stack-diagram > div:nth-child(3) { animation-delay: .66s; }

/* Evidence-chain rows cascade like the log being written. */
@keyframes bb-row-in {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: none; }
}
.anim .reveal:not(.in) #trace-rows > div { opacity: 0; }
.anim .reveal.in #trace-rows > div { animation: bb-row-in .45s var(--bb-ease-out) backwards; }
.anim .reveal.in #trace-rows > div:nth-child(1) { animation-delay: 0.35s; }
.anim .reveal.in #trace-rows > div:nth-child(2) { animation-delay: 0.41s; }
.anim .reveal.in #trace-rows > div:nth-child(3) { animation-delay: 0.47s; }
.anim .reveal.in #trace-rows > div:nth-child(4) { animation-delay: 0.53s; }
.anim .reveal.in #trace-rows > div:nth-child(5) { animation-delay: 0.59s; }
.anim .reveal.in #trace-rows > div:nth-child(6) { animation-delay: 0.65s; }
.anim .reveal.in #trace-rows > div:nth-child(7) { animation-delay: 0.71s; }
.anim .reveal.in #trace-rows > div:nth-child(8) { animation-delay: 0.77s; }
.anim .reveal.in #trace-rows > div:nth-child(9) { animation-delay: 0.83s; }
.anim .reveal.in #trace-rows > div:nth-child(10) { animation-delay: 0.89s; }
.anim .reveal.in #trace-rows > div:nth-child(11) { animation-delay: 0.95s; }
.anim .reveal.in #trace-rows > div:nth-child(12) { animation-delay: 1.01s; }
.anim .reveal.in #trace-rows > div:nth-child(13) { animation-delay: 1.07s; }
.anim .reveal.in #trace-rows > div:nth-child(14) { animation-delay: 1.13s; }
.anim .reveal.in #trace-rows > div:nth-child(15) { animation-delay: 1.19s; }

/* One-time attention pulse on the walkthrough's Start button, fired
   when the controls actually reach the viewport (see initReveal). */
@keyframes bb-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(234,71,0,0.45); }
  70%  { box-shadow: 0 0 0 14px rgba(234,71,0,0); }
  100% { box-shadow: 0 0 0 0 rgba(234,71,0,0); }
}
#demo-next.cue { animation: bb-pulse 1.6s cubic-bezier(0.22,0.61,0.36,1) .4s 2; }

/* Reading-progress hairline under the nav. */
#scroll-progress {
  position: absolute; left: 0; bottom: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, #EA4700, #FF9900);
  z-index: 60; pointer-events: none; transition: width .1s linear;
}

@media (prefers-reduced-motion: reduce) {
  .anim .reveal > *, .anim #top .gx > div > *, .anim .reveal #evidence-flow > span,
  .anim .reveal:not(.in) #stack-diagram > div, .anim .reveal.in #stack-diagram > div,
  .anim .reveal:not(.in) #trace-rows > div, .anim .reveal.in #trace-rows > div,
  .anim #top > div:first-child img, .anim #top img.hero-fade, #demo-next.cue {
    animation: none !important; transition: none !important; opacity: 1 !important; transform: none !important;
  }
  .anim .reveal div[style*="height:3px"] { width: 56px !important; transition: none !important; }
  #scroll-progress { display: none; }
}

/* Readable measure for body copy inside the content columns. */
.wrap > p, .wrap > h2, .wrap > ol { max-width: 760px; }

/* ── Responsive ──────────────────────────────────────────────────── */
/* Nine nav items: tighten item padding on laptop widths so the full set
   fits beside the GitHub button without scrolling. */
@media (max-width: 1300px) {
  .nav-links a { padding: 8px 7px !important; }
}
/* Even tightened, seven items + lockup + buttons need ~1115px — below
   that the links get cut off, so the burger takes over early. */
@media (max-width: 1140px) {
  .nav-links { display: none !important; }
}
@media (max-width: 1024px) {
  .gx { padding-left: 32px !important; padding-right: 32px !important; }
}
@media (max-width: 768px) {
  .gx { padding-left: 24px !important; padding-right: 24px !important; }
  .wrap { padding-top: 60px !important; padding-bottom: 60px !important; }
  .sec-h1 { font-size: clamp(26px, 6vw, 34px) !important; }
  .aud-entry { display: flex !important; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
  .aud-entry > span:nth-child(4) { display: none; }
}
@media (max-width: 480px) {
  .gx { padding-left: 16px !important; padding-right: 16px !important; }
  .agg-bar { grid-template-columns: 78px 1fr 30px !important; gap: 10px !important; }
  .agg-bar > div:first-child { font-size: 12px !important; }
  /* Tighten nav spacing so the logo lockup + GitHub button fit down to 320px. */
  nav.gx { gap: 12px !important; }
  nav.gx > div:first-child { gap: 12px !important; }
}

/* Hero: extra darkening on small screens, where the copy spans the full width
   and would otherwise sit over the brighter (right) part of the photo. */
@media (max-width: 900px) { .hero-scrim-m { display: block !important; } }

/* Fixed-size demo windows (03 · See it work): the frame stays put; the demo
   plays and scrolls inside it. Taller on narrow screens, where the embedded
   demo stacks its chat and ledger panes vertically. */
.demo-frame { height: 760px; }
/* The replay frame carries its Play/Pause + Replay controls above the window. */
iframe.demo-frame[data-demo-view="replay"] { height: 815px; }
@media (max-width: 940px) {
  .demo-frame { height: 1280px; }
  iframe.demo-frame[data-demo-view="replay"] { height: 1340px; }
}

/* Typography pass (round-6): headings never orphan a single word — balance
   distributes the break; body copy relies on per-element text-wrap:pretty. */
h1, h2, h3, h4 { text-wrap: balance; }
p { text-wrap: pretty; }

/* Hero headline: hold the two-line break on desktop – the copy column is
   narrower than the headline, so let it overhang rather than wrap to three. */
@media (min-width: 768px) { .hero-h1 { white-space: nowrap; } }

/* Scenario cards (04 · At every scale): the grid is authored as three
   across; step down to two on tablet and one on phones. */
@media (max-width: 1024px) { #vignettes { grid-template-columns: repeat(2, 1fr) !important; } }
@media (max-width: 640px)  { #vignettes { grid-template-columns: 1fr !important; } }

/* Nav on small screens: the lockup wraps to two lines and the header
   buttons compact so logo + lockup + arXiv + GitHub fit at 375px. */
@media (max-width: 640px) {
  /* Support-triage demo: the stage grows as the log fills, so the control
     bar pins to the bottom of the screen while the card is in view. The
     card swaps overflow:hidden for clip (hidden breaks position:sticky);
     participants compress to a chip row; narration caps with inner scroll. */
  .demo-card { overflow: clip !important; }
  .demo-controls { position: sticky; bottom: 0; z-index: 5; padding: 12px 16px 14px !important; box-shadow: 0 -8px 18px -14px rgba(0,0,0,0.35); }
  #demo-explainer { max-height: 76px; overflow-y: auto; margin-top: 10px !important; font-size: 14px !important; }
  #demo-participants { grid-template-columns: repeat(3, 1fr) !important; gap: 8px !important; margin-bottom: 14px !important; }
  #demo-participants .pcard { flex-direction: column; text-align: center; padding: 10px 6px !important; gap: 6px !important; }
  #demo-participants .pavatar { width: 34px !important; height: 34px !important; font-size: 15px !important; }
  #demo-participants .pcard > div:last-child > div:first-child { font-size: 13px !important; }
  #demo-participants .pcard > div:last-child > div:last-child { display: none; }
  /* Section headers stack: small number above kicker + full-width title,
     so the divider lines up with the text instead of floating left. */
  .sec-head { display: block !important; }
  .sec-head > div { padding-top: 0 !important; }
  .sec-num { font-size: 30px !important; line-height: 1.1 !important; margin: 0 0 8px; }
  .nav-lockup { white-space: nowrap; }
  .nav-lockup .lockup-br { display: block; }
  .nav-btn { padding: 9px 12px !important; }
  nav.gx { gap: 14px !important; }
  nav.gx > div:first-child { gap: 12px !important; }
}
@media (max-width: 480px) {
  nav.gx a[aria-label="Back to top"] img { height: 34px !important; }
  nav.gx > div:first-child > div:nth-child(2) { display: none; }  /* divider */
  nav.gx { gap: 10px !important; }
  nav.gx > div:first-child { gap: 10px !important; }
  .nav-lockup { letter-spacing: 0.08em !important; }
  .nav-btn { padding: 8px 10px !important; }
}

/* Burger menu: below 768px the section links leave the bar, so a burger
   reveals them in a dropdown under the nav. The arXiv button folds into
   the menu below 640px so the bar still fits at 375. */
.nav-burger { display: none; }
#nav-menu { display: none; }
@media (max-width: 1140px) {
  .nav-burger { display: inline-flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; width: 40px; height: 40px; background: transparent; border: 1px solid rgba(255,255,255,0.3); border-radius: 10px; cursor: pointer; flex-shrink: 0; padding: 0; }
  .nav-burger span { display: block; width: 16px; height: 2px; background: #fff; border-radius: 2px; transition: transform .2s var(--bb-ease-out), opacity .2s; }
  .nav-burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .nav-burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .nav-burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  #nav-menu { position: absolute; top: 100%; left: 0; right: 0; background: #282829; border-top: 1px solid rgba(255,255,255,0.12); box-shadow: 0 22px 34px -20px rgba(0,0,0,0.6); padding: 6px 0 10px; max-height: calc(100vh - 78px); overflow-y: auto; }
  #nav-menu.open { display: block; }
  #nav-menu a { display: flex; align-items: baseline; gap: 14px; padding: 13px 24px; text-decoration: none; }
  #nav-menu .m-num { font: 400 11px/1 var(--bb-font-mono); color: #EA4700; min-width: 18px; }
  #nav-menu .m-label { font: 600 14px/1.2 var(--bb-font-sans); color: rgba(255,255,255,0.88); }
  #nav-menu a.nav-menu-cta { border-top: 1px solid rgba(255,255,255,0.10); margin-top: 6px; padding-top: 15px; }
  #nav-menu a.nav-menu-cta .m-label { color: #FF9900; text-transform: uppercase; letter-spacing: 0.08em; font-size: 12px; }
}
@media (max-width: 640px) {
  .nav-btn[href*="arxiv"] { display: none !important; }
  /* Stack-diagram layer cards: name above description, both left-aligned,
     instead of the desktop name-left / description-right split. */
  #stack-diagram > div { flex-direction: column !important; align-items: flex-start !important; gap: 10px !important; }
  #stack-diagram > div > div:last-child { text-align: left !important; max-width: none !important; }
}
