:root{
  --bg-time-offset: 0s;     /* set by bg-anim-sync.js */
  --bg-cycle: 600s;         /* 10 minutes */
}

/* optional: quick test mode */
:root.debug { --bg-cycle: 20s; }

html,body{
  height: 100%;
  margin: 0;
  background: #000;
  color: rgba(255,255,255,0.92);
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,"Helvetica Neue",Arial,sans-serif;
}

/* =========================
   Background stack (base = HOME)
   ========================= */

.bg-stack{
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
  isolation: isolate;
}

/* two-layer image stack */
.bg-under, .bg-over{
  position: absolute;
  inset: 0;
  background-position: 50% 50%;
  background-size: cover;
  background-repeat: no-repeat;
  transform: translateZ(0);
}

/* HOME defaults */
.bg-under{
  background-image: url("/assets/bg/RBH-2.webp");
  filter: saturate(1.05) contrast(1.05);
  background-color: #222; /* fallback */
  z-index: 1;
}

.bg-over{
  background-image: url("/assets/bg/RBH-1.webp");
  opacity: 1;
  z-index: 2;
}

/* VHS overlays (exist always, animate only on HOME) */
.bg-stack::before,
.bg-stack::after{
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 3;
}

/* scanlines + vignette */
.bg-stack::before{
  background-image:
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,0.05) 0px,
      rgba(255,255,255,0.05) 1px,
      rgba(0,0,0,0) 2px,
      rgba(0,0,0,0) 4px
    ),
    radial-gradient(
      circle at 50% 50%,
      rgba(0,0,0,0) 0%,
      rgba(0,0,0,0.35) 70%,
      rgba(0,0,0,0.65) 100%
    );
  mix-blend-mode: overlay;
}

/* noise layer */
.bg-stack::after{
  background-image:
    linear-gradient(
      to bottom,
      rgba(0,0,0,0) 0%,
      rgba(255,255,255,0.06) 48%,
      rgba(255,255,255,0.18) 50%,
      rgba(255,255,255,0.06) 52%,
      rgba(0,0,0,0) 100%
    ),
    linear-gradient(0deg, rgba(255,255,255,0.06), rgba(0,0,0,0.06)),
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,0.03) 0px,
      rgba(255,255,255,0.03) 1px,
      rgba(0,0,0,0) 2px,
      rgba(0,0,0,0) 6px
    );
  mix-blend-mode: overlay;
  opacity: 0;
  transform: translateZ(0);
}

.bg-snow{
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 4;
  mix-blend-mode: screen;
  filter: contrast(1.1);
  background-image:
    radial-gradient(circle at 10% 20%, rgba(255,255,255,0.12) 0 1px, transparent 1px 5px),
    radial-gradient(circle at 70% 80%, rgba(255,255,255,0.10) 0 1px, transparent 1px 6px),
    radial-gradient(circle at 40% 50%, rgba(255,255,255,0.08) 0 1px, transparent 1px 4px);
  background-size: 120px 120px, 180px 180px, 90px 90px;
}

/* =========================
   HOME animations (gated)
   ========================= */
/* ::before — scanlines + tracking + vignette opacity */
body.bg-anim-ready[data-page="home"] .bg-stack::before {
  animation: rbh-scanlines var(--bg-cycle) linear infinite;
  animation-delay: var(--bg-time-offset);
}

/* ::after — grain/noise layer */
body.bg-anim-ready[data-page="home"] .bg-stack::after {
  animation:
    rbh-grain     var(--bg-cycle) linear    infinite,
    rbh-noise-fast 0.18s          steps(2,end) infinite;
  animation-delay: var(--bg-time-offset), var(--bg-time-offset);
}

/* snow */
body.bg-anim-ready[data-page="home"] .bg-snow {
  animation:
    rbh-snow-envelope var(--bg-cycle) linear       infinite,
    rbh-snow-jitter    0.12s          steps(2,end) infinite;
  animation-delay: var(--bg-time-offset), var(--bg-time-offset);
}

/* fg image layer — shake stays separate since it owns transform alone */
body.bg-anim-ready[data-page="home"] .bg-over {
  animation:
    rbh-fg-distort var(--bg-cycle) linear       infinite,
    rbh-shake      var(--bg-cycle) steps(12,end) infinite,
    rbh-drift      23s             ease-in-out   infinite alternate;
  animation-delay:
    var(--bg-time-offset),
    var(--bg-time-offset),
    0s;
}

/* =========================
   Persona pages: slideshow only
   ========================= */

body[data-page="hazel"] .bg-stack::before,
body[data-page="hazel"] .bg-stack::after,
body[data-page="riotmike"] .bg-stack::before,
body[data-page="riotmike"] .bg-stack::after,
body[data-page="bradley"] .bg-stack::before,
body[data-page="bradley"] .bg-stack::after,
body[data-page="hazel"] .bg-snow,
body[data-page="riotmike"] .bg-snow,
body[data-page="bradley"] .bg-snow{
  display: none;
}

/* persona slideshow crossfade (bg-under updated by JS) */
body[data-page="hazel"] .bg-under,
body[data-page="riotmike"] .bg-under,
body[data-page="bradley"] .bg-under{
  transition: background-image 3s ease-in-out;
}

/* reduced motion */
@media (prefers-reduced-motion: reduce){
  .bg-under,.bg-over,.bg-stack::before,.bg-stack::after,.bg-snow{
    transition: none !important;
    animation: none !important;
  }

  body[data-page="hazel"] .bg-under    { background-image: url("/assets/bg/hazel-1.webp") !important; }
  body[data-page="riotmike"] .bg-under { background-image: url("/assets/bg/riotmike-1.webp") !important; }
  body[data-page="bradley"] .bg-under  { background-image: url("/assets/bg/bradley-1.webp") !important; }
}

/* =========================
   Merged keyframes
   ========================= */

/* ---- .bg-stack::before ----
   Controls: opacity, filter, background-position
   Merges: rbh-envelope + rbh-tracking + rbh-scan-jitter
   background-position format: scanlines-layer, vignette-layer
   ---------------------------------------------------------------- */
@keyframes rbh-scanlines {
  /* quiet */
  0%, 88%  {
    opacity: 0;
    filter: none;
    background-position: 0 0, 50% 50%;
  }

  /* ramp up — tracking bands drift, scanlines sharpen */
  91%  {
    opacity: 0.15;
    filter: none;
    background-position: 0 -2px, 50% 50%;
  }
  93%  {
    opacity: 0.28;
    filter: none;
    background-position: 0 12%, 50% 50%;
  }
  95%  {
    opacity: 0.50;
    filter: none;
    background-position: 0 -5px, 50% 50%;
  }
  96%  {
    opacity: 0.68;
    filter: none;
    background-position: 0 32%, 50% 50%;
  }
  96.5% {
    opacity: 0.82;
    filter: none;
    background-position: 0 7px, 50% 50%;
  }

  /* clean takeover window */
  97%, 98.5% {
    opacity: 0;
    filter: none;
    background-position: 0 0, 50% 50%;
  }

  /* ramp down */
  99%  {
    opacity: 0.38;
    filter: none;
    background-position: 0 2px, 50% 50%;
  }
  99.5% {
    opacity: 0.16;
    filter: none;
    background-position: 0 -1px, 50% 50%;
  }
  100% {
    opacity: 0;
    filter: none;
    background-position: 0 0, 50% 50%;
  }
}


/* ---- .bg-stack::after ----
   Controls: opacity, transform, filter
   Merges: rbh-envelope + rbh-noise (slow, cycle-synced)
   rbh-noise-fast (0.18s loop) runs alongside and only touches
   transform+filter at high frequency — no conflict since
   rbh-grain resets both to neutral during the quiet window.
   ---------------------------------------------------------------- */
@keyframes rbh-grain {
  /* quiet — keep transform/filter neutral so fast noise loop is visible */
  0%, 88%  { opacity: 0; transform: translate3d(0,0,0); filter: none; }

  /* ramp up */
  91%  { opacity: 0.12; transform: translate3d(-1px, 1px,0); filter: contrast(1.05); }
  93%  { opacity: 0.28; transform: translate3d( 1px,-1px,0); filter: contrast(1.10); }
  95%  { opacity: 0.50; transform: translate3d(-2px, 1px,0); filter: contrast(1.16); }
  96%  { opacity: 0.68; transform: translate3d( 1px,-2px,0); filter: contrast(1.20); }
  96.5% { opacity: 0.82; transform: translate3d( 2px,-2px,0); filter: contrast(1.22); }

  /* clean takeover window */
  97%, 98.5% { opacity: 0; transform: translate3d(0,0,0); filter: none; }

  /* ramp down */
  99%  { opacity: 0.36; transform: translate3d(-1px, 1px,0); filter: contrast(1.08); }
  99.5% { opacity: 0.16; transform: translate3d( 1px, 0px,0); filter: contrast(1.04); }
  100% { opacity: 0;    transform: translate3d(0,0,0);       filter: none; }
}

/* Fast noise jitter — only meaningful when rbh-grain has opacity > 0.
   Kept as a separate short loop so it doesn't need cycle-length keyframes. */
@keyframes rbh-noise-fast {
  0%   { transform: translate3d( 0px,  0px, 0); }
  50%  { transform: translate3d(-1px,  1px, 0); }
  100% { transform: translate3d( 1px, -1px, 0); }
}


/* ---- .bg-snow ----
   Controls: opacity (envelope), transform + background-position (jitter)
   No conflicts — kept as two separate animations, renamed for clarity.
   ---------------------------------------------------------------- */
@keyframes rbh-snow-envelope {
  0%, 88%    { opacity: 0; }
  91%        { opacity: 0.04; }
  93%        { opacity: 0.10; }
  95%        { opacity: 0.22; }
  96.5%      { opacity: 0.38; }
  97%, 98.5% { opacity: 0; }
  99%        { opacity: 0.18; }
  99.5%      { opacity: 0.08; }
  100%       { opacity: 0; }
}

/* rbh-snow-jitter unchanged — no conflicts */
@keyframes rbh-snow-jitter {
  0%   { transform: translate3d( 0px,  0px, 0); background-position:   0px   0px,   0px   0px, 0px 0px; }
  50%  { transform: translate3d(-2px,  1px, 0); background-position:  30px -10px, -18px  22px, 12px -8px; }
  100% { transform: translate3d( 2px, -1px, 0); background-position: -24px  16px,  25px -14px, -10px  9px; }
}


/* ---- .bg-over ----
   Controls: opacity, filter, mask-image (rbh-fg-distort)
             transform             (rbh-shake — no conflicts, keep separate)
             background-position   (rbh-drift — no conflicts, keep separate)

   Merges: rbh-glitch + rbh-instability + rbh-peek
   Priority decisions:
     filter     → instability values (richer than glitch's plain none)
     mask-image → glitch bands during build-up, peek bands just before takeover,
                  both cleared during takeover window and ramp-down
   ---------------------------------------------------------------- */
@keyframes rbh-fg-distort {
  /* quiet */
  0%, 88% {
    opacity: 1;
    filter: none;
    mask-image: none;
    -webkit-mask-image: none;
    background-position: 50% 50%;
  }

  /* early distortion begins — subtle filter, no mask yet */
  91% {
    opacity: 1;
    filter: saturate(1.05) contrast(1.06);
    mask-image: none;
    -webkit-mask-image: none;
    background-position: 50% 50%;
  }

  /* glitch bands start, chromatic aberration builds */
  93% {
    opacity: 0.99;
    filter: saturate(1.10) contrast(1.10)
            drop-shadow(-1px 0 rgba(255,40,40,.18))
            drop-shadow( 1px 0 rgba(40,200,255,.12));
    mask-image: repeating-linear-gradient(to bottom, #000 0 28px, transparent 28px 36px);
    -webkit-mask-image: repeating-linear-gradient(to bottom, #000 0 28px, transparent 28px 36px);
    background-position: 49% 50%;
  }

  /* bands tighten, aberration peaks */
  95% {
    opacity: 0.97;
    filter: saturate(1.12) contrast(1.12)
            drop-shadow(-2px 0 rgba(255,40,40,.22))
            drop-shadow( 2px 0 rgba(40,200,255,.16));
    mask-image: repeating-linear-gradient(to bottom, #000 0 18px, transparent 18px 36px);
    -webkit-mask-image: repeating-linear-gradient(to bottom, #000 0 18px, transparent 18px 36px);
    background-position: 48% 50%;
  }

  /* peek — fine bands just before fg disappears */
  96.5% {
    opacity: 0.95;
    filter: saturate(1.15) contrast(1.15)
            drop-shadow(-2px 0 rgba(255,40,40,.28))
            drop-shadow( 2px 0 rgba(40,200,255,.20));
    mask-image: repeating-linear-gradient(to bottom, #000 0 6px, transparent 6px 14px);
    -webkit-mask-image: repeating-linear-gradient(to bottom, #000 0 6px, transparent 6px 14px);
    mask-position: 0 12px;
    -webkit-mask-position: 0 12px;
    background-position: 48% 50%;
  }

  /* clean takeover — fg fully hidden */
  97%, 98.5% {
    opacity: 0;
    filter: none;
    mask-image: none;
    -webkit-mask-image: none;
    background-position: 50% 50%;
  }

  /* return — fg snaps back, slight position jitter */
  99% {
    opacity: 1;
    filter: saturate(1.06) contrast(1.06);
    mask-image: none;
    -webkit-mask-image: none;
    background-position: 51% 50%;
  }
  99.5% {
    opacity: 1;
    filter: none;
    mask-image: none;
    -webkit-mask-image: none;
    background-position: 50.5% 50%;
  }
  100% {
    opacity: 1;
    filter: none;
    mask-image: none;
    -webkit-mask-image: none;
    background-position: 50% 50%;
  }
}

/* rbh-shake unchanged — owns transform, no conflicts */
@keyframes rbh-shake {
  0%, 88%  { transform: translate3d(0,0,0) scale(1); }
  92%      { transform: translate3d(-2px,  1px, 0) scale(1.01); }
  94%      { transform: translate3d( 3px, -2px, 0) scale(1.02) rotate( 0.08deg); }
  96%      { transform: translate3d(-5px,  2px, 0) scale(1.03) rotate(-0.12deg); }
  96.5%    { transform: translate3d( 6px, -4px, 0) scale(1.03) rotate( 0.14deg); }
  97%, 98.5% { transform: translate3d(0,0,0) scale(1); }
  99.2%    { transform: translate3d(-2px,  1px, 0) scale(1.01); }
  100%     { transform: translate3d(0,0,0) scale(1); }
}

/* rbh-drift unchanged — owns background-position on bg-over, no conflicts */
@keyframes rbh-drift {
  0%   { background-position: 50%   50%;   }
  50%  { background-position: 50.2% 49.9%; }
  100% { background-position: 49.9% 50.2%; }
}

/* Layout: content sits above background */
.content {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  position: relative;
  z-index: 1;
}

.content-area {
  width: 100%;
}

/* Force footer + nav below initial viewport (mobile-safe) */
.fold-spacer {
  min-height: 120vh;
  min-height: 120svh;
}

/* Footer */
.rbh-footer {
  margin-top: 4rem;
  padding: 2rem 1rem 1rem;
  text-align: center;
  font-size: 0.7rem;
  line-height: 1.5;
  opacity: 0.6;
}

.rbh-footer-inner {
  max-width: 36rem;
  margin: 0 auto;
}

.rbh-footer p {
  margin: 0.4rem 0;
}

.rbh-footer-links a {
  color: inherit;
  text-decoration: none;
}

.rbh-footer-links a:hover,
.rbh-footer-links a:focus {
  opacity: 0.9;
  text-decoration: underline;
}

.rbh-footer-links span {
  padding: 0 0.35em;
}

/* Bottom nav */
.bottom-nav {
  margin: 1.5rem auto 2.5rem;
  padding: 0 1rem;
  text-align: center;
  font-size: 0.75rem;
  line-height: 1.4;
  opacity: 0.65;
}

.bottom-nav a {
  color: inherit;
  text-decoration: none;
}

.bottom-nav a:hover,
.bottom-nav a:focus {
  opacity: 0.9;
  text-decoration: underline;
}

.nav-sep {
  padding: 0 0.35em;
  pointer-events: none;
}

.bg-next {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 3s ease-in-out;
}

.bg-next.visible {
  opacity: 1;
}

/* =========================
   Collapsible player
   ========================= */

.player {
  max-width: 640px;
  margin: 2rem auto;
  color: #ccc;
}

.player__summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(6px);
}

.player__summary::-webkit-details-marker { display: none; }

.player__summary::after {
  content: "▾";
  float: right;
  opacity: 0.7;
  transition: transform 220ms ease;
}

.player[open] .player__summary::after {
  transform: rotate(-180deg);
}

.player__panel {
  /* animated container */
  max-height: 0;
  overflow: hidden;
  transition: max-height 380ms ease;
  will-change: max-height;
}

.player[open] .player__panel {
  /* JS sets --player-open-height; fallback if JS fails */
  max-height: var(--player-open-height, 520px);
}

.player__inner {
  padding: 0.9rem 0.1rem 0.2rem;
}

.player-frame {
  height: 420px;            /* tune this */
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.45);
}

.player-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.player__hint {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  opacity: 0.75;
}

.player__hint a {
  color: inherit;
  text-decoration: underline;
}

.player-links {
  margin-top: 0.6rem;
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.85;
}

.player-links a {
  color: inherit;
  text-decoration: none;
}

.player-links a:hover,
.player-links a:focus {
  text-decoration: underline;
  opacity: 0.95;
}

.player-links .sep {
  padding: 0 0.35em;
  opacity: 0.65;
}

