/* =====================================================================
   HOME 2 (prototype, index2.html) — loaded after home.css.

   Each card's face is its own layer (.card) holding the animation, so
   it can be faded out on its own. On desktop / compact layouts the
   selected card becomes the top of its project page:

     animation    stays centred and grows, as on index.html
     around 1/4   the card face fades into the page background
     lower part   the dithered preview of the page (.bpv, placed and
                  run by home2.js), down to the bottom of the card;
                  clicking it opens the project. The animation is
                  drawn in front of it (keyed, with a dark halo)
     bottom       the title and VIEW PROJECT button, as on index.html,
                  drawn over the faded-out bottom of the preview

   The preview lives inside the card, so it scrolls with the strip.
   Portrait phones/tablets keep the split view from home.css.
   ===================================================================== */

/* --fc: where the card face starts fading into the page colour; it
   animates when a card opens or closes. */
@property --fc {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 100%;
}

body.home2 .box {
  background-color: transparent;
  border: 0;
  padding: 2px;                 /* same outer size as the old 2px border */
  overflow: hidden;
  transition: width var(--dur) var(--ease-out);
}
body.home2 .box.active {
  background-color: transparent;
}

/* the face fades to the page colour (opaque), so the animation's lighten
   blend still has something under it all the way down */
body.home2 .card {
  --fc: 100%;
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  border-radius: 12px;
  background-color: var(--dark-accent);
  /* a soft step, not a straight ramp, so there's no visible line where it starts */
  background-image: linear-gradient(to bottom,
    rgba(5, 18, 32, 0) var(--fc),
    rgba(5, 18, 32, 0.22) calc(var(--fc) + 5%),
    rgba(5, 18, 32, 0.55) calc(var(--fc) + 11%),
    rgba(5, 18, 32, 0.82) calc(var(--fc) + 17%),
    rgba(5, 18, 32, 0.95) calc(var(--fc) + 22%),
    rgb(5, 18, 32) calc(var(--fc) + 26%));
  transition:
    background-color var(--dur) var(--ease-out),
    --fc var(--dur) var(--ease-out-2);
}
body.home2 .box.active .card { background-color: var(--dark-secondary); }

.fx-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* the animation's own layer inside the card (in the split view it's just
   a plain box and the clip blends onto the card as on index.html) */
body.home2 .anim-wrap {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* title, labels and button stay above the preview */
body.home2 .s-title,
body.home2 .see-more { z-index: 4; }


/* ---------------------------------------------------------------------
   Desktop and compact (everything but the portrait split view)
   --------------------------------------------------------------------- */
@media not all and (orientation: portrait) and (max-width: 1100px) {

  /* face fades to the page colour over 21-47 % (centred on a third).
     The animation isn't moved or masked: it grows with the card and stays
     centred, as on index.html, and runs down behind the preview */
  body.home2 .box.active .card { --fc: 12%; }   /* fades over 12-38 %: light quarter, dark three quarters */

  /* the animation goes in front of the preview. The card can't be its own
     layer for that (it would trap the clip under the preview), and the clip
     can't use lighten in front (the preview's dots would show through it),
     so #anim-key (index2.html) turns its black into transparency and puts a
     soft dark halo under it to set it off from the dots */
  body.home2 .card { z-index: auto; }
  body.home2 .anim-wrap {
    z-index: 3;
    -webkit-filter: url(#anim-key);
    filter: url(#anim-key);
  }
  body.home2 .anim-wrap .anims { mix-blend-mode: normal; }
  body.home2 .box .index-label { z-index: 4; }

  /* open cards about 20 % narrower than on index.html */
  body.home2 .track { --card-w-active: 32vw; }

  /* ---- the preview inside the open card ---- */

  .bpv {
    position: absolute;
    left: 50%;
    /* the lower two thirds or so, down to the card's bottom edge */
    bottom: 0;
    z-index: 2;
    /* sized for the open card so it never resizes while the card grows or
       shrinks; the card's edges simply uncover / cover it */
    width: var(--card-w-active);
    height: calc(var(--card-h) * 0.67);
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s var(--ease-out);
  }
  .box.active .bpv {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.9s var(--ease-out) 0.15s;
  }

  .bpv-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
  }

  /* the page's videos play here, out of sight under a patch of page colour
     at the bottom middle (where the card has already faded away, and away
     from the rounded corners, whose anti-aliased edge would let a sliver of
     video through); the canvas copies their frames */
  .bpv-media {
    position: absolute;
    left: calc(50% - 32px);
    bottom: 3px;
    width: 64px;
    height: 36px;
    overflow: hidden;
    pointer-events: none;
  }
  .bpv-media video { position: absolute; top: 0; left: 0; width: 64px; height: 36px; }
  .bpv-stage::after {           /* a little larger, so no edge of the video peeks out */
    content: "";
    position: absolute;
    left: calc(50% - 36px);
    bottom: 0;
    width: 72px;
    height: 42px;
    background-color: var(--dark-primary);
    pointer-events: none;
  }

  .bpv-dither {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.92;
  }

  /* the whole pane opens the project; the button below says so */
  .bpv-open {
    position: absolute;
    inset: 0;
    z-index: 3;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .bpv-open[aria-disabled="true"] { cursor: default; }
  .bpv-cta { display: none; }

  /* the open card's upper half closes it again */
  body.home2 .box.active { cursor: n-resize; cursor: zoom-out; }
}

/* compact: sizes come from the card height there (as in home.css) */
@media (max-width: 1380px), (max-height: 640px) {
  @media not all and (orientation: portrait) and (max-width: 1100px) {
    body.home2 .track {
      --card-w-active: min(calc(var(--card-h) * 0.8), 62vw);
    }
    /* 0.8 of home.css's size, like the card */
    body.home2 .box.active .s-title { font-size: clamp(13px, calc(var(--card-h) * 0.058), 32px); }
  }
}

@media (prefers-reduced-motion: reduce) {
  body.home2 .card { transition: none; }
}
