/* ==========================================================================
   AI Content Portfolio page
   ========================================================================== */

.page-header {
  position: relative;
  z-index: 2;
  padding: clamp(20px, 4vh, 36px) var(--gutter) clamp(28px, 6vh, 48px);
  max-width: var(--max-width);
  margin: 0 auto;
}

.page-header::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 260px;
  z-index: -1;
  background: linear-gradient(to bottom, rgba(2, 5, 3, 0.82) 0%, rgba(2, 5, 3, 0) 100%);
  pointer-events: none;
}

.back-link {
  position: sticky;
  top: 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.92rem;
  color: var(--ink);
  padding: 0.55em 1.1em 0.55em 0.85em;
  border: 1px solid rgba(60, 255, 122, 0.35);
  border-radius: 999px;
  background: rgba(4, 7, 5, 0.55);
  backdrop-filter: blur(6px);
  transition: border-color 0.25s var(--ease-out), background 0.25s var(--ease-out);
  z-index: 10;
}

.back-link:hover,
.back-link:focus-visible {
  border-color: var(--code-bright);
  background: rgba(14, 61, 32, 0.45);
}

.back-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.page-title {
  margin: clamp(24px, 5vh, 40px) 0 6px;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  color: var(--ink-hi);
}

.page-subtitle {
  margin: 0 0 clamp(24px, 5vh, 40px);
  color: var(--ink-lo);
  font-size: 0.95rem;
  max-width: 60ch;
}

/* ---- Gallery grid --------------------------------------------------------- */

.gallery {
  position: relative;
  z-index: 2;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--gutter) clamp(60px, 10vh, 120px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: clamp(12px, 2vw, 22px);
}

.video-card {
  position: relative;
  border: 0;
  padding: 0;
  background: var(--bg-panel);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 9 / 16;
  isolation: isolate;
  box-shadow: 0 0 0 1px rgba(60, 255, 122, 0.08);
  transition: box-shadow 0.3s var(--ease-out), transform 0.3s var(--ease-out);
}

/* All tiles stay uniform (9:16) regardless of a video's real orientation —
   the actual video keeps its native aspect ratio once opened in the lightbox. */
.video-card--landscape { aspect-ratio: 9 / 16; }

.video-card:hover,
.video-card:focus-visible {
  box-shadow: 0 0 0 1px var(--code-bright), 0 10px 30px rgba(0, 0, 0, 0.45);
  transform: translateY(-3px);
}

.video-card__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s var(--ease-out);
}

.video-card__poster[data-loaded="true"] { opacity: 1; }

.video-card__placeholder {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(160deg, #0a1f13 0%, #05130b 60%, #030a06 100%);
}

.video-card__placeholder-index {
  position: absolute;
  top: 10px;
  left: 12px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  color: var(--code-bright);
  opacity: 0.55;
}

.video-card__title {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 22px 12px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-hi);
  background: linear-gradient(to top, rgba(2,5,3,0.85), transparent);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s var(--ease-out), transform 0.25s var(--ease-out);
}

.video-card:hover .video-card__title,
.video-card:focus-visible .video-card__title {
  opacity: 1;
  transform: translateY(0);
}

.play-glyph {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1.5px solid rgba(60, 255, 122, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--code-bright);
  z-index: 2;
  transition: transform 0.25s var(--ease-out), background 0.25s var(--ease-out);
}

/* Overlay variant: centered on top of a loaded poster image (the placeholder's
   own play-glyph is positioned by its flex container instead). */
.video-card__play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.video-card:hover .video-card__play-overlay,
.video-card:focus-visible .video-card__play-overlay {
  transform: translate(-50%, -50%) scale(1.08);
}

.video-card:hover .play-glyph,
.video-card:focus-visible .play-glyph {
  transform: scale(1.08);
  background: rgba(60, 255, 122, 0.12);
}

/* ---- Glitch reveal on scroll into view ------------------------------------ */

.video-card {
  opacity: 0;
}

.video-card.is-revealed {
  animation: card-glitch-in 0.5s steps(6, end) forwards;
}

@keyframes card-glitch-in {
  0%   { opacity: 0; clip-path: inset(0 0 100% 0); filter: brightness(2.4) saturate(0); }
  35%  { opacity: 1; clip-path: inset(0 0 55% 0);  filter: brightness(1.8) saturate(0.3); }
  60%  { opacity: 1; clip-path: inset(0 0 20% 0);  filter: brightness(1.3) saturate(0.6); }
  80%  { opacity: 1; clip-path: inset(0 0 4% 0);   filter: brightness(1.05); }
  100% { opacity: 1; clip-path: inset(0 0 0 0);    filter: brightness(1) saturate(1); }
}

@media (prefers-reduced-motion: reduce) {
  .video-card { opacity: 1; animation: none; }
}

/* ---- Lightbox -------------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 5, 3, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 24px;
}

.lightbox.is-open { display: flex; }

.lightbox__inner {
  position: relative;
  max-width: 96vw;
  max-height: 92vh;
  display: flex;
  align-items: stretch;
  gap: 0;
  background: transparent;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

/* Center: video — sized to its own aspect ratio, not stretched to fill
   leftover space (that's what was causing empty black bars beside 9:16
   videos). The two side columns flank it closely instead. */
.lightbox__video-col {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.lightbox__video-col video {
  display: block;
  height: min(86vh, 800px);
  width: auto;
  max-width: min(58vw, 620px);
  object-fit: contain;
}

/* Left: reference photos/videos — column width stays fixed, but each item
   automatically shares the available height equally with however many
   siblings exist (1 fills it, 2 split it in half, 3 in thirds). */
.lightbox__refs-col {
  flex: 0 0 240px;
  min-width: 0;
  padding: 22px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: transparent;
}

/* Fewer references = more room each: widen the column so a single (or
   pair of) reference(s) can actually render bigger, not just float
   centered in leftover space. Progressive enhancement — falls back to
   the 240px default in browsers without :has() support. */
.lightbox__refs-col:has(.lightbox__ref:only-child) {
  flex-basis: 360px;
}

.lightbox__refs-col:has(.lightbox__ref:nth-child(2):last-child) {
  flex-basis: 300px;
}

.lightbox__refs-heading {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--code-bright);
}

.lightbox__refs {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 6px;
  min-height: 0;
}

/* No frame, no fixed shape — each reference is just the file itself,
   sized by flex to share the column equally with its siblings, and
   object-fit:contain so the whole image/video is visible uncropped. */
.lightbox__ref {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ref-glitch-flicker 2s steps(1) infinite;
}

.lightbox__ref img,
.lightbox__ref video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Gentle, occasional RGB-split glitch on the reference itself — mostly
   calm, brief flicker every couple seconds, same technique as the
   headline/Contact-button glitch, applied to the media's own silhouette. */
@keyframes ref-glitch-flicker {
  0%, 84% { filter: none; }
  85% { filter: drop-shadow(-4px 0 rgba(255, 59, 70, 0.9)) drop-shadow(4px 0 rgba(59, 139, 255, 0.9)); }
  87% { filter: drop-shadow(4px 0 rgba(255, 59, 70, 0.9)) drop-shadow(-4px 0 rgba(59, 139, 255, 0.9)); }
  89% { filter: drop-shadow(-4px 0 rgba(255, 59, 70, 0.9)) drop-shadow(4px 0 rgba(59, 139, 255, 0.9)); }
  91% { filter: drop-shadow(4px 0 rgba(255, 59, 70, 0.9)) drop-shadow(-4px 0 rgba(59, 139, 255, 0.9)); }
  93% { filter: drop-shadow(-3px 0 rgba(255, 59, 70, 0.7)) drop-shadow(3px 0 rgba(59, 139, 255, 0.7)); }
  95%, 100% { filter: none; }
}

.lightbox__ref:nth-child(2) { animation-delay: 0.65s; }
.lightbox__ref:nth-child(3) { animation-delay: 1.3s; }

@media (prefers-reduced-motion: reduce) {
  .lightbox__ref { animation: none; }
}

/* Right: title + description */
.lightbox__desc-col {
  flex: 0 0 320px;
  min-width: 0;
  max-width: 320px;
  padding: 22px 22px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: transparent;
}

.lightbox__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-hi);
  overflow-wrap: break-word;
  min-width: 0;
}

.lightbox__description {
  font-family: var(--font-display);
  font-size: 0.85rem;
  line-height: 1.65;
  color: var(--ink-lo);
  white-space: pre-line;
  /* pre-line keeps \n line breaks working, but on its own it lets long
     lines run off to the right; overflow-wrap forces wrapping at word
     boundaries. min-width:0 is needed because this sits in a flex column,
     where the default min-width:auto would let it overflow. */
  overflow-wrap: break-word;
  min-width: 0;
  max-width: 100%;
}

.lightbox__description--empty {
  color: rgba(143, 230, 160, 0.35);
  font-style: italic;
}

.lightbox__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(60, 255, 122, 0.4);
  background: rgba(4, 7, 5, 0.7);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}

.lightbox__close:hover,
.lightbox__close:focus-visible {
  border-color: var(--code-bright);
}

@media (max-width: 820px) {
  .lightbox__inner {
    flex-direction: column;
    max-height: 94vh;
    overflow-y: auto;
  }

  .lightbox__video-col { order: 1; }
  .lightbox__refs-col { order: 2; }
  .lightbox__desc-col { order: 3; }

  .lightbox__video-col { flex: 0 0 auto; width: 100%; }

  .lightbox__video-col video {
    height: auto;
    width: 100%;
    max-width: 100%;
    max-height: 46vh;
  }

  .lightbox__refs-col,
  .lightbox__desc-col {
    flex: 0 0 auto;
    padding: 18px 20px;
  }

  .lightbox__refs {
    flex-direction: row;
    height: 22vh;
  }

  .lightbox__ref {
    flex: 1 1 0;
    width: auto;
    height: 100%;
  }
}

/* ---- Responsive ------------------------------------------------------------- */

@media (max-width: 480px) {
  .gallery {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1440px) {
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }
}
