/* ============================================================
   Portrait Carousel — carousel.css
   Scope: .portrait-carousel wrapper (set by initPortraitCarousel)
   Theme: override --pc-* custom properties via JS config.theme
   ============================================================ */

.portrait-carousel {
  /* Layout */
  --pc-card-width: min(64vw, 360px);
  --pc-peek-width: clamp(34px, 11vw, 132px);
  --pc-slider-side-width: calc(var(--pc-card-width) * 0.8);
  --pc-slider-overlap: -18px;

  /* Card */
  --pc-card-bg: #030603;
  --pc-card-border: rgba(222, 241, 214, 0.18);

  /* Pill */
  --pc-pill-bg: linear-gradient(180deg, rgba(215, 222, 217, 0.98), rgba(203, 213, 207, 0.98));
  --pc-pill-shadow: 0 24px 40px rgba(0, 0, 0, 0.18);
  --pc-pill-title: #1f2b23;
  --pc-pill-sub: #425145;

  /* HUD buttons */
  --pc-hud-bg: rgba(14, 22, 16, 0.42);
  --pc-hud-border: rgba(255, 255, 255, 0.24);
}

/* ── Panel ─────────────────────────────────────────────── */

.portrait-carousel .carousel-panel {
  position: relative;
  padding: 0 0 24px;
  overflow: visible;
}

/* ── Stage ─────────────────────────────────────────────── */

.portrait-carousel .stage {
  position: relative;
  height: calc(var(--pc-card-width) * 16 / 9);
  overflow: visible;
  background: none;
  touch-action: pan-y;
}

.portrait-carousel .track {
  position: absolute;
  inset: 0;
}

/* ── Card base ─────────────────────────────────────────── */

.portrait-carousel .card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--pc-card-width);
  max-width: calc(100% - 36px);
  aspect-ratio: 9 / 16;
  border-radius: 34px;
  overflow: hidden;
  background: var(--pc-card-bg);
  border: 1px solid var(--pc-card-border);
  box-shadow: 0 28px 52px rgba(0, 0, 0, 0.34);
  transform-origin: center;
  transition:
    transform 360ms cubic-bezier(.22,.61,.36,1),
    opacity 320ms ease,
    filter 320ms ease,
    box-shadow 320ms ease;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

.portrait-carousel .card video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #071108;
}

.portrait-carousel .card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 0%, transparent 60%, rgba(2, 5, 3, 0.82) 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease;
}

.portrait-carousel .card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease;
  z-index: 1;
}

/* ── Active card ───────────────────────────────────────── */

.portrait-carousel .card.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) translateX(0) scale(1);
  z-index: 3;
  border-color: rgba(224, 232, 236, 0.72);
  box-shadow:
    0 0 0 2px rgba(224, 232, 236, 0.44),
    0 0 0 4px rgba(224, 232, 236, 0.10),
    0 36px 72px rgba(0, 0, 0, 0.4);
}

.portrait-carousel .card.active::before {
  opacity: 1;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.015) 100%);
  box-shadow: inset 0 0 0 2px rgba(228, 234, 238, 0.28);
}

/* ── Peek cards (standard strip mode) ─────────────────── */

.portrait-carousel .card.peek-next video,
.portrait-carousel .card.peek-prev video {
  object-fit: cover;
}

.portrait-carousel .card.peek-next,
.portrait-carousel .card.peek-prev {
  opacity: 0.88;
  z-index: 2;
  filter: saturate(0.84) brightness(0.92);
}

.portrait-carousel .card.peek-next::after,
.portrait-carousel .card.peek-prev::after {
  opacity: 1;
}

.portrait-carousel .card.peek-next {
  transform: translate(-50%, -50%) translateX(calc((var(--pc-card-width) / 2) + var(--pc-peek-width))) scale(0.94);
  clip-path: inset(0 calc(100% - var(--pc-peek-width)) 0 0 round 26px);
}

.portrait-carousel .card.peek-next::after {
  background: linear-gradient(90deg, rgba(2, 5, 3, 0.65) 0%, rgba(2, 5, 3, 0.18) 55%, rgba(2, 5, 3, 0) 100%);
}

.portrait-carousel .stage.show-prev .card.peek-prev {
  transform: translate(-50%, -50%) translateX(calc(((var(--pc-card-width) / 2) + var(--pc-peek-width)) * -1)) scale(0.94);
  clip-path: inset(0 0 0 calc(100% - var(--pc-peek-width)) round 26px);
}

.portrait-carousel .stage.show-prev .card.peek-prev::after {
  background: linear-gradient(270deg, rgba(2, 5, 3, 0.65) 0%, rgba(2, 5, 3, 0.18) 55%, rgba(2, 5, 3, 0) 100%);
}

/* ── Slider peek mode ──────────────────────────────────── */

.portrait-carousel .stage.slider-peek .card.peek-next,
.portrait-carousel .stage.slider-peek .card.peek-prev {
  opacity: 0.94;
  z-index: 1;
  width: var(--pc-slider-side-width);
  filter: saturate(0.72) brightness(0.68);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.18);
  clip-path: none;
  border-color: rgba(224, 232, 236, 0.22);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}

.portrait-carousel .stage.slider-peek .card.peek-next::before,
.portrait-carousel .stage.slider-peek.show-prev .card.peek-prev::before {
  opacity: 1;
}

.portrait-carousel .stage.slider-peek .card.peek-next {
  transform: translate(-50%, -50%) translateX(calc((var(--pc-card-width) / 2) + (var(--pc-slider-side-width) / 2) + var(--pc-slider-overlap)));
  border-radius: 34px;
  -webkit-mask-image: linear-gradient(90deg,
    rgba(0,0,0,1) 0%, rgba(0,0,0,0.99) 18%, rgba(0,0,0,0.90) 34%,
    rgba(0,0,0,0.58) 52%, rgba(0,0,0,0.24) 68%, rgba(0,0,0,0.06) 82%, rgba(0,0,0,0) 100%);
  mask-image: linear-gradient(90deg,
    rgba(0,0,0,1) 0%, rgba(0,0,0,0.99) 18%, rgba(0,0,0,0.90) 34%,
    rgba(0,0,0,0.58) 52%, rgba(0,0,0,0.24) 68%, rgba(0,0,0,0.06) 82%, rgba(0,0,0,0) 100%);
}

.portrait-carousel .stage.slider-peek .card.peek-next::before {
  background: linear-gradient(90deg,
    rgba(11,18,13,0.08) 0%, rgba(11,18,13,0.16) 20%, rgba(11,18,13,0.34) 42%,
    rgba(11,18,13,0.58) 60%, rgba(11,18,13,0.82) 78%, rgba(11,18,13,0.96) 100%);
}

.portrait-carousel .stage.slider-peek .card.peek-next::after {
  background: linear-gradient(180deg, rgba(2,5,3,0.08) 0%, rgba(2,5,3,0.14) 100%);
}

.portrait-carousel .stage.slider-peek.show-prev .card.peek-prev {
  transform: translate(-50%, -50%) translateX(calc(((var(--pc-card-width) / 2) + (var(--pc-slider-side-width) / 2) + var(--pc-slider-overlap)) * -1));
  border-radius: 34px;
  -webkit-mask-image: linear-gradient(270deg,
    rgba(0,0,0,1) 0%, rgba(0,0,0,0.99) 18%, rgba(0,0,0,0.90) 34%,
    rgba(0,0,0,0.58) 52%, rgba(0,0,0,0.24) 68%, rgba(0,0,0,0.06) 82%, rgba(0,0,0,0) 100%);
  mask-image: linear-gradient(270deg,
    rgba(0,0,0,1) 0%, rgba(0,0,0,0.99) 18%, rgba(0,0,0,0.90) 34%,
    rgba(0,0,0,0.58) 52%, rgba(0,0,0,0.24) 68%, rgba(0,0,0,0.06) 82%, rgba(0,0,0,0) 100%);
}

.portrait-carousel .stage.slider-peek.show-prev .card.peek-prev::before {
  background: linear-gradient(270deg,
    rgba(11,18,13,0.08) 0%, rgba(11,18,13,0.16) 20%, rgba(11,18,13,0.34) 42%,
    rgba(11,18,13,0.58) 60%, rgba(11,18,13,0.82) 78%, rgba(11,18,13,0.96) 100%);
}

.portrait-carousel .stage.slider-peek.show-prev .card.peek-prev::after {
  background: linear-gradient(180deg, rgba(2,5,3,0.08) 0%, rgba(2,5,3,0.14) 100%);
}

/* ── Hidden card ───────────────────────────────────────── */

.portrait-carousel .card.hidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.88);
  z-index: 1;
}

/* ── HUD shared styles ─────────────────────────────────── */

.portrait-carousel .hud-chip,
.portrait-carousel .restart-btn,
.portrait-carousel .arrow-btn {
  border: 1px solid var(--pc-hud-border);
  background: var(--pc-hud-bg);
  color: #fff;
  border-radius: 999px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.14),
    0 12px 24px rgba(0,0,0,0.24);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.portrait-carousel .hud-chip,
.portrait-carousel .restart-btn,
.portrait-carousel .arrow-btn,
.portrait-carousel .card-control-btn {
  transition: transform 180ms ease, background-color 180ms ease, opacity 180ms ease;
}

.portrait-carousel .hud-chip:hover,
.portrait-carousel .hud-chip:focus-visible,
.portrait-carousel .restart-btn:hover,
.portrait-carousel .restart-btn:focus-visible,
.portrait-carousel .arrow-btn:hover,
.portrait-carousel .arrow-btn:focus-visible,
.portrait-carousel .card-control-btn:hover,
.portrait-carousel .card-control-btn:focus-visible {
  transform: translateY(-1px);
  background: rgba(20, 30, 23, 0.58);
}

/* ── Mute chip ─────────────────────────────────────────── */

.portrait-carousel .hud-chip {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  padding: 9px 13px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
}

.portrait-carousel .card.active .hud-chip {
  opacity: 1;
  pointer-events: auto;
}

/* ── Captions ──────────────────────────────────────────── */

.portrait-carousel .captions {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  width: calc(100% - 26px);
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(5, 8, 6, 0.72);
  color: #fff;
  text-align: center;
  line-height: 1.45;
  font-size: 0.84rem;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
  z-index: 5;
}

.portrait-carousel .captions.visible {
  opacity: 1;
}

/* ── Card controls ─────────────────────────────────────── */

.portrait-carousel .card-controls {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 2px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.portrait-carousel .card.active .card-controls {
  opacity: 1;
  pointer-events: auto;
}

.portrait-carousel .card-control-btn {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(14, 22, 16, 0.42);
  color: #fff;
  border-radius: 999px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.14),
    0 12px 24px rgba(0,0,0,0.24);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  min-width: 46px;
  width: 46px;
  height: 46px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.portrait-carousel .card-control-btn img {
  width: 30px;
  height: 30px;
  display: block;
  filter: brightness(0) invert(1);
}

.portrait-carousel .card-control-main {
  width: 54px;
  min-width: 54px;
  height: 54px;
}

.portrait-carousel .card-control-main img {
  width: 34px;
  height: 34px;
}

/* ── Restart button ────────────────────────────────────── */

.portrait-carousel .restart-btn {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  min-width: 146px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
}

.portrait-carousel .restart-btn img {
  width: 26px;
  height: 26px;
  display: block;
  filter: brightness(0) invert(1);
}

.portrait-carousel .card.ended .restart-btn {
  opacity: 1;
  pointer-events: auto;
}

/* ── Nav + meta pill ───────────────────────────────────── */

.portrait-carousel .nav {
  display: block;
  margin-top: 14px;
}

.portrait-carousel .meta {
  min-width: 0;
  width: min(100%, var(--pc-card-width));
  max-width: var(--pc-card-width);
  margin: 0 auto;
  padding: 13px 18px 11px;
  background: var(--pc-pill-bg);
  border-radius: 28px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.55),
    var(--pc-pill-shadow);
}

.portrait-carousel .meta-title {
  font-size: clamp(1.1rem, 2.4vw, 1.45rem);
  font-weight: 800;
  margin: 0 0 4px;
  color: var(--pc-pill-title);
}

.portrait-carousel .meta-sub {
  margin: 0;
  color: var(--pc-pill-sub);
  font-size: 0.95rem;
  line-height: 1.55;
  min-height: calc(2 * 0.95rem * 1.55);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Framed variant ────────────────────────────────────── */
/* Add class="portrait-carousel--framed" to mount element,  */
/* then set --pc-frame-* vars via config theme or inline CSS */

.portrait-carousel--framed {
  --pc-slider-overlap: -16px;
  --pc-card-width: min(56vw, 280px); /* explicit width — frame sizes around the card */
  padding: var(--pc-frame-padding, 14px);
  border-radius: var(--pc-frame-radius, 18px);
  background: var(--pc-frame-bg, transparent);
  border: var(--pc-frame-border, none);
  box-shadow: var(--pc-frame-shadow, none);
  /* overflow visible on desktop — mask gradient fades peek card to white page bg */
  overflow: visible;
  display: block;
  width: 100%;
}

.portrait-carousel--framed .carousel-panel {
  padding-bottom: 0;
}

.portrait-carousel--framed .nav {
  margin-top: 10px;
}

/* Pill as caption — transparent, no shadow */
.portrait-carousel--framed .meta {
  width: var(--pc-card-width);
  max-width: 100%;
  background: transparent;
  box-shadow: none;
  padding-left: 4px;
  padding-right: 4px;
}

/* Active card: thick visible ring + right-side shadow falling onto peek card */
.portrait-carousel--framed .card.active {
  box-shadow:
    0 0 0 5px rgba(180, 210, 172, 0.90),   /* thick green-tinted frame ring */
    0 0 0 7px rgba(160, 196, 150, 0.30),   /* soft outer halo */
    0 36px 72px rgba(0, 0, 0, 0.38),
    16px 0 32px rgba(0, 0, 0, 0.20);
}

/* Peek cards: clickable, thinner ring, dark overlay for depth/z-stack feel */
.portrait-carousel--framed .card.peek-next,
.portrait-carousel--framed .card.peek-prev {
  cursor: pointer;
  box-shadow:
    0 0 0 var(--pc-peek-ring-width, 2px) var(--pc-peek-ring-color, rgba(180, 210, 172, 0.50));
}

.portrait-carousel--framed .stage.slider-peek .card.peek-next::before {
  opacity: 1;
  /* cast shadow only in the ~16px overlap zone, clear after that */
  background: linear-gradient(90deg,
    rgba(0,0,0,0.45) 0px,
    rgba(0,0,0,0.18) 16px,
    rgba(0,0,0,0)    28px);
  z-index: 2;
}

.portrait-carousel--framed .stage.slider-peek.show-prev .card.peek-prev::before {
  opacity: 1;
  background: linear-gradient(270deg,
    rgba(0,0,0,0.55) 0px,
    rgba(0,0,0,0.30) 12px,
    rgba(0,0,0,0.08) 28px,
    rgba(0,0,0,0)    48px);
  z-index: 2;
}

/* Fully opaque for first 40%, then fade to white — desktop only */
.portrait-carousel--framed .stage.slider-peek .card.peek-next {
  -webkit-mask-image: linear-gradient(90deg,
    rgba(0,0,0,1) 0%, rgba(0,0,0,1) 40%,
    rgba(0,0,0,0.80) 50%, rgba(0,0,0,0.40) 60%,
    rgba(0,0,0,0.10) 68%, rgba(0,0,0,0) 75%);
  mask-image: linear-gradient(90deg,
    rgba(0,0,0,1) 0%, rgba(0,0,0,1) 40%,
    rgba(0,0,0,0.80) 50%, rgba(0,0,0,0.40) 60%,
    rgba(0,0,0,0.10) 68%, rgba(0,0,0,0) 75%);
  box-shadow: -6px 6px 28px rgba(0, 0, 0, 0.18);
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 780px) {
  .portrait-carousel {
    --pc-card-width: min(72vw, 300px);
    --pc-peek-width: 13vw;
    --pc-slider-side-width: calc(var(--pc-card-width) * 0.77);
    --pc-slider-overlap: -12px;
  }

  .portrait-carousel .stage {
    height: calc((var(--pc-card-width) * 16 / 9) + 32px);
  }

  .portrait-carousel .card.active,
  .portrait-carousel .card.peek-next,
  .portrait-carousel .stage.show-prev .card.peek-prev,
  .portrait-carousel .stage.slider-peek .card.peek-next,
  .portrait-carousel .stage.slider-peek.show-prev .card.peek-prev,
  .portrait-carousel .card.hidden {
    top: calc(50% + 16px);
  }

  /* Framed: narrower card leaves room for peek card on right */
  .portrait-carousel--framed {
    --pc-card-width: 78vw;
    --pc-slider-side-width: calc(var(--pc-card-width) * 0.80);
    --pc-slider-overlap: -8px;
    overflow: hidden; /* clip peek card at frame edge on mobile — no page blowout */
    padding: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
    background: transparent;
    width: 100%;
    max-width: 100%;
  }

  /* On mobile the meta pill becomes a plain flush box — no rounded pill needed */
  .portrait-carousel--framed .meta {
    width: 100%;
    border-radius: 0;
    padding: 10px 2px 4px;
    background: transparent;
    box-shadow: none;
  }

  .portrait-carousel--framed .meta-title {
    font-size: 1rem;
  }

  .portrait-carousel--framed .meta-sub {
    font-size: 0.875rem;
  }

  .portrait-carousel .carousel-panel {
    padding: 0 0 18px;
  }

  .portrait-carousel .stage.slider-peek.show-prev .card.peek-prev,
  .portrait-carousel .stage.slider-peek .card.peek-next {
    opacity: 0.9;
  }

  .portrait-carousel .nav {
    margin-top: 12px;
  }

  .portrait-carousel .meta {
    padding: 12px 14px 10px;
  }

  .portrait-carousel .card-control-btn {
    min-width: 44px;
    width: 44px;
    height: 44px;
  }

  .portrait-carousel .card-control-main {
    width: 50px;
    min-width: 50px;
    height: 50px;
  }

  .portrait-carousel .card-control-btn img {
    width: 26px;
    height: 26px;
  }

  .portrait-carousel .card-control-main img {
    width: 32px;
    height: 32px;
  }
}
