/* ============================================================================
   OPENING — a transcription of Portfolio_series/src/components/OpeningSequence.tsx

   Same choreography as the series, only the palette is the portfolio's
   (css/site.css :root — #05070d ground, #3b82f6 accent, #22d3ee cyan,
   #e9effc text). Nothing about the motion was re-timed.

     empty frame → studio card → name → THE SERIES → portrait reveal
                 → role line  → letterbox retracts, then a 1s hold

   Beat classes come from js/audience-series.js and match the series' TIMELINE:
     beat-studio 300 · beat-name 1900 · beat-series 2700
     beat-portrait 3400 · beat-role 4300 · beat-release 5000
   Durations are the series' own: name 1.3s, series tag 1.1s, portrait 1.6s,
   role 0.8s, letterbox 1.2s.

   The frame starts EMPTY: every element rests hidden and each beat animates it
   in with fill-mode `both`, which also holds the finished state afterwards.
   `.timeline-done` (added by the JS once the timeline has run) forces the
   finished card, so the text is still readable anywhere animations are
   throttled or unavailable.
   ========================================================================== */

#series-opening {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: block;
  overflow: hidden;
  background:
    radial-gradient(ellipse 62% 52% at 50% 46%, rgba(59, 130, 246, .16), transparent 72%),
    radial-gradient(ellipse at 50% 52%, #0a1220 0%, #05070d 58%, #02040a 100%);
  color: #e9effc;
  font-family: 'Inter', sans-serif;
  transition: opacity .85s ease, visibility .85s ease;
}
#series-opening.is-gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---- letterbox ---------------------------------------------------------- */
#series-opening .series-letterbox {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 30;
  height: 7vh;
  background: #05070d;
  transition: transform 1.2s cubic-bezier(.22, 1, .36, 1);
}
#series-opening .series-letterbox-top {
  top: 0;
  border-bottom: 1px solid rgba(59, 130, 246, .16);
}
#series-opening .series-letterbox-bottom {
  bottom: 0;
  border-top: 1px solid rgba(59, 130, 246, .16);
}
#series-opening.beat-release .series-letterbox-top { transform: translateY(-100%); }
#series-opening.beat-release .series-letterbox-bottom { transform: translateY(100%); }

/* ---- projector light ---------------------------------------------------- */
#series-opening .series-opening-glow {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0;
  pointer-events: none;
  /* opacity-only animation: promote it so the beat never repaints the frame */
  will-change: opacity;
  background:
    radial-gradient(58% 48% at 50% 55%, rgba(59, 130, 246, .26), transparent 70%),
    radial-gradient(26% 20% at 50% 54%, rgba(34, 211, 238, .1), transparent 70%);
}
#series-opening.beat-name .series-opening-glow {
  animation: open-projector 1.4s ease both;
}
@keyframes open-projector {
  0%   { opacity: 0; }
  30%  { opacity: .9; }
  60%  { opacity: .5; }
  100% { opacity: .9; }
}

/* ---- portrait ----------------------------------------------------------- */
#series-opening .series-opening-media {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 68vh;
  max-width: 900px;
  margin: 0 auto;
  padding: 0;
}
#series-opening .series-opening-portrait {
  position: static;
  height: 100%;
  width: auto;
  max-width: none;
  margin: 0;
  object-fit: contain;
  object-position: center bottom;
  clip-path: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent 98%);
  mask-image: linear-gradient(to bottom, #000 55%, transparent 98%);
  transform-origin: center bottom;
  opacity: 0;
  transform: scale(1);
  filter: none;
  /* The reveal animates on its own compositor layer: scale/opacity/filter are
     all GPU properties, so the 900px-wide image is never re-rastered with the
     rest of the frame. */
  will-change: opacity, transform, filter;
  backface-visibility: hidden;
}
#series-opening.beat-portrait .series-opening-portrait {
  animation: open-portrait 1.6s cubic-bezier(.22, 1, .36, 1) both;
}
/* No brightness() step: opacity already fades it up from the dark, and every
   extra filter function makes the browser re-rasterise the whole image per
   frame. Blur radius is kept small for the same reason. */
@keyframes open-portrait {
  0%   { opacity: 0; transform: scale(1.06); filter: blur(10px); }
  100% { opacity: 1; transform: scale(1);    filter: blur(0); }
}

/* darkens the frame edges and seats the title over the portrait */
#series-opening .series-opening-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(70% 60% at 50% 40%, transparent 30%, rgba(0, 0, 0, .85) 100%);
}

/* ---- title block --------------------------------------------------------
   Centred, then lifted clear of the portrait when it arrives — the series'
   signature move. The lift stops short of the letterbox so the name never
   slides under the bar. */
#series-opening .series-opening-copy {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: auto;
  max-width: none;
  margin: 0;
  padding: 0 16px;
  text-align: center;
  opacity: 1;
  transform: translateY(0);
  will-change: transform;
  transition: transform 1.3s cubic-bezier(.22, 1, .36, 1);
}
#series-opening.beat-portrait .series-opening-copy { transform: translateY(-20vh); }

#series-opening .series-opening-copy h1 {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 0;
  font-family: 'Bebas Neue', 'Oswald', Impact, sans-serif;
  font-weight: 400;
  font-size: clamp(4.2rem, 17vw, 13rem);
  line-height: .82;
  letter-spacing: .04em;
  text-indent: .04em;
  color: #ffffff;
  text-shadow: 0 8px 40px rgba(0, 0, 0, .8), 0 0 80px rgba(59, 130, 246, .22);
  opacity: 0;
  transform: scale(1);
  filter: none;
  /* One cached layer for the whole entrance: the huge glyphs are rasterised
     once, then only scale/opacity/blur are animated on the compositor. */
  will-change: opacity, transform, filter;
  backface-visibility: hidden;
}
#series-opening.beat-name .series-opening-copy h1 {
  animation: open-name 1.3s cubic-bezier(.22, 1, .36, 1) both;
}
/* The tracking collapse is gone from this keyframe on purpose.
   Animating letter-spacing/text-indent on a clamp(4.2rem, 17vw, 13rem) name is
   a layout + text-reshaping job every single frame: at .5em tracking the line
   was ~2x the viewport wide, so the flex column re-laid-out (and the blurred
   glyphs re-rasterised) 60 times a second. That was the lag. The scale gesture
   below reads as the same tightening and costs nothing. */
@keyframes open-name {
  0% {
    opacity: 0;
    transform: scale(1.16);
    filter: blur(10px);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

/* the name lines are inert: the h1 above owns the whole entrance */
#series-opening .series-opening-copy h1 span {
  display: block;
  width: auto;
  max-width: 100%;
  margin: 0;
  background: none;
  color: inherit;
  -webkit-text-fill-color: currentColor;
  opacity: 1;
  clip-path: none;
  transform: none;
  filter: none;
  animation: none;
}
#series-opening .series-opening-copy h1 span::before { content: none; }
#series-opening .series-opening-copy h1 .series-surname {
  margin-top: .06em;
  font-size: .34em;
  letter-spacing: .3em;
  text-indent: .3em;
  color: #93c5fd;
}

/* ---- THE SECURITY SERIES ------------------------------------------------ */
#series-opening .series-title {
  margin: clamp(10px, 1.8vh, 20px) 0 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(.7rem, 1.5vw, .95rem);
  font-weight: 700;
  letter-spacing: .34em;
  text-indent: .34em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #3b82f6;
  text-shadow: 0 2px 22px rgba(0, 0, 0, .9), 0 0 26px rgba(59, 130, 246, .55);
  opacity: 0;
}
#series-opening.beat-series .series-title {
  animation: open-series 1.1s cubic-bezier(.22, 1, .36, 1) both;
}
/* Short line, so the tracking spread can stay — but the start value is capped
   at 1em (was 1.4em) so the line can never wrap on a narrow phone and reflow
   the name above it on every frame. */
@keyframes open-series {
  0%   { opacity: 0; letter-spacing: 1em; text-indent: 1em; }
  100% { opacity: 1; letter-spacing: .34em; text-indent: .34em; }
}

/* ---- studio card (only lives for the first beat) ------------------------ */
#series-opening .series-studio {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .2em;
  text-indent: .2em;
  text-transform: uppercase;
  text-align: center;
  color: rgba(233, 239, 252, .6);
  pointer-events: none;
  opacity: 0;
}
#series-opening.beat-studio .series-studio {
  animation: open-studio 1.6s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes open-studio {
  0%   { opacity: 0; letter-spacing: .2em; text-indent: .2em; }
  100% { opacity: 1; letter-spacing: .6em; text-indent: .6em; }
}
#series-opening.beat-name .series-studio {
  animation: none;
  opacity: 0;
  filter: blur(6px);
  transition: opacity .6s ease, filter .6s ease;
}

/* ---- role line ----------------------------------------------------------
   audience-series.css used to dress .series-opening-copy .series-tagline as a
   filled blue pill; the plain line of type is reset here. */
#series-opening .series-tagline {
  margin: 0;
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(.58rem, 1vw, .78rem);
  font-weight: 500;
  letter-spacing: .3em;
  text-indent: .3em;
  text-transform: uppercase;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  line-height: 1.6;
  color: rgba(233, 239, 252, .9);
  opacity: 0;
  transform: translateY(0);
}
#series-opening .series-opening-end {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9vh;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  text-align: center;
}
#series-opening.beat-role .series-tagline {
  animation: open-role .8s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes open-role {
  0%   { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---- skip --------------------------------------------------------------- */
#series-opening .series-skip {
  position: absolute;
  top: calc(7vh + 12px);
  right: 18px;
  bottom: auto;
  z-index: 40;
  min-height: 0;
  padding: 9px 18px;
  border: 1px solid rgba(59, 130, 246, .4);
  border-radius: 999px;
  background: rgba(13, 21, 38, .6);
  color: rgba(233, 239, 252, .8);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 1;
  transition: border-color .25s ease, color .25s ease, background .25s ease;
}
#series-opening .series-skip:hover,
#series-opening .series-skip:focus-visible {
  border-color: rgba(59, 130, 246, .9);
  background: rgba(59, 130, 246, .14);
  color: #ffffff;
}

/* ---- fail-safe: the finished card --------------------------------------
   Important so it also wins over the beat animations, which hold their 0%
   keyframe wherever the browser throttles animation timelines. */
#series-opening.timeline-done .series-opening-copy h1 {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
  filter: none !important;
  letter-spacing: .04em !important;
  text-indent: .04em !important;
}
#series-opening.timeline-done .series-opening-portrait {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
  filter: none !important;
}
#series-opening.timeline-done .series-title {
  animation: none !important;
  opacity: 1 !important;
}
#series-opening.timeline-done .series-tagline {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
}
#series-opening.timeline-done .series-opening-glow { opacity: .9 !important; }

/* The card is static once the timeline has run, so give the layers back. */
#series-opening.timeline-done .series-opening-copy,
#series-opening.timeline-done .series-opening-copy h1,
#series-opening.timeline-done .series-opening-portrait,
#series-opening.timeline-done .series-opening-glow { will-change: auto; }

/* ---- narrow screens ----------------------------------------------------- */
@media (max-width: 700px) {
  #series-opening .series-opening-media { height: 58vh; }
  #series-opening.beat-portrait .series-opening-copy { transform: translateY(-16vh); }
  #series-opening .series-opening-copy h1 { font-size: clamp(3rem, 18vw, 6rem); }
  #series-opening .series-opening-copy h1 .series-surname { letter-spacing: .28em; text-indent: .28em; }
  #series-opening .series-title { font-size: .62rem; }
  #series-opening .series-tagline { font-size: .5rem; letter-spacing: .18em; text-indent: .18em; }
  #series-opening .series-opening-end { bottom: 7vh; }
  #series-opening .series-skip { top: calc(7vh + 10px); right: 12px; padding: 8px 14px; font-size: 9px; }
}

/* ---- short viewports: less lift, so the name stays clear of the bar ------ */
@media (max-height: 620px) {
  #series-opening .series-opening-copy h1 { font-size: clamp(2.4rem, 12vw, 6rem); }
  #series-opening.beat-portrait .series-opening-copy { transform: translateY(-12vh); }
  #series-opening .series-opening-media { height: 74vh; }
  #series-opening .series-title { margin-top: 8px; }
}

/* ---- reduced motion: the finished card, no timeline --------------------- */
@media (prefers-reduced-motion: reduce) {
  #series-opening .series-letterbox { transition: none; }
  #series-opening .series-letterbox-top { transform: translateY(-100%); }
  #series-opening .series-letterbox-bottom { transform: translateY(100%); }
  #series-opening .series-opening-glow { opacity: .9; animation: none; }
  #series-opening .series-opening-portrait { opacity: 1; filter: none; transform: none; animation: none; }
  #series-opening .series-opening-copy { transform: translateY(-20vh); transition: none; }
  #series-opening .series-opening-copy h1 {
    opacity: 1;
    transform: none;
    filter: none;
    letter-spacing: .04em;
    text-indent: .04em;
    animation: none;
  }
  #series-opening .series-studio { opacity: 0; animation: none; }
  #series-opening .series-title,
  #series-opening .series-tagline {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
