/* Tiny Tomato Games — CINEMATIC INTRO (title open)
   A film-style shutter-door opening that plays once on load, then hands off to
   the existing cinematic hero (shard assembly + kinetic headline). Built and
   gated entirely in JS, motion-safe only — reduced-motion / no-JS users never
   see this layer and land straight on the hero. Fully skippable. */

#cinema {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: auto;
  --ease-door: cubic-bezier(0.76, 0, 0.18, 1);
  font-family: 'IBM Plex Mono', monospace;
}
#cinema.gone { display: none; }

/* ---- shutter panels (the cinema doors) ---- */
.cinema-panel {
  position: absolute;
  left: 0;
  right: 0;
  height: 50.4%;
  background:
    radial-gradient(120% 140% at 50% var(--gy, 100%), color-mix(in oklab, var(--accent) 11%, transparent), transparent 62%),
    var(--bg);
  will-change: transform;
}
.cinema-panel.top    { top: 0;    --gy: 150%; box-shadow: inset 0 -1px 0 rgba(255,255,255,0.05); }
.cinema-panel.bottom { bottom: 0; --gy: -50%; box-shadow: inset 0 1px 0 rgba(255,255,255,0.05); }

#cinema.out .cinema-panel.top    { transform: translateY(-100%); transition: transform 0.92s var(--ease-door); }
#cinema.out .cinema-panel.bottom { transform: translateY(100%);  transition: transform 0.92s var(--ease-door); }

/* ---- bright seam where the doors part ---- */
.cinema-seam {
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 2px;
  transform: translateY(-50%) scaleX(0);
  background: linear-gradient(90deg, transparent, var(--accent) 18%, #fff 50%, var(--accent) 82%, transparent);
  box-shadow: 0 0 26px 6px color-mix(in oklab, var(--accent) 70%, transparent);
  opacity: 0;
  pointer-events: none;
}
#cinema.flash .cinema-seam {
  animation: cinema-seam 0.62s ease-out forwards;
}
@keyframes cinema-seam {
  0%   { opacity: 0; transform: translateY(-50%) scaleX(0); }
  30%  { opacity: 1; transform: translateY(-50%) scaleX(1); }
  100% { opacity: 0; transform: translateY(-50%) scaleX(1); }
}

/* ---- texture: scanlines + drifting grain ---- */
.cinema-grain {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}
.cinema-scan {
  position: absolute; left: -30%; top: 0; bottom: 0; width: 28%;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, color-mix(in oklab, var(--accent) 20%, transparent), transparent);
  filter: blur(6px);
  animation: cinema-scan 2.1s linear infinite;
}
@keyframes cinema-scan {
  0%   { transform: translateX(0); }
  100% { transform: translateX(560%); }
}

/* ---- center stack ---- */
.cinema-core {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
  z-index: 3;
  transition: opacity 0.34s ease, transform 0.5s cubic-bezier(0.5, 0, 0.2, 1), filter 0.4s ease;
}
#cinema.out .cinema-core {
  opacity: 0;
  transform: scale(1.06);
  filter: blur(7px);
}

/* mark + drawing ring */
.cinema-mark {
  position: relative;
  width: 96px; height: 96px;
  display: grid; place-items: center;
  opacity: 0;
  transform: scale(0.5) rotate(-22deg);
  animation: cinema-mark-in 0.9s cubic-bezier(0.18, 0.9, 0.24, 1) 0.05s forwards;
}
.cinema-mark img { width: 84px; height: auto; display: block; filter: drop-shadow(0 8px 22px rgba(0,0,0,0.5)); }
@keyframes cinema-mark-in {
  0%   { opacity: 0; transform: scale(0.5) rotate(-22deg); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
.cinema-ring {
  position: absolute; inset: -10px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in oklab, var(--accent) 70%, transparent);
  clip-path: inset(0 0 0 50%);
  animation: cinema-ring 1.05s linear 0.2s 2;
  opacity: 0.9;
}
@keyframes cinema-ring { to { transform: rotate(360deg); } }

/* wordmark — letters rise out of a clip */
.cinema-word {
  display: flex; gap: 0.04em;
  font-family: 'Archivo', sans-serif;
  font-weight: 900;
  font-size: clamp(28px, 6.4vw, 64px);
  letter-spacing: -0.01em;
  line-height: 0.96;
  color: var(--text);
}
.cinema-word .cw-gap { width: 0.42em; }
.cinema-word .cw {
  display: inline-block; overflow: hidden; vertical-align: top;
  padding: 0.06em 0; margin: -0.06em 0;
}
.cinema-word .cw > span {
  display: inline-block;
  transform: translateY(112%);
  animation: cinema-letter 0.7s cubic-bezier(0.2, 0.9, 0.22, 1) forwards;
  animation-delay: calc(0.34s + var(--ci, 0) * 0.045s);
}
.cinema-word .cw.accent > span { color: var(--accent); }
@keyframes cinema-letter { to { transform: translateY(0); } }

/* scramble subtitle */
.cinema-sub {
  font-size: clamp(10px, 1.5vw, 13px);
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: var(--muted);
  min-height: 1em;
  white-space: nowrap;
}
.cinema-sub b { color: var(--leaf); font-weight: 500; }

/* progress + readout */
.cinema-meta {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-top: 6px;
}
.cinema-prog {
  width: clamp(180px, 26vw, 320px); height: 2px;
  background: var(--line);
  position: relative; overflow: hidden; border-radius: 2px;
}
.cinema-prog > i {
  position: absolute; inset: 0 100% 0 0;
  background: linear-gradient(90deg, color-mix(in oklab, var(--accent) 60%, var(--text)), var(--accent));
  box-shadow: 0 0 14px color-mix(in oklab, var(--accent) 70%, transparent);
}
.cinema-readout {
  font-size: 10.5px; letter-spacing: 0.26em; text-indent: 0.26em;
  color: var(--faint); white-space: nowrap;
}

/* skip affordance */
.cinema-skip {
  position: absolute; right: 22px; bottom: 20px; z-index: 4;
  appearance: none; cursor: pointer;
  background: transparent; border: 1px solid var(--line); border-radius: 99px;
  color: var(--faint);
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; letter-spacing: 0.18em;
  padding: 8px 15px;
  opacity: 0;
  animation: cinema-skip-in 0.5s ease 1.1s forwards;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.cinema-skip:hover { color: var(--text); border-color: color-mix(in oklab, var(--accent) 60%, var(--line)); background: color-mix(in oklab, var(--accent) 10%, transparent); }
@keyframes cinema-skip-in { to { opacity: 1; } }
#cinema.out .cinema-skip { opacity: 0; transition: opacity 0.2s ease; }

/* keep the hero from peeking with a layout shift while covered */
html.cinema-armed { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  #cinema { display: none !important; }
}
