@font-face {
  font-family: 'Safi';
  src: url('../fonts/safi.woff2') format('truetype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --bg: #000000;
  --card-bg: #1c1c1c;
  --text: #e9e9ef;
  --muted: #b7b7c5;
  --gap: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Safi', ui-sans-serif, system-ui, sans-serif;
  color-scheme: dark;
}

.wrap {
  min-height: 100svh;
  display: grid;
  place-items: start center;
  padding: 16px;
}

.gallery-header {
  text-align: center;
  margin-bottom: 32px;
  margin-top: 16px;
  max-width: 600px;
  width: 100%;
}

.gallery-header h1 {
  margin: 0 0 12px 0;
  font-size: clamp(28px, 4vw, 36px);
}

.gallery-header p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(16px, 2vw, 18px);
  line-height: 1.5;
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(92vw, 1200px);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  grid-auto-rows: 6px;
}

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

@media (min-width: 980px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.card {
  position: relative;
  background: var(--card-bg);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.25s ease;
  align-self: start;
}

.card:hover {
  transform: scale(1.03);
  z-index: 10;
}

.card-content {
  display: block;
}

.card img, .card video {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
}

.card-body {
  padding: 12px 16px;
}

.card:not(.has-title) .card-body {
  display: none;
}

.title {
  margin: 0;
  font-size: clamp(18px, 2vw, 20px);
  line-height: 1.2;
}

.card.has-desc.has-title .card-body {
  position: relative;
  padding-right: 40px;
}

.card.has-desc.has-title .card-body::after {
  content: '';
  position: absolute;
  right: 16px;
  bottom: 12px;
  width: 20px;
  height: 20px;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23b7b7c5"><circle cx="5" cy="12" r="2.5"/><circle cx="12" cy="12" r="2.5"/><circle cx="19" cy="12" r="2.5"/></svg>') no-repeat center;
  background-size: contain;
}

.card.has-desc:not(.has-title) .card-content {
  position: relative;
}

.card.has-desc:not(.has-title) .card-content::after {
  content: '';
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 28px;
  height: 28px;
  background: rgba(0,0,0,0.6) url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23ffffff"><circle cx="5" cy="12" r="2"/><circle cx="12" cy="12" r="2"/><circle cx="19" cy="12" r="2"/></svg>') no-repeat center;
  background-size: 16px;
  border-radius: 50%;
  z-index: 2;
}

.card.has-video .card-content {
  position: relative;
}

.card.has-video .card-content::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  background: rgba(0,0,0,0.6) url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23ffffff"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>') no-repeat center;
  background-size: 22px;
  background-position: 55% center;
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.card.has-video:hover .card-content::before {
  opacity: 0;
}

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

#lightbox.active {
  opacity: 1;
  pointer-events: auto;
}

.lb-container {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  width: 100%;
  max-height: 98dvh;
  background: var(--card-bg);
  border-radius: 8px;
  overflow: hidden;
}

.lb-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 24px;
  cursor: pointer;
  z-index: 10;
}

.lb-image-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #000;
  flex: 0 1 auto;
  min-height: 0;
}

.lb-image-wrapper img, .lb-image-wrapper video {
  max-width: 100%;
  max-height: 98dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  flex: 0 1 auto;
  min-height: 0;
}

.lb-text {
  flex: 0 0 auto;
  max-height: 25vh;
  overflow-y: auto;
  padding: 20px;
  background: var(--card-bg);
}

.lb-text p {
  margin: 8px 0 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.reflect {
  display: inline-block;
  transform: scaleY(-1);
}