body {
  position: relative;
  /* Establish a stacking context so body::after { z-index: -1 } is trapped here
     and paints above body's bg but below content. Without this, the pseudo
     escapes to the root SC and gets occluded by html's bg from critical CSS. */
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: -5%;
  right: -5%;
  width: 500px;
  height: 600px;
  background: url('/LX.webp') no-repeat center;
  background-size: contain;
  opacity: 0.2;
  pointer-events: none;
  z-index: -1;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
}

.container {
  max-width: 960px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-top: 2rem;
}

h1 {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #e9d5ff, #c084fc, #a78bfa, #e9d5ff);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradient-shift 8s ease infinite;
  margin-bottom: 0.4rem;
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

header {
  position: relative;
}

header::before {
  content: '';
  position: absolute;
  top: -2rem;
  left: 50%;
  transform: translateX(-50%);
  width: 500px;
  height: 300px;
  background: radial-gradient(ellipse, rgba(192, 132, 252, 0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
}

.subtitle a {
  color: var(--text);
  text-decoration: none;
}

.subtitle a:hover {
  color: var(--accent);
}

.cta-btn {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.6rem 1.5rem;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 2rem;
  text-decoration: none;
  transition: background 0.2s, transform 0.15s;
}

.cta-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  color: var(--bg);
}

.contribute {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.contribute a {
  color: var(--accent);
  text-decoration: none;
}

.contribute a:hover {
  color: var(--accent-hover);
}

/* Thumbnail ribbon */
.ribbon {
  overflow: hidden;
  margin: 1.5rem 0;
  opacity: 0;
  transition: opacity 0.5s ease;
  mask-image: linear-gradient(to right, transparent, black 8%, black 92%, transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 8%, black 92%, transparent);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ribbon.loaded {
  opacity: 0.5;
}

.ribbon.loaded:hover {
  opacity: 0.7;
}

.ribbon-track {
  display: flex;
  gap: 0.5rem;
  width: max-content;
  animation: scroll-left 80s linear infinite;
}

.ribbon-track.reverse {
  animation-name: scroll-right;
  animation-duration: 90s;
}

.ribbon:hover .ribbon-track {
  animation-play-state: paused;
}

.ribbon-track a {
  flex-shrink: 0;
  display: block;
  border-radius: 0.4rem;
  overflow: hidden;
  transition: opacity 0.2s;
}

.ribbon-track a:hover {
  opacity: 0.8;
}

.ribbon-track img {
  width: 120px;
  height: 70px;
  object-fit: cover;
  border-radius: 0.4rem;
  flex-shrink: 0;
}

.ribbon-track img[data-error],
.card-thumb img[data-error] {
  display: none;
}

.ribbon-thumb-composite {
  width: 120px;
  height: 70px;
  background-size: 340% auto;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 0.4rem;
  flex-shrink: 0;
}

@keyframes scroll-left {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@keyframes scroll-right {
  from { transform: translateX(-50%); }
  to { transform: translateX(0); }
}

/* Tag filter bar */
.tag-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin: 0.75rem auto 1rem;
  max-width: 760px;
}

.tag-chip {
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.25rem 0.6rem;
  border-radius: 0.3rem;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  color: white;
}

.tag-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.5);
}

.tag-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tag-chip.tag-default {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-muted);
}

/* When any chip is active, dim siblings so the active one stands out by
   contrast — no extra ring needed since the search input already echoes the
   tag name as direct confirmation. */
.tag-bar.has-active .tag-chip:not(.active) {
  opacity: 0.45;
}

.tag-chip-count {
  font-size: 0.65rem;
  font-weight: 500;
  opacity: 0.75;
}

/* Search */
.search-wrap {
  max-width: 480px;
  margin: 0 auto 0.75rem;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-wrap input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 1rem 0.75rem 2.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.search-wrap input[type="text"]::placeholder { color: var(--text-muted); }
.search-wrap input[type="text"]:focus { border-color: var(--accent); }

.r18-toggle {
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.r18-toggle input {
  cursor: pointer;
  accent-color: var(--accent);
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
  pointer-events: none;
}

/* Year sections */
.year-section {
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
  transition: box-shadow 0.3s ease;
}

.year-section.open {
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.4);
}

.year-section .files {
  display: none;
}

.year-section.open .files {
  display: grid;
}

.year-header {
  padding: 1.1rem 1.5rem;
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

@media (hover: hover) {
  .year-header:hover { background: rgba(255, 255, 255, 0.03); }
}

.year-header::before {
  content: '\25B6';
  font-size: 0.8rem;
  color: var(--accent);
  transition: transform 0.3s ease;
  display: inline-block;
  flex-shrink: 0;
}

.year-section.open .year-header::before {
  transform: rotate(90deg);
}

.year-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Card grid */
.files {
  padding: 0 1.25rem 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.file-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
}

@media (hover: hover) {
  .file-card {
    animation: card-enter 0.4s ease both;
  }
}

@keyframes card-enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.file-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px -8px rgba(0, 0, 0, 0.5),
              0 0 0 1px var(--accent-glow);
  border-color: rgba(192, 132, 252, 0.3);
}

.card-thumb {
  position: relative;
  width: 100%;
  height: 150px;
  overflow: hidden;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.file-card:hover .card-thumb img {
  transform: scale(1.05);
}

.card-thumb::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(transparent, rgba(13, 11, 18, 0.6));
  pointer-events: none;
}

.card-body {
  padding: 0.875rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-title {
  font-weight: 500;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  line-height: 1.4;
}

.card-creator {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.card-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: auto;
}

.card-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 0.25rem;
  z-index: 2;
}

.card-thumb-placeholder {
  width: 100%;
  height: 150px;
  background: linear-gradient(135deg, var(--surface), var(--card));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 2rem;
  position: relative;
}

.no-results {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 0;
  font-size: 1.1rem;
}

/* Footer */
footer {
  max-width: 960px;
  margin: 3rem auto 0;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.8;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover { color: var(--accent-hover); }

/* Loading */
.loading-text {
  text-align: center;
  color: var(--text-muted);
  padding: 4rem 0;
  font-size: 1.1rem;
}

@media (max-width: 640px) {
  h1 { font-size: 2rem; }
  .files {
    grid-template-columns: 1fr;
  }
  .card-thumb { height: 120px; }
}
