/*
 * ============================================================================
 * PLAYLIST GALLERY — restyled to match the Redline portfolio design system
 * ============================================================================
 * Reuses the global theme tokens from css/styles.css (defined on the
 * [data-theme] element). var() fallbacks mirror the dark theme so the gallery
 * still renders correctly if mounted before the theme attribute is set.
 * Loaded by playlist.html after css/styles.css.
 * ============================================================================
 */

.pg-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-2xl, 3rem) var(--space-lg, 1.5rem);
}

/* ── States (loading / error / empty) ───────────────────────────────────── */
.pg-state {
  padding: var(--space-3xl, 4rem) var(--space-lg, 1.5rem);
  text-align: center;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: var(--text-sm, 0.875rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-tertiary, #737b8d);
}
.pg-error {
  color: var(--color-accent-secondary, #ff1f1f);
}

/* ── Grid ────────────────────────────────────────────────────────────────
 * Mirrors the .cabinet / .projects-grid convention: auto-fit tracks that
 * collapse to a single column at the site's primary 768px breakpoint.
 */
.pg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-lg, 1.5rem);
}

/* ── Carousel shelves (one horizontal rail per playlist) ─────────────────── */
.pg-shelf {
  margin-bottom: var(--space-3xl, 4rem);
}
.pg-shelf:last-child {
  margin-bottom: 0;
}

.pg-shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-md, 1rem);
  margin-bottom: var(--space-lg, 1.5rem);
  padding-bottom: var(--space-sm, 0.5rem);
  border-bottom: 1px dashed var(--color-surface-border, rgba(204, 17, 17, 0.18));
}
.pg-shelf-title {
  margin: 0;
  font-family: var(--font-serif, 'Playfair Display', Georgia, serif);
  font-size: clamp(1.25rem, 2.6vw, 1.8rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--color-text-primary, #ffffff);
}
.pg-shelf-count {
  flex: 0 0 auto;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: var(--text-xs, 0.75rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-tertiary, #737b8d);
}

/* Rail layout: arrow | horizontal scroller | arrow */
.pg-rail-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-sm, 0.5rem);
}

.pg-rail {
  display: flex;
  gap: var(--space-lg, 1.5rem);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding-left: var(--space-xs, 0.25rem);
  padding: var(--space-xs, 0.25rem) var(--space-xs, 0.25rem) var(--space-md, 1rem);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* arrows drive navigation; hide the bar (Firefox) */
  cursor: grab;
}
.pg-rail::-webkit-scrollbar {
  display: none; /* WebKit */
}
.pg-rail-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
  scroll-behavior: auto;
  user-select: none;
}
.pg-rail-dragging * {
  cursor: grabbing;
}
.pg-rail .pg-card {
  flex: 0 0 clamp(240px, 78vw, 300px);
  width: clamp(240px, 78vw, 300px);
  scroll-snap-align: start;
}

/* Arrow controls — tokenized circular buttons, matching .pg-close */
.pg-arrow {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--color-surface-border, rgba(204, 17, 17, 0.18));
  background: var(--color-surface-card, rgba(15, 15, 15, 0.82));
  color: var(--color-accent-primary, #cc1111);
  cursor: pointer;
  transition:
    transform var(--transition-base, 300ms ease),
    border-color var(--transition-base, 300ms ease),
    color var(--transition-base, 300ms ease),
    box-shadow var(--transition-base, 300ms ease),
    opacity var(--transition-base, 300ms ease);
}
.pg-arrow:hover:not(:disabled) {
  transform: scale(1.05);
  border-color: var(--color-surface-border-hover, rgba(255, 31, 31, 0.55));
  color: var(--color-accent-secondary, #ff1f1f);
  box-shadow: 0 4px 20px var(--color-accent-glow, rgba(204, 17, 17, 0.35));
}
.pg-arrow:focus-visible {
  outline: 2px solid var(--color-accent-secondary, #ff1f1f);
  outline-offset: 2px;
}
.pg-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}
/* When the whole playlist already fits, drop the arrows */
.pg-rail-static .pg-arrow {
  display: none;
}

@media (hover: none) {
  /* Touch: swipe to scroll, hide the arrows */
  .pg-arrow {
    display: none;
  }
  .pg-rail {
    scroll-snap-type: x mandatory;
  }
}

/* ── Card ─────────────────────────────────────────────────────────────────
 * Editorial card pattern shared with .project-card / .resource-card:
 * accent-tinted border, surface-card ground, lift + glow on hover, sharp
 * corners (large content cards in this system are not rounded).
 */
.pg-card {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 26%),
    var(--color-surface-card, rgba(15, 15, 15, 0.82));
  border: 1px solid var(--color-surface-border, rgba(204, 17, 17, 0.18));
  overflow: hidden;
  transition:
    transform var(--transition-base, 300ms ease),
    border-color var(--transition-base, 300ms ease),
    box-shadow var(--transition-base, 300ms ease);
}
.pg-card:hover {
  transform: translateY(-4px);
  border-color: var(--color-surface-border-hover, rgba(255, 31, 31, 0.55));
  box-shadow:
    0 16px 38px var(--color-shadow-deep, rgba(0, 0, 0, 0.8)),
    0 0 0 1px var(--color-accent-glow, rgba(204, 17, 17, 0.35));
}
.pg-card:focus-visible {
  outline: 2px solid var(--color-accent-secondary, #ff1f1f);
  outline-offset: 3px;
}

/* ── Thumbnail ───────────────────────────────────────────────────────────── */
.pg-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--color-bg-tertiary, #101010);
  border-bottom: 1px solid var(--color-surface-border, rgba(204, 17, 17, 0.18));
}
.pg-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow, 500ms ease);
  -webkit-user-drag: none;
  user-select: none;
}

/* Diagonal sheen sweep on hover — echoes .project-card .card-image::before */
.pg-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(120deg, transparent 18%, rgba(255, 255, 255, 0.08) 50%, transparent 82%);
  transform: translateX(-120%);
  transition: transform var(--transition-dramatic, 800ms cubic-bezier(0.4, 0, 0.2, 1));
}
.pg-card:hover .pg-thumb::after {
  transform: translateX(120%);
}

/* Play affordance — accent disc matching .featured-badge / .cta-button-primary */
.pg-play {
  position: absolute;
  inset: 0;
  margin: auto;
  z-index: 2;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-primary, #cc1111);
  color: var(--color-bg-primary, #050505);
  box-shadow: 0 6px 20px var(--color-accent-glow, rgba(204, 17, 17, 0.35));
  opacity: 0;
  transform: scale(0.85);
  transition:
    opacity var(--transition-base, 300ms ease),
    transform var(--transition-base, 300ms ease);
}
/* Reveal on hover and on keyboard focus so the affordance isn't mouse-only */
.pg-card:hover .pg-play,
.pg-card:focus-visible .pg-play {
  opacity: 1;
  transform: scale(1);
}
.pg-play svg {
  margin-left: 3px; /* optical centering of the triangle */
}

/* ── Title ───────────────────────────────────────────────────────────────
 * Serif, matching the .card-title / .resource-title editorial voice.
 */
.pg-title {
  margin: 0;
  padding: var(--space-md, 1rem) var(--space-md, 1rem) var(--space-lg, 1.5rem);
  font-family: var(--font-serif, 'Playfair Display', Georgia, serif);
  font-size: var(--text-base, 1rem);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--color-text-primary, #ffffff);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Lightbox ────────────────────────────────────────────────────────────
 * Dark media scrim (conventional for video in both themes) with the site's
 * backdrop-blur, framed by an accent border + glow like .portfolio-terminal.
 */
.pg-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg, 1.5rem);
  background: rgba(5, 5, 5, 0.86);
  backdrop-filter: blur(8px);
}
.pg-modal {
  position: relative;
  width: 100%;
  max-width: 880px;
}
.pg-player {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--color-surface-border-hover, rgba(255, 31, 31, 0.55));
  border-radius: var(--radius-md, 8px);
  background: #000;
  box-shadow:
    0 30px 80px var(--color-shadow-deep, rgba(0, 0, 0, 0.8)),
    0 0 0 1px var(--color-accent-glow, rgba(204, 17, 17, 0.35));
}
.pg-player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Circular control matching .resource-chevron / .theme-toggle */
.pg-close {
  position: absolute;
  top: -48px;
  right: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--color-surface-border, rgba(204, 17, 17, 0.18));
  border-radius: 50%;
  background: var(--color-surface-card, rgba(15, 15, 15, 0.82));
  color: var(--color-accent-primary, #cc1111);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition:
    transform var(--transition-base, 300ms ease),
    border-color var(--transition-base, 300ms ease),
    color var(--transition-base, 300ms ease),
    box-shadow var(--transition-base, 300ms ease);
}
.pg-close:hover {
  transform: scale(1.05);
  border-color: var(--color-surface-border-hover, rgba(255, 31, 31, 0.55));
  color: var(--color-accent-secondary, #ff1f1f);
  box-shadow: 0 4px 20px var(--color-accent-glow, rgba(204, 17, 17, 0.35));
}
.pg-close:focus-visible {
  outline: 2px solid var(--color-accent-secondary, #ff1f1f);
  outline-offset: 2px;
}

/* ── Interactive polish (borders / motion) ───────────────────────────────── */
/* Animated accent bar across the top edge on hover/focus */
.pg-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 4;
  background: linear-gradient(
    90deg,
    var(--color-accent-tertiary, #7a0909),
    var(--color-accent-primary, #cc1111),
    var(--color-accent-secondary, #ff1f1f)
  );
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform var(--transition-base, 300ms ease);
}
.pg-card:hover::before,
.pg-card:focus-visible::before {
  transform: scaleX(1);
}

/* Thumbnail zoom on hover/focus */
.pg-card:hover .pg-thumb img,
.pg-card:focus-visible .pg-thumb img {
  transform: scale(1.06);
}

/* Play disc pulse while hovered */
.pg-card:hover .pg-play,
.pg-card:focus-visible .pg-play {
  animation: pgPlayPulse 1.6s ease-in-out infinite;
}
@keyframes pgPlayPulse {
  0%, 100% { box-shadow: 0 6px 20px var(--color-accent-glow, rgba(204, 17, 17, 0.35)); }
  50% { box-shadow: 0 8px 30px var(--color-accent-secondary, rgba(255, 31, 31, 0.55)); }
}

/* Shelves fade up on load (staggered) */
.pg-shelf {
  animation: pgFadeUp 0.6s ease both;
}
.pg-shelf:nth-child(2) { animation-delay: 0.08s; }
.pg-shelf:nth-child(3) { animation-delay: 0.16s; }
.pg-shelf:nth-child(4) { animation-delay: 0.24s; }
.pg-shelf:nth-child(5) { animation-delay: 0.32s; }
@keyframes pgFadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

/* ── Floating, edge-snapping mini-player ─────────────────────────────────── */
.pg-overlay.is-floating {
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  pointer-events: none; /* page stays usable behind the mini-player */
}

.pg-modal-bar {
  display: flex;
  align-items: center;
  gap: var(--space-xs, 0.25rem);
  margin-bottom: var(--space-sm, 0.5rem);
}
.pg-modal-title {
  flex: 1 1 auto;
  min-width: 0;
  margin-right: var(--space-sm, 0.5rem);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: var(--text-xs, 0.75rem);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-tertiary, #737b8d);
}

.pg-ctrl {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--color-surface-border, rgba(204, 17, 17, 0.18));
  background: var(--color-surface-card, rgba(15, 15, 15, 0.82));
  color: var(--color-accent-primary, #cc1111);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition:
    transform var(--transition-base, 300ms ease),
    border-color var(--transition-base, 300ms ease),
    color var(--transition-base, 300ms ease),
    box-shadow var(--transition-base, 300ms ease);
}
.pg-ctrl:hover {
  transform: scale(1.06);
  border-color: var(--color-surface-border-hover, rgba(255, 31, 31, 0.55));
  color: var(--color-accent-secondary, #ff1f1f);
  box-shadow: 0 4px 18px var(--color-accent-glow, rgba(204, 17, 17, 0.35));
}
.pg-ctrl:focus-visible {
  outline: 2px solid var(--color-accent-secondary, #ff1f1f);
  outline-offset: 2px;
}

.pg-modal-floating {
  position: fixed;
  width: clamp(260px, 42vw, 384px);
  max-width: none;
  margin: 0;
  padding: var(--space-sm, 0.5rem);
  background: var(--color-bg-elevated, #151515);
  border: 1px solid var(--color-surface-border-hover, rgba(255, 31, 31, 0.55));
  box-shadow:
    0 24px 60px var(--color-shadow-deep, rgba(0, 0, 0, 0.8)),
    0 0 0 1px var(--color-accent-glow, rgba(204, 17, 17, 0.35));
  pointer-events: auto; /* interactive even though the overlay is click-through */
  z-index: 1001;
  cursor: grab; /* whole frame is a drag handle */
  transition:
    left 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.pg-modal-floating .pg-modal-bar {
  cursor: grab;
  margin-bottom: var(--space-xs, 0.25rem);
}
.pg-modal-floating.pg-dragging,
.pg-modal-floating.pg-dragging .pg-modal-bar {
  cursor: grabbing;
}
.pg-modal-floating.pg-dragging {
  transition: none;
  cursor: grabbing;
  box-shadow:
    0 30px 70px var(--color-shadow-deep, rgba(0, 0, 0, 0.85)),
    0 0 0 1px var(--color-accent-secondary, #ff1f1f);
}
.pg-modal-floating .pg-player {
  border-radius: var(--radius-sm, 4px);
  border-color: var(--color-surface-border, rgba(204, 17, 17, 0.18));
  box-shadow: none;
}

/* ── Responsive — same primary breakpoint as the site grids ──────────────── */
@media (max-width: 768px) {
  .pg-wrap {
    padding: var(--space-xl, 2rem) var(--space-md, 1rem);
  }
  .pg-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md, 1rem);
  }
  .pg-overlay {
    padding: var(--space-md, 1rem);
  }
  .pg-close {
    top: -44px;
  }
  .pg-shelf {
    margin-bottom: var(--space-2xl, 3rem);
  }
}

/* On touch devices (no hover) keep the play affordance gently visible */
@media (hover: none) {
  .pg-play {
    opacity: 0.9;
    transform: scale(1);
  }
}

/* ── Motion preferences — mirrors the site's reduced-motion handling ─────── */
@media (prefers-reduced-motion: reduce) {
  .pg-card,
  .pg-card::before,
  .pg-play,
  .pg-thumb img,
  .pg-thumb::after,
  .pg-arrow,
  .pg-ctrl,
  .pg-shelf,
  .pg-modal-floating,
  .pg-close {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
  .pg-card:hover {
    transform: none;
  }
  .pg-card:hover .pg-thumb img {
    transform: none;
  }
  .pg-card:hover .pg-thumb::after {
    transform: translateX(-120%);
  }
}
