* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  cursor: none;
  background: #000;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- video layers ---------- */

.video-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: 1;
  pointer-events: none;
  background: #000;
}

.video-layer.masked {
  z-index: 2;
  /* The reveal hole (+ punched-out skull) is a clip-path set live from
     script.js — a hard vector edge, and cross-browser unlike CSS mask-image
     fragment refs (which WebKit/Safari don't apply). */
}

/* ---------- icon controls ----------
   Siblings of #stage (not descendants) so their clicks never bubble into
   the reveal-transition click handler. mix-blend-mode: difference keeps
   them readable against any footage — no separate contrast check needed. */

.icon-btn {
  position: fixed;
  top: 22px;
  z-index: 60;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  mix-blend-mode: difference;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn .icon {
  width: 20px;
  height: 20px;
  color: #fff;
  /* No filter here on purpose: mix-blend-mode: difference already does the
     contrast work (white pixel vs. any backdrop = always visible). Stacking
     filter: invert(1) on top used to flip white to black first, which
     difference-blends right back to the backdrop color — i.e. it made the
     icon exactly match its background and disappear. That was the bug. */
}

#muteBtn {
  left: 22px;
}

#muteBtn .icon-on {
  display: none;
}

#muteBtn.on .icon-on {
  display: block;
}

#muteBtn.on .icon-off {
  display: none;
}

#gridBtn {
  right: 22px;
}

/* Contact + socials in the bottom-left, mirroring the top icons. The <nav> uses
   display:contents so it generates no box — otherwise its stacking context would
   trap the icons' mix-blend-mode and they'd vanish on light footage. Each icon
   keeps .icon-btn's own fixed position + mix-blend-mode: difference, blending
   against the video behind it. Spaced ~52px apart, sharing bottom:22px so the
   row lines up cleanly. */
#socialCluster {
  display: contents;
}

#contactBtn,
#igBtn,
#liBtn {
  top: auto;
  bottom: 22px;
  text-decoration: none;
}

#contactBtn { left: 22px; }
#igBtn { left: 74px; }
#liBtn { left: 126px; }

/* ---------- buffering spinner ---------- */
#loader {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  z-index: 55;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  mix-blend-mode: difference;
  transition: opacity 0.25s ease;
}

#loader.show {
  opacity: 1;
  visibility: visible;
  animation: loaderSpin 0.8s linear infinite;
}

@keyframes loaderSpin {
  to { transform: rotate(360deg); }
}

/* ---------- clip picker overlay ---------- */

#gridOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px 40px;
  background: rgba(8, 8, 8, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease;
}

#gridOverlay.open {
  opacity: 1;
  visibility: visible;
}

#gridOverlay #gridClose {
  position: fixed;
  top: 22px;
  right: 22px;
  mix-blend-mode: normal;
}

#gridOverlay #gridClose .icon {
  filter: none;
  color: #fff;
}

/* Channel-guide layout: a small wordmark header over a wrapping grid. */
#gridPanel {
  width: 100%;
  max-width: 940px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
}

#gridHead {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 2px;
  color: #fff;
  flex: 0 0 auto;
}

#gridHead .grid-mark {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

#gridHead .grid-count {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

#gridList {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.grid-tile {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: 12px;
  overflow: hidden;
  background: #0c0c0c center / cover no-repeat;
  cursor: pointer;
  border: 0;
  padding: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1),
              box-shadow 0.22s ease;
}

/* Scrim only over the label area, so thumbnails read clean up top. */
.grid-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0) 46%);
  pointer-events: none;
}

.grid-tile:hover,
.grid-tile:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55), 0 0 0 2px #fff;
  outline: none;
}

.grid-tile.active {
  box-shadow: 0 0 0 2px #fff, 0 0 22px rgba(255, 255, 255, 0.25);
}

/* Thumbless tiles (e.g. fresh phone uploads) still look intentional:
   a big channel number on a dark card. */
.grid-tile.no-thumb {
  background:
    radial-gradient(120% 90% at 50% 0%, #1c1c1c 0%, #0c0c0c 70%);
}
.grid-tile.no-thumb .grid-tile-num {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  font-size: clamp(34px, 8vw, 54px);
  opacity: 0.5;
}

.grid-tile-num {
  position: absolute;
  top: 9px;
  left: 11px;
  font: 700 13px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);
  z-index: 2;
}

.grid-tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22px 12px 11px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
  z-index: 2;
}

/* "Now playing" dot on the active tile. */
.grid-tile.active .grid-tile-num::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: #fff;
  vertical-align: middle;
  box-shadow: 0 0 8px #fff;
  animation: gridPulse 1.6s ease-in-out infinite;
}
@keyframes gridPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

@media (pointer: coarse) {
  #stage {
    cursor: default;
    /* Let the reveal-drag own touch gestures instead of scrolling/zooming. */
    touch-action: none;
  }
}
