:root {
  --lime: #8fd400;
  --lime-hi: #c8ff3a;
  --lime-glow: rgba(160, 255, 40, .55);
  --navy: #071328;
  --navy-2: #0d2147;
  --ink: #f4f7ef;
  --dim: rgba(244, 247, 239, .72);
  --glass: rgba(6, 14, 30, .62);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --display: "Russo One", "Arial Black", system-ui, sans-serif;
  --cond: "Saira Condensed", "Arial Narrow", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #02060e; color: var(--ink);
  font-family: var(--cond); font-weight: 600;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation; overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }

/* Phone-shaped stage. Full bleed on phones, centred 9:16 on desktop. */
#app {
  position: relative; margin: 0 auto; overflow: hidden;
  width: 100vw; height: 100vh; height: 100dvh;
  background: radial-gradient(120% 80% at 50% 10%, #12305e 0%, #071328 55%, #02060e 100%);
}
@media (min-aspect-ratio: 3/4) {
  #app { width: min(100vw, calc(100dvh * 9 / 19.5)); box-shadow: 0 0 80px rgba(0,0,0,.8); }
}

#game, #selfie { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#selfie { opacity: 0; transition: opacity .5s; pointer-events: none; }
#cam { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
[data-screen="helmet"] #selfie, [data-screen="finish"] #selfie { opacity: 1; }

#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 40; }
#flash.on { animation: flash .5s ease-out; }
@keyframes flash { from { opacity: .95 } to { opacity: 0 } }

/* ---------- brand bar ---------- */
.brand {
  position: absolute; z-index: 20; left: 0; right: 0; top: 0;
  padding: calc(14px + var(--safe-t)) 14px 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  pointer-events: none;
}
.brand .kcb { width: 27%; max-width: 132px; filter: drop-shadow(0 0 10px var(--lime-glow)); }
.brand .wordmark { width: 62%; max-width: 300px; margin-top: -4px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.6)); transition: transform .5s, width .5s; transform-origin: top right; }
[data-screen="splash"] .brand .wordmark { width: 0; opacity: 0; }
[data-screen="drive"] .brand .wordmark { width: 44%; }
[data-screen="drive"] .brand .kcb { width: 22%; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(84px + var(--safe-t)) 18px calc(22px + var(--safe-b));
  opacity: 0; visibility: hidden; transition: opacity .45s, visibility 0s .45s;
}
#app[data-screen="splash"] #s-splash,
#app[data-screen="helmet"] #s-helmet,
#app[data-screen="drive"]  #s-drive,
#app[data-screen="crash"]  #s-crash,
#app[data-screen="finish"] #s-finish,
#app[data-screen="share"]  #s-share { opacity: 1; visibility: visible; transition: opacity .45s; }

/* ---------- buttons ---------- */
.cta {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 14px;
  width: min(86%, 340px); height: 64px; border-radius: 18px;
  background: linear-gradient(180deg, #b6f52a, #6fbf00);
  color: var(--navy); font-family: var(--display); font-size: 22px; letter-spacing: .04em;
  box-shadow: 0 0 0 2px rgba(255,255,255,.35) inset, 0 10px 30px rgba(120,220,0,.35), 0 0 40px var(--lime-glow);
  transition: transform .12s;
}
.cta:active { transform: scale(.96); }
.ghost {
  margin-top: 12px; padding: 10px 18px; border-radius: 12px;
  color: var(--dim); font-size: 17px; text-decoration: none;
  border: 1px solid rgba(255,255,255,.18); background: rgba(0,0,0,.25); backdrop-filter: blur(6px);
}

/* icons (inline SVG masks) */
i[class^="ico-"] { display: inline-block; width: 30px; height: 30px; background: currentColor;
  -webkit-mask: var(--m) center/contain no-repeat; mask: var(--m) center/contain no-repeat; }
.ico-helmet { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' fill='none' stroke='black' stroke-width='4' stroke-linejoin='round'%3E%3Cpath d='M8 38c0-17 11-28 26-28 13 0 22 9 22 22v12c0 5-3 8-8 8H18c-6 0-10-5-10-14z'/%3E%3Cpath d='M14 30h40v10H22c-5 0-8-4-8-10z'/%3E%3Cpath d='M30 52v-6'/%3E%3C/svg%3E"); }
.ico-tap { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' fill='none' stroke='black' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M26 34V12a5 5 0 0 1 10 0v18l12 3c4 1 6 4 5 8l-3 13H28L18 42c-2-3 1-7 5-5z'/%3E%3Cpath d='M16 14a14 14 0 0 1 30 0' opacity='.6'/%3E%3C/svg%3E"); }
.ico-cam { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' fill='none' stroke='black' stroke-width='5' stroke-linejoin='round'%3E%3Crect x='6' y='18' width='52' height='36' rx='8'/%3E%3Cpath d='M22 18l4-8h12l4 8'/%3E%3Ccircle cx='32' cy='36' r='10'/%3E%3C/svg%3E"); }
.ico-share { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' fill='none' stroke='black' stroke-width='5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M32 40V8M20 20 32 8l12 12'/%3E%3Cpath d='M14 30v22h36V30'/%3E%3C/svg%3E"); }

/* ---------- splash ---------- */
#s-splash { justify-content: flex-end; background: linear-gradient(180deg, rgba(2,6,14,0) 30%, rgba(2,6,14,.85) 75%); }
.splash-copy { width: 100%; margin-bottom: 26px; }
.kicker { margin: 0 0 6px; color: var(--lime-hi); font-size: 15px; letter-spacing: .22em; font-weight: 800; }
.splash-copy h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(28px, 8.4vw, 40px); line-height: 1.04; letter-spacing: .01em; text-transform: uppercase; }
.splash-copy .sub { margin: 12px 0 0; color: var(--dim); font-size: 18px; line-height: 1.3; max-width: 30ch; }
.legal { margin: 14px 0 0; color: rgba(255,255,255,.45); font-size: 13px; }
#s-splash .splash-hero { position: absolute; }
.splash-logo { width: 100%; }

/* ---------- helmet / rev ---------- */
#s-helmet { justify-content: space-between; }
.badge-helmet {
  align-self: flex-end; margin-top: 62%;
  display: grid; justify-items: center; gap: 3px; width: 84px; padding: 10px 6px 8px;
  border-radius: 20px; background: var(--glass); backdrop-filter: blur(8px);
  border: 2px solid var(--lime-hi); box-shadow: 0 0 24px var(--lime-glow), inset 0 0 18px rgba(160,255,40,.18);
  color: var(--lime-hi); text-align: center; font-family: var(--display); font-size: 13px; line-height: 1.05;
  transform: scale(.6); opacity: 0; transition: transform .45s cubic-bezier(.2,1.6,.4,1), opacity .3s;
}
.badge-helmet b { color: #fff; font-weight: 400; }
.badge-helmet .big { width: 40px; height: 40px; }
.badge-helmet .tick { width: 26px; height: 15px; border: solid var(--lime-hi); border-width: 0 0 4px 4px; transform: rotate(-45deg) translate(2px,-4px); }
.badge-helmet.on { transform: none; opacity: 1; }
.hint { margin: 0; padding: 8px 14px; border-radius: 999px; background: var(--glass); color: var(--dim); font-size: 16px; transition: opacity .3s; }
.hint.off { opacity: 0; }
.rev-wrap { display: grid; justify-items: center; gap: 10px; width: 100%; }
.rev-meter { position: relative; width: 210px; height: 10px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; }
.rev-meter i { position: absolute; inset: 0; width: 0; border-radius: inherit; background: linear-gradient(90deg, #5fd400, #c8ff3a 70%, #ff5a2a); box-shadow: 0 0 14px var(--lime-glow); }
.rev {
  display: flex; align-items: center; gap: 14px; padding: 14px 28px 14px 22px; border-radius: 22px;
  background: var(--glass); backdrop-filter: blur(8px);
  border: 2px solid var(--lime-hi); box-shadow: 0 0 26px var(--lime-glow), inset 0 0 20px rgba(160,255,40,.15);
  color: var(--lime-hi); transition: transform .1s;
}
.rev i { width: 48px; height: 48px; }
.rev span { display: grid; text-align: left; font-family: var(--display); font-size: 40px; line-height: .95; color: #fff; }
.rev small { font-size: 20px; }
.rev:active, .rev.kick { transform: scale(.93); }
.rev.small span { font-size: 28px; } .rev.small small { font-size: 16px; } .rev.small i { width: 38px; height: 38px; }
.rev-count { margin: 0; color: var(--dim); font-size: 16px; }

/* ---------- drive HUD ---------- */
.hud { padding: 0; pointer-events: none; }
.pill {
  position: absolute; top: calc(25% + var(--safe-t)); left: 50%; transform: translateX(-50%);
  padding: 12px 26px; border-radius: 24px; white-space: nowrap; text-align: center;
  background: rgba(4,12,28,.72); border: 1.5px solid rgba(180,255,80,.7);
  box-shadow: 0 0 20px rgba(160,255,40,.35); font-family: var(--display); font-size: clamp(15px, 4.6vw, 21px); line-height: 1.2;
  transition: opacity .6s, transform .6s;
}
.pill.off { opacity: 0; transform: translate(-50%, -12px); }
.topline { position: absolute; left: 14px; right: 14px; top: calc(66px + var(--safe-t)); display: flex; align-items: center; gap: 12px; }
.clock { display: grid; font-family: var(--display); }
.clock b { font-weight: 400; font-size: 26px; letter-spacing: .02em; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
.clock small { color: #ff8a5a; font-size: 14px; min-height: 14px; }
.progress { position: relative; flex: 1; height: 8px; border-radius: 99px; background: rgba(255,255,255,.18); }
.progress i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: inherit; background: linear-gradient(90deg, #5fd400, #c8ff3a); box-shadow: 0 0 10px var(--lime-glow); }
.progress .cp { position: absolute; top: -3px; width: 3px; height: 14px; background: rgba(255,255,255,.7); border-radius: 2px; }
#pip {
  position: absolute; right: 12px; top: calc(112px + var(--safe-t)); width: 92px; height: 92px; border-radius: 50%;
  border: 2.5px solid var(--lime-hi); box-shadow: 0 0 18px var(--lime-glow); background: #0a1428;
}
#pip.hidden { display: none; }
.chev { position: absolute; top: 56%; display: flex; gap: 0; opacity: .25; transition: opacity .12s; }
.chev.left { left: 8%; } .chev.right { right: 8%; }
.chev i { width: 26px; height: 46px; margin: 0 -5px; background: var(--lime-hi);
  clip-path: polygon(100% 0, 55% 50%, 100% 100%, 62% 100%, 18% 50%, 62% 0); filter: drop-shadow(0 0 6px var(--lime-glow)); }
.chev.right i { transform: scaleX(-1); }
.chev i:nth-child(1) { opacity: 1; } .chev i:nth-child(2) { opacity: .7; } .chev i:nth-child(3) { opacity: .4; }
.chev.right i:nth-child(1) { opacity: .4; } .chev.right i:nth-child(3) { opacity: 1; }
.speedo { position: absolute; left: 50%; bottom: calc(8px + var(--safe-b)); width: min(56%, 230px); transform: translateX(-50%); }
.speedo svg { display: block; width: 100%; overflow: visible; }
.arc-bg, .arc-fg { fill: none; stroke-width: 16; stroke-linecap: butt; }
.arc-bg { stroke: rgba(8,16,32,.75); }
.arc-fg { stroke: url(#g-arc); stroke-dasharray: 252; stroke-dashoffset: 252; }
#ticks line { stroke: rgba(255,255,255,.75); stroke-width: 2; }
.speed-read { position: absolute; left: 0; right: 0; bottom: 4px; display: grid; justify-items: center; line-height: .9; }
.speed-read small { font-size: 16px; color: var(--dim); font-family: var(--display); }
.speed-read b { font-family: var(--display); font-weight: 400; font-size: 52px; text-shadow: 0 3px 10px rgba(0,0,0,.7); }
.banner {
  position: absolute; top: 38%; left: 0; right: 0; text-align: center;
  font-family: var(--display); font-size: 30px; color: var(--lime-hi); text-shadow: 0 0 18px var(--lime-glow), 0 3px 0 #000;
  opacity: 0; transform: scale(.8);
}
.banner.show { animation: banner 1.4s ease-out; }
@keyframes banner { 0% { opacity: 0; transform: scale(.6) } 15% { opacity: 1; transform: scale(1.08) } 70% { opacity: 1; transform: scale(1) } 100% { opacity: 0; transform: scale(1) } }
.count {
  position: absolute; top: 34%; left: 0; right: 0; text-align: center;
  font-family: var(--display); font-size: 120px; line-height: 1; color: #fff; text-shadow: 0 0 30px var(--lime-glow), 0 6px 0 rgba(0,0,0,.5);
}
.count.go { color: var(--lime-hi); }
.count .pop { display: inline-block; animation: pop .9s ease-out forwards; }
@keyframes pop { 0% { transform: scale(2); opacity: 0 } 20% { transform: scale(1); opacity: 1 } 80% { opacity: 1 } 100% { transform: scale(.9); opacity: 0 } }

/* ---------- crash / roar ---------- */
#s-crash { justify-content: flex-end; background: radial-gradient(90% 60% at 50% 45%, rgba(120,70,20,.25), rgba(4,8,16,.85)); }
.roar-stage { position: absolute; left: 0; right: 0; top: 16%; height: 52%; }
#lion { position: absolute; left: 50%; top: 50%; width: 132%; transform: translate(-50%,-50%) scale(.4); opacity: 0; filter: saturate(1.1) contrast(1.05); }
#dustfx { position: absolute; inset: -20% -10%; width: 120%; height: 140%; }
[data-screen="crash"] #lion { animation: lion 2.4s cubic-bezier(.15,.9,.25,1) forwards; }
@keyframes lion {
  0%   { opacity: 0; transform: translate(-50%,-40%) scale(.35); filter: blur(10px) brightness(1.8); }
  25%  { opacity: 1; transform: translate(-50%,-52%) scale(1.06); filter: blur(0) brightness(1.15); }
  32%  { transform: translate(-49%,-51%) scale(1.02); }
  38%  { transform: translate(-51%,-50%) scale(1.04); }
  100% { opacity: 1; transform: translate(-50%,-50%) scale(1); filter: none; }
}
.roar-title { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(36px, 11vw, 54px); letter-spacing: .01em; text-shadow: 0 4px 0 #000, 0 0 30px rgba(255,170,60,.5); opacity: 0; }
.roar-title em { font-style: normal; color: #ffb43a; }
[data-screen="crash"] .roar-title { animation: rise .6s .7s ease-out forwards; }
.roar-sub { margin: 4px 0 18px; color: #ff9a6a; font-size: 18px; opacity: 0; }
[data-screen="crash"] .roar-sub { animation: rise .6s .9s ease-out forwards; }
#btn-continue { opacity: 0; pointer-events: none; }
#btn-continue.ready { animation: rise .4s ease-out forwards; pointer-events: auto; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }

/* ---------- finish ---------- */
#s-finish { justify-content: space-between; background: linear-gradient(180deg, rgba(2,6,14,0) 40%, rgba(2,6,14,.7) 100%); }
.result {
  align-self: flex-start; margin-top: 4px; padding: 10px 16px; border-radius: 16px;
  background: var(--glass); backdrop-filter: blur(8px); border-left: 4px solid var(--lime-hi);
}
.result p { margin: 0; font-size: 14px; letter-spacing: .2em; color: var(--lime-hi); font-weight: 800; }
.result b { display: block; font-family: var(--display); font-weight: 400; font-size: 34px; }
.result small { color: var(--dim); font-size: 14px; }
.startline { width: 100%; display: grid; justify-items: center; gap: 10px; margin-top: auto; margin-bottom: 18px; }
.startline h3 { margin: 0; align-self: start; font-family: var(--display); font-weight: 400; font-size: clamp(24px, 7.4vw, 34px); text-shadow: 0 3px 10px rgba(0,0,0,.8); }
.field {
  width: 100%; height: 64px; padding: 0 18px; display: flex; align-items: center; border-radius: 20px;
  background: rgba(4,10,22,.72); backdrop-filter: blur(6px);
  border: 2.5px solid var(--lime-hi); box-shadow: 0 0 24px var(--lime-glow), inset 0 0 18px rgba(160,255,40,.15);
}
.field input { width: 100%; border: 0; outline: 0; background: none; font-family: var(--display); font-size: 22px; color: #fff; -webkit-user-select: text; user-select: text; }
.field input::placeholder { color: rgba(255,255,255,.35); }
.tag { padding: 8px 18px; border-radius: 14px; font-family: var(--cond); font-weight: 800; font-size: 22px; background: linear-gradient(180deg, #4f9a12, #2f6a06); border: 1.5px solid #9be04a; box-shadow: 0 0 16px rgba(120,220,0,.4); }
.finish-actions { width: 100%; display: grid; justify-items: center; }

/* ---------- share ---------- */
#s-share { justify-content: flex-end; background: rgba(2,6,14,.92); padding-top: calc(20px + var(--safe-t)); }
#poster { flex: 1; min-height: 0; max-width: 100%; object-fit: contain; border-radius: 16px; margin-bottom: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.1); }
[data-screen="share"] .brand { opacity: 0; }

/* ---------- loader / rotate ---------- */
#loader { position: absolute; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px; background: #02060e; color: var(--dim); font-size: 17px; transition: opacity .5s; }
#loader.done { opacity: 0; pointer-events: none; }
#loader i { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(255,255,255,.12); border-top-color: var(--lime-hi); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(1turn) } }
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  #rotate { display: grid; place-content: center; position: absolute; inset: 0; z-index: 60; background: #02060e; font-family: var(--display); font-size: 20px; }
}

/* ---------- minimap / pace notes / edge warning / best ---------- */
.clock .best { color: var(--lime-hi); font-family: var(--cond); font-weight: 800; letter-spacing: .06em; font-size: 13px; min-height: 0; }
#minimap { position: absolute; left: 12px; top: calc(112px + var(--safe-t)); width: 86px; height: 108px; }
.pace {
  position: absolute; left: 50%; top: calc(108px + var(--safe-t)); transform: translateX(-50%) scale(.85);
  display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 10px; border-radius: 14px;
  background: rgba(4,12,28,.78); border: 1.5px solid rgba(255,255,255,.25);
  font-family: var(--display); font-size: 20px; color: #fff; white-space: nowrap; opacity: 0; transition: opacity .25s, transform .25s;
}
.pace svg { width: 30px; height: 30px; color: var(--lime-hi); }
.pace.right svg { transform: scaleX(-1); }
.pace.hot { border-color: #ff7a3a; }
.pace.hot svg { color: #ff7a3a; }
.pace.on { opacity: 1; transform: translateX(-50%) scale(1); }
.edge-warn { position: absolute; inset: 0; pointer-events: none; opacity: 0; box-shadow: inset 0 0 90px 30px rgba(255,60,30,.75); display: grid; place-items: center; }
.edge-warn span { opacity: 0; transition: opacity .15s; }
.edge-warn.hot span { opacity: 1; }
.edge-warn span { margin-top: 30%; padding: 6px 14px; border-radius: 10px; background: rgba(120,10,0,.7); font-family: var(--display); font-size: 18px; letter-spacing: .04em; }
