/* ================================================================
   Virtual 3D Interactive Library - Trends Showcase Stylesheet
   Infinite 3D Dual-Shelf Display & High-Resolution Lightbox Modal
   ================================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #e5e7eb;
  background:
    radial-gradient(100% 70% at 10% 10%, rgba(56, 189, 248, 0.22), transparent 55%),
    radial-gradient(90% 70% at 90% 0%, rgba(168, 85, 247, 0.18), transparent 58%),
    linear-gradient(180deg, #070b14 0%, #0d1527 50%, #0a0f1d 100%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ----------------------------------------------------------------
   3D Scene & Shelves Layout
   ---------------------------------------------------------------- */

.scene {
  --row-count: 2;
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-rows: repeat(var(--row-count), 1fr);
  gap: clamp(14px, 2.2vh, 24px);
  padding: clamp(16px, 2.8vh, 26px) 0;
  perspective: 1200px;
  overflow: hidden;
}

.row {
  position: relative;
  overflow: hidden;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.008));
  box-shadow: inset 0 20px 30px rgba(0, 0, 0, 0.25), inset 0 -18px 26px rgba(0, 0, 0, 0.22);
  touch-action: pan-y;
  cursor: grab;
}

.row.is-grabbing,
.row.is-grabbing .card {
  cursor: grabbing !important;
}

/* Shelf center line accent */
.row::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(148, 163, 184, 0.25) 10%, rgba(148, 163, 184, 0.25) 90%, transparent);
  pointer-events: none;
}

.track {
  height: 100%;
  display: flex;
  align-items: center;
  gap: clamp(14px, 1.8vw, 24px);
  width: max-content;
  padding-inline: 24px;
  transform-style: preserve-3d;
  will-change: transform;
  touch-action: pan-y;
  user-select: none;
}

/* ----------------------------------------------------------------
   Interactive Publication Cards
   ---------------------------------------------------------------- */

.card {
  --w: clamp(100px, 9.6vw, 155px);
  --h: calc(var(--w) * 1280 / 720);
  width: var(--w);
  height: var(--h);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  overflow: visible;
  perspective: 1000px;
  -webkit-perspective: 1000px;
  transform-style: preserve-3d;
  flex-shrink: 0;
  touch-action: manipulation;
  pointer-events: auto;
  transform: translateY(0) translateZ(0);
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1), z-index 0.3s ease;
}

.card:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.85);
  outline-offset: 4px;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  background: #0d1527;
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.25, 1), box-shadow 0.35s ease, filter 0.35s ease;
  pointer-events: auto;
}

/* Top Shelf - Arabic RTL Tilt */
.card-inner.dir-rtl {
  transform: rotateY(22deg) translateZ(0);
  box-shadow: -10px 14px 26px rgba(0, 0, 0, 0.45);
}

/* Bottom Shelf - English LTR Tilt (Hover Fully Fixed) */
.card-inner.dir-ltr {
  transform: rotateY(-22deg) translateZ(0);
  box-shadow: 10px 14px 26px rgba(0, 0, 0, 0.45);
}

/* Shimmer highlight overlay */
.card-inner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16) 0%, transparent 45%, rgba(255, 255, 255, 0.08) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

/* Hover & Focus State on BOTH Arabic & English Shelves */
.card:hover,
.card:focus-visible {
  transform: translateY(-10px) translateZ(32px);
  z-index: 20;
}

.card:hover .card-inner,
.card:focus-visible .card-inner {
  transform: rotateY(0deg) scale(1.05);
  box-shadow: 0 22px 42px rgba(0, 0, 0, 0.65), 0 0 20px rgba(56, 189, 248, 0.3);
  filter: brightness(1.08);
}

.card:hover .card-inner::after,
.card:focus-visible .card-inner::after,
.card.is-tapped .card-inner::after {
  opacity: 1;
}

.card.is-tapped {
  transform: translateY(-4px) scale(0.98);
}

.card-inner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* ----------------------------------------------------------------
   High-Resolution Lightbox Modal
   ---------------------------------------------------------------- */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vh, 32px);
  background: rgba(4, 7, 16, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s ease;
  cursor: pointer;
}

#overlay.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.lightbox-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 92vw;
  max-height: 92vh;
  transform: scale(0.92) translateY(10px);
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.26s ease;
  cursor: default;
}

#overlay.is-open .lightbox-container {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.lightbox-img {
  max-width: min(88vw, 560px);
  max-height: min(88vh, 900px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.8), 0 0 24px rgba(56, 189, 248, 0.2);
  display: block;
}

.lightbox-close {
  position: absolute;
  top: -16px;
  right: -16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(18, 26, 44, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  z-index: 10;
}

.lightbox-close:hover {
  background: rgba(30, 41, 68, 0.98);
  color: #38bdf8;
  transform: scale(1.1);
}

.lightbox-close:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

/* ----------------------------------------------------------------
   Responsive Breakpoints & Reduced Motion
   ---------------------------------------------------------------- */

@media (max-width: 768px) {
  .lightbox-close {
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card-inner, #overlay, .lightbox-container {
    transition: none !important;
  }
}
