:root {
  --cream: #f8ecd2;
  --brown: #8a5a2b;
  --brown-dark: #5c3a1a;
  --radius: 8px;
  --border: 2px solid var(--brown);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--brown-dark);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

.topbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clickmore {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 50;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--brown-dark);
  border: 2px solid var(--brown-dark);
  border-radius: 999px;
  padding: 8px 16px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(90, 55, 20, 0.25);
}
.clickmore:hover { background: #fff; color: var(--brown-dark); }

.searchwrap {
  position: relative;
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  padding: 6px 6px 6px 18px;
}

.search {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  padding: 10px 0;
  color: #444;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--cream);
}

.card {
  position: relative;
  background: #fff;
  border: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.featured-wrap {
  margin-top: 20px;
}

.card.featured {
  width: 100%;
  height: 420px;
}

.card.featured img,
.card.featured video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.count {
  text-align: center;
  font-size: 12px;
  color: var(--brown);
  opacity: 0.7;
  margin: 16px 0 8px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-top: 8px;
}

.grid .card {
  aspect-ratio: 1 / 1;
  width: 100%;
}

.grid .card img,
.grid .card video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.grid .card .cardtitle {
  display: none;
}

@media (max-width: 700px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card.featured { height: 280px; }
}

.sentinel { height: 1px; }

.loading {
  text-align: center;
  padding: 20px;
  color: var(--brown);
  opacity: 0.7;
  font-size: 14px;
}
.loading[hidden] { display: none; }

.empty {
  text-align: center;
  padding: 40px;
  color: var(--brown);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.lightbox-content {
  position: relative;
  z-index: 1;
  background: var(--cream);
  border: var(--border);
  border-radius: var(--radius);
  max-width: min(90vw, 800px);
  max-height: 90vh;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.lightbox-media {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
}

.lightbox-media img,
.lightbox-media video {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
}

.lightbox-title {
  margin: 0;
  font-size: 18px;
  text-align: center;
}

.lightbox-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.lightbox-tags span {
  background: #fff;
  border: 1px solid var(--brown);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--brown-dark);
}

.lightbox-download {
  background: var(--brown);
  color: #fff;
  text-decoration: none;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
}
.lightbox-download:hover { background: var(--brown-dark); }

.lightbox-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--brown-dark);
  cursor: pointer;
  padding: 4px 10px;
}

/* subtle cue while a search request is in flight */
input.search.searching {
  background-image: linear-gradient(90deg, transparent, rgba(138, 90, 43, 0.15), transparent);
  background-size: 200% 100%;
  animation: searching-sweep 1s linear infinite;
}
@keyframes searching-sweep {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* --- live ticker: one slim line, newest meme rotating + since-last-visit chip --- */
.ticker {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.marquee {
  flex: 1;
  overflow: hidden;
  border-radius: 8px;
  /* vertical headroom so hover-scaled thumbs aren't clipped; negative margin
     keeps the strip visually as slim as before */
  /* room for scale(1.35) growth + shadow blur so nothing gets clipped */
  padding: 28px 0;
  margin: -28px 0;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
}
.marquee-track {
  display: flex;
  gap: 10px;
  width: max-content;
}
.marquee-track.scrolling {
  animation: marquee-slide var(--marquee-secs, 40s) linear infinite;
}
.marquee:hover .marquee-track { animation-play-state: paused; }
@keyframes marquee-slide {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.marquee-thumb {
  flex: none;
  width: 96px;
  cursor: pointer;
  text-align: center;
}
.marquee-thumb img, .marquee-thumb video {
  width: 96px;
  height: 72px;
  object-fit: cover;
  border: 2px solid var(--brown-dark);
  border-radius: 8px;
  background: #fff;
  display: block;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.marquee-thumb {
  position: relative;
}
.marquee-thumb:hover {
  z-index: 5;
}
.marquee-thumb:hover img, .marquee-thumb:hover video {
  /* transform doesn't affect layout flow — neighbors stay put */
  transform: scale(1.35);
  box-shadow: 0 4px 14px rgba(90, 55, 20, 0.35);
}
.marquee-thumb small {
  display: block;
  font-size: 10px;
  color: var(--brown-dark);
  opacity: 0.7;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticker-since {
  flex: none;
  border: 1.5px solid var(--brown-dark);
  background: #fff;
  color: var(--brown-dark);
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
}
.ticker-since:hover, .ticker-since.active {
  background: var(--brown-dark);
  color: #fff;
}

.new-icon {
  width: 11px;
  height: 11px;
  fill: var(--brown-dark);
  vertical-align: -1px;
  margin-right: 3px;
}

/* top nav text links (left) — the fixed Meme Exhibition button floats right */
.navlinks {
  display: flex;
  gap: 18px;
  align-items: center;
  padding-right: 190px; /* keep clear of the fixed button */
  min-height: 30px;
}
.navlinks a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 700;
  color: var(--brown-dark);
  text-decoration: none;
  opacity: 0.9;
}
.navlinks a:hover { text-decoration: underline; }
.nav-icon { width: 13px; height: 13px; fill: currentColor; }

/* copy-to-clipboard button on cards + lightbox */
.copybtn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 2px solid var(--brown-dark);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--brown-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  z-index: 3;
}
.card:hover .copybtn, .copybtn.in-lightbox { opacity: 1; }
.copybtn:hover {
  background: var(--brown-dark);
  color: #fff;
  transform: scale(1.12);
}
.copybtn { transition: opacity 0.15s ease, background 0.15s ease, transform 0.12s ease, color 0.15s ease; }
.copybtn svg { width: 16px; height: 16px; fill: currentColor; }
.copybtn svg + svg { display: none; }
.copybtn.copied { background: var(--brown-dark); color: #fff; }
.copybtn.copied svg { display: none; }
.copybtn.copied svg + svg { display: block; }
.copybtn.copyfail { background: #7a2b2b; border-color: #7a2b2b; color: #fff; }
.copybtn.in-lightbox {
  position: static;
  width: auto;
  padding: 0 14px;
  height: 38px;
  gap: 6px;
  margin-right: 8px;
}

/* media-type filter (All / Pics / Videos) */
.filterbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 10px;
}
.seg {
  display: inline-flex;
  border: 2px solid var(--brown-dark);
  border-radius: 999px;
  overflow: hidden;
  background: #fff;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--brown-dark);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 16px;
  cursor: pointer;
}
.seg button + button { border-left: 1.5px solid var(--brown-dark); }
.seg button.active { background: var(--brown-dark); color: #fff; }
.seg-spacer { width: 170px; } /* balances the segmented control so the count stays centered */
@media (max-width: 640px) { .seg-spacer { display: none; } }

.copytoast {
  position: absolute;
  top: 46px;
  right: 8px;
  background: var(--brown-dark);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  white-space: nowrap;
  z-index: 4;
  animation: toast-in 0.15s ease;
  pointer-events: none;
}
.copytoast.fail { background: #7a2b2b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }
.lightbox-content .copytoast { position: static; display: inline-block; margin-right: 8px; }

/* favorites */
.favtoggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--brown-dark);
  border-radius: 999px;
  background: #fff;
  color: var(--brown-dark);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 16px;
  cursor: pointer;
}
.favtoggle svg { width: 14px; height: 14px; fill: currentColor; }
.favtoggle:hover, .favtoggle.active { background: #d4a017; border-color: #b8860b; color: #fff; }

.favbtn {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 34px;
  height: 34px;
  border: 2px solid var(--brown-dark);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--brown-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.12s ease, color 0.15s ease;
  z-index: 3;
}
.card:hover .favbtn { opacity: 1; }
.favbtn:hover { transform: scale(1.12); }
.favbtn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; }
.favbtn.faved { opacity: 1; background: #d4a017; border-color: #b8860b; color: #fff; }
.favbtn.faved svg { fill: #fff; stroke: #fff; }

.card.fav { border-color: #d4a017; box-shadow: 0 0 0 1.5px #d4a017, 0 2px 10px rgba(212, 160, 23, 0.35); }
