:root { --ink: #1b1340; --pink: #ff4fa3; --yellow: #ffd23f; --lime: #7ae582; --sky: #2ec4ff; --violet: #9b5de5; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd3ff; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; -webkit-tap-highlight-color: transparent; color: var(--ink); }
canvas { display: block; }
button { font-family: inherit; }

/* ---------- HUD ---------- */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud { position: absolute; top: 0; bottom: 0; overflow: hidden; }
.hud[hidden] { display: none; }
.hud-tl { position: absolute; left: 12px; top: 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.pos { font: 900 64px/0.9 system-ui, sans-serif; color: var(--yellow); -webkit-text-stroke: 3px var(--ink); text-shadow: 4px 4px 0 var(--ink); letter-spacing: -1px; display: flex; align-items: baseline; transform-origin: 20% 80%; }
.pos span { font-size: 0.42em; color: #fff; -webkit-text-stroke: 2px var(--ink); margin-left: 3px; }
.pos.bump { animation: bump .35s ease-out; }
@keyframes bump { 0% { transform: scale(1.35) rotate(-6deg); } 100% { transform: scale(1); } }
.pill { background: rgba(255,255,255,.94); color: var(--ink); border: 3px solid var(--ink); border-radius: 14px; padding: 3px 11px; font-weight: 900; font-size: 15px; box-shadow: 3px 3px 0 var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill.lap { background: var(--yellow); font-size: 17px; }
.pill.best { font-size: 13px; background: #e9fbe9; }
.pill.best.new { background: var(--lime); animation: bump .4s; }
.mm { position: absolute; right: 12px; top: 62px; width: 150px; height: 150px; background: rgba(255,255,255,.88); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 3px 3px 0 var(--ink); }
.mm canvas { width: 100%; height: 100%; }
.slot span { opacity: .35; filter: grayscale(.6); }
.slot.has span, .slot.spin span { opacity: 1; filter: none; }
.slot { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: 64px; height: 64px; border-radius: 50%; background: rgba(255,255,255,.92); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); display: grid; place-items: center; font-size: 36px; }
.slot.has { background: var(--yellow); animation: slotin .4s ease-out; }
.slot.spin span { animation: slotspin .12s linear infinite; }
@keyframes slotin { 0% { transform: translateX(-50%) scale(1.5); } 100% { transform: translateX(-50%) scale(1); } }
@keyframes slotspin { 0% { transform: translateY(-6px); opacity: .5; } 100% { transform: translateY(6px); opacity: 1; } }
.slot small { position: absolute; bottom: -20px; font: 900 11px system-ui; white-space: nowrap; color: #fff; -webkit-text-stroke: 0; text-shadow: 0 0 3px var(--ink), 1px 1px 0 var(--ink); }
.speedo { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); text-align: center; color: #fff; font: 900 16px system-ui; text-shadow: 2px 2px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); }
.speedo b { display: block; font-size: 40px; line-height: 1; color: #fff; -webkit-text-stroke: 2px var(--ink); text-shadow: 3px 3px 0 var(--ink); }
.dbar { width: 150px; height: 12px; margin: 5px auto 0; border: 3px solid var(--ink); border-radius: 10px; background: rgba(255,255,255,.7); overflow: hidden; box-shadow: 2px 2px 0 var(--ink); opacity: 0; transition: opacity .2s; }
.dbar.on { opacity: 1; }
.dbar i { display: block; height: 100%; width: 0; background: var(--sky); transition: background .2s; }
.warn { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); font: 900 clamp(26px, 6vw, 46px)/1 system-ui; color: #ff5a4f; -webkit-text-stroke: 2.5px var(--ink); text-shadow: 4px 4px 0 var(--ink); white-space: nowrap; display: none; animation: blink .5s steps(2) infinite; }
.warn.on { display: block; }
@keyframes blink { 50% { opacity: .35; } }
.tag { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%); font: 900 14px system-ui; background: var(--ink); color: #fff; padding: 3px 10px; border-radius: 10px; display: none; }
.split .tag { display: block; }
.hud.split .mm { top: 62px; width: 120px; height: 120px; }
.splat { position: absolute; inset: 0; opacity: 0; transition: opacity .6s; pointer-events: none; }
.splat.on { opacity: 1; transition: opacity .05s; }
.splat i { position: absolute; border-radius: 50%; background: radial-gradient(circle at 42% 38%, rgba(255,150,120,.95) 0 14%, rgba(236,58,46,.93) 38%, rgba(196,22,30,.92) 72%); }
.splat i.blob { box-shadow: inset -6px -8px 0 rgba(140,10,20,.25); }
.splat i.seed { width: 8px; height: 13px; background: #fff3c4; border-radius: 50%; box-shadow: 0 0 0 1.5px rgba(255,200,140,.6); }
.splat i.drip { border-radius: 0 0 50% 50%; background: linear-gradient(rgba(214,31,38,.95), rgba(184,20,28,.85)); }

#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 4; overflow: hidden; }
.say { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); background: #fff; color: var(--ink); border: 3px solid var(--ink); border-radius: 18px; padding: 6px 12px; font-weight: 900; font-size: 15px; box-shadow: 3px 3px 0 var(--ink); white-space: nowrap; opacity: 0; transition: opacity .2s; }
.say::after { content: ""; position: absolute; left: 50%; bottom: -12px; border: 9px solid transparent; border-top-color: var(--ink); border-bottom: 0; transform: translateX(-50%); }
.say.on { opacity: 1; }
.say b { color: var(--pink); }

#banner { position: fixed; left: 50%; top: 34%; transform: translate(-50%, -50%); z-index: 6; font: 900 clamp(34px, 9vw, 84px)/1.02 system-ui, sans-serif; color: var(--yellow); -webkit-text-stroke: 3px var(--ink); text-shadow: 5px 5px 0 var(--ink); text-align: center; pointer-events: none; opacity: 0; white-space: nowrap; }
#banner.on { opacity: 1; }
#banner.pop { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
#banner small { display: block; font-size: .36em; color: #fff; -webkit-text-stroke: 1.5px var(--ink); text-shadow: 3px 3px 0 var(--ink); margin-top: 6px; }
#banner.go { color: var(--lime); font-size: clamp(48px, 13vw, 120px); }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
#flash { position: fixed; inset: 0; z-index: 3; pointer-events: none; background: #fff; opacity: 0; transition: opacity .5s; }

#topbtns { position: fixed; right: 12px; top: 10px; z-index: 7; display: flex; gap: 8px; }
#topbtns button { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--ink); background: rgba(255,255,255,.94); font-size: 19px; box-shadow: 2px 2px 0 var(--ink); cursor: pointer; padding: 0; line-height: 1; }
#topbtns button[hidden] { display: none; }
.pz { display: inline-block; width: 14px; height: 16px; border-left: 5px solid var(--ink); border-right: 5px solid var(--ink); box-sizing: border-box; vertical-align: middle; }

/* ---------- Сенсорное управление ---------- */
#touch { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#touch[hidden] { display: none; }
.tc { position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; pointer-events: none; }
.tc-left { left: calc(14px + env(safe-area-inset-left)); }
.tc-right { right: calc(14px + env(safe-area-inset-right)); display: grid; grid-template-columns: auto auto; grid-template-areas: "item drift" "brake gas"; gap: 10px; align-items: end; justify-items: center; }
.tbtn { pointer-events: auto; border: 4px solid var(--ink); background: rgba(255,255,255,.82); color: var(--ink); font-weight: 900; box-shadow: 3px 3px 0 var(--ink); border-radius: 50%; touch-action: none; padding: 0; display: grid; place-items: center; }
.tbtn.on, .tbtn:active { transform: translate(3px, 3px); box-shadow: none; background: var(--yellow); }
.steer { width: 84px; height: 84px; font-size: 34px; }
.gas { grid-area: gas; width: 86px; height: 86px; font-size: 18px; background: rgba(122,229,130,.9); }
.gas.auto { background: var(--lime); box-shadow: 0 0 0 4px rgba(122,229,130,.45), 3px 3px 0 var(--ink); }
.brake { grid-area: brake; width: 60px; height: 60px; font-size: 22px; background: rgba(255,170,160,.9); }
.drift { grid-area: drift; width: 74px; height: 74px; font-size: 13px; background: rgba(46,196,255,.88); color: #fff; text-shadow: 1px 1px 0 var(--ink); }
.item { grid-area: item; width: 62px; height: 62px; font-size: 28px; opacity: .5; }
.item.has { opacity: 1; background: var(--yellow); animation: slotin .4s; }
.tc-toggles { position: absolute; left: calc(14px + env(safe-area-inset-left)); bottom: calc(110px + env(safe-area-inset-bottom)); display: flex; gap: 6px; pointer-events: none; }
@media (max-height: 520px) { .tc-toggles { bottom: calc(92px + env(safe-area-inset-bottom)); } }
.toggle { pointer-events: auto; font: 800 12px system-ui; border: 2.5px solid var(--ink); border-radius: 12px; background: rgba(255,255,255,.88); padding: 5px 8px; color: var(--ink); white-space: nowrap; }
.toggle.on { background: var(--lime); }

/* ---------- Экраны ---------- */
.screen { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(27,19,64,.45); padding: 12px 12px 64px; box-sizing: border-box; overflow: auto; }
.screen.clear { background: transparent; place-items: end center; padding-bottom: 64px; }
.screen[hidden] { display: none; }
.card { background: #fff; color: var(--ink); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 6px 6px 0 var(--pink); padding: 20px 22px; max-width: 480px; width: 100%; text-align: center; box-sizing: border-box; animation: cardin .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes cardin { 0% { transform: translateY(30px) scale(.94); opacity: 0; } 100% { transform: none; opacity: 1; } }
.card h1 { margin: 4px 0 8px; font-size: clamp(25px, 6.6vw, 36px); line-height: 1.04; letter-spacing: -.5px; }
.card p { font-size: 15.5px; line-height: 1.38; margin: 0 0 10px; }
.hl { color: var(--pink); }
.kicker { display: inline-block; background: var(--yellow); border: 2.5px solid var(--ink); border-radius: 10px; padding: 2px 10px; font: 900 12px system-ui; letter-spacing: .5px; text-transform: uppercase; box-shadow: 2px 2px 0 var(--ink); }
.small { font-size: 13.5px !important; color: #5b5480; }
.label { font: 900 12px system-ui; text-transform: uppercase; letter-spacing: .6px; color: #5b5480; margin: 9px 0 5px; text-align: left; }
.start-card { max-width: 600px; padding-top: 14px; }
.start-card h1 { font-size: clamp(25px, 6.6vw, 38px); margin: 6px 0 6px; }
.start-card .lead { font-size: 15px; margin-bottom: 4px; }
.start-card .btn.big { margin-top: 10px; }
.btn { font: 900 19px system-ui, sans-serif; border: 3px solid var(--ink); border-radius: 16px; background: var(--pink); color: #fff; padding: 11px 24px; box-shadow: 3px 3px 0 var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
.btn.big { font-size: 22px; padding: 13px 34px; margin-top: 12px; }
.btn.white { background: #fff; color: var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: none; }
.stars { font-size: 40px; letter-spacing: 4px; line-height: 1.1; }
.stars i { font-style: normal; opacity: .22; filter: grayscale(1); }
.hero { font-size: 56px; line-height: 1; }
.racers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rc { border: 3px solid var(--ink); border-radius: 16px; background: #f4f0ff; padding: 4px 2px 6px; cursor: pointer; font-weight: 900; font-size: 13px; line-height: 1.1; color: var(--ink); box-shadow: 2px 2px 0 var(--ink); position: relative; }
.rc img, .rc canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 10px; }
.rc .tr { display: block; font: 700 10.5px/1.15 system-ui; color: #5b5480; margin-top: 2px; }
.rc.on { background: var(--yellow); box-shadow: 0 0 0 3px var(--pink), 3px 3px 0 var(--ink); transform: translateY(-2px); }
.rc .p2 { position: absolute; top: -9px; right: -6px; background: var(--sky); color: #fff; font: 900 10px system-ui; border: 2px solid var(--ink); border-radius: 8px; padding: 1px 5px; display: none; }
.rc.on2 .p2 { display: block; }
.rc.on2 { background: #c9f1ff; }
.tracks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tk { border: 3px solid var(--ink); border-radius: 14px; background: #fff; padding: 7px 4px; cursor: pointer; font: 900 13px/1.12 system-ui; color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.tk em { display: block; font-style: normal; font-size: 22px; margin-bottom: 2px; }
.tk.on { background: var(--lime); box-shadow: 0 0 0 3px var(--pink), 3px 3px 0 var(--ink); }
.mode { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.mode[hidden] { display: none; }
.chip { border: 3px solid var(--ink); border-radius: 12px; background: #fff; font: 900 14px system-ui; padding: 6px 12px; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--sky); color: #fff; text-shadow: 1px 1px 0 var(--ink); }
.hint { margin: 10px 0 0 !important; }
.results { text-align: left; margin: 8px 0 10px; display: grid; gap: 5px; }
.res { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 8px; align-items: center; border: 2.5px solid var(--ink); border-radius: 12px; padding: 5px 10px; font-weight: 800; font-size: 15px; background: #faf8ff; }
.res.me { background: var(--yellow); }
.res .pl { font: 900 20px system-ui; }
.res .tm { font-variant-numeric: tabular-nums; color: #5b5480; font-size: 13px; }
.res .pts { font: 900 13px system-ui; background: var(--ink); color: #fff; border-radius: 8px; padding: 2px 7px; }
.res .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); margin-right: 6px; vertical-align: -1px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.podium-card { max-width: 440px; padding: 14px 18px; }
.podium-card h1 { font-size: clamp(21px, 5.6vw, 30px); margin: 2px 0 6px; }
.podium-card .row { flex-wrap: nowrap; }
@media (max-width: 600px) {
  .podium-card { padding: 10px 12px; }
  .podium-card .stars { font-size: 26px; }
  .podium-card .results { gap: 3px; margin: 4px 0 6px; }
  .podium-card .res { padding: 2px 8px; font-size: 13.5px; grid-template-columns: 26px 1fr auto auto; }
  .podium-card .res .pl { font-size: 17px; }
  .podium-card p.small { margin-bottom: 6px; font-size: 12px !important; }
  .podium-card .btn { font-size: 16px; padding: 9px 14px; }
}
.podium-card .stars { font-size: 32px; }
.final-card { max-width: 500px; padding-top: 12px; }
.final-card .cuprow { display: flex; align-items: center; justify-content: center; gap: 10px; }
.final-card .cup { font-size: 50px; line-height: 1; animation: cup 1.6s ease-in-out infinite; display: inline-block; }
.final-card .stars { font-size: 32px; }
.final-card h1 { font-size: clamp(23px, 6vw, 32px); margin: 2px 0 6px; }
.final-card p { font-size: 14.5px; margin-bottom: 8px; }
.final-card .results { margin: 4px 0 8px; gap: 4px; }
.final-card .res { padding: 3px 10px; font-size: 14px; }
.final-card .btn.big { margin-top: 2px; }
.final-card .cta-note { margin: 8px 0 10px !important; }
.final-card #again { font-size: 16px; padding: 8px 18px; }
@media (min-aspect-ratio: 11/10) and (min-width: 700px) { #podium.screen.clear { place-items: center end; padding: 16px 4vw 70px 16px; } }
@keyframes cup { 50% { transform: rotate(-8deg) scale(1.08); } }

@media (max-width: 600px), (max-height: 520px) {
  .pos { font-size: 46px; -webkit-text-stroke: 2.5px var(--ink); text-shadow: 3px 3px 0 var(--ink); }
  .pill { font-size: 13px; padding: 2px 8px; border-width: 2.5px; box-shadow: 2px 2px 0 var(--ink); }
  .pill.lap { font-size: 14px; }
  .pill.best { font-size: 11.5px; }
  .mm { width: 108px; height: 108px; top: 60px; border-radius: 18px; }
  .slot { width: 52px; height: 52px; font-size: 28px; top: 10px; }
  .speedo { bottom: auto; top: 76px; font-size: 12px; }
  .speedo b { font-size: 26px; }
  .dbar { width: 96px; height: 10px; }
  .card { padding: 16px 14px; border-radius: 22px; }
  .card p { font-size: 14.5px; }
  .rc { font-size: 12px; }
  .rc .tr { font-size: 9.5px; }
  .say { font-size: 13px; padding: 5px 9px; border-width: 2.5px; }
  .btn.big { font-size: 20px; padding: 12px 28px; }
}
@media (max-height: 520px) {
  .steer { width: 70px; height: 70px; }
  .gas { width: 72px; height: 72px; }
  .drift { width: 62px; height: 62px; }
  .item { width: 54px; height: 54px; }
  .brake { width: 52px; height: 52px; }
  .tc-right { gap: 6px; }
  .speedo { top: auto; bottom: 46px; }
  .start-card { max-width: 640px; }
  .start-card .lead { display: none; }
  .screen.clear { padding-bottom: 50px; }
  .podium-card { padding: 10px 14px; }
  .podium-card .results { gap: 3px; }
  .podium-card .res { padding: 3px 8px; font-size: 13px; }
}
.touchmode .slot { display: none; }
.touchmode .speedo { bottom: auto; top: 8px; left: 50%; transform: translateX(-50%); }
.touchmode .speedo b { font-size: 30px; }

.speedfx { position: absolute; inset: -10%; pointer-events: none; opacity: 0; transition: opacity .25s;
  background: repeating-conic-gradient(from 0deg at 50% 55%, rgba(255,255,255,.0) 0deg 5deg, rgba(255,255,255,.55) 5.4deg 5.9deg, rgba(255,255,255,0) 6.3deg 11deg);
  -webkit-mask-image: radial-gradient(ellipse at 50% 55%, transparent 0 38%, #000 75%); mask-image: radial-gradient(ellipse at 50% 55%, transparent 0 38%, #000 75%); }
.speedfx.on { opacity: .55; animation: sfx .18s steps(2) infinite; }
@keyframes sfx { 50% { transform: rotate(2.5deg) scale(1.02); } }

@media (max-height: 520px) and (min-aspect-ratio: 4/3) {
  .start-card { max-width: 820px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 0 18px; align-items: center; padding: 10px 16px; }
  .start-card h1 { font-size: 25px; }
  .start-card .col-b .label:first-child { margin-top: 0; }
  .start-card .btn.big { margin-top: 8px; font-size: 19px; padding: 10px 26px; }
  .start-card .hint { font-size: 11.5px !important; line-height: 1.3; }
  .start-card .rc .tr { display: none; }
  .screen { padding-bottom: 56px; }
}

#vignette { position: fixed; inset: 0; z-index: 1; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 58%, rgba(27,19,64,.22) 100%); }
#banner.cd { font-size: clamp(80px, 20vw, 160px); }
#banner.small { font-size: clamp(22px, 5vw, 40px); white-space: normal; width: max-content; max-width: 90vw; -webkit-text-stroke-width: 2px; text-shadow: 3px 3px 0 var(--ink); }
#banner.small small { font-size: .55em; -webkit-text-stroke: 1px var(--ink); text-shadow: 2px 2px 0 var(--ink); }
