:root {
  --red: #ff2a3d;
  --red-glow: rgba(255, 42, 61, 0.55);
  --green: #3dff8a;
  --amber: #ffc53d;
  --ink: #f4f4f6;
  --dim: rgba(244, 244, 246, 0.7);
  --panel: rgba(8, 8, 12, 0.82);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body { display: grid; place-items: center; }

/* 16:9 stage that fits the viewport; everything inside is sized in cqw. */
#stage {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  container-type: inline-size;
  overflow: hidden;
  background: #000;
}

/* Own stacking context, so the clips' climbing z-index stays below the overlay. */
#videos { position: absolute; inset: 0; z-index: 0; }

#videos video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transition: filter 0.4s;
}
#videos video.active { opacity: 1; }

#stage.slowmo #videos video.active { filter: saturate(0.45) contrast(1.15) brightness(0.85); }

#fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(120, 0, 10, 0.65) 100%);
}
#stage.slowmo #fx { opacity: 1; animation: pulse-vignette 0.9s ease-in-out infinite; }
#fx.flash-good { background: rgba(61, 255, 138, 0.35); opacity: 1; transition: none; }
#fx.flash-bad { background: rgba(255, 42, 61, 0.45); opacity: 1; transition: none; }

@keyframes pulse-vignette { 50% { opacity: 0.6; } }

/* ---------- Action overlay ---------- */

#overlay { position: absolute; inset: 0; touch-action: none; }
#overlay.capture { cursor: crosshair; }

.action-label {
  position: absolute;
  top: 6cqw;
  left: 0;
  right: 0;
  text-align: center;
  font-size: max(5cqw, 20px);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 0 1.2cqw #000, 0 0 2.5cqw var(--red-glow);
  animation: label-in 0.25s ease-out;
  pointer-events: none;
}
.action-hint {
  position: absolute;
  top: calc(6cqw + max(5cqw, 20px) * 1.3);
  left: 0;
  right: 0;
  text-align: center;
  font-size: max(1.8cqw, 12px);
  color: var(--dim);
  text-shadow: 0 0 0.6cqw #000;
  pointer-events: none;
}
@keyframes label-in { from { transform: scale(1.6); opacity: 0; } }

.timer {
  position: absolute;
  top: 2.5cqw;
  left: 25%;
  width: 50%;
  height: 0.9cqw;
  border-radius: 1cqw;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
  pointer-events: none;
}
.timer > div {
  height: 100%;
  width: 100%;
  background: var(--red);
  box-shadow: 0 0 1cqw var(--red);
  transform-origin: left center;
}

.result-pop {
  position: absolute;
  top: 40%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 7cqw;
  font-weight: 900;
  pointer-events: none;
  animation: pop 0.7s ease-out forwards;
  text-shadow: 0 0 2cqw #000;
}
.result-pop.good { color: var(--green); }
.result-pop.bad { color: var(--red); }
@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  25% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

/* Red target circle */
.target {
  position: absolute;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;
}
.target .core {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 2cqw var(--red), inset 0 0 1cqw rgba(255, 255, 255, 0.5);
  animation: core-pulse 0.5s ease-in-out infinite alternate;
}
.target .ring {
  position: absolute;
  inset: -60%;
  border-radius: 50%;
  border: 0.35cqw solid var(--red);
  animation: ring-close linear forwards;
  animation-duration: inherit;
}
.target.hit .core { background: var(--green); box-shadow: 0 0 3cqw var(--green); animation: none; }
.target.hit { animation: hit 0.25s ease-out forwards; pointer-events: none; }
@keyframes core-pulse { to { transform: scale(1.12); } }
@keyframes ring-close { from { inset: -90%; opacity: 0.3; } to { inset: 18%; opacity: 1; } }
@keyframes hit { to { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } }

/* Mash + hold big button */
.big-btn {
  position: absolute;
  left: 50%;
  bottom: 9cqw;
  width: 15cqw;
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: max(2.6cqw, 13px);
  font-weight: 900;
  background: radial-gradient(circle at 35% 30%, #ff6b77, var(--red) 55%, #9a0010);
  box-shadow: 0 0 3cqw var(--red-glow);
  touch-action: none;
  cursor: pointer;
}
.big-btn.bump { animation: bump 0.12s ease-out; }
.big-btn.holding { transform: translateX(-50%) scale(0.92); }
@keyframes bump { 50% { transform: translateX(-50%) scale(0.86); } }

.meter {
  position: absolute;
  left: 30%;
  width: 40%;
  bottom: 4.5cqw;
  height: 1.6cqw;
  border-radius: 1cqw;
  border: 0.2cqw solid rgba(255, 255, 255, 0.6);
  overflow: hidden;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.5);
}
.meter > div { height: 100%; width: 0; background: var(--green); box-shadow: 0 0 1cqw var(--green); }

.hold-ring { position: absolute; inset: -12%; pointer-events: none; }
.hold-ring circle { fill: none; stroke-width: 6; }
.hold-ring .bg { stroke: rgba(255, 255, 255, 0.25); }
.hold-ring .fg { stroke: var(--green); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }

/* Swipe */
.swipe-track {
  position: absolute;
  border: 0.3cqw dashed rgba(255, 255, 255, 0.55);
  border-radius: 2cqw;
  pointer-events: none;
}
.swipe-goal {
  position: absolute;
  width: 6cqw;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 0.35cqw solid var(--green);
  box-shadow: 0 0 1.5cqw var(--green);
  pointer-events: none;
  animation: core-pulse 0.5s ease-in-out infinite alternate;
}
.swipe-arrow {
  position: absolute;
  font-size: 4cqw;
  transform: translate(-50%, -50%);
  pointer-events: none;
  color: var(--ink);
  text-shadow: 0 0 1cqw #000;
  animation: nudge 0.6s ease-in-out infinite alternate;
}
@keyframes nudge { to { opacity: 0.3; } }

/* Pull lever */
.pull-track {
  position: absolute;
  left: 84%;
  top: 22%;
  height: 62%;
  width: 4cqw;
  transform: translateX(-50%);
  border-radius: 2cqw;
  background: rgba(0, 0, 0, 0.55);
  border: 0.2cqw solid rgba(255, 255, 255, 0.5);
}
.pull-zone {
  position: absolute;
  left: -0.4cqw;
  right: -0.4cqw;
  border-radius: 1cqw;
  background: rgba(61, 255, 138, 0.28);
  border: 0.2cqw solid var(--green);
  pointer-events: none;
}
.pull-handle {
  position: absolute;
  left: 50%;
  width: 7cqw;
  height: 3.2cqw;
  transform: translate(-50%, -50%);
  border-radius: 1cqw;
  background: linear-gradient(#ff6b77, var(--red));
  box-shadow: 0 0 2cqw var(--red-glow);
  cursor: grab;
  touch-action: none;
}
.pull-handle.ok { background: linear-gradient(#8dffb9, #1fc663); box-shadow: 0 0 2cqw var(--green); }
.pull-warn {
  position: absolute;
  left: 84%;
  top: 87%;
  transform: translateX(-50%);
  font-size: max(2.2cqw, 12px);
  font-weight: 900;
  color: var(--amber);
  white-space: nowrap;
  text-shadow: 0 0 0.8cqw #000;
  pointer-events: none;
}

/* ---------- Screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6cqw;
  text-align: center;
  background: var(--panel);
  padding: 4cqw;
  animation: fade-in 0.35s ease-out;
}
.screen.hidden, .hidden { display: none !important; }
@keyframes fade-in { from { opacity: 0; } }

.screen h1 { margin: 0; font-size: 6.5cqw; letter-spacing: 0.08em; font-weight: 900; }
.screen h1.bad { color: var(--red); }
.screen h1.good { color: var(--green); }
.screen p { margin: 0; font-size: max(2cqw, 13px); color: var(--dim); line-height: 1.5; }
.screen .small { font-size: max(1.3cqw, 11px); opacity: 0.6; }

.screen button {
  font: inherit;
  font-size: max(2.3cqw, 14px);
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: max(1.2cqw, 8px) max(4cqw, 20px);
  border-radius: 99cqw;
  border: none;
  color: #fff;
  background: var(--red);
  box-shadow: 0 0 2.5cqw var(--red-glow);
  cursor: pointer;
}
.screen button.ghost { background: transparent; box-shadow: none; font-size: max(1.6cqw, 12px); font-weight: 500; text-decoration: underline; }

.bar { width: 40%; height: 0.8cqw; background: rgba(255, 255, 255, 0.15); border-radius: 1cqw; overflow: hidden; }
#load-fill { height: 100%; width: 0; background: var(--red); transition: width 0.2s; }

#win-stats { margin: 0; padding: 0; list-style: none; font-size: max(1.6cqw, 11px); color: var(--dim); columns: 2; column-gap: 4cqw; }
#win-stats li { margin: 0.3cqw 0; }
#win-stats b { color: var(--ink); }

/* Shown while the next clip is still downloading. */
#buffering {
  position: absolute;
  right: 2cqw;
  bottom: 2cqw;
  padding: max(0.6cqw, 5px) max(1.4cqw, 10px);
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.7);
  font-size: max(1.5cqw, 12px);
  color: var(--dim);
  animation: blink 1s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes blink { to { opacity: 0.4; } }

/* Phones held upright: the 16:9 game would be a thin strip, so ask to rotate. */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  text-align: center;
  background: #000;
}
@media (orientation: portrait) and (max-width: 600px) {
  body:not(.portrait-ok) #rotate { display: flex; }
}
#rotate .phone {
  width: 44px;
  height: 78px;
  border: 3px solid var(--ink);
  border-radius: 9px;
  animation: turn 2.4s ease-in-out infinite;
}
@keyframes turn {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
#rotate p { margin: 0; font-size: 18px; font-weight: 700; }
#rotate button {
  font: inherit;
  font-size: 14px;
  color: var(--dim);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

#debug {
  position: absolute;
  left: 0.6cqw;
  bottom: 0.6cqw;
  padding: 0.4cqw 0.8cqw;
  font: 1.2cqw/1.4 ui-monospace, Consolas, monospace;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 0.4cqw;
  pointer-events: none;
  white-space: pre;
}
