/* Deck-of-cards carousel — 3D Cover-Flow-style.
 *
 * The Rust component sets `--active-offset` (a JS number = sum of integer
 * `active_idx` plus a fractional drag offset) on the deck root. Each card
 * computes its position from `data-offset` minus the deck's active offset.
 *
 * During an active drag, the deck has class `is-dragging` and CSS transitions
 * are disabled; on release, the class is removed and the cards animate to
 * their snap target.
 */

.deck {
  position: relative;
  width: 100%;
  height: clamp(420px, 60vh, 640px);
  perspective: 1200px;
  perspective-origin: 50% 40%;
  overflow: hidden;
  /* Vertical page scroll passes through; horizontal is owned by the deck. */
  touch-action: pan-y;
  /* Avoid pull-to-refresh tugging when swiping at edges. */
  overscroll-behavior-x: contain;
  user-select: none;
  -webkit-user-select: none;
  background: linear-gradient(
    180deg,
    var(--navy-deep) 0%,
    var(--navy-mid) 100%
  );
  outline: none;
}

.deck:focus-visible {
  box-shadow: inset 0 0 0 2px var(--gold);
}

.deck.is-dragging .card {
  transition: none !important;
}

.card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(220px, 28vw, 380px);
  height: calc(clamp(220px, 28vw, 380px) * 4 / 3);
  margin-left: calc(clamp(220px, 28vw, 380px) / -2);
  margin-top: calc(clamp(220px, 28vw, 380px) * 4 / 3 / -2);
  background: var(--navy-card);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transform-origin: 50% 50%;
  transform-style: preserve-3d;
  transition:
    transform 320ms cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 240ms ease-out,
    box-shadow 240ms ease-out;
  cursor: pointer;
  /* GPU promotion (will-change) is only set during an active drag —
   * keeping near cards perpetually layer-promoted on a 3D-perspective
   * deck keeps WindowServer's compositor warm even when the deck is
   * idle, and on Apple Silicon that surfaces as low-%CPU lag in other
   * windows. The pointer-drag handler adds `is-dragging` on the deck
   * for the lifetime of the gesture; transitions are also disabled
   * there so the GPU promotion is exactly when it pays for itself.
   */
}

.deck.is-dragging .card.is-near {
  will-change: transform;
}

.card.is-active {
  box-shadow:
    0 0 0 2px var(--gold),
    0 18px 50px -10px var(--gold-glow),
    var(--shadow-card);
}

.card__cover {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.card__image {
  width: 100%;
  flex: 1 1 auto;
  background: var(--navy-mid);
  background-size: cover;
  background-position: center;
}

.card__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card__title-bar {
  padding: 0.85rem 1rem 1rem;
  background: linear-gradient(0deg, var(--navy-deep), transparent);
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  color: var(--ink);
}

.card__title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.15em 0;
  line-height: 1.2;
}

.card__tagline {
  font-size: 0.85rem;
  color: var(--ink-dim);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Detail panel, opens beneath the active card */

/* The expand/collapse animates `grid-template-rows` from 0fr to 1fr rather
 * than a fixed `max-height`. A hard max-height clips any content taller than
 * the ceiling (the CV ran past 1200px, cutting off everything after the
 * "Project Highlights" header) and makes short cards' open animation finish
 * early. The single grid row resolves to the inner panel's natural height, so
 * arbitrarily long content is fully visible and the transition is honest. */
.deck-details {
  max-width: 720px;
  margin: 1.25rem auto 2.5rem;
  padding: 0 1rem;
  display: grid;
  grid-template-rows: 1fr;
  transition:
    grid-template-rows 320ms ease,
    opacity 240ms ease 80ms;
}

.deck-details.is-collapsed {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
  margin-bottom: 0;
}

.deck-details.is-expanded {
  grid-template-rows: 1fr;
  opacity: 1;
}

.deck-details__inner {
  /* min-height:0 lets the grid item shrink below its content; overflow:hidden
   * clips the content (and the panel's own padding/border) while collapsed. */
  min-height: 0;
  overflow: hidden;
  background: var(--navy-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.deck-details__meta {
  color: var(--ink-dim);
  font-size: 0.92rem;
  margin-bottom: 1rem;
}

/* Nav buttons */

.deck-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 0;
}

.deck-controls__btn {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--border);
  padding: 0.5em 1em;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.deck-controls__btn:hover {
  color: var(--gold);
  border-color: var(--gold);
}

.deck-controls__btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.deck-controls__indicator {
  font-family: ui-monospace, monospace;
  color: var(--ink-faint);
  font-size: 0.85rem;
  min-width: 4ch;
  text-align: center;
}

/* Mobile tightening */

@media (max-width: 768px) {
  .deck {
    perspective: 900px;
    height: 60vh;
    min-height: 360px;
  }
  .card {
    width: clamp(220px, 72vw, 360px);
    height: calc(clamp(220px, 72vw, 360px) * 4 / 3);
    margin-left: calc(clamp(220px, 72vw, 360px) / -2);
    margin-top: calc(clamp(220px, 72vw, 360px) * 4 / 3 / -2);
  }
}

/* Reduced motion: drop the 3D transforms entirely, fall back to a horizontal
 * scroll-snap strip. The Rust component still maintains the active index;
 * keyboard nav still works.
 */

@media (prefers-reduced-motion: reduce) {
  .deck {
    perspective: none;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 50%;
    touch-action: auto;
    height: auto;
  }
  .card {
    position: relative;
    left: auto;
    top: auto;
    margin: 0;
    transform: none !important;
    opacity: 1 !important;
    transition:
      outline 200ms ease,
      box-shadow 200ms ease;
    scroll-snap-align: center;
    flex: 0 0 clamp(220px, 72vw, 360px);
  }
}
