* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #07080a; color: #f2f3f5; font: 14px/1.4 -apple-system, system-ui, sans-serif; overflow: hidden; }

/* 16:9 like the previs camera; the H3 video (1344x768) is stretched 1.6% to fill it,
   the same mapping the collision fit was measured on. */
#stage { position: absolute; inset: 0; margin: auto; width: min(100vw, calc(100vh * 16 / 9)); aspect-ratio: 16 / 9; overflow: hidden; background: #000; }
#video, #gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#video { object-fit: fill; }

#impact { position: absolute; inset: 0; pointer-events: none; opacity: 0; backdrop-filter: blur(22px) saturate(.6) brightness(1.25); background: radial-gradient(ellipse at center, rgba(255,255,255,.18), rgba(255,60,60,.28)); }
#flash { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 0 rgba(255, 40, 40, 0); transition: box-shadow .35s ease-out; }
#flash.on { box-shadow: inset 0 0 120px 30px rgba(255, 40, 40, .55); transition: none; }

.plate { position: absolute; background: rgba(8, 10, 14, .62); backdrop-filter: blur(6px); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.k { color: #9aa3b2; font-size: 11px; letter-spacing: .06em; }
#stats { top: 12px; left: 12px; display: flex; gap: 16px; }
#stats b { font-size: 18px; font-variant-numeric: tabular-nums; }
#modes { top: 12px; right: 12px; display: grid; gap: 2px; }
#modes[hidden] { display: none; }
#modes .k { display: inline-block; min-width: 16px; padding: 0 3px; text-align: center; background: rgba(255,255,255,.12); border-radius: 3px; color: #fff; margin-right: 4px; }
#help { bottom: 12px; left: 50%; transform: translateX(-50%); white-space: nowrap; color: #c9cfda; }
#toast { position: absolute; top: 18%; left: 50%; transform: translate(-50%, 0) scale(.9); font-size: 34px; font-weight: 800; letter-spacing: .04em; color: #ff4d4d; text-shadow: 0 2px 12px rgba(0,0,0,.6); opacity: 0; transition: opacity .4s, transform .4s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0) scale(1); transition: none; }
#toast.good { color: #5de39a; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: #07080a; color: #9aa3b2; font-size: 15px; }
#loading[hidden] { display: none; }

/* Whole stage shakes, so the video and the 3D layer stay registered. */
#stage.shake { animation: shake .28s linear; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(5px, -4px); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(3px, -1px); }
}

/* Segment game: H3 clips are 1344x768, two stacked for crossfades. */
.segments #stage { width: min(100vw, calc(100vh * 1344 / 768)); aspect-ratio: 1344 / 768; }
.clip { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: fill; opacity: 0; }
.segments #gl { z-index: 2; }
.segments #impact, .segments #flash { z-index: 3; }
.segments .plate, .segments #toast, .segments #loading { z-index: 4; }

/* --- segment game: blending and game feel --- */
/* A light grade on the 3D layer only: a touch less saturated and contrasty, a hair soft,
   like the generated video. */
.segments #gl { filter: saturate(.86) contrast(.94) brightness(.97) blur(.3px); }
.segments #lines { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }
.segments #vignette { position: absolute; inset: 0; z-index: 3; pointer-events: none; background: radial-gradient(ellipse at 50% 55%, transparent 55%, rgba(0, 0, 0, .38) 100%); }
/* One grain over video and 3D alike, so they read as one image. */
.segments #grain { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; opacity: .05; mix-blend-mode: overlay; image-rendering: pixelated; }
.segments #crash { position: absolute; left: 50%; top: 30%; z-index: 4; pointer-events: none; font: 900 72px/1 -apple-system, system-ui, sans-serif; letter-spacing: .02em; color: #ffdf3d;
  -webkit-text-stroke: 4px #2b1200; paint-order: stroke fill; text-shadow: 0 6px 0 #b3261e, 0 10px 24px rgba(0,0,0,.5); opacity: 0; transform: translate(-50%, -50%); }
.segments #crash.on { animation: crash .9s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes crash {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(2.4) rotate(-14deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(.9) rotate(-6deg); }
  30% { transform: translate(-50%, -50%) scale(1.05) rotate(-8deg); }
  75% { opacity: 1; transform: translate(-50%, -55%) scale(1) rotate(-8deg); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(.9) rotate(-8deg); }
}
.segments #toast.on { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: translate(-50%, 0) scale(1.6); } 100% { transform: translate(-50%, 0) scale(1); } }
.segments #stage.shake { animation: bigshake .42s linear; }
.segments #stage.shake-small { animation: shake .22s linear; }
@keyframes bigshake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  12% { transform: translate(-14px, 8px) rotate(-1.2deg); }
  26% { transform: translate(12px, -10px) rotate(1deg); }
  40% { transform: translate(-9px, 6px) rotate(-.7deg); }
  55% { transform: translate(7px, -4px) rotate(.5deg); }
  70% { transform: translate(-4px, 3px) rotate(-.25deg); }
  85% { transform: translate(2px, -1px) rotate(0); }
}

/* --- full screen: the stage covers the window (cropping the overflow), so video and 3D stay
   registered while there are no black bars. Poster = first frame of the warm-up clip. --- */
.segments #stage {
  --w: max(100vw, calc(100vh * 1344 / 768));
  --w: max(100vw, calc(100dvh * 1344 / 768));
  position: fixed; inset: auto; margin: 0; aspect-ratio: auto;
  width: var(--w); height: calc(var(--w) * 768 / 1344);
  left: calc(50% - var(--w) / 2); top: calc(50% - var(--w) * 384 / 1344);
  background: #000 url(poster.jpg) center / 100% 100%;
}
.segments #stats { position: static; display: block; color: #fff; }
html, body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }

/* Phones held upright: ask for landscape. */
#rotate { display: none; position: fixed; inset: 0; z-index: 100; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px;
  text-align: center; background: #07080a; color: #f6efe0; font: 16px/1.4 -apple-system, system-ui, sans-serif; }
#rotate b { font-size: 24px; color: #ffdf3d; }
#rotate span { color: rgba(255, 255, 255, .7); }
#rotate .phone { width: 46px; height: 80px; border: 4px solid #ffdf3d; border-radius: 10px; margin-bottom: 14px; animation: turn 2.2s ease-in-out infinite; }
@keyframes turn { 0%, 25% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }
@media (pointer: coarse) and (orientation: portrait) { #rotate { display: flex; } }
/* The title is the loading screen; this box only shows if loading fails. */
.segments #loading { background: none; color: transparent; pointer-events: none; }
.segments #loading.failed { position: fixed; z-index: 20; color: #ff8a80; background: rgba(7, 8, 10, .9); font-size: 17px; padding: 24px; text-align: center; }

/* Boot screen: plain HTML, up before any script has loaded. Same look as the title. */
#boot { position: fixed; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px; text-align: center;
  background: linear-gradient(rgba(10, 14, 28, .55), rgba(10, 14, 28, .88)), #000 url(poster.jpg) center / cover; font-family: -apple-system, system-ui, sans-serif; }
#boot .logo { font-weight: 900; font-size: clamp(48px, 9vw, 92px); letter-spacing: .02em; line-height: 1; color: #ffdf3d;
  -webkit-text-stroke: 4px #2b1200; paint-order: stroke fill; text-shadow: 0 6px 0 #b3261e, 0 12px 28px rgba(0, 0, 0, .5); }
#boot .say { font-size: clamp(16px, 2.4vw, 20px); color: #ffdf3d; }
#boot .bar { width: min(360px, 70vw); height: 6px; background: rgba(255, 255, 255, .12); border-radius: 3px; overflow: hidden; }
#boot .bar i { display: block; width: 30%; height: 100%; background: linear-gradient(90deg, #ffdf3d, #ff9a50); animation: boot 1.1s ease-in-out infinite; }
@keyframes boot { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
#boot .controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 620px; font-size: 15px; color: #f6efe0; }
#boot .controls span { display: inline-flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, .1); border-radius: 999px; padding: 5px 14px 5px 5px; }
#boot .controls b { font-size: 14px; font-weight: 900; padding: 5px 9px; border-radius: 999px; background: #ffdf3d; color: #1a1408; }
