/* ════════════════════════════════════════════════════════════════════
   works-v2.css — "أعمالنا" portfolio + lightbox, rebuilt from scratch.
   --------------------------------------------------------------------
   Goals:
     • Fast: uniform responsive grid, lazy thumbnails, only ONE inline
       video plays at a time (hover). No mass autoplay.
     • Clean lightbox: a FRESH <video> is created per open (no DOM
       reparenting of a live video → no "corner then zoom" glitch).
       The stage is sized deterministically so there is zero reflow.
     • Handles big reels: progressive R2 MP4 streams behind the poster,
       torn down on close to free bandwidth + decoder.

   Self-contained: brand-new `wrk-*` class names so none of the legacy
   cine-* / apple-perf !important rules can interfere. Loaded LAST.

   Reuses the global brand vars from cinematic.css :root
   (--cine-red, --cine-amber, --cine-deep, --cine-charcoal, *-rgb).
   ════════════════════════════════════════════════════════════════════ */

.wrk {
  --wrk-bg:        var(--cine-deep, #050307);
  --wrk-card:      var(--cine-charcoal, #0c0a10);
  --wrk-red:       var(--cine-red, #e6101c);
  --wrk-red-soft:  var(--cine-red-soft, #ff3b47);
  --wrk-amber:     var(--cine-amber, #ff9466);
  --wrk-red-rgb:   var(--cine-red-rgb, 230, 16, 28);
  --wrk-amber-rgb: var(--cine-amber-rgb, 255, 148, 102);
  --wrk-radius:    18px;

  position: relative;
  padding: clamp(64px, 9vw, 130px) clamp(14px, 4vw, 40px) clamp(80px, 10vw, 150px);
  background: var(--wrk-bg);
  overflow: hidden;
  isolation: isolate;
}

/* Soft brand glow backdrop — pure decoration, no animation cost. */
.wrk::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 50% at 25% 18%, rgba(var(--wrk-red-rgb), 0.13), transparent 60%),
    radial-gradient(ellipse 55% 45% at 78% 82%, rgba(var(--wrk-amber-rgb), 0.08), transparent 60%);
}

/* ── Header ───────────────────────────────────────────────────────── */
.wrk__head {
  position: relative;
  z-index: 2;
  max-width: 760px;
  margin: 0 auto clamp(34px, 5vw, 64px);
  text-align: center;
}
.wrk__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: clamp(0.6rem, 1.4vw, 0.72rem);
  letter-spacing: 0.42em;
  font-weight: 700;
  text-transform: uppercase;
  color: rgba(var(--wrk-red-rgb), 0.92);
  margin-bottom: 18px;
}
.wrk__eyebrow::before,
.wrk__eyebrow::after {
  content: '';
  width: clamp(24px, 5vw, 48px);
  height: 1.5px;
  background: linear-gradient(90deg, transparent, var(--wrk-red), transparent);
}
.wrk__title {
  font-size: clamp(2rem, 5.4vw, 4.2rem);
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: -0.025em;
  margin: 0 0 16px;
  color: #fff;
}
.wrk__title span {
  background: linear-gradient(180deg, #fff 0%, #d4d0cb 65%, #a8a39c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-inline-end: 10px;
}
.wrk__title em {
  font-style: normal;
  background: linear-gradient(135deg, #fff 0%, #ffd6cb 25%, var(--wrk-amber) 55%, var(--wrk-red-soft) 80%, var(--wrk-red) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 16px rgba(var(--wrk-red-rgb), 0.3));
}
.wrk__sub {
  color: rgba(230, 227, 223, 0.68);
  font-size: clamp(0.92rem, 2vw, 1.05rem);
  line-height: 1.8;
  max-width: 620px;
  margin: 0 auto;
}

/* ── Filters ──────────────────────────────────────────────────────── */
.wrk__filters {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: clamp(22px, 3vw, 32px);
}
.wrk__chip {
  appearance: none;
  font: inherit;
  font-size: clamp(0.7rem, 1.6vw, 0.82rem);
  font-weight: 600;
  color: rgba(230, 227, 223, 0.78);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 18px;
  border-radius: 100px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.wrk__chip:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
}
.wrk__chip.is-active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--wrk-red), var(--wrk-red-soft));
  box-shadow: 0 8px 22px rgba(var(--wrk-red-rgb), 0.4);
}
.wrk__chip:focus-visible {
  outline: 2px solid var(--wrk-amber);
  outline-offset: 3px;
}

/* ── Grid — bento masonry (12-col, fixed row unit) ────────────────── */
.wrk__grid {
  position: relative;
  z-index: 2;
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: 72px;
  gap: clamp(10px, 1.4vw, 16px);
}

/* ── Card ─────────────────────────────────────────────────────────── */
.wrk-card {
  position: relative;
  grid-column: span 3;     /* default; overridden per size variant below */
  grid-row: span 4;
  border-radius: var(--wrk-radius);
  overflow: hidden;
  background: linear-gradient(135deg, var(--wrk-card), #18121a);
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transform: translateZ(0);            /* own layer, stable */
  transition: transform 0.22s ease-out, box-shadow 0.22s ease-out;
  /* Entrance */
  opacity: 0;
  animation: wrk-card-in 0.7s cubic-bezier(.16, 1, .3, 1) forwards;
}
.wrk-card.is-hidden { display: none; }

/* Varied sizes interlock: tall reels, big features, small squares.
   Cycled by index in JS (SIZE_VARIANTS) — not by content type. */
.wrk-card--reel    { grid-column: span 3; grid-row: span 5; }
.wrk-card--design  { grid-column: span 3; grid-row: span 4; }
.wrk-card--wide    { grid-column: span 4; grid-row: span 4; }
.wrk-card--square  { grid-column: span 3; grid-row: span 3; }
.wrk-card--feature { grid-column: span 4; grid-row: span 5; }
.wrk-card--narrow  { grid-column: span 3; grid-row: span 4; }

/* Staggered rise */
.wrk-card[data-delay="1"] { animation-delay: 0.05s; }
.wrk-card[data-delay="2"] { animation-delay: 0.13s; }
.wrk-card[data-delay="3"] { animation-delay: 0.21s; }
.wrk-card[data-delay="4"] { animation-delay: 0.29s; }
.wrk-card[data-delay="5"] { animation-delay: 0.37s; }
.wrk-card[data-delay="6"] { animation-delay: 0.45s; }
.wrk-card[data-delay="7"] { animation-delay: 0.53s; }

@keyframes wrk-card-in {
  from { opacity: 0; transform: translateY(26px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.wrk-card:hover {
  transform: translateY(-5px);
  box-shadow:
    0 26px 60px rgba(0, 0, 0, 0.6),
    0 0 36px rgba(var(--wrk-red-rgb), 0.22);
}
.wrk-card:focus-visible {
  outline: 2px solid var(--wrk-amber);
  outline-offset: 3px;
}

/* Media (img / video / poster) all fill the card identically. */
.wrk-card__media,
.wrk-card__media img,
.wrk-card__media video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.wrk-card__media {
  background: linear-gradient(135deg, var(--wrk-card), #18121a);
}
.wrk-card__media video {
  opacity: 0;
  transition: opacity 0.3s ease;
}
.wrk-card__media video.is-playing { opacity: 1; }

/* Bottom gradient + label */
.wrk-card::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 55%, rgba(5, 3, 7, 0.72) 100%);
  opacity: 0.85;
  transition: opacity 0.25s;
}
.wrk-card:hover::after { opacity: 1; }

.wrk-card__info {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 3;
  padding: 16px 14px 13px;
  pointer-events: none;
}
.wrk-card__cat {
  display: block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--wrk-amber);
  margin-bottom: 3px;
}
.wrk-card__name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Play badge for video cards */
.wrk-card__play {
  position: absolute;
  z-index: 3;
  top: 12px;
  inset-inline-start: 12px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform 0.25s, background 0.25s;
}
.wrk-card:hover .wrk-card__play {
  transform: scale(1.08);
  background: linear-gradient(135deg, var(--wrk-red), var(--wrk-red-soft));
  border-color: transparent;
}
[dir="rtl"] .wrk-card__play i { transform: scaleX(1); }

/* Image fallback when no media */
.wrk-card__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.18);
  font-size: 2.2rem;
  z-index: 1;
}

/* ── Empty / loading state ────────────────────────────────────────── */
.wrk__empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 70px 20px;
  color: rgba(230, 227, 223, 0.5);
  font-size: 0.95rem;
}
.wrk__empty i { font-size: 2.6rem; opacity: 0.32; display: block; margin-bottom: 14px; }
.wrk__empty .fa-spin { color: var(--wrk-red-soft); opacity: 0.8; }

/* ── Show more ────────────────────────────────────────────────────── */
.wrk__more-wrap {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  margin-top: clamp(32px, 4vw, 50px);
}
.wrk__more[hidden] { display: none; }
.wrk__more {
  appearance: none;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 30px;
  border-radius: 100px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.14);
  transition: background 0.25s, border-color 0.25s, transform 0.2s, box-shadow 0.25s;
}
.wrk__more:hover {
  transform: translateY(-2px);
  border-color: transparent;
  background: linear-gradient(135deg, rgba(var(--wrk-red-rgb), 0.18), rgba(var(--wrk-amber-rgb), 0.1));
  box-shadow: 0 18px 40px rgba(var(--wrk-red-rgb), 0.28);
}
.wrk__more-arrow {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  background: linear-gradient(135deg, var(--wrk-red), var(--wrk-red-soft));
}
.wrk__more:focus-visible { outline: 2px solid var(--wrk-amber); outline-offset: 3px; }

/* ════════════════════════════════════════════════════════════════════
   LIGHTBOX MODAL — fresh element, deterministic sizing, clean fade+zoom.
   ════════════════════════════════════════════════════════════════════ */
.wrk-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 3vw, 28px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.wrk-modal.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s ease;
}
.wrk-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 3, 7, 0.92);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
}

/* The stage is the ONLY element that scales on open. It animates in
   place at the viewport centre — never from a corner — because it is a
   self-contained box whose final position is fixed by the flex centre. */
.wrk-modal__stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 22px;
  overflow: hidden;
  background: #000;
  box-shadow:
    0 50px 120px rgba(0, 0, 0, 0.8),
    0 0 70px rgba(var(--cine-red-rgb, 230, 16, 28), 0.28);
  transform: scale(0.96);
  opacity: 0;
  transition: transform 0.28s cubic-bezier(.16, 1, .3, 1), opacity 0.28s ease;
  will-change: transform, opacity;
}
.wrk-modal.is-open .wrk-modal__stage {
  transform: scale(1);
  opacity: 1;
}

/* Media box — sized BEFORE the video loads so there is zero reflow.
   Video reels (portrait) get a fixed 9:16 box capped to the viewport.
   Images size to their natural ratio within viewport caps. */
.wrk-modal__media {
  position: relative;
  display: grid;
  place-items: center;
  background: #000;
  overflow: hidden;
}
.wrk-modal__media[data-kind="video"] {
  aspect-ratio: 9 / 16;
  height: min(86vh, 1100px);
  max-width: 94vw;
}
.wrk-modal__media[data-kind="image"] {
  max-width: 94vw;
  max-height: 86vh;
}

.wrk-modal__media video,
.wrk-modal__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.wrk-modal__media[data-kind="image"] img {
  width: auto;
  height: auto;
  max-width: 94vw;
  max-height: 86vh;
}

/* Poster shows instantly; the real video fades over it. */
.wrk-modal__poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 0;
}
.wrk-modal__media video {
  position: relative;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.wrk-modal__media video.is-ready { opacity: 1; }

/* Loading spinner over the poster while the reel buffers. */
.wrk-modal__spinner {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.wrk-modal__spinner-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--cine-red-soft, #ff3b47);
  animation: wrk-spin 0.9s linear infinite;
}
.wrk-modal__media.is-ready .wrk-modal__spinner { display: none; }
@keyframes wrk-spin { to { transform: rotate(360deg); } }

.wrk-modal__empty {
  display: grid;
  place-items: center;
  gap: 12px;
  min-width: min(60vw, 360px);
  min-height: 40vh;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.95rem;
}
.wrk-modal__empty i { font-size: 2.6rem; opacity: 0.4; }

/* Caption */
.wrk-modal__caption {
  width: 100%;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  color: #fff;
}
.wrk-modal__caption strong { display: block; font-size: 0.98rem; }
.wrk-modal__caption small {
  color: rgba(230, 227, 223, 0.55);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.wrk-modal__caption:empty { display: none; }

/* Controls */
.wrk-modal__close {
  position: absolute;
  z-index: 5;
  top: clamp(12px, 2vw, 20px);
  inset-inline-end: clamp(12px, 2vw, 20px);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.25s, transform 0.25s;
}
.wrk-modal__close:hover {
  background: var(--cine-red, #e6101c);
  transform: rotate(90deg);
}

.wrk-modal__nav {
  position: absolute;
  z-index: 4;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.05rem;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.22s, transform 0.18s;
}
.wrk-modal__nav:hover { background: rgba(var(--cine-red-rgb, 230, 16, 28), 0.85); }
.wrk-modal__nav:active { transform: translateY(-50%) scale(0.94); }
.wrk-modal__nav--prev { inset-inline-start: clamp(8px, 2vw, 24px); }
.wrk-modal__nav--next { inset-inline-end:   clamp(8px, 2vw, 24px); }

.wrk-modal__counter {
  position: absolute;
  z-index: 4;
  top: clamp(12px, 2vw, 20px);
  inset-inline-start: clamp(12px, 2vw, 20px);
  padding: 7px 14px;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  direction: ltr;                /* keep "3 / 20" readable inside RTL page */
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.wrk-modal__close:focus-visible,
.wrk-modal__nav:focus-visible {
  outline: 2px solid var(--cine-amber, #ff9466);
  outline-offset: 2px;
}

/* ── Tablet / mobile — keep the interlocking masonry, fewer columns ── */
@media (max-width: 900px) {
  .wrk__grid { grid-template-columns: repeat(4, 1fr); grid-auto-rows: 52px; }
  .wrk-card         { grid-column: span 1; grid-row: span 4; }
  .wrk-card--reel    { grid-column: span 1; grid-row: span 5; }
  .wrk-card--design  { grid-column: span 1; grid-row: span 4; }
  .wrk-card--wide    { grid-column: span 2; grid-row: span 4; }
  .wrk-card--square  { grid-column: span 1; grid-row: span 3; }
  .wrk-card--feature { grid-column: span 2; grid-row: span 5; }
  .wrk-card--narrow  { grid-column: span 1; grid-row: span 4; }
  .wrk-modal__nav { width: 44px; height: 44px; font-size: 0.95rem; }
  .wrk-modal__media[data-kind="video"] { height: min(80vh, 900px); max-width: 96vw; }
}
@media (max-width: 600px) {
  .wrk__grid { grid-template-columns: repeat(3, 1fr); grid-auto-rows: 46px; gap: 9px; }
  .wrk-card         { grid-column: span 1; grid-row: span 4; }
  .wrk-card--reel    { grid-column: span 1; grid-row: span 5; }
  .wrk-card--design  { grid-column: span 1; grid-row: span 4; }
  .wrk-card--wide    { grid-column: span 2; grid-row: span 4; }
  .wrk-card--square  { grid-column: span 1; grid-row: span 3; }
  .wrk-card--feature { grid-column: span 2; grid-row: span 5; }
  .wrk-card--narrow  { grid-column: span 1; grid-row: span 4; }
  .wrk-card__name { font-size: 0.82rem; }
}

/* ── Light theme ──────────────────────────────────────────────────── */
body.light .wrk { background: #ffffff; }
body.light .wrk::before {
  background:
    radial-gradient(ellipse 60% 50% at 25% 18%, rgba(var(--wrk-red-rgb), 0.06), transparent 60%),
    radial-gradient(ellipse 55% 45% at 78% 82%, rgba(var(--wrk-amber-rgb), 0.05), transparent 60%);
}
body.light .wrk__title span { color: #0f172a; -webkit-text-fill-color: #0f172a; background: none; }
body.light .wrk__sub { color: rgba(15, 23, 42, 0.7); }
body.light .wrk__chip {
  color: rgba(15, 23, 42, 0.75);
  background: rgba(15, 23, 42, 0.05);
  border-color: rgba(15, 23, 42, 0.1);
}
body.light .wrk__chip:hover { color: #0f172a; border-color: rgba(15, 23, 42, 0.25); }
body.light .wrk__chip.is-active { color: #fff; }
body.light .wrk-card {
  background: #f1f3f8;
  border-color: rgba(15, 23, 42, 0.08);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}
body.light .wrk-card:hover { box-shadow: 0 22px 50px rgba(15, 23, 42, 0.2); }
body.light .wrk__more {
  color: #0f172a;
  background: rgba(15, 23, 42, 0.04);
  border-color: rgba(15, 23, 42, 0.12);
}
body.light .wrk__empty { color: rgba(15, 23, 42, 0.55); }

/* ── Reduced motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .wrk-card { animation: none; opacity: 1; }
  .wrk-modal__stage,
  .wrk-card,
  .wrk-card__media video { transition: opacity 0.15s linear; }
  .wrk-modal__stage { transform: none; }
  .wrk-modal__spinner-ring { animation-duration: 1.6s; }
}
