:root {
  --bg: #14161a;
  --panel: #1e2229;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #4f8cff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

main {
  flex: 1 0 auto;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid #2a2f38;
}

.header-titles {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

h1 { margin: 0; font-size: 1.4rem; }

.category-subtitle {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
}

.count { color: var(--muted); font-size: 0.9rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  padding: 24px;
}

.item {
  position: relative;
  display: block;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
  aspect-ratio: 1;
}

.item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.item:hover img { transform: scale(1.04); }

.item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.item:hover video { transform: scale(1.04); }

.badge-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 4px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  pointer-events: none;
}

.item .caption {
  position: absolute;
  inset: auto 0 0 0;
  padding: 20px 10px 8px;
  font-size: 0.78rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item:hover .caption { opacity: 1; }

.back-link {
  position: sticky;
  top: 20px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 4px;
  margin: 20px 24px 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid #2a2f38;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.back-link-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.back-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: #232833;
}

.categories-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 20px;
  padding: 32px;
}

.category-card {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: var(--card-size, 220px);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
  aspect-ratio: 1;
  transition: transform 0.2s ease;
}

.category-card:hover {
  transform: translateY(-2px);
}

.category-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.category-card:hover img { transform: scale(1.04); }

.category-card-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #2a2f38, #1e2229);
}

.category-card-info {
  position: absolute;
  inset: auto 0 0 0;
  padding: 28px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
}

.category-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
}

.category-card-count {
  font-size: 0.78rem;
  color: var(--muted);
}

.empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--muted);
}

.empty code {
  background: var(--panel);
  padding: 2px 8px;
  border-radius: 6px;
}

footer {
  padding: 20px 24px;
  text-align: center;
}

footer p {
  margin: 0;
  font-size: 0.8em;
  color: var(--muted);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
}

.lightbox[hidden] { display: none; }

.lightbox figure {
  margin: 0;
  max-width: 92vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.lightbox img,
.lightbox video {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 4px;
}

.lightbox figcaption {
  color: var(--muted);
  font-size: 0.85rem;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 20px;
}

.lightbox-close,
.lightbox-nav {
  background: none;
  border: none;
  color: #fff;
  font-size: 2.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 8px 14px;
  user-select: none;
  z-index: 101;
}

.lightbox-close:hover,
.lightbox-nav:hover { color: var(--accent); }

.lightbox-prev { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); }
.lightbox-next { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }
