:root {
  --bg: #000;
  --fg: #ffffff;
  --sans: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  overflow: hidden;
  cursor: pointer;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: relative;
  height: 100vh;
  width: 100vw;
}

#frame {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#still {
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  filter: contrast(1.05) saturate(0.55) brightness(0.78);
  opacity: 0;
  transition: opacity 0.5s ease-in;
}

#still.loaded {
  opacity: 1;
}

/* analog TV static — chunky noise + horizontal scanlines + RGB phosphor mask. */
#static {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #161616;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40'><filter id='s'><feTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='1' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.95 0'/></filter><rect width='100%' height='100%' filter='url(%23s)'/></svg>");
  background-repeat: repeat;
  background-size: 320px 320px; /* 8x upscale → big chunky pixels */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  opacity: 0;
  transition: opacity 0.18s ease-out;
  animation: fuzz 0.09s steps(8) infinite;
}

/* RGB phosphor mask — vertical stripes — sits over the noise */
#static::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: repeating-linear-gradient(
    to right,
    rgba(255, 40, 40, 0.22)  0px,
    rgba(255, 40, 40, 0.22)  1.5px,
    rgba(40, 255, 40, 0.22)  1.5px,
    rgba(40, 255, 40, 0.22)  3px,
    rgba(40, 40, 255, 0.22)  3px,
    rgba(40, 40, 255, 0.22)  4.5px
  );
  mix-blend-mode: screen;
}

/* horizontal scanlines on top of phosphor */
#static::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0)   0px,
    rgba(0, 0, 0, 0)   2px,
    rgba(0, 0, 0, 0.55) 2px,
    rgba(0, 0, 0, 0.55) 3px
  );
  mix-blend-mode: multiply;
  /* subtle inner vignette suggests curved CRT glass */
  box-shadow: inset 0 0 220px rgba(0, 0, 0, 0.85);
}

#stage.loading #static {
  opacity: 1;
}

#static span {
  position: absolute;
  z-index: 2;
  bottom: 8vh;
  left: 50%;
  transform: translateX(-50%);
  font: italic 600 clamp(1.2rem, 2.2vw, 1.9rem) var(--sans);
  color: #fff;
  letter-spacing: 0.02em;
  padding: 0.35rem 1rem;
  background: rgba(0, 0, 0, 0.55);
  text-shadow:
    0 0 4px rgba(0,0,0,0.95),
    0 0 12px rgba(0,0,0,0.85),
    0 0 24px rgba(0,0,0,0.7);
  animation: btn-flicker 2.4s ease-in-out infinite;
  white-space: nowrap;
}

@keyframes fuzz {
  0%   { background-position:    0    0; }
  12%  { background-position:  -47px  17px; }
  25%  { background-position:   91px -53px; }
  37%  { background-position:  -23px  41px; }
  50%  { background-position:   71px  89px; }
  62%  { background-position:  -89px -29px; }
  75%  { background-position:   13px -71px; }
  87%  { background-position:  -61px  53px; }
  100% { background-position:    0    0; }
}

@keyframes btn-flicker {
  0%, 100% { opacity: 0.95; }
  50%      { opacity: 0.7; }
}

/* film grain overlay — shift background-position (not transform) so edges never
   uncover. SVG noise tile repeats, so any offset keeps the viewport fully covered. */
#stage::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.22;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.85'/></svg>");
  background-repeat: repeat;
  animation: grain 0.6s steps(4) infinite;
}

@keyframes grain {
  0%   { background-position:    0    0; }
  25%  { background-position: -67px  43px; }
  50%  { background-position:  53px -39px; }
  75%  { background-position: -21px -57px; }
  100% { background-position:    0    0; }
}

/* vignette — soft, just enough to keep title edges legible on bright frames */
#stage::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.32) 100%),
    linear-gradient(to bottom, rgba(0,0,0,0.18) 0%, transparent 25%, transparent 70%, rgba(0,0,0,0.28) 100%);
}

#intertitle {
  position: absolute;
  z-index: 3;
  left: 50%;
  transform: translateX(-50%);
  width: min(86vw, 1300px);
  text-align: center;
  font-family: var(--sans);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.005em;
  color: var(--fg);
  text-wrap: balance;
  /* hard outline + tight offset shadow — close to the letter, not chunky */
  text-shadow:
    -1px -1px 0 #000,
     1px -1px 0 #000,
    -1px  1px 0 #000,
     1px  1px 0 #000,
     2px  2px 0 rgba(0,0,0,0.95);
  opacity: 0;
  transition: opacity 0.55s ease-in 0.18s;
  /* defaults — overridden by variant classes */
  bottom: 18vh;
  font-size: clamp(2rem, 3.6vw, 3.2rem);
}

#intertitle.shown { opacity: 1; }

/* position variants */
#intertitle.pos-bottom {
  top: auto;
  bottom: 14vh;
}
#intertitle.pos-center {
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
}
#intertitle.pos-top {
  top: 14vh;
  bottom: auto;
}

/* size variants */
#intertitle.size-md {
  font-size: clamp(1.9rem, 3.4vw, 3rem);
  line-height: 1.2;
}
#intertitle.size-lg {
  font-size: clamp(2.4rem, 4.4vw, 4rem);
  font-weight: 700;
  line-height: 1.13;
}
#intertitle.size-xl {
  font-size: clamp(3.4rem, 7.4vw, 7rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.018em;
}

/* case variants */
#intertitle.case-upper {
  text-transform: uppercase;
  letter-spacing: 0.005em;
  font-weight: 700;
}
#intertitle.case-upper.size-xl {
  letter-spacing: -0.005em;
}
#intertitle.case-sentence {
  text-transform: none;
}

/* colour variants */
#intertitle.color-white {
  color: #ffffff;
}
#intertitle.color-red {
  color: #ff1a1a;
  text-shadow:
    -1px -1px 0 #000,
     1px -1px 0 #000,
    -1px  1px 0 #000,
     1px  1px 0 #000,
     2px  2px 0 rgba(0,0,0,0.95);
}

#meta {
  position: fixed;
  bottom: 1rem;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.2rem;
  padding: 0 1.2rem;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  text-shadow: 0 0 4px rgba(0,0,0,0.9);
  opacity: 1;
  transition: opacity 0.25s ease-out;
}

#stage.loading #meta {
  opacity: 0;
}

#meta a {
  color: inherit;
  text-decoration: none;
  pointer-events: auto;
  letter-spacing: 0.02em;
}

#meta a:hover {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: underline;
}

#meta #source {
  flex: 1;
  text-align: right;
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#meta #about-link {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.62rem;
}

#hint {
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.6rem;
}

/* share button + menu */
#share {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font: 600 0.72rem var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#share:hover {
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.45);
}
#share svg {
  display: block;
}

#share-menu {
  position: fixed;
  top: 3.4rem;
  right: 1rem;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.05rem;
  min-width: 180px;
  padding: 0.4rem;
  background: rgba(0, 0, 0, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font: 500 0.78rem var(--sans);
}
#share-menu[hidden] { display: none; }
#share-menu button {
  appearance: none;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.85);
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
#share-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
#share-status {
  padding: 0.3rem 0.7rem 0.4rem;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.55);
  font-style: italic;
  min-height: 1em;
}

@media (max-width: 600px) {
  #intertitle {
    width: 92vw;
  }
  #intertitle.size-md { font-size: 1.45rem; }
  #intertitle.size-lg { font-size: 1.85rem; }
  #intertitle.size-xl { font-size: 2.4rem; }
}
