/* PeptideScope: intro (v4, "simpler, faster, for teens"). Markup: index.html #intro. Script: js/intro.js.
   Pattern: 21st.dev "scroll-triggered video hero" (sticky media, cross-fades, progress indicator,
   accessible text) rebuilt in plain CSS; style: ui-ux-pro-max "Minimalism & Swiss" (spacious,
   light-first, one violet accent). Real photographs and our own anatomy renders, no WebGL.

   Two layouts, one DOM:
     default        a plain vertical story (no script, reduced motion, or intro.js not loaded yet):
                    every chapter stacked, images lazy-load natively, the end card at the bottom.
     .intro--scrolly  set by js/intro.js when motion is allowed: #intro scrolls a tall, empty track
                    under a sticky full-screen stage; one chapter per swipe (scroll snapping); the
                    active chapter cross-fades in (opacity/transform only).
   Other classes from js/intro.js: .is-active / .is-near on .intro-ch, .is-active / .is-done on
   .intro-dot, .intro--instant (suppresses transitions for one frame), .is-broken on .intro-frame.
   Theme-aware (site tokens, light first); photos sit on soft neutral frames. Visibility of #intro
   itself is owned by app.css (html[data-intro]). */

#intro {
  --intro-bar-h: 108px;                     /* two rows on phones: brand + Skip, then the safety line */
  --intro-dots-h: 52px;
  --intro-bottom: calc(var(--disclaimer-h, 40px) + var(--intro-dots-h));
  --intro-ease: cubic-bezier(.16, 1, .3, 1);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}
#intro:focus { outline: none; }
@media (min-width: 720px) {
  #intro { --intro-bar-h: 80px; }
}

/* ------------------------------------------------------------------ top bar: name, safety line, Skip */
.intro-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "brand skip" "safety safety";
  align-items: center;
  gap: 8px 12px;
  min-height: var(--intro-bar-h);
  padding: max(10px, env(safe-area-inset-top)) var(--gutter) 10px;
  background: var(--bg);
}
@media (min-width: 720px) {
  .intro-bar {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "brand safety skip";
    padding-block: 16px;
  }
}
.intro-brand {
  grid-area: brand;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin: 0;
}
.intro-brand .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
.intro-brand .brand-mark svg { width: 23px; height: 23px; }
.intro-brand-word {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.1875rem;
  line-height: 1.1;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.intro-safety {
  grid-area: safety;
  justify-self: center;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0 8px;
  margin: 0;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.35;
}
.intro-safety > span { white-space: nowrap; }
@media (max-width: 389.98px) {
  .intro-safety { gap: 0 6px; padding: 5px 10px; font-size: 0.75rem; }
}
.intro-safety > .intro-sep { color: var(--line-strong); }
.intro-skip {
  grid-area: skip;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 700;
  white-space: nowrap;
  transition: border-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.intro-skip:hover { border-color: var(--primary); color: var(--primary); }

/* scroll-linked progress hairline (scrolly only) */
.intro-progress { display: none; }
.intro-progress > span {
  display: block;
  height: 100%;
  background: var(--primary);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

/* ------------------------------------------------------------------ chapters (default: vertical story) */
#intro .intro-story { /* #intro: beats app.css `ol[class] { padding: 0 }` */
  list-style: none;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(var(--disclaimer-h, 40px) + 48px);
}
.intro-ch {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "media" "line";
  justify-items: center;
  align-content: center;
  row-gap: 20px;
  padding-block: clamp(56px, 10vh, 120px);
  text-align: center;
}
.intro-ch--text { grid-template-areas: "line" "cue"; }
.intro-ch--end { grid-template-areas: "end"; }
.intro-ch:first-child,
.intro-ch--end {
  min-height: calc(100svh - var(--intro-bar-h) - var(--disclaimer-h, 40px));
  padding-block: 24px;
}

.intro-line {
  grid-area: line;
  max-width: 19ch;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.875rem, 1.05rem + 2.6vw, 3.75rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
  color: var(--text);
}
.intro-ch--text .intro-line {
  max-width: 14ch;
  font-size: clamp(2.5rem, 1.2rem + 5vw, 5.5rem);
  line-height: 1.04;
  letter-spacing: -0.025em;
}

/* the first chapter's cue: a real button (next chapter) that reads like a hint */
.intro-cue {
  grid-area: cue;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  margin-top: clamp(28px, 7vh, 64px);
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 700;
  transition: color var(--dur-1) var(--ease);
}
.intro-cue:hover { color: var(--primary); }
.intro-cue svg { width: 22px; height: 22px; transform: rotate(90deg); }
.intro-cue-text--swipe { display: none; }
@media (pointer: coarse) {
  .intro-cue-text--scroll { display: none; }
  .intro-cue-text--swipe { display: inline; }
}

/* ------------------------------------------------------------------ pictures */
.intro-media {
  grid-area: media;
  display: grid;
  justify-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
}
.intro-frame {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  width: min(100%, 480px, calc((100svh - 400px) * 0.8));
  min-width: 200px;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-l);
  background: var(--surface-2);
  box-shadow: var(--shadow-3);
}
.intro-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 8%, transparent);
  pointer-events: none;
}
.intro-frame picture { display: block; width: 100%; height: 100%; }
/* the anatomy renders come with a light and a dark stage background; the site theme picks one */
html[data-theme="dark"] .intro-pic--light,
html:not([data-theme="dark"]) .intro-pic--dark { display: none; }
.intro-frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
.intro-frame.is-broken img { visibility: hidden; }

/* the syringe: a real photo cut out of its white studio background, on a soft neutral card; turned
   45° in portrait frames, needle cap up and to the right (never pointing down at a body) */
.intro-frame--cutout {
  background:
    radial-gradient(110% 80% at 50% 38%, var(--surface) 0%, transparent 70%),
    var(--surface-2);
}
.intro-frame--cutout img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 104%;
  height: auto;
  object-fit: contain;
  transform: translate(-50%, -50%) rotate(-45deg);
  filter: drop-shadow(0 16px 14px rgb(var(--shadow-ink) / 0.16));
}
/* the micrograph is black and white (electron microscopes record no colour); a warm red tint makes it
   read as blood. The caption says "colour added". */
.intro-frame--tint img { filter: sepia(1) saturate(3.2) hue-rotate(-42deg) brightness(0.9) contrast(1.06); }

.intro-credit {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  font-weight: 500;
  color: var(--muted);
}

/* ------------------------------------------------------------------ end card */
.intro-end {
  grid-area: end;
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
}
.intro-end-mark.brand-mark { width: 64px; height: 64px; border-radius: 20px; }
.intro-end-mark.brand-mark svg { width: 40px; height: 40px; }
.intro-title {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(3rem, 1.6rem + 5.4vw, 6rem);
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text);
}
.intro-tagline {
  max-width: 30ch;
  margin: 0;
  font-size: clamp(1.0625rem, 0.95rem + 0.5vw, 1.375rem);
  line-height: 1.4;
  font-weight: 500;
  color: var(--muted);
  text-wrap: balance;
}
.intro-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}
@media (max-width: 479.98px) {
  .intro-actions { flex-direction: column; width: min(100%, 320px); }
  .intro-actions .btn { width: 100%; }
}
.intro-credits {
  position: relative;
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--muted);
}
.intro-credits > summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  list-style: none;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 0.2em;
}
.intro-credits > summary::-webkit-details-marker { display: none; }
.intro-credits > summary:hover { color: var(--primary); }
.intro-credits-text {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  z-index: 2;
  width: min(calc(100vw - 32px), 34rem);
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-m);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  color: var(--text-2);
  line-height: 1.55;
  text-align: left;
  transform: translateX(-50%);
}

/* "Next" (scrolly only): a real button that stays put on every chapter but the end card; the keyboard
   hint shows next to it for keyboard users */
.intro-next, .intro-keys { display: none; }
.intro--scrolly .intro-next:not([hidden]) {
  position: absolute;
  right: var(--gutter);
  bottom: calc(var(--disclaimer-h, 40px) + 10px);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px 0 18px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 700;
}
.intro--scrolly .intro-next svg { width: 18px; height: 18px; transform: rotate(90deg); }
@media (hover: hover) and (pointer: fine) {
  .intro--scrolly .intro-next:hover { border-color: var(--primary); color: var(--primary); }
}
.intro--scrolly .intro-next:not([hidden]):focus-visible ~ .intro-keys,
.intro--scrolly:focus-visible .intro-keys {
  position: absolute;
  right: var(--gutter);
  bottom: calc(var(--disclaimer-h, 40px) + 60px);
  z-index: 3;
  display: block;
  margin: 0;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

/* dots (scrolly only) */
.intro-dots { display: none; }
.intro-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: transform var(--dur-3) var(--ease), background-color var(--dur-3) var(--ease);
}
.intro-dot.is-done { background: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.intro-dot.is-active { background: var(--primary); transform: scale(1.4); }

.intro-track { display: none; }

/* ------------------------------------------------------------------ wide screens: words left, picture right */
@media (min-width: 1024px) and (min-aspect-ratio: 5/4) {
  .intro-ch {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    grid-template-areas: "line media";
    column-gap: clamp(40px, 5vw, 96px);
    align-items: center;
    justify-items: start;
    text-align: left;
  }
  .intro-ch--text { grid-template-columns: minmax(0, 1fr); grid-template-areas: "line" "cue"; justify-items: center; text-align: center; }
  .intro-ch--end { grid-template-columns: minmax(0, 1fr); grid-template-areas: "end"; justify-items: center; }
  .intro-line { max-width: 13ch; }
  .intro-media { justify-items: end; }
  .intro-frame {
    width: min(100%, calc((100svh - 300px) * 16 / 9));
    aspect-ratio: 16 / 9;
  }
  .intro-frame--cutout img { width: 84%; transform: translate(-50%, -50%); }
}

/* ------------------------------------------------------------------ scrolly: sticky stage, one chapter per swipe */
#intro.intro--scrolly {
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
#intro.intro--scrolly::-webkit-scrollbar { display: none; }
.intro--scrolly .intro-stage {
  position: sticky;
  top: 0;
  height: 100%;
  overflow: hidden;
}
.intro--scrolly .intro-bar {
  position: absolute;
  inset: 0 0 auto 0;
  background: transparent;
}
.intro--scrolly .intro-progress {
  display: block;
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 4;
  height: 3px;
}
#intro.intro--scrolly .intro-story {
  position: absolute;
  inset: 0;
  max-width: none;
  padding: 0;
}
.intro--scrolly .intro-ch {
  position: absolute;
  inset: 0;
  max-width: 1240px;
  min-height: 0;
  margin-inline: auto;
  padding: calc(var(--intro-bar-h) + 8px) var(--gutter) calc(var(--intro-bottom) + 4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 450ms var(--ease);
}
.intro--scrolly .intro-ch.is-active {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 900ms var(--intro-ease) 60ms;
}
.intro--scrolly .intro-ch.is-near { will-change: opacity; }
/* pictures more than one chapter away are not rendered, so their lazy images do not load yet */
.intro--scrolly .intro-ch:not(.is-near) .intro-media { display: none; }
.intro--scrolly .intro-line {
  transform: translate3d(0, 16px, 0);
  transition: transform 450ms var(--ease);
}
.intro--scrolly .is-active .intro-line {
  transform: none;
  transition: transform 1100ms var(--intro-ease) 140ms;
}
.intro--scrolly .intro-frame picture {
  transform: scale(1.06);
  transition: transform 450ms var(--ease);
}
.intro--scrolly .is-active .intro-frame picture {
  transform: none;
  transition: transform 1800ms var(--intro-ease);
}
.intro--scrolly .is-active .intro-cue svg { animation: intro-bob 2.6s var(--ease-in-out) infinite; }
@keyframes intro-bob {
  0%, 100% { translate: 0 -2px; }
  50% { translate: 0 5px; }
}
.intro--scrolly.intro--instant .intro-ch,
.intro--scrolly.intro--instant .intro-ch * { transition: none !important; }

.intro--scrolly .intro-dots {
  display: flex;
  position: absolute;
  inset: auto 0 calc(var(--disclaimer-h, 40px) + 22px) 0;
  z-index: 2;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
}
/* phones: the dots move left so they never touch the Next button on the right */
@media (max-width: 479.98px) {
  .intro--scrolly .intro-dots { justify-content: flex-start; gap: 10px; padding-left: calc(var(--gutter) + 6px); bottom: calc(var(--disclaimer-h, 40px) + 28px); }
}
.intro--scrolly .intro-track { display: block; }
.intro-snap {
  position: absolute;
  left: 0;
  width: 1px;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  pointer-events: none;
  visibility: hidden;
}

/* short landscape phones: a compact one-row bar, words beside a smaller picture, no dots (the
   hairline still shows progress), a compact end card */
@media (max-height: 560px) and (orientation: landscape) {
  #intro { --intro-bar-h: 64px; --intro-dots-h: 6px; }
  .intro-bar { padding-block: 8px; }
  .intro-ch { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "line media"; column-gap: 32px; align-items: center; justify-items: start; text-align: left; }
  .intro-ch--text, .intro-ch--end { grid-template-columns: minmax(0, 1fr); justify-items: center; text-align: center; }
  .intro-ch--text { grid-template-areas: "line" "cue"; }
  .intro-ch--end { grid-template-areas: "end"; }
  .intro-line { font-size: clamp(1.5rem, 1rem + 2vw, 2.25rem); }
  .intro-ch--text .intro-line { font-size: clamp(2rem, 1.2rem + 3vw, 3rem); }
  .intro-cue { margin-top: 12px; }
  .intro-media { justify-items: end; gap: 6px; }
  .intro-frame { width: min(100%, calc((100svh - 180px) * 0.8)); min-width: 0; }
  .intro-end { gap: 6px; }
  .intro-end-mark { display: none; }
  .intro-title { font-size: 2.5rem; margin: 0; }
  .intro-tagline { font-size: 1rem; max-width: none; }
  .intro-actions { margin-top: 6px; }
  .intro-actions .btn--lg { min-height: 48px; }
  .intro-credits { margin-top: 0; }
  .intro--scrolly .intro-dots { display: none; }
}
/* the one-row bar only where it fits; narrower short screens (e.g. a laptop at 400% zoom, 320 × 180)
   keep the two rows, so "Skip intro" never overlaps the safety line (a11y review) */
@media (max-height: 560px) and (orientation: landscape) and (min-width: 640px) {
  .intro-bar { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-areas: "brand safety skip"; }
}
@media (max-height: 300px) {
  #intro { --intro-bar-h: 84px; }
  /* very short screens use the plain story (intro.js): the bar scrolls away with it */
  #intro:not(.intro--scrolly) .intro-bar { position: static; }
  .intro-bar { gap: 4px 8px; padding-block: 4px; }
  .intro-brand .brand-mark { width: 28px; height: 28px; }
  .intro-skip { min-height: 44px; padding: 0 12px; font-size: 0.8125rem; }
  .intro-safety { padding: 2px 8px; font-size: 0.6875rem; }
  .intro--scrolly .intro-next:not([hidden]) { bottom: calc(var(--disclaimer-h, 40px) + 4px); }
}

@media (forced-colors: active) {
  .intro-progress > span, .intro-dot.is-active { background: Highlight; }
  .intro-frame--tint img { filter: none; }
}
