/* ═══════════════════════════════════════════════════════════
   PORTFOLIO CAROUSEL (.pf-carousel)
   Extracted from the RunSmart prototype carousel
   (runsmart-prototype.9bitstudios.io) and rebuilt on portfolio tokens.

   Works without JS: native horizontal scroll + scroll-snap.
   carousel.js adds .is-enhanced → prev/next buttons, edge fades that only
   show when there is more to scroll, and image fade-in on load.

   Sizing: every slide image is as tall as a 2-up card image (.card-visual,
   16:10 of half the content width); the carousel shape sets slide width.

   Options (classes on .pf-carousel):
     .pf-carousel--ar-4-5 | --ar-4-3 | --ar-16-9 | --ar-1-1   shape (default 16:10)
     .pf-carousel--sm | --lg    scale the slide height (0.75× / 1.2×)
     .pf-carousel--bleed        Apple-style: first slide on the content margin,
                                track runs to both window edges when scrolled
   Options (classes on .pf-carousel__media):
     .is-placeholder            placeholder tile (no image yet)
   ═══════════════════════════════════════════════════════════ */

.pf-carousel {
  /* Card-image height: half the content width (minus the 28px grid gap) at 16:10 */
  --pf-card-h: calc((min(100vw, var(--max-width)) - 2 * var(--gutter) - 28px) / 2 * 0.625);
  --pf-scale: 1;
  --pf-ar: 1.6;
  --pf-gap: 24px;
  /* Left edge of the page content, measured from the window edge */
  --pf-inset: max(var(--gutter), calc((100vw - var(--max-width)) / 2 + var(--gutter)));
  --pf-fade-w: 72px;
  --pf-fade-color: var(--bg);
  grid-column: 1 / -1;
  min-width: 0;
}
/* A carousel belongs to the card above it — separate the group from the next card */
.pf-carousel + .card { margin-top: 48px; }
.pf-carousel--sm { --pf-scale: 0.75; }
.pf-carousel--lg { --pf-scale: 1.2; }
.pf-carousel--ar-4-5  { --pf-ar: 0.8; }
.pf-carousel--ar-4-3  { --pf-ar: 1.3333; }
.pf-carousel--ar-16-9 { --pf-ar: 1.7778; }
.pf-carousel--ar-1-1  { --pf-ar: 1; }

/* ─── Header ─── */
.pf-carousel__header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
.pf-carousel__title {
  font-size: clamp(22px, 2.4vw, 28px); font-weight: 700; letter-spacing: -0.02em;
  color: var(--text-primary);
}
.pf-carousel__meta {
  font-size: 15px; color: var(--text-secondary); margin-top: 6px;
}
/* Right side of the header: optional link button (external demo / download) + prev/next */
.pf-carousel__actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.pf-carousel__cta { padding: 10px 18px; font-size: 14px; min-height: 42px; }
.pf-carousel__controls { display: none; gap: 8px; flex-shrink: 0; }
.pf-carousel.is-enhanced .pf-carousel__controls { display: flex; }
.pf-carousel__btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border); cursor: pointer;
  transition: border-color 0.2s, background 0.2s, opacity 0.2s;
}
.pf-carousel__btn:hover:not(:disabled) { border-color: var(--border-hover); background: var(--violet-glow); }
.pf-carousel__btn:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
.pf-carousel__btn:disabled { opacity: 0.35; cursor: default; }

/* ─── Viewport + edge fades ─── */
.pf-carousel__viewport { position: relative; }
.pf-carousel__viewport::before,
.pf-carousel__viewport::after {
  content: ''; position: absolute; top: 0; bottom: 0;
  width: var(--pf-fade-w); z-index: 2; pointer-events: none;
  opacity: 0; transition: opacity 0.25s;
}
.pf-carousel__viewport::before { left: 0;  background: linear-gradient(to right, var(--pf-fade-color), transparent); }
.pf-carousel__viewport::after  { right: 0; background: linear-gradient(to left,  var(--pf-fade-color), transparent); }
.pf-carousel.has-prev .pf-carousel__viewport::before,
.pf-carousel.has-next .pf-carousel__viewport::after { opacity: 1; }

/* ─── Track ─── */
.pf-carousel__track {
  display: flex; gap: var(--pf-gap);
  margin: 0; padding: 6px 0 14px; list-style: none;
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scroll-behavior: smooth;
  scrollbar-width: none;
}
.pf-carousel__track::-webkit-scrollbar { display: none; }
.pf-carousel__track:focus-visible { outline: 2px solid var(--violet); outline-offset: 4px; border-radius: var(--r-md); }

.pf-carousel__slide {
  flex: 0 0 min(calc(var(--pf-card-h) * var(--pf-scale) * var(--pf-ar)), 82vw);
  scroll-snap-align: start;
}

/* ─── Bleed (Apple-style) ───
   The viewport breaks out to the full window width; the track is inset by the
   content margin so slide 1 lines up with the text above, and snapping keeps
   each slide on that margin. No edge fades — slides run off both edges. */
.pf-carousel--bleed .pf-carousel__viewport { margin-inline: calc(50% - 50vw); }
.pf-carousel--bleed .pf-carousel__viewport::before,
.pf-carousel--bleed .pf-carousel__viewport::after { display: none; }
.pf-carousel--bleed .pf-carousel__track {
  padding-inline: var(--pf-inset);
  scroll-padding-inline: var(--pf-inset);
}
.pf-carousel--bleed .pf-carousel__track:focus-visible { outline-offset: -2px; border-radius: 0; }

/* ─── Slide card ─── */
.pf-carousel__card {
  margin: 0; height: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1), border-color 0.3s, box-shadow 0.3s;
}
.pf-carousel__card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-hover), 0 0 32px var(--violet-glow);
}

.pf-carousel__media {
  position: relative; aspect-ratio: var(--pf-ar); overflow: hidden;
  background: linear-gradient(135deg, #0A0A0A, #1A0A22);
  border-bottom: 1px solid var(--border);
}
.pf-carousel__media.is-4-3  { aspect-ratio: 4 / 3; }
.pf-carousel__media.is-16-9 { aspect-ratio: 16 / 9; }
.pf-carousel__media.is-1-1  { aspect-ratio: 1 / 1; }
.pf-carousel__media img {
  display: block; width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1), opacity 0.3s;
}
.pf-carousel.is-enhanced .pf-carousel__media img:not(.is-loaded) { opacity: 0; }
.pf-carousel__card:hover .pf-carousel__media img { transform: scale(1.04); }

.pf-carousel__media.is-placeholder {
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 80% 20%, rgba(214,51,132,0.35), transparent 50%),
    linear-gradient(135deg, #1A0640 0%, #3A1275 55%, #5A1E6E 100%);
}
.pf-carousel__placeholder-label {
  font-size: 11px; font-weight: 590; letter-spacing: 0.1em; text-transform: uppercase;
  color: rgba(240,244,255,0.55);
}

/* ─── Caption ─── */
.pf-carousel__caption { padding: 16px 20px 18px; }
.pf-carousel__slide-title {
  font-size: 17px; font-weight: 590; color: var(--text-primary);
  transition: color 0.2s;
}
.pf-carousel__card:hover .pf-carousel__slide-title { color: var(--violet); }
.pf-carousel__features { list-style: none; margin: 8px 0 0; padding: 0; }
.pf-carousel__features li {
  position: relative; padding: 2px 0 2px 14px;
  font-size: 12px; color: var(--text-secondary);
}
.pf-carousel__features li::before {
  content: '•'; position: absolute; left: 0; color: var(--violet); font-weight: 700;
}
.pf-carousel__link {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 10px;
  font-size: 12px; font-weight: 510; color: var(--violet);
  transition: gap 0.15s;
}
.pf-carousel__link:hover { gap: 8px; }

@media (max-width: 600px) {
  /* Cards are single-column here, so the card-image height is 16:10 of the full content width */
  .pf-carousel { --pf-fade-w: 36px; --pf-gap: 14px; --pf-card-h: calc((100vw - 2 * var(--gutter)) * 0.625); }
  .pf-carousel__header { flex-wrap: wrap; align-items: flex-start; }
  .pf-carousel__actions { width: 100%; justify-content: space-between; }
  .pf-carousel__actions > .pf-carousel__controls:only-child { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .pf-carousel__track { scroll-behavior: auto; }
  .pf-carousel__card, .pf-carousel__card:hover,
  .pf-carousel__card:hover .pf-carousel__media img { transform: none; }
}
