/* DM ORIGINALS: chapter 1, the opening.
   The dive (a tall track around a sticky stage), then the reading column.
   Motion states are written by js/opening.js; this file holds the rest composition. */

.opening {
  min-height: 100svh;  /* held before the script builds it: the footer must not flash into the first screen */
  --col: 38rem;
  --bulb-x: 50.3%;   /* the bulb inside the mark; js/opening.js sets the same values */
  --bulb-y: 49.6%;
  position: relative;
  z-index: var(--z-content);
}

/* ------------------------------------------------------------------ the dive */

.opening__track { position: relative; }
.js-motion .opening__track { height: 260svh; }

.opening__stage {
  position: relative;
  height: 100svh;
  isolation: isolate;
  overflow: hidden;
}
@supports (overflow: clip) {
  /* clip sideways only: the light may run past the bottom edge while a phone's toolbar is retracted */
  .opening__stage { overflow: visible; overflow-x: clip; }
}
.js-motion .opening__stage { position: sticky; top: 0; }
html:not(.js-motion) .opening__stage { height: auto; min-height: 100svh; }

/* Mark, title and action. No stacking context here, so the light field can pass between them. */
.opening__hero {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-block: calc(env(safe-area-inset-top, 0px) + 64px) var(--tabbar-space);
  padding-inline: var(--gutter);
  text-align: center;
}
html:not(.js-motion) .opening__hero { min-height: 100svh; }

.opening__mark {
  position: relative;
  z-index: 1;
  flex: none;
  width: min(48vw, 360px, 40svh);
  aspect-ratio: 720 / 838;
  transform-origin: var(--bulb-x) var(--bulb-y);
}
.js-motion .opening__mark { will-change: transform; }
.opening__img {
  width: 100%;
  height: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* The bulb: the only light source on the page */
.opening__glow {
  position: absolute;
  left: var(--bulb-x);
  top: var(--bulb-y);
  width: 80%;
  aspect-ratio: 1;
  translate: -50% -50%;
  pointer-events: none;
}
.opening__halo,
.opening__filament {
  position: absolute;
  border-radius: 50%;
  mix-blend-mode: screen;
  opacity: 0;
}
.opening__halo {
  inset: 0;
  /* tight falloff: as the mark grows toward the camera the halo grows with it, and navy must stay at the edges */
  background: radial-gradient(closest-side,
    rgba(255, 244, 224, 0.98),
    rgba(255, 210, 140, 0.7) 14%,
    rgba(255, 176, 84, 0.24) 28%,
    rgba(255, 164, 70, 0.06) 42%,
    rgba(255, 164, 70, 0) 54%);
}
.opening__filament {
  inset: 41%;
  background: radial-gradient(closest-side, var(--tungsten-soft), rgba(255, 226, 176, 0.65) 34%, rgba(255, 201, 120, 0));
}

/* It catches once: dark, a first glow in the filament, then the bloom. No loop. */
.js-motion .opening.is-lit .opening__filament { animation: opening-catch 1000ms var(--ease-out) 240ms both; }
.js-motion .opening.is-lit .opening__halo { animation: opening-bloom 1000ms var(--ease-out) 240ms both; }
html:not(.js-motion) .opening__halo,
html:not(.js-motion) .opening__filament { animation: none; opacity: 1; }

@keyframes opening-catch {
  0% { opacity: 0; transform: scale(0.5); }
  20% { opacity: 0.85; transform: scale(1); }
  30% { opacity: 0.4; }
  48%, 100% { opacity: 1; transform: scale(1); }
}
@keyframes opening-bloom {
  0%, 22% { opacity: 0; transform: scale(0.3); }
  100% { opacity: 1; transform: scale(1); }
}

.opening__title {
  position: relative;
  z-index: 3;
  margin-top: clamp(18px, 3.4svh, 40px);
  font-size: var(--step-display-xl);
  line-height: 1.02;
  letter-spacing: -0.012em;
}

.opening__title-sub {
  display: block;
  margin-top: 0.45em;
  font-weight: 400;
  font-size: var(--step-display-s);
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--ink-2);
}

.opening__cta {
  position: relative;
  z-index: 3;
  margin-top: clamp(22px, 4.4svh, 44px);
}
@media (hover: hover) and (pointer: fine) {
  .opening__cta:hover .btn__icon { transform: translateY(2px) scale(1.06); }
}

/* Sparks: drawn by js, taller than the stage so a retracting toolbar never shows an edge */
.opening__field {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: max(100%, 100lvh);
  pointer-events: none;
}

/* Passing through the bulb: its light fills the screen for a moment */
.opening__bloom {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-radius: 50%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* Light adds, it never paints over: screen-blended, a white-hot core falling off to navy,
     so the deep still shows at the edges for the whole passage (js caps the scale for that). */
  mix-blend-mode: screen;
  /* short and saturated: past the white core the light stays warm and hands straight back to navy,
     never lingering as a thin wash (thin warm light over navy reads grey) */
  background: radial-gradient(closest-side,
    #fffaf0 0%,
    rgba(255, 242, 220, 0.95) 7%,
    rgba(255, 222, 168, 0.8) 16%,
    rgba(255, 190, 100, 0.5) 26%,
    rgba(255, 168, 72, 0.2) 36%,
    rgba(255, 160, 64, 0.06) 46%,
    rgba(255, 160, 64, 0) 56%);
}
/* Leaving the light: a ring that opens from the centre and rushes out past the edges */
.opening__bloom--iris {
  background: radial-gradient(closest-side,
    rgba(255, 190, 100, 0) 44%,
    rgba(255, 190, 100, 0.2) 54%,
    rgba(255, 236, 204, 0.66) 64%,
    rgba(255, 184, 96, 0.34) 76%,
    rgba(255, 168, 72, 0) 88%);
  border-radius: 0;
}
.js-motion .opening__bloom { will-change: transform, opacity; }
html:not(.js-motion) .opening__bloom { display: none; }

/* Inside: the first line, alone in the centre of the screen */
.opening__intro {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 64px) var(--gutter) var(--tabbar-space);
  pointer-events: none;
}
.opening__intro .opening__intro-inner {
  width: 100%;
  max-width: var(--col);
  transform-origin: 50% 50%;
}
.opening__intro-inner:focus { outline: none; }
.opening__w { display: inline-block; }
.opening__temp { margin-bottom: var(--s-5); }

/* ------------------------------------------------------------------ the reading column */

.opening__read {
  position: relative;
  padding-block: clamp(8px, 3svh, 40px) clamp(24px, 4svh, 48px);
}
/* the column and the collages behind it. It starts well inside the track, so the story follows the
   first line after a beat, not after an empty screen: it rises into view from p = 0.78, once the first
   line is whole (js/opening.js), and at p = 1 it sits about a tenth of a screen under that line */
.opening__zone { position: relative; isolation: isolate; }
.js-motion .opening__zone { margin-top: -36svh; }
.opening__column {
  position: relative;
  max-width: var(--col);
  margin-inline: auto;
}

.opening__lead {
  font-family: var(--font-ui);
  font-weight: 400;
  font-size: var(--step-display-s);
  line-height: 1.5;
  color: var(--paper);
}
.opening__q {
  margin-top: clamp(36px, 6svh, 64px);
  max-width: 20ch;
  font-size: var(--step-display-m);
  line-height: 1.12;
}
.opening__p {
  margin-top: var(--s-5);
  max-width: 60ch;
  font-size: var(--step-body-l);
  line-height: 1.75;
  color: var(--ink-2);
}
/* the question keeps clear air under it, more than between two paragraphs, so it reads as a heading */
.opening__q + .opening__p { margin-top: calc(var(--s-6) + var(--s-1)); }
.opening__quote { margin-top: clamp(36px, 6svh, 64px); }
.opening__quote p {
  max-width: 17ch;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--step-display-l);
  line-height: 1.12;
  letter-spacing: -0.01em;
  color: var(--paper);
  text-wrap: balance;
}
.opening__signoff {
  margin-top: clamp(56px, 9svh, 96px);
  font-size: var(--step-body-l);
  font-weight: 500;
  color: var(--paper);
}
/* whatever opens the column (the first question, or the first line under reduced motion) sits flush */
.opening__thread + * { margin-top: 0; }

/* The one authored detail: a thread of the bulb's light follows the reader down the column */
.opening__thread {
  position: absolute;
  top: 0;
  bottom: 0;
  inset-inline-start: calc(-1 * clamp(12px, 3.6vw, 56px));
  width: 1px;
  overflow: hidden;
  pointer-events: none;
}
.opening__trail {
  position: absolute;
  inset: 0;
  background: rgba(255, 201, 120, 0.28);
  transform-origin: 50% 0;
  transform: scaleY(0);
}
.opening__head {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 120px;
  background: linear-gradient(rgba(255, 201, 120, 0), var(--tungsten) 78%, var(--tungsten-soft));
  opacity: 0;
}
html:not(.js-motion) .opening__thread { display: none; }

/* ------------------------------------------------------------------ the collages behind the story */
/* Each part of Dor's story brings its own collage (content: scenes): his own collages, as he made them.
   The layer is pinned under the column while it is read; the collage lies centred behind the words,
   a little askew, faded into the deep. Only opacity changes between parts, and the collage settles
   from a slight zoom as it arrives. Leaving is quicker than arriving. */
/* the layer reaches a screen above the column, so it is already pinned when the first part of the
   story reaches the middle of the screen */
.opening__backdrop {
  position: absolute;
  inset: -100svh 0 0;
  z-index: -1;
  pointer-events: none;
}
.opening__pin {
  position: sticky;
  top: 0;
  height: 100svh;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 6%, #000 94%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 6%, #000 94%, transparent);
}
.opening__scene {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 500ms var(--ease-out);
}
.opening__scene.is-on { opacity: 1; transition-duration: 900ms; }
/* a soft pool of the deep behind the column, so the words read while the collage's edges stay clear */
.opening__scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse min(26rem, 60vw) 46% at 50% 50%, rgba(10, 18, 38, 0.46), rgba(10, 18, 38, 0) 100%);
}
/* on phones the collage runs a little past the edges, so its photos stay large */
.opening__collage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(118vw, calc(84svh * var(--r, 1.2)));
  max-width: none;
  height: auto;
  opacity: 0.36;
  transform: translate(-50%, -50%) rotate(var(--tilt, 0deg));
  -webkit-user-select: none;
  user-select: none;
}
.js-motion .opening__collage {
  transform: translate(-50%, -50%) rotate(var(--tilt, 0deg)) scale(1.05);
  transition: transform 1800ms var(--ease-out);
}
.js-motion .opening__scene.is-on .opening__collage { transform: translate(-50%, -50%) rotate(var(--tilt, 0deg)); }
@media (min-width: 1000px) {
  .opening__collage { width: min(84vw, 1240px, calc(84svh * var(--r, 1.2))); opacity: 0.4; }
}
/* the words keep a soft shadow of the deep, so they read over any photo */
.opening__zone .opening__p,
.opening__zone .opening__lead {
  text-shadow: 0 1px 3px rgba(5, 9, 20, 0.9), 0 0 24px rgba(5, 9, 20, 0.7);
}

/* ------------------------------------------------------------------ short screens (landscape phones) */

@media (max-height: 520px) {
  .opening__hero { padding-block: calc(env(safe-area-inset-top, 0px) + 40px) var(--tabbar-space); }
  .opening__mark { width: min(48vw, 28svh); }
  .opening__title { font-size: min(var(--step-display-xl), 12svh); }
  .opening__intro { padding-block: 40px var(--tabbar-space); }
}

@media (forced-colors: active) {
  .opening__halo, .opening__filament, .opening__bloom, .opening__thread { display: none; }
}
