/* ============================================================
   Infinite Meme Wall & Remix Station
   Dark theme — matches the mikesailab.com palette:
   bg #060606 · borders zinc-800 · text zinc-100 · accent sky-400
   ============================================================ */

:root {
  --bg: #060606;
  --surface: rgba(24, 24, 27, 0.55);
  --surface-hover: rgba(24, 24, 27, 0.85);
  --border: rgba(39, 39, 42, 0.9);
  --border-hover: #52525b;
  --fg: #f4f4f5;
  --fg-dim: #a1a1aa;
  --fg-faint: #71717a;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --radius: 14px;
  --gap: 18px;
  --maxw: 1600px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* subtle vignette so the wall floats on pure black */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 80% at 50% -10%, rgba(56, 189, 248, 0.06), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ───────────────────────── Header ───────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(6, 6, 6, 0.78);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-glyph {
  font-size: 1.7rem;
  color: var(--accent);
  line-height: 1;
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.5));
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-text p {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

.header-controls { display: flex; align-items: center; gap: 18px; }

/* share-bar containers — position only; the bar styles itself (tool-share.js) */
.header-share { display: flex; align-items: center; }
.viewer-share { display: flex; justify-content: center; }

.meme-count {
  font-size: 0.78rem;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* endless toggle */
.endless-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}
.endless-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.endless-toggle .track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #27272a;
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
}
.endless-toggle .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg-dim);
  transition: transform 0.2s, background 0.2s;
}
.endless-toggle input:checked + .track {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.endless-toggle input:checked + .track .thumb {
  transform: translateX(16px);
  background: var(--accent);
}
.endless-label {
  font-size: 0.78rem;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
}

/* ───────────────────────── Wall ───────────────────────── */
main {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 36px);
}

.wall {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
}

.wall-col {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

/* ── meme card (flip) ── */
.card {
  perspective: 1400px;
  cursor: pointer;
  border-radius: var(--radius);
  animation: rise 0.5s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-inner {
  position: relative;
  width: 100%;
  transition: transform 0.6s cubic-bezier(0.4, 0.1, 0.2, 1);
  transform-style: preserve-3d;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-front { display: block; }
.card-front img {
  display: block;
  width: 100%;
  height: auto;
  background: #111;
}

/* small creation-date stamp under each meme */
.card-date {
  display: block;
  margin-top: 7px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg-dim);
  text-align: center;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-date.is-undated {
  font-style: italic;
  color: var(--fg-faint);
}

.card:hover .card-face {
  border-color: var(--border-hover);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
}

/* tiny hint badge */
.card-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(6, 6, 6, 0.7);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s;
}
.card:hover .card-badge { opacity: 1; }

/* front-face "view large" button (mirrors the flip badge, top-right) */
.card-expand {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  background: rgba(6, 6, 6, 0.7);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  backdrop-filter: blur(6px);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.15s, border-color 0.15s;
}
.card:hover .card-expand { opacity: 1; }
.card-expand:hover { color: var(--accent); border-color: var(--accent); }
/* touch devices have no hover — keep the button reachable */
@media (hover: none) {
  .card-expand { opacity: 0.9; }
}

/* Full-size viewer overlay */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 3rem);
}
.viewer[hidden] { display: none; }
.viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 3, 4, 0.88);
  backdrop-filter: blur(4px);
}
.viewer-fig {
  position: relative;
  z-index: 1;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  max-width: 100%;
  max-height: 100%;
}
.viewer-fig img {
  max-width: min(92vw, 1100px);
  max-height: 82vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  object-fit: contain;
}
.viewer-fig figcaption {
  color: var(--fg-dim);
  font-size: 0.85rem;
  text-align: center;
  max-width: 90vw;
}
.viewer-close {
  position: absolute;
  top: clamp(0.75rem, 3vw, 1.5rem);
  right: clamp(0.75rem, 3vw, 1.5rem);
  z-index: 2;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  font-size: 1.05rem;
  background: rgba(6, 6, 6, 0.8);
  border: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.viewer-close:hover { color: var(--accent); border-color: var(--accent); }

/* back of card — meta */
.card-back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
  background:
    radial-gradient(140% 100% at 0% 0%, rgba(56, 189, 248, 0.1), transparent 55%),
    var(--surface-hover);
}
.card-back h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.card-back .back-date {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
}
.meta-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 7px;
}
.meta-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.76rem;
  color: var(--fg-dim);
  border-bottom: 1px dashed var(--border);
  padding-bottom: 6px;
}
.meta-list li span:last-child {
  color: var(--fg);
  text-align: right;
  word-break: break-word;
}
.card-back .back-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.card-back .back-actions .btn { flex: 1; }
.card-back .back-note {
  margin: 10px 0 0;
  font-size: 0.68rem;
  color: var(--fg-faint);
  line-height: 1.4;
}

/* ── sentinel / loader ── */
.sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 70px;
  margin-top: 10px;
}
.sentinel .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: pulse 1s ease-in-out infinite;
}
.sentinel .dot:nth-child(2) { animation-delay: 0.15s; }
.sentinel .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50%      { opacity: 1;    transform: scale(1.1); }
}
.sentinel.hidden { display: none; }

.wall-end {
  text-align: center;
  color: var(--fg-faint);
  font-size: 0.85rem;
  padding: 20px 0 40px;
}

/* ───────────────────── Buttons ───────────────────── */
.btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--fg);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-hover); background: #1f1f23; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  color: #04141d;
  background: var(--accent);
  border-color: var(--accent);
}
.btn-primary:hover { background: #5cc9fa; border-color: #5cc9fa; }
.btn-ghost { background: transparent; }

/* ───────────────────── Lightbox / Remix ───────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3vw, 32px);
}
.lightbox[hidden] { display: none; }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 2, 4, 0.82);
  backdrop-filter: blur(8px);
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.lightbox-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 0;
  width: min(1100px, 100%);
  max-height: 92vh;
  background: #0c0c0e;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
  animation: pop 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes pop { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

.lb-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(6, 6, 6, 0.7);
  color: var(--fg);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.lb-close:hover { background: #1f1f23; border-color: var(--border-hover); }

.lb-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(80% 80% at 50% 30%, rgba(56, 189, 248, 0.07), transparent 70%),
    repeating-linear-gradient(45deg, #0a0a0c 0 12px, #0c0c0e 12px 24px);
  min-width: 0;
}
.remix-canvas {
  max-width: 100%;
  max-height: calc(92vh - 48px);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.lb-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 20px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
}
.lb-meta h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.lb-sub { margin: 3px 0 0; font-size: 0.76rem; color: var(--fg-faint); }

.ctl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ctl label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ctl label .val {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
}
.ctl input[type="text"] {
  font-family: inherit;
  font-size: 0.86rem;
  color: var(--fg);
  background: #141417;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s;
}
.ctl input[type="text"]:focus { border-color: var(--accent); }
.ctl input[type="range"] { width: 100%; accent-color: var(--accent); }
.ctl input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #141417;
  cursor: pointer;
}
.ctl-row { display: flex; gap: 12px; align-items: flex-end; }
.ctl-row .ctl { flex: 1; }

.ctl.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding-bottom: 4px;
}
.ctl.checkbox input { accent-color: var(--accent); width: 16px; height: 16px; }
.ctl.checkbox span {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
}

.lb-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.lb-actions .btn-primary { grid-column: 1 / -1; }

.lb-toast {
  margin: 2px 0 0;
  min-height: 1em;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  transition: opacity 0.2s;
}
.lb-note {
  margin: auto 0 0;
  font-size: 0.68rem;
  color: var(--fg-faint);
  line-height: 1.4;
}

/* ───────────────────── Footer ───────────────────── */
.site-footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px 16px 40px;
  color: var(--fg-faint);
  font-size: 0.78rem;
}
.site-footer .sep { opacity: 0.5; }

/* ───────────────────── Responsive ───────────────────── */
@media (max-width: 760px) {
  .lightbox-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    max-height: 94vh;
  }
  .lb-stage { padding: 16px; }
  .remix-canvas { max-height: 42vh; }
  .lb-controls { border-left: none; border-top: 1px solid var(--border); }
  .brand-text p { display: none; }
  /* The tool-level share bar overflows the tight sticky header on phones
     (it collapses into a vertical stack). Sharing the wall itself is low-value
     on mobile; the per-meme viewer share (opened on any meme) stays available. */
  .header-share { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- Image Studio selector (header, far right) ------------------------- */
/* Three-way segmented selector, mirrors the Image Studio bar so every surface
   shows the same top-right selector. Hidden when embedded (shell bar covers it). */
.studio-switch {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(6, 6, 6, 0.6);
}
.studio-switch[hidden] { display: none; }
.studio-seg {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.34rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--fg-dim);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.studio-seg svg { width: 14px; height: 14px; }
.studio-seg:not(.is-active):hover { color: var(--fg); background: rgba(255, 255, 255, 0.06); }
.studio-seg.is-active {
  color: var(--fg);
  background: color-mix(in srgb, #a78bfa 20%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #a78bfa 50%, transparent);
  cursor: default;
}
.studio-seg.is-active svg { color: #a78bfa; }
@media (max-width: 820px) {
  .studio-seg span { display: none; }
  .studio-seg { padding: 0.4rem 0.5rem; }
}
