/* Deck — mobile-only single-card carousel.
 *
 * Activated on a `.grid` by adding `data-deck`. JS wires up the controls
 * (prev/next buttons, dot indicators) and rotates which child card has
 * `.is-current`. CSS handles the visual: stack all children in the same
 * grid cell so the container sizes to the tallest card, then fade/slide
 * the current card in and the others out. Desktop keeps the original
 * grid layout untouched. */

/* Hide the JS-injected controls on desktop — the grid shows everything. */
.deck__controls { display: none; }

@media (max-width: 640px) {
  /* Stack-in-cell trick: a single grid cell that all children share. The
     cell sizes to the tallest child, so the container height stays stable
     as cards swap. No JS height measurement needed. */
  .grid[data-deck] {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    gap: 0;
    position: relative;
    isolation: isolate; /* contain z-index to the deck */
    /* Allow vertical page scroll over the deck, but reserve horizontal
       gestures for our swipe handler. Without this, the browser can
       intercept horizontal motion (e.g. back-gesture on iOS Safari). */
    touch-action: pan-y;
  }

  /* Subtle stacked-deck visual: two card "shadows" peeking from behind the
     current card, hinting that there are more cards in the deck. */
  .grid[data-deck]::before,
  .grid[data-deck]::after {
    content: "";
    position: absolute;
    inset: 0;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow:
      0 6px 14px rgba(30, 58, 138, 0.10),
      inset 0 0 0 1px rgba(30, 58, 138, 0.06);
    pointer-events: none;
    z-index: 0;
  }
  .grid[data-deck]::before {
    transform: translate(10px, 10px);
    opacity: 0.42;
  }
  .grid[data-deck]::after {
    transform: translate(5px, 5px);
    opacity: 0.7;
  }

  /* All children share grid cell 1/1 so they overlap. */
  .grid[data-deck] > * {
    grid-column: 1;
    grid-row: 1;
    opacity: 0;
    transform: translateX(24px);
    pointer-events: none;
    transition:
      opacity var(--dur-slow) var(--ease-out),
      transform var(--dur-slow) var(--ease-out);
    position: relative;
    z-index: 1;
  }
  .grid[data-deck] > .is-current {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
    z-index: 2;
  }
  /* Cards leaving (when JS unsets is-current) slide left a touch so the
     direction reads "we just moved forward". JS adds .is-leaving briefly
     for cleaner directionality; without it, prev/next look identical. */
  .grid[data-deck] > .is-leaving {
    opacity: 0;
    transform: translateX(-24px);
  }

  /* Controls — sit below the deck, inserted by JS as a sibling. */
  .deck__controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-top: var(--space-lg);
  }

  .deck__btn {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1.5px solid var(--color-border-strong);
    background: #fff;
    color: var(--color-ink);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    transition:
      background var(--dur) var(--ease),
      border-color var(--dur) var(--ease),
      transform var(--dur-fast) var(--ease),
      box-shadow var(--dur) var(--ease);
  }
  .deck__btn:hover {
    background: var(--color-bg-warm);
    border-color: var(--color-accent);
    color: var(--color-accent-ink);
  }
  .deck__btn:focus-visible {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--color-accent);
  }
  .deck__btn:active { transform: scale(0.94); }

  /* Dot indicators — show position in the deck. Tappable for quick jumps. */
  .deck__dots {
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1 1 auto;
    justify-content: center;
    min-height: 24px;
  }
  .deck__dot {
    appearance: none;
    -webkit-appearance: none;
    width: 8px;
    height: 8px;
    padding: 0;
    border-radius: 50%;
    border: none;
    background: rgba(30, 58, 138, 0.22);
    cursor: pointer;
    transition:
      background var(--dur) var(--ease),
      transform var(--dur) var(--ease);
  }
  .deck__dot.is-active {
    background: var(--color-accent);
    transform: scale(1.4);
  }
  .deck__dot:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--color-accent);
  }

  /* Reduced motion: skip the slide, just fade. */
  @media (prefers-reduced-motion: reduce) {
    .grid[data-deck] > * {
      transition: opacity var(--dur) linear;
      transform: none;
    }
    .grid[data-deck] > .is-leaving { transform: none; }
    .deck__btn:active { transform: none; }
    .deck__dot.is-active { transform: none; }
  }
}
