/* Rock 2000 Punter Uploader
   Black ground, one red, no network assets. Nothing here is loaded from a
   CDN on purpose: the wall's rule about not trusting the venue network
   applies just as much to the page the punters are asked to load. */

:root {
  --red: #e2001a;
  --red-hot: #ff3a2a;
  --red-dim: #8d0010;
  --ink: #f4f4f4;
  --ink-dim: rgba(244, 244, 244, 0.6);

  --frame-radius: 26px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  /* Set from script: how far the framed media has to travel to reach the
     mouth of the tunnel, which is the middle of the viewport. */
  --dx: 0px;
  --dy: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: "Oswald", "Arial Narrow", "Helvetica Neue", Helvetica, Arial, sans-serif;
  overflow: hidden;
  /* A hold on the shutter must not turn into a text selection, a callout
     menu, or a page zoom. On a phone all three are one gesture away. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* iOS toolbars eat the bottom of a 100vh layout, so use the dynamic unit
   where it exists and fall back where it does not. */
body { height: 100vh; height: 100dvh; }

#tunnel {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Not justify-content: center. A centred flex column that is taller than
     the screen overflows at both ends and the top end, the logo, is what
     gets cut off. Auto margins on the first and last child centre it when
     there is room and anchor it to the top when there is not.

     Deliberately NOT a scroll container. overflow: auto here made the shell
     a compositing layer on iOS, and a live <video> with no transform of its
     own inside a preserve-3d subtree under that painted black. The front
     camera survived only because its mirror is a transform. The frame is
     sized to fit instead, see .window. */
  justify-content: flex-start;
  gap: clamp(10px, 2.2vh, 22px);
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  /* The fall is a real 3D move into the screen, so the depth has to be
     established on the container the media sits in. */
  perspective: 1100px;
  perspective-origin: 50% 50%;
}

/* ------------------------------------------------------------------ brand */

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  transition: opacity 320ms var(--ease-out), transform 320ms var(--ease-out);
}

.brand .logo {
  width: clamp(64px, 18vw, 132px);
  height: auto;
  display: block;
  /* The mark is dark artwork, so it is knocked out to sit on black. */
  filter: brightness(0) invert(1) drop-shadow(0 0 14px rgba(226, 0, 26, 0.45));
  opacity: 0.95;
}

.brand .title {
  font-size: clamp(15px, 4.4vw, 22px);
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 0 22px rgba(226, 0, 26, 0.55);
}

/* ----------------------------------------------------------------- window

   The viewfinder. One framed hole in the tunnel that the camera looks
   through, and the same hole the media falls out of when it is sent. */

.window {
  position: relative;
  /* Wide as the phone allows, but never so tall that the logo above and the
     shutter below no longer fit on the screen with it. The 340px is what
     everything else in the column needs; the 0.75 turns that spare height
     back into a width for a 3:4 frame. dvh where it exists, so the Safari
     toolbars are not counted as screen. */
  width: max(200px, min(92vw, 500px, calc((100vh - 340px) * 0.75)));
  width: max(200px, min(92vw, 500px, calc((100dvh - 340px) * 0.75)));
  transform-style: preserve-3d;
  will-change: transform, opacity, filter;
  animation: window-in 760ms var(--ease-out) both;
}

/* Ratio held with a spacer rather than aspect-ratio, so an older iPhone
   still lays it out instead of collapsing to nothing. */
.window::before {
  content: "";
  display: block;
  padding-top: 133.333%;
}

@media (min-width: 760px) and (orientation: landscape) {
  .window {
    width: max(280px, min(74vw, 780px, calc((100vh - 250px) * 1.7777)));
    width: max(280px, min(74vw, 780px, calc((100dvh - 250px) * 1.7777)));
  }
  .window::before { padding-top: 56.25%; }
}

/* Used to bring the frame back after a send that failed, and after a send
   that worked and is going round again. */
.window.replay { animation: window-in 520ms var(--ease-out) both; }

@keyframes window-in {
  from { opacity: 0; transform: scale(0.88) translateY(18px); filter: blur(10px); }
  to   { opacity: 1; transform: none; filter: none; }
}

.frame {
  position: absolute;
  inset: 0;
  border-radius: var(--frame-radius);
  overflow: hidden;
  background: #050505;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.10),
    0 0 0 1px rgba(226, 0, 26, 0.55),
    0 0 46px rgba(226, 0, 26, 0.26),
    0 26px 70px rgba(0, 0, 0, 0.85);
  transition: box-shadow 260ms var(--ease-out);
}

.frame > video,
.frame > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #050505;
}

/* Only ever one of the three visible at a time. */
#viewfinder, #shot, #clip { opacity: 0; transition: opacity 200ms linear; }
body.state-viewfinder #viewfinder,
body.state-recording #viewfinder { opacity: 1; }
body.state-review #shot.has-media,
body.state-sending #shot.has-media,
body.state-review #clip.has-media,
body.state-sending #clip.has-media { opacity: 1; }

/* The viewfinder always gets a layer of its own. Without a transform of
   any kind, iOS has been seen to composite a live camera as black inside a
   3D subtree, and the only reason the selfie side ever looked fine is that
   its mirror is a transform. translateZ(0) is the no-op that buys the layer. */
#viewfinder { transform: translateZ(0); backface-visibility: hidden; }

/* The front camera is mirrored to look at, because everyone expects that of
   a selfie. What gets captured is not, because a shirt has to read the right
   way round on a wall at Spark Arena. */
#viewfinder.mirror { transform: scaleX(-1) translateZ(0); }

/* Corner ticks. Camera furniture, and they give the frame a scale. */
.ticks i {
  position: absolute;
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  opacity: 0.75;
}
.ticks i:nth-child(1) { top: 12px;    left: 12px;  border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.ticks i:nth-child(2) { top: 12px;    right: 12px; border-left: 0;  border-bottom: 0; border-top-right-radius: 8px; }
.ticks i:nth-child(3) { bottom: 12px; left: 12px;  border-right: 0; border-top: 0;    border-bottom-left-radius: 8px; }
.ticks i:nth-child(4) { bottom: 12px; right: 12px; border-left: 0;  border-top: 0;    border-bottom-right-radius: 8px; }

body.state-review .ticks, body.state-sending .ticks { opacity: 0; }
.ticks { transition: opacity 240ms linear; }

/* Recording. The rim goes hot and stays that way until the finger lifts. */
body.state-recording .frame {
  box-shadow:
    inset 0 0 0 2px rgba(226, 0, 26, 0.85),
    0 0 0 1px rgba(226, 0, 26, 0.9),
    0 0 90px rgba(226, 0, 26, 0.5),
    0 26px 70px rgba(0, 0, 0, 0.85);
  animation: rim-pulse 1.5s ease-in-out infinite;
}

@keyframes rim-pulse {
  50% { box-shadow:
    inset 0 0 0 2px rgba(255, 58, 42, 1),
    0 0 0 1px rgba(255, 58, 42, 1),
    0 0 130px rgba(226, 0, 26, 0.68),
    0 26px 70px rgba(0, 0, 0, 0.85); }
}

.rec {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 12px;
  letter-spacing: 0.16em;
  backdrop-filter: blur(4px);
}
body.state-recording .rec { display: flex; }

.rec .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red-hot);
  box-shadow: 0 0 12px var(--red-hot);
  animation: blink 1s steps(1, end) infinite;
}
@keyframes blink { 50% { opacity: 0.15; } }

.chip {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.55);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  opacity: 0;
  transition: opacity 220ms linear;
}
.chip.on { opacity: 1; }

/* Shown in place of the picture when there is no camera to show. */
.blocked {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 26px;
  text-align: center;
}
body.state-blocked .blocked { display: flex; }
.blocked p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  max-width: 26ch;
}

/* ------------------------------------------------------------------ hint */

.hint {
  margin: 0;
  font-size: clamp(10px, 3vw, 12px);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: center;
  transition: opacity 260ms var(--ease-out);
}
.hint b { color: var(--ink); font-weight: 400; }

/* -------------------------------------------------------------- controls */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(22px, 8vw, 46px);
  transition: opacity 320ms var(--ease-out), transform 320ms var(--ease-out);
}
body.state-review .controls,
body.state-sending .controls { opacity: 0; pointer-events: none; transform: translateY(10px); }

.aux {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 200ms, border-color 200ms, transform 140ms;
}
.aux:active { transform: scale(0.92); }
.aux:disabled { opacity: 0.25; pointer-events: none; }
.aux svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; }

/* The one button. Tap it, or hold it. */
.shutter {
  position: relative;
  width: 92px;
  height: 92px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: none;
}

.shutter .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 26px rgba(226, 0, 26, 0.35);
  transition: transform 200ms var(--ease-out), border-color 200ms;
}

.shutter .core {
  position: relative;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.25);
  transition: width 240ms var(--ease-out), height 240ms var(--ease-out),
              border-radius 240ms var(--ease-out), background 240ms var(--ease-out);
}

.shutter:active .core { background: #d8d8d8; }

/* Holding turns it into a stop button, which is the only affordance anyone
   needs to be told that it is now recording. */
body.state-recording .shutter .core {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--red);
  box-shadow: 0 0 30px rgba(226, 0, 26, 0.85);
}
body.state-recording .shutter .ring { border-color: rgba(255, 255, 255, 0.35); }

/* The countdown on the hold. An SVG arc rather than a conic gradient,
   because a dash offset animates smoothly on everything. */
.shutter svg.arc {
  position: absolute;
  inset: -6px;
  width: calc(100% + 12px);
  height: calc(100% + 12px);
  transform: rotate(-90deg);
  pointer-events: none;
}
.shutter svg.arc circle {
  fill: none;
  stroke: var(--red-hot);
  stroke-width: 3.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px rgba(255, 58, 42, 0.9));
  opacity: 0;
  transition: opacity 160ms linear;
}
body.state-recording .shutter svg.arc circle { opacity: 1; }

/* --------------------------------------------------------------- confirm */

.confirm {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 300ms var(--ease-out), transform 300ms var(--ease-out);
}
body.state-review .confirm { opacity: 1; pointer-events: auto; transform: none; }

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: clamp(12px, 3.6vw, 14px);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 14px 26px;
  border-radius: 999px;
  color: var(--ink);
  transition: transform 140ms, box-shadow 220ms, background 220ms;
}
.btn:active { transform: scale(0.96); }

.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.btn.go {
  background: var(--red);
  box-shadow: 0 0 0 1px rgba(255, 90, 70, 0.5), 0 10px 34px rgba(226, 0, 26, 0.45);
  padding-inline: 34px;
}
.btn.go:hover { background: var(--red-hot); }

/* ---------------------------------------------------------------- status */

.status {
  margin: 0 0 auto;
  min-height: 1.2em;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: center;
  transition: color 200ms;
}
.status.bad { color: var(--red-hot); }

/* ------------------------------------------------------------------ send

   The fall. A real translate in z with the shell's perspective behind it,
   so it goes away from you rather than merely getting smaller, tumbling as
   it goes and burning out to light at the throat. */

body.state-sending .brand,
body.state-sending .hint { opacity: 0; }

body.state-sending .frame { box-shadow: 0 0 90px rgba(226, 0, 26, 0.6); }

body.state-sending .window {
  animation: fall var(--fall-ms, 1400ms) cubic-bezier(.5, 0, .82, .18) forwards;
}

@keyframes fall {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
    filter: none;
    opacity: 1;
  }
  /* A short pull back first. It reads as the tunnel taking hold of it. */
  18% {
    transform: translate3d(calc(var(--dx) * 0.10), calc(var(--dy) * 0.10 - 10px), -70px)
               scale(0.94) rotateX(-6deg) rotateZ(-2deg);
    filter: brightness(1.08);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--dx), var(--dy), -1500px)
               scale(0.06) rotateX(46deg) rotateZ(30deg);
    filter: brightness(2.6) saturate(1.5) blur(3px);
    opacity: 0;
  }
}

/* ------------------------------------------------------------------ sent

   Once it has gone down the tunnel it has gone. The frame is not brought
   back to sit there empty behind the message, because the last thing anyone
   saw was their photo falling into the throat and putting the box back
   undoes that. What is left is what it says and the way to go again.

   No transition on the way out: the shell has to be gone in the same frame
   the fall ends, or the frame snaps back to full size for a moment first. */

body.state-sent .shell {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sent {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  text-align: center;
  padding: 24px;
}
body.state-sent .sent { display: flex; }

.sent .headline {
  margin: 0;
  font-size: clamp(22px, 8vw, 46px);
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  text-transform: uppercase;
  line-height: 1.2;
  text-shadow: 0 0 40px rgba(226, 0, 26, 0.8);
  animation: sent-in 620ms var(--ease-out) both;
}

.sent .sub {
  display: none;
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
  animation: sent-in 620ms 120ms var(--ease-out) both;
}

body.dry-run .sent .sub { display: block; }

.sent .btn { animation: sent-in 620ms 240ms var(--ease-out) both; }

@keyframes sent-in {
  from { opacity: 0; transform: scale(0.9) translateY(14px); filter: blur(8px); }
  to   { opacity: 1; transform: none; filter: none; }
}

/* ----------------------------------------------------------------- badge */

/* Only ever on the test instance, so nobody mistakes a dry run for a send. */
.dry {
  position: fixed;
  top: 8px;
  right: 10px;
  z-index: 3;
  font-size: 10px;
  letter-spacing: 0.2em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.5);
  display: none;
}
body.dry-run .dry { display: block; }

/* --------------------------------------------------------- reduced motion

   The tunnel is the point of the page so it stays, but it stays calmer:
   the shake is already off in script, and the fall stops tumbling. */
@media (prefers-reduced-motion: reduce) {
  .window { animation-duration: 1ms; }
  @keyframes fall {
    0%   { transform: none; opacity: 1; }
    100% { transform: translate3d(var(--dx), var(--dy), -900px) scale(0.08); opacity: 0; }
  }
  .rec .dot, body.state-recording .frame { animation: none; }
}
