/* Sticky card-stack scroll (enabled via JS .card-stack-active).
   Scroll-linked values come from card-stack.js:
   --stack-scale, --stack-dim, --stack-fade, --stack-lift */

:root {
  /* How dark a fully covered card gets (multiplied by --stack-dim). */
  --stack-dim-strength: 0.5;
  --stack-shadow-rgb: 0, 0, 0;
  --stack-shadow-alpha: 0.75;
  --stack-edge-rgb: 255, 123, 0;
}

[data-theme="light"] {
  --stack-dim-strength: 0.14;
  --stack-shadow-rgb: 30, 30, 35;
  --stack-shadow-alpha: 0.32;
  --stack-edge-rgb: 200, 100, 0;
}

/* Stacked cards must stay opaque. Several cards use a translucent fill
   (--card-hover is rgba, contact info cards have no fill at all). Once
   they pin on top of each other, that alpha lets the lower card's text
   show through. A solid fill keeps only the intended edge peek visible. */
.card-stack-active .card-stack-item,
.card-stack-active .card-stack-item:hover,
.card-stack-active .card-stack-item:focus,
.card-stack-active .card-stack-item:focus-within {
  background-color: var(--card-bg);
}

.card-stack-active .card-stack-item:hover,
.card-stack-active .card-stack-item:focus,
.card-stack-active .card-stack-item:focus-within {
  background-color: #2c2c30;
}

[data-theme="light"] .card-stack-active .card-stack-item,
[data-theme="light"] .card-stack-active .card-stack-item:hover,
[data-theme="light"] .card-stack-active .card-stack-item:focus,
[data-theme="light"] .card-stack-active .card-stack-item:focus-within {
  --card-bg: #f2f0ec;
  --card-hover: #e8e6e1;
  --surface: #f2f0ec;
  --surface2: #e8e6e1;
  background-color: #f2f0ec;
}

[data-theme="light"] .card-stack-active .card-stack-item:hover,
[data-theme="light"] .card-stack-active .card-stack-item:focus,
[data-theme="light"] .card-stack-active .card-stack-item:focus-within {
  background-color: #e8e6e1;
}

/* ── Container + item rules, shared by the three activation modes ──
   mobile (default) · [data-card-stack-all] · [data-card-stack-desktop] */
@media (max-width: 768px) {
  section:has([data-card-stack].card-stack-active),
  #facilities-main:has([data-card-stack].card-stack-active) {
    overflow: visible !important;
  }

  section:has([data-card-stack].card-stack-active) .sec,
  #facilities-main:has([data-card-stack].card-stack-active) .sec,
  #values .values-layout,
  #values .reveal-right {
    overflow: visible;
  }

  .card-stack-reveal-parent.reveal,
  .card-stack-reveal-parent.reveal-left,
  .card-stack-reveal-parent.reveal-right,
  .card-stack-reveal-parent.anim {
    transform: none !important;
    opacity: 1 !important;
  }
}

@media (min-width: 769px) {
  section:has([data-card-stack-desktop].card-stack-active) {
    overflow: visible !important;
  }

  section:has([data-card-stack-desktop].card-stack-active) .sec {
    overflow: visible;
  }
}

.card-stack-active {
  display: flex !important;
  flex-direction: column;
  gap: 0 !important;
  grid-template-columns: unset !important;
  transform: none !important;
  opacity: 1 !important;
  padding-bottom: 0;
}

.card-stack-active .card-stack-item {
  position: sticky;
  top: calc(
    var(--card-stack-top, 100px) +
      var(--stack-offset, calc(var(--stack-i, 0) * 12px))
  );
  z-index: calc(var(--stack-i, 0) + 1);
  margin-bottom: 18px;
  /* Scroll-linked: no transform transition, so the card tracks the finger. */
  transform: scale(var(--stack-scale, 1));
  transform-origin: center top;
  filter: brightness(
    calc(1 - var(--stack-dim, 0) * var(--stack-dim-strength))
  );
  opacity: var(--stack-fade, 1);
  /* Shadow is cast upward onto the card being covered, plus a thin
     accent line along the top edge that shows in the peek strip. */
  box-shadow:
    0 -18px 34px -20px
      rgba(
        var(--stack-shadow-rgb),
        calc(var(--stack-lift, 0) * var(--stack-shadow-alpha))
      ),
    0 -1px 0 0 rgba(var(--stack-edge-rgb), calc(var(--stack-lift, 0) * 0.35));
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease;
  will-change: transform;
  backface-visibility: hidden;
}

.card-stack-active .card-stack-item:last-child {
  margin-bottom: 0;
}

.card-stack-active .card-stack-item:hover {
  transform: scale(var(--stack-scale, 1));
}

/* Buried cards shouldn't take taps meant for the card on top. */
.card-stack-active .card-stack-item.is-stack-buried {
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .card-stack-active .card-stack-item {
    will-change: auto;
  }
}
