/* StonkPad meme gallery: collage background, caption ticker, the Stonks wall, art slots.
   Uses the page's --accent / --text / --panel / --line tokens when present. */

:root {
  --mg-accent: var(--accent, #35d07f);
  --mg-text: var(--text, #eef3f1);
  --mg-dim: var(--dim, #8c9794);
  --mg-panel: var(--panel, #0f1213);
  --mg-line: var(--line, #1b2022);
  --mg-bg: var(--bg, #07090a);
}

/* ---------- 1. collage background ---------- */
[data-meme-bg] {
  position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  background: var(--mg-bg); contain: strict;
}
[data-meme-bg] .mg-tiles {
  position: absolute; top: -20%; left: -20%; width: 140%; height: 140%;
  display: grid; grid-template-columns: repeat(var(--mg-cols, 10), 1fr); gap: 10px;
  transform: rotate(-8deg); opacity: .16;
  animation: mg-drift 140s linear infinite;
  will-change: transform; contain: layout paint;
}
[data-meme-bg] .mg-tiles img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block;
  opacity: 0; transition: opacity 1.2s ease;
}
[data-meme-bg] .mg-tiles img.on { opacity: 1; }
[data-meme-bg]::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, transparent 0%, var(--mg-bg) 78%),
    linear-gradient(180deg, transparent 40%, var(--mg-bg) 100%);
}
@keyframes mg-drift {
  from { transform: rotate(-8deg) translate3d(0, 0, 0); }
  to { transform: rotate(-8deg) translate3d(-6%, -12%, 0); }
}

/* ---------- 2. caption ticker ---------- */
[data-meme-ticker] {
  position: relative; overflow: hidden; border-block: 1px solid var(--mg-line);
  background: color-mix(in srgb, var(--mg-panel) 82%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  mask: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}
.mg-track { display: flex; width: max-content; animation: mg-scroll var(--mg-speed, 90s) linear infinite; }
[data-meme-ticker]:hover .mg-track { animation-play-state: paused; }
.mg-chip {
  display: inline-flex; align-items: center; gap: 10px; padding: 10px 22px 10px 10px;
  font: 600 13px/1 Archivo, system-ui, sans-serif; color: var(--mg-text); white-space: nowrap; cursor: pointer;
  text-decoration: none; border-right: 1px solid var(--mg-line);
}
.mg-chip img { width: 30px; height: 30px; border-radius: 7px; object-fit: cover; }
.mg-chip:hover { color: var(--mg-accent); }
.mg-chip .mg-up { color: var(--mg-accent); font-size: 11px; }
@keyframes mg-scroll { to { transform: translateX(-50%); } }

/* ---------- 3. the Stonks wall ---------- */
[data-meme-gallery] { position: relative; }
.mg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.mg-search {
  flex: 1 1 220px; min-width: 0; height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--mg-line); background: color-mix(in srgb, var(--mg-bg) 85%, transparent);
  color: var(--mg-text); font: 500 13px Archivo, system-ui, sans-serif;
}
.mg-search:focus { outline: none; border-color: var(--mg-accent); }
.mg-btn {
  height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--mg-line);
  background: transparent; color: var(--mg-text); font: 700 12.5px Archivo, system-ui, sans-serif; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; transition: border-color .15s, background .15s, transform .15s;
}
.mg-btn:hover { border-color: var(--mg-dim); transform: translateY(-1px); }
.mg-btn.mg-hot { background: var(--mg-accent); color: var(--on-accent, #03140a); border-color: var(--mg-accent); }
.mg-tags { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 18px; scrollbar-width: none; }
.mg-tags::-webkit-scrollbar { display: none; }
.mg-tag {
  flex: none; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--mg-line); background: transparent;
  color: var(--mg-dim); font: 500 10.5px "Martian Mono", ui-monospace, monospace; letter-spacing: .05em; text-transform: uppercase; cursor: pointer;
}
.mg-tag.on { background: var(--mg-text); color: var(--mg-bg); border-color: var(--mg-text); }
.mg-count { font: 500 10.5px "Martian Mono", ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase; color: var(--mg-dim); }

.mg-grid { display: flex; gap: 12px; align-items: flex-start; }
.mg-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.mg-card {
  margin: 0; position: relative; border-radius: 14px; overflow: hidden; cursor: zoom-in;
  background: var(--mg-panel); border: 1px solid var(--mg-line);
  transform-style: preserve-3d; transition: transform .25s ease, box-shadow .25s ease, opacity .5s ease;
  opacity: 0; transform: translateY(18px) scale(.98);
}
.mg-card.in { opacity: 1; transform: none; }
.mg-card:hover { box-shadow: 0 18px 40px rgba(0, 0, 0, .45), 0 0 0 1px var(--mg-accent); z-index: 2; }
.mg-card img { display: block; width: 100%; height: auto; background: var(--mg-line); }
.mg-card figcaption {
  position: absolute; inset: auto 0 0 0; padding: 26px 12px 10px; color: #fff; font: 500 11.5px/1.35 Archivo, system-ui, sans-serif;
  background: linear-gradient(transparent, rgba(0, 0, 0, .82)); opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s;
}
.mg-card:hover figcaption, .mg-card:focus-visible figcaption { opacity: 1; transform: none; }
.mg-card .mg-badge {
  position: absolute; top: 8px; left: 8px; padding: 3px 7px; border-radius: 999px; background: rgba(0, 0, 0, .65); color: #fff;
  font: 600 9.5px "Martian Mono", ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase;
}
.mg-more { display: flex; justify-content: center; margin-top: 18px; }
.mg-credit { margin-top: 14px; text-align: center; font: 400 10.5px "Martian Mono", ui-monospace, monospace; color: var(--mg-dim); }
.mg-credit a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }

/* roulette spotlight */
.mg-spot {
  display: none; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 22px; align-items: center;
  margin-bottom: 18px; padding: 16px; border-radius: 16px; border: 1px solid var(--mg-accent);
  background: color-mix(in srgb, var(--mg-panel) 90%, transparent);
}
.mg-spot.on { display: grid; animation: mg-pop .35s cubic-bezier(.3, 1.5, .5, 1); }
.mg-spot .mg-reel { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--mg-line); }
.mg-spot .mg-reel img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mg-spot .mg-reel.spinning img { animation: mg-flick .09s steps(1) infinite; }
.mg-spot h3 { margin: 0 0 8px; font: 800 22px/1.15 Archivo, system-ui, sans-serif; color: var(--mg-text); }
.mg-spot p { margin: 0 0 14px; color: var(--mg-dim); font-size: 13.5px; line-height: 1.55; }
@keyframes mg-pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes mg-flick { 50% { filter: brightness(1.4) hue-rotate(40deg); } }

/* lightbox */
.mg-lb {
  position: fixed; inset: 0; z-index: 1000; display: none; place-items: center; padding: 24px;
  background: rgba(3, 5, 6, .9); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.mg-lb.on { display: grid; animation: mg-fade .2s ease; }
.mg-lb figure { margin: 0; max-width: min(92vw, 900px); display: grid; gap: 12px; justify-items: center; }
.mg-lb img { max-width: 100%; max-height: 74vh; border-radius: 12px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.mg-lb figcaption { color: #e9efec; font: 400 14px/1.5 Archivo, system-ui, sans-serif; text-align: center; max-width: 70ch; }
.mg-lb .mg-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.mg-lb .mg-btn { color: #fff; border-color: rgba(255, 255, 255, .25); }
.mg-lb .mg-nav {
  position: fixed; top: 50%; translate: 0 -50%; width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(0, 0, 0, .4); color: #fff; font-size: 22px; cursor: pointer;
}
.mg-lb .mg-prev { left: 16px; } .mg-lb .mg-next { right: 16px; }
.mg-lb .mg-close { position: fixed; top: 16px; right: 16px; }
@keyframes mg-fade { from { opacity: 0; } }

/* ---------- 4. art slots ---------- */
[data-meme-art] { position: relative; overflow: hidden; }
.mg-art {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .22; pointer-events: none;
  animation: mg-float 9s ease-in-out infinite alternate;
}
@keyframes mg-float { from { transform: scale(1.04) translateY(0); } to { transform: scale(1.1) translateY(-3%); } }

@media (max-width: 640px) {
  .mg-grid, .mg-col { gap: 8px; }
  .mg-card { border-radius: 10px; }
  .mg-spot { grid-template-columns: 1fr; }
  .mg-lb .mg-nav { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  [data-meme-bg] .mg-tiles, .mg-track, .mg-art { animation: none !important; }
  .mg-card { transition: none; opacity: 1; transform: none; }
}
