/* ==========================================================================
   Scene two — the engineering universe.
   A dark room, a red core burning behind the figure, and twelve glass cards
   holding the stack. Everything is live DOM + SVG: the cards rise together
   as one event, then float; the pointer leans the room by depth; red lines
   run from the core out to each card.
   Card geometry comes from custom properties set inline per card:
     --x / --y  centre, as fractions of the section
     --w        width, as a fraction of the section width
     --d        depth 0..1 (near cards move more and sit brighter)
   ========================================================================== */

.flow {
  position: relative;
  z-index: 2;
}

html { scroll-behavior: smooth; }

/* The hero is position:fixed, so its scroll height has to be reserved here or
   the universe would start at the top of the document and sit on top of it. */
.hero-spacer {
  height: 100svh;
  pointer-events: none;
}

.universe {
  --px: 0;                 /* pointer, -1..1, written by boot2 */
  --py: 0;
  position: relative;
  height: 100svh;
  min-height: 520px;
  background: #000;
  overflow: hidden;
  box-shadow: 0 -1px 0 0 #000;
  container-type: size;
}

/* ---- the room ------------------------------------------------------------ */
.universe__room { position: absolute; inset: 0; }

.universe__glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(38% 46% at 50% 54%, rgba(222, 27, 28, 0.34), transparent 70%),
    radial-gradient(70% 34% at 50% 96%, rgba(150, 12, 14, 0.30), transparent 72%),
    radial-gradient(120% 90% at 50% 40%, #120405 0%, #050102 60%, #000 100%);
  opacity: 0;
  transition: opacity 2.2s var(--ease-out);
}
.universe.is-on .universe__glow { opacity: 1; }

.universe__core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(62cqh, 46cqw);
  aspect-ratio: 1;
  translate: calc(-50% + var(--px) * -6px) calc(-50% + var(--py) * -4px);
  opacity: 0;
  scale: 0.86;
  transition: opacity 1.8s var(--ease-out) 0.2s, scale 2.4s var(--ease-out) 0.2s;
  overflow: visible;
}
.universe.is-on .universe__core { opacity: 1; scale: 1; }
.universe__core circle {
  fill: none;
  stroke: var(--ink);
  vector-effect: non-scaling-stroke;
  transform-origin: 0 0;
}
.universe__core .c1 { stroke-width: 1; stroke-dasharray: 2 5; opacity: 0.55; animation: uSpin 90s linear infinite; }
.universe__core .c2 { stroke-width: 1.5; stroke-dasharray: 120 40 14 40; opacity: 0.85; animation: uSpin 46s linear infinite reverse; filter: drop-shadow(0 0 6px rgba(255, 42, 43, 0.8)); }
.universe__core .c3 { stroke-width: 1; stroke-dasharray: 60 22; opacity: 0.5; animation: uSpin 30s linear infinite; }
.universe__core .c4 { stroke-width: 2; stroke-dasharray: 30 90; opacity: 0.9; animation: uSpin 18s linear infinite reverse; filter: drop-shadow(0 0 8px rgba(255, 42, 43, 0.9)); }
@keyframes uSpin { to { rotate: 360deg; } }

.universe__lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.universe__lines path {
  fill: none;
  stroke: var(--ink-hot);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 1.6s var(--ease-out) calc(0.9s + var(--i) * 0.03s),
              opacity 0.6s ease 0.9s;
}
.universe.is-on .universe__lines path { opacity: 0.34; stroke-dashoffset: 0; }
.universe__lines circle {
  fill: #ffd9c8;
  opacity: 0;
  filter: drop-shadow(0 0 4px #ff2a2b);
}
.universe.is-live .universe__lines circle { opacity: 0.9; }

.universe__floor {
  position: absolute;
  left: 50%;
  top: 88%;
  width: min(74cqw, 120cqh);
  aspect-ratio: 5 / 1;
  translate: -50% -50%;
}
.universe__floor i {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 90, 60, 0.42);
  border-radius: 50%;
  opacity: 0;
  scale: 0.6;
  transition: opacity 1.4s ease 0.5s, scale 2s var(--ease-out) 0.5s;
  box-shadow: 0 0 22px rgba(222, 27, 28, 0.25), inset 0 0 26px rgba(222, 27, 28, 0.16);
}
.universe__floor i:nth-child(2) { inset: 17% 15%; border-color: rgba(255, 120, 80, 0.30); }
.universe__floor i:nth-child(3) { inset: 34% 30%; border-color: rgba(255, 200, 170, 0.34); }
.universe.is-on .universe__floor i { opacity: 1; scale: 1; }

/* ---- title --------------------------------------------------------------- */
.universe__title {
  position: absolute;
  top: clamp(26px, 6.5vh, 66px);
  left: 50%;
  transform: translate(-50%, 14px);
  z-index: 6;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.3s var(--ease-out) 0.75s,
              transform 1.6s var(--ease-out) 0.75s;
}
.universe.is-on .universe__title { opacity: 1; transform: translate(-50%, 0); }

.universe__over {
  margin: 0 0 0.9em;
  font-family: var(--ui);
  font-size: clamp(7.5px, 0.62vw, 9.5px);
  font-weight: 500;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  text-transform: uppercase;
  color: #b98a6a;
}
.universe__name {
  margin: 0;
  font-family: 'Bodoni Moda', 'Times New Roman', serif;
  font-weight: 400;
  font-size: clamp(20px, 2.3vw, 36px);
  line-height: 1.22;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  text-transform: uppercase;
  color: #f2e8dc;
  text-shadow: 0 0 0.6em rgba(0, 0, 0, 0.9), 0 0 2em rgba(0, 0, 0, 0.7);
}
.universe__sub {
  margin: 1.1em 0 0;
  font-family: var(--ui);
  font-size: clamp(7.5px, 0.6vw, 9.5px);
  font-weight: 400;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: rgba(222, 200, 180, 0.55);
}

/* ---- the cards ----------------------------------------------------------- */
.universe__world { position: absolute; inset: 0; }
.universe__deck {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.u-card {
  --cw: calc(var(--w) * 100cqw);
  position: absolute;
  left: calc(var(--x) * 100%);
  top: calc(var(--y) * 100%);
  width: var(--cw);
  aspect-ratio: 1.22;
  z-index: calc(10 + var(--d) * 10);
  /* the pointer leans the room: near cards travel furthest */
  translate:
    calc(-50% + var(--px) * var(--d) * -26px)
    calc(-50% + var(--py) * var(--d) * -16px);
  opacity: 0;
  transform: translateY(9cqh) scale(0.94);
  /* one coordinated rise: every card shares the same clock */
  transition: opacity 1.1s var(--ease-out) 0.55s, transform 1.7s var(--ease-out) 0.55s;
}
.universe.is-on .u-card { opacity: 1; transform: none; }

.u-card__in {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 9% 10% 9%;
  border-radius: calc(var(--cw) * 0.06);
  border: 1px solid rgba(255, 220, 205, calc(0.16 + var(--d) * 0.26));
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.07), transparent 38%),
    linear-gradient(180deg, rgba(34, 9, 10, 0.86), rgba(8, 3, 4, 0.92));
  box-shadow:
    0 0 calc(10px + var(--d) * 26px) rgba(222, 27, 28, calc(0.10 + var(--d) * 0.22)),
    inset 0 0 calc(var(--cw) * 0.12) rgba(222, 27, 28, 0.10);
  backdrop-filter: blur(3px);
  filter: brightness(calc(0.66 + var(--d) * 0.42));
  rotate: calc((0.5 - var(--x)) * 9deg);
  animation: uFloat calc(6.2s + var(--i) * 0.47s) ease-in-out
             calc(var(--i) * -1.31s) infinite alternate paused;
  transition: filter 0.45s ease, scale 0.5s var(--ease-out), border-color 0.45s ease;
}
.universe.is-live .u-card__in { animation-play-state: running; }
@keyframes uFloat {
  from { translate: 0 0; }
  to   { translate: 0 calc(-5px - var(--d) * 7px); }
}
.u-card:hover { z-index: 40; }
.u-card:hover .u-card__in {
  filter: brightness(1.25);
  scale: 1.06;
  border-color: rgba(255, 190, 170, 0.9);
}

.u-card b {
  font-family: var(--disp);
  font-weight: 400;
  font-size: calc(var(--cw) * 0.27);
  line-height: 0.95;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-shadow: 0 0 calc(var(--cw) * 0.12) rgba(255, 42, 43, 0.55);
}
.u-card strong {
  margin-top: auto;
  font-family: var(--ui);
  font-weight: 500;
  font-size: max(7px, calc(var(--cw) * 0.088));
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f2e8dc;
  line-height: 1.25;
}
.u-card em {
  margin-top: 0.35em;
  font-family: var(--ui);
  font-style: normal;
  font-weight: 300;
  font-size: max(6px, calc(var(--cw) * 0.066));
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(222, 200, 180, 0.62);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- the figure ---------------------------------------------------------- */
.universe__figure {
  position: absolute;
  left: 50%;
  bottom: 9.5%;
  height: 47%;
  width: auto;
  z-index: 16;
  translate: calc(-50% + var(--px) * -9px) calc(var(--py) * -5px);
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 1.6s var(--ease-out) 0.35s, transform 2s var(--ease-out) 0.35s;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 0 26px rgba(222, 27, 28, 0.35));
}
.universe.is-on .universe__figure { opacity: 1; transform: none; }

/* ---- corner captions + grain --------------------------------------------- */
.u-cap {
  position: absolute;
  z-index: 6;
  margin: 0;
  font-family: var(--ui);
  font-size: clamp(7.5px, 0.62vw, 9.5px);
  font-weight: 400;
  letter-spacing: 0.42em;
  line-height: 2.1;
  text-transform: uppercase;
  color: rgba(222, 200, 180, 0.5);
  opacity: 0;
  transition: opacity 1.2s ease 1.5s;
}
.universe.is-on .u-cap { opacity: 1; }
.u-cap--bl { left: var(--edge); bottom: clamp(18px, 5vh, 46px); padding-left: 12px; border-left: 1px solid var(--ink); }
.u-cap--br { right: var(--edge); bottom: clamp(18px, 5vh, 46px); text-align: right; }

.universe__grain {
  position: absolute;
  inset: -64px;
  z-index: 50;
  background: url('../../public/tex/grain.png') 0 0 / 256px 256px;
  mix-blend-mode: overlay;
  opacity: 0.22;
  pointer-events: none;
  animation: uGrain 0.9s steps(4) infinite paused;
}
.universe.is-live .universe__grain { animation-play-state: running; }
@keyframes uGrain { to { translate: 64px 32px; } }

/* ---- portrait: the room restacks instead of shrinking --------------------- */
@media (max-aspect-ratio: 1/1) {
  .universe__core { top: 74%; width: 74cqw; }
  .universe__floor { top: 93%; width: 120cqw; }
  .universe__lines { display: none; }
  .universe__deck {
    inset: auto 0 auto 0;
    top: 19%;
    height: 46%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2.2cqw;
    padding: 0 4cqw;
    align-content: center;
  }
  .u-card {
    --cw: 28.5cqw;
    position: relative;
    left: auto;
    top: auto;
    width: auto;
    aspect-ratio: 1.55;
    translate: none;
  }
  .u-card__in { rotate: none; filter: brightness(calc(0.82 + var(--d) * 0.26)); }
  .u-card b { font-size: calc(var(--cw) * 0.19); }
  .universe__figure { height: 33%; bottom: 4.5%; }
  .u-cap { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .universe *, .universe__figure { animation: none !important; transition-duration: 0.01ms !important; transition-delay: 0s !important; }
}
