/* Self-hosted fonts (SIL Open Font License, see assets/fonts/OFL-*.txt): no external requests. */
@font-face {
  font-family: 'Fredoka';
  src: url(assets/fonts/fredoka-latin.woff2) format('woff2');
  font-weight: 300 700;
  font-display: swap;
}
@font-face {
  font-family: 'Lilita One';
  src: url(assets/fonts/lilita-one-latin.woff2) format('woff2');
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #8cc6f7;
  --pill: #22304d;
  --pill-edge: #3b4d75;
  --green: #3fd15a;
  --blue: #3d8de0;
  --blue-dark: #2560a0;
  --red: #ff4757;
  --red-dark: #b02a37;
  --card: rgba(30, 42, 70, 0.9);
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  font-family: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* Boost speed lines: radial streaks around the edges, flickering by rotating one stripe period */
#speedLines {
  position: fixed; inset: -25%; pointer-events: none; opacity: 0;
  background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 255, 255, .7) 0deg .5deg, transparent .5deg 6deg);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 30%, #000 62%);
  mask-image: radial-gradient(circle at 50% 50%, transparent 30%, #000 62%);
  animation: streak .18s steps(3) infinite;
}
@keyframes streak { to { transform: rotate(6deg); } }

/* One arcade panel style shared by the HUD and the touch controls */
.panel {
  background: var(--pill); border: 3px solid var(--pill-edge); border-radius: 16px;
  box-shadow: 0 4px 0 #121b2e, inset 0 2px 0 rgba(255, 255, 255, .12);
  box-sizing: border-box;
}

/* HUD: one compact row */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 0;
  pointer-events: none;
  z-index: 5;  /* above the tap-to-start overlay so pause stays reachable */
}
.pill {
  height: 48px; padding: 0 14px 0 6px; display: flex; gap: 8px; align-items: center;
  font-weight: 700; font-size: 24px; min-width: 64px; font-variant-numeric: tabular-nums;
}
.coin-icon {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 35%, #fff2a8, #ffc81f 55%, #d99200);
  box-shadow: inset 0 0 0 3px #ffdd55, 0 2px 0 #a86f00;
}
.pill.bump { animation: bump .25s ease-out; }
@keyframes bump { 50% { transform: scale(1.15); } }

.center { flex: 1; min-width: 0; max-width: 230px; display: flex; flex-direction: column; gap: 4px; }
.center-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 0 22px 0 4px; }
#levelLabel, .score-chip {
  font-weight: 700; line-height: 1; color: #fff;
  -webkit-text-stroke: 1.5px #22304d; paint-order: stroke fill; text-shadow: 0 3px 0 #22304d;
}
#levelLabel { font-size: 20px; letter-spacing: .5px; white-space: nowrap; }
.score-chip { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#hudStars { margin-right: 5px; letter-spacing: -2px; }
#hudStars span { color: rgba(255, 255, 255, .35); transition: color .2s; }
#hudStars span.earned { color: #ffd84a; animation: starPop .4s ease-out; }
@keyframes starPop { 50% { transform: scale(1.6); } }

.ready-stars { display: flex; gap: 10px; align-items: center; background: var(--card); padding: 4px 14px; border-radius: 999px; font-weight: 700; }
#readyStars span { color: rgba(255, 255, 255, .3); font-size: 20px; }
#readyStars span.earned { color: #ffd84a; }
#readyGoals { font-size: 14px; opacity: .85; white-space: pre; }

#doneStars { display: flex; justify-content: center; gap: 6px; margin: -4px 0 0; }
.big-star { font-size: 52px; line-height: 1; color: rgba(255, 255, 255, .18); -webkit-text-stroke: 2px rgba(255, 255, 255, .25); }
.big-star:nth-child(2) { transform: translateY(-8px); font-size: 60px; }
.big-star.earned { color: #ffd84a; -webkit-text-stroke: 2px #c98a00; animation: bigStar .45s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes bigStar { from { transform: scale(0) rotate(-40deg); } }
#doneGoal { font-size: 14px; opacity: .8; margin-top: -4px; }
.progress-wrap { position: relative; padding-right: 18px; }
.progress { height: 20px; border-radius: 12px; overflow: hidden; padding: 2px; }
#progressFill {
  height: 100%; width: 0; border-radius: 8px; min-width: 10px;
  background: linear-gradient(#8af59a, var(--green) 50%, #23a03d);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15);
  transition: width .15s linear;
}
.flag {
  position: absolute; right: 0; top: 50%; width: 30px; height: 22px;
  margin-top: -14px; transform-origin: left center;
  background: conic-gradient(#111 25%, #fff 0 50%, #111 0 75%, #fff 0) 0 0 / 11px 11px;
  border: 3px solid #22304d; border-radius: 4px; box-shadow: 0 3px 0 #121b2e;
  animation: wave 1.1s ease-in-out infinite;
}
@keyframes wave {
  0%, 100% { transform: rotate(-8deg) skewY(0deg); }
  50% { transform: rotate(-2deg) skewY(-8deg); }
}
.flag.near { animation-duration: .45s; }

.icon-btn {
  pointer-events: auto; width: 48px; height: 48px; flex: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0;
}
.icon-btn span { width: 7px; height: 19px; background: #fff; border-radius: 3px; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #121b2e; }

/* Touch controls: left thumb steers (floating joystick), right thumb drives */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: flex-end; align-items: flex-end;
  padding: 0 14px calc(env(safe-area-inset-bottom) + 18px);
  pointer-events: none;
  z-index: 5;
}
.ctl-group { display: flex; gap: 10px; align-items: flex-end; }
.ctl {
  pointer-events: auto; touch-action: none; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: 1px;
  background: rgba(34, 48, 77, .86);
  transition: transform .05s, box-shadow .05s, background .05s;
}
.ctl.on { transform: translateY(3px); box-shadow: 0 1px 0 #121b2e, inset 0 2px 0 rgba(255, 255, 255, .12); }
#stickZone {
  position: fixed; left: 0; bottom: 0; width: 50%; height: 62%;
  pointer-events: auto; touch-action: none;
}
#stick {
  --size: 124px;
  position: absolute; width: var(--size); height: var(--size); margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  left: calc(env(safe-area-inset-left) + 92px); top: calc(100% - env(safe-area-inset-bottom) - 96px);
  border-radius: 50%; background: rgba(40, 40, 46, .62); border: 3px solid rgba(255, 255, 255, .95);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  opacity: .45; transition: opacity .15s;
  pointer-events: none;
}
#stick.active { opacity: 1; transition: none; }
#stickKnob {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; margin: -23% 0 0 -23%;
  border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
}
.pedal { width: 78px; border-radius: 20px; }
.pedal.brake { height: 74px; }
.pedal.gas { height: 110px; }
.pedal-icon { width: 34px; height: 8px; border-radius: 4px; }
.pedal.brake .pedal-icon { background: var(--red); box-shadow: 0 2px 0 var(--red-dark); }
.pedal.gas .pedal-icon { background: var(--green); box-shadow: 0 2px 0 #23a03d; height: 30px; width: 10px; }
.pedal.brake.on { background: #8a2a3a; border-color: var(--red); }
.pedal.gas.on { background: #1f7a3a; border-color: var(--green); }

/* Popups */
#popups {
  position: fixed; top: 36%; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: none;
}
.popup {
  font-weight: 700; font-size: 26px; white-space: nowrap;
  text-shadow: 0 3px 0 rgba(30, 20, 50, .5);
  animation: rise 1.2s ease-out forwards;
}
.popup.edge { color: #ffe066; }
.popup.big { font-size: 34px; }
.popup.great { color: #ffb347; font-size: 30px; }
.popup.insane { color: #ff5fa2; font-size: 36px; -webkit-text-stroke: 1px #fff; }
.popup.perfect { color: #ffd84a; font-size: 28px; }
.popup.combo { color: #6fe3ff; font-size: 24px; }
.popup.near { color: #fff; font-size: 24px; text-shadow: 0 3px 0 #e8333a; }
.popup.small { font-size: 18px; opacity: .9; }
.popup.gate { color: #2fd6ff; font-size: 30px; -webkit-text-stroke: 1px #fff; }

/* Live drift counter, positioned over the car each frame */
#driftLive {
  position: fixed; left: 0; top: 0; pointer-events: none; opacity: 0;
  font-weight: 700; font-size: 22px; color: #fff; white-space: pre;
  background: rgba(34, 48, 77, .88); border: 2px solid #3b4d75; border-radius: 999px;
  padding: 2px 12px; box-shadow: 0 3px 0 rgba(10, 20, 40, .35); transition: opacity .15s;
}
#driftLive.show { opacity: 1; }
#driftLive.great { color: #ffb347; font-size: 25px; border-color: #ffb347; }
#driftLive.insane { color: #ff5fa2; font-size: 28px; border-color: #ff5fa2; }
#driftLive.perfect { color: #ffd84a; }
@keyframes rise {
  0% { opacity: 0; transform: translateY(10px) scale(.8); }
  15% { opacity: 1; transform: translateY(0) scale(1.12); }
  30% { transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-36px); }
}

/* Screens */
.screen {
  position: fixed; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 16px;
}
.screen.show { display: flex; }
.screen { z-index: 4; }
.screen.dim { z-index: 6; }
.screen.dim { background: rgba(20, 35, 70, .4); }
#screenReady { justify-content: flex-end; padding-bottom: calc(env(safe-area-inset-bottom) + 150px); cursor: pointer; }
.title {
  font-size: 64px; font-weight: 700; line-height: .9; letter-spacing: 2px;
  text-shadow: 0 5px 0 #e5262f, 0 10px 0 rgba(20, 35, 70, .35);
  margin-bottom: auto; margin-top: 18vh;
}
.level-tag { background: var(--pill); border: 3px solid var(--pill-edge); padding: 5px 16px; border-radius: 999px; font-weight: 700; letter-spacing: 1px; box-shadow: 0 4px 0 #121b2e; }
.hint { font-size: 15px; line-height: 1.45; background: var(--card); padding: 10px 16px; border-radius: 14px; max-width: 320px; }
.tap { font-size: 22px; text-shadow: 0 2px 0 rgba(30, 20, 50, .5); font-weight: 700; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.96); } }

.card {
  background: var(--card); border-radius: 22px; padding: 24px 24px 20px;
  width: 100%; max-width: 320px; box-sizing: border-box;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
  display: flex; flex-direction: column; gap: 12px;
}
.card h2 { margin: 0 0 4px; font-size: 30px; }
.stats { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.stats div { display: flex; justify-content: space-between; font-size: 18px; background: rgba(255, 255, 255, .07); padding: 8px 12px; border-radius: 10px; }
.stats span { opacity: .75; }

.btn {
  border: 0; border-radius: 14px; padding: 13px 20px;
  font: inherit; font-weight: 700; font-size: 20px; color: #fff;
  background: var(--red); box-shadow: 0 5px 0 var(--red-dark); cursor: pointer;
}
.btn.secondary { background: var(--blue); box-shadow: 0 5px 0 var(--blue-dark); }
.btn.ghost { background: rgba(255, 255, 255, .1); box-shadow: none; font-size: 17px; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--red-dark); }
.btn.secondary:active { box-shadow: 0 2px 0 var(--blue-dark); }
.btn.ghost:active { box-shadow: none; }

.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) {
  #controls, .touch-only { display: none; }
  .desktop-only { display: inline; }
}

/* Short screens (phones in landscape): compact HUD, smaller controls, one-line title */
@media (max-height: 500px) {
  #hud { padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 12px) 0 calc(env(safe-area-inset-left) + 12px); }
  .pill { height: 40px; font-size: 20px; padding: 0 12px 0 5px; }
  .coin-icon { width: 26px; height: 26px; }
  .icon-btn { width: 40px; height: 40px; }
  .icon-btn span { height: 15px; width: 6px; }
  #levelLabel { font-size: 17px; }
  .score-chip { font-size: 15px; }
  .progress { height: 16px; }
  .flag { width: 24px; height: 18px; margin-top: -11px; }

  #controls { padding: 0 calc(env(safe-area-inset-right) + 14px) calc(env(safe-area-inset-bottom) + 12px) calc(env(safe-area-inset-left) + 14px); }
  #stick { --size: 104px; left: calc(env(safe-area-inset-left) + 80px); top: calc(100% - env(safe-area-inset-bottom) - 76px); }
  #stickZone { height: 75%; }
  .pedal { width: 66px; }
  .pedal.brake { height: 62px; }
  .pedal.gas { height: 88px; }

  #popups { top: 26%; }
  .popup { font-size: 22px; }
  .popup.insane { font-size: 28px; }

  #screenReady { justify-content: center; gap: 10px; padding-bottom: 16px; }
  .title { font-size: 44px; line-height: 1; margin: 0; }
  .title br { display: none; }
  .hint { font-size: 14px; padding: 8px 14px; max-width: 420px; }
  .tap { font-size: 19px; }

  .card { padding: 16px 20px 14px; gap: 8px; max-width: 360px; }
  .card h2 { font-size: 24px; margin: 0; }
  .stats { flex-direction: row; gap: 6px; margin-bottom: 2px; }
  .stats div { flex: 1; flex-direction: column; align-items: center; gap: 2px; font-size: 16px; padding: 6px 8px; }
  .stats span { font-size: 13px; }
  .big-star { font-size: 38px; }
  .big-star:nth-child(2) { font-size: 44px; }
  .ready-stars { padding: 2px 12px; }
  .btn { padding: 10px 16px; font-size: 18px; }
}

/* ---------- Title screen ---------- */
.title-screen {
  position: fixed; inset: 0; z-index: 8; display: none; overflow: hidden;
  background: #5aa9f0;
}
.title-screen.show { display: block; }
body.on-title #hud, body.on-title #controls { display: none; }
.title-bg {
  position: absolute; inset: 0;
  /* Square artwork on a tall screen: sized to 92% of the height so the whole car fits across
     the width and sits between the logo and PLAY; the strip below fades from the art's road
     tone under the menu buttons. */
  /* Portrait art (if present) covers everything; otherwise the square art shows through,
     fitted as described above. Slight over-scale anchored at the bottom keeps the car above PLAY. */
  background-color: #8a7884;
  background-image: url(assets/title-bg-portrait.webp), linear-gradient(to bottom, rgba(196, 176, 182, 0) 82%, #c4b0b6 91.5%, #8a7884 100%), url(assets/title-bg.webp);
  background-size: auto 114%, 100% 100%, auto 92%;
  background-position: 40% 100%, 0 0, 36% 0;
  background-repeat: no-repeat;
}
.title-top {
  position: absolute; top: calc(env(safe-area-inset-top) + 14px); left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: center;
}
.icon-btn.gear { pointer-events: auto; }
.logo {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top) + 74px); transform: translateX(-50%) rotate(-3deg);
  width: min(88vw, 460px); filter: drop-shadow(0 8px 0 rgba(20, 35, 70, .35));
  animation: logoIn .7s cubic-bezier(.3, 1.5, .5, 1) both;
}
@keyframes logoIn { from { transform: translateX(-50%) rotate(-3deg) scale(.6); opacity: 0; } }
.title-bottom {
  position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 18px);
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 14px;
}
.play-btn {
  pointer-events: auto; cursor: pointer; border: 4px solid #22304d; border-radius: 28px;
  width: min(78vw, 340px); height: 84px; display: flex; align-items: center; justify-content: center; gap: 18px;
  font: 700 44px Fredoka, ui-rounded, system-ui, sans-serif; color: #fff; letter-spacing: 1px;
  text-shadow: 0 3px 0 #b5470c;
  background: linear-gradient(#ffb43a, #ff8a14 55%, #f56d0a);
  box-shadow: 0 7px 0 #22304d, inset 0 4px 0 rgba(255, 255, 255, .45), inset 0 -6px 0 rgba(160, 50, 0, .35);
  animation: playPulse 1.6s ease-in-out infinite;
}
.play-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 #22304d, inset 0 4px 0 rgba(255, 255, 255, .45); animation: none; }
@keyframes playPulse { 50% { transform: scale(1.04); } }
.play-tri {
  width: 0; height: 0; border-top: 18px solid transparent; border-bottom: 18px solid transparent;
  border-left: 28px solid #fff; filter: drop-shadow(0 3px 0 #b5470c);
}
.play-sub {
  font-weight: 700; font-size: 16px; letter-spacing: 1px; color: #fff;
  background: rgba(34, 48, 77, .8); padding: 3px 14px; border-radius: 999px;
}
.play-sub .s { color: rgba(255, 255, 255, .35); }
.play-sub .s.on { color: #ffd84a; }
.menu-row { display: flex; gap: 10px; justify-content: center; margin-top: 4px; width: 100%; max-width: 440px; }
.menu-btn {
  pointer-events: auto; cursor: pointer; flex: 1; background: none; border: 0; padding: 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font: 700 12px Fredoka, ui-rounded, system-ui, sans-serif; letter-spacing: .5px; color: #fff;
  text-shadow: 0 2px 0 #22304d, 0 0 6px rgba(20, 35, 70, .6);
}
.menu-icon { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; border-radius: 18px; }
.menu-icon svg { width: 34px; height: 34px; }
.menu-btn:active .menu-icon { transform: translateY(3px); box-shadow: 0 1px 0 #121b2e; }

/* ---------- Menu panels (levels, cars, leaderboard, shop, settings) ---------- */
#screenMenu { z-index: 9; }
.menu-card { position: relative; max-width: 380px; max-height: 82vh; overflow: auto; }
.close-btn {
  position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; border-radius: 12px;
  border: 0; background: rgba(255, 255, 255, .12); color: #fff; font-size: 26px; line-height: 1; cursor: pointer;
}
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.world-head { font-weight: 700; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; opacity: .8; margin: 10px 0 6px; text-align: left; }
.world-head:first-child { margin-top: 0; }
.world-tag { font-weight: 700; font-size: 13px; letter-spacing: 1.5px; color: #fff; text-shadow: 0 2px 0 rgba(20, 35, 70, .6); }
.level-tile {
  aspect-ratio: 1; border-radius: 14px; border: 3px solid var(--pill-edge); background: #2c3d62; color: #fff;
  font: 700 21px Fredoka, ui-rounded, system-ui, sans-serif; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: 0 4px 0 #121b2e;
}
.level-tile .stars { font-size: 12px; letter-spacing: -1px; color: rgba(255, 255, 255, .3); }
.level-tile .stars .on { color: #ffd84a; }
.level-tile.current { border-color: #ff8a14; background: #3a4a72; }
.level-tile.locked { opacity: .45; cursor: default; }
.car-option {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  background: rgba(255, 255, 255, .07); border: 3px solid transparent; border-radius: 16px; padding: 12px; color: #fff; cursor: pointer;
  font: inherit;
}
.car-option.selected { border-color: #ff8a14; background: rgba(255, 138, 20, .15); }
.car-option b { font-size: 18px; display: block; }
.car-option small { opacity: .75; font-size: 13px; }
.car-option .tag { margin-left: auto; font-weight: 700; font-size: 13px; color: #ffb43a; }
.board-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, .07); font-size: 17px; }
.board-row + .board-row { margin-top: 6px; }
.board-row .stars { color: #ffd84a; letter-spacing: -1px; }
.menu-note { opacity: .75; font-size: 14px; margin: 4px 0 0; line-height: 1.4; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; font-size: 18px; }

@media (max-height: 500px) {
  .logo { width: min(40vw, 340px); top: calc(env(safe-area-inset-top) + 10px); }
  .title-bg { background-image: url(assets/title-bg.webp); background-size: cover; background-position: 42% 58%; }
  .title-bottom { gap: 6px; bottom: calc(env(safe-area-inset-bottom) + 10px); }
  .play-btn { height: 60px; width: 240px; font-size: 32px; border-radius: 22px; }
  .play-tri { border-top-width: 13px; border-bottom-width: 13px; border-left-width: 20px; }
  .menu-row { position: absolute; right: calc(env(safe-area-inset-right) + 12px); bottom: 0; flex-direction: column; width: auto; gap: 6px; }
  .menu-btn { flex-direction: row; gap: 8px; }
  .menu-icon { width: 44px; height: 44px; border-radius: 13px; }
  .menu-icon svg { width: 24px; height: 24px; }
  .play-sub { font-size: 14px; }
}

/* Wide screens (tablets in landscape, desktop): plain cover framing on the car and track. */
@media (min-aspect-ratio: 9/10) {
  .title-bg { background-image: url(assets/title-bg.webp); background-size: cover; background-position: 42% 62%; }
}

/* 16:9-ish phones: less height above the buttons, so lift the art a bit more. */
@media (min-aspect-ratio: 1/2) and (max-aspect-ratio: 2/3) {
  .title-bg { background-size: auto 125%, 100% 100%, auto 92%; }
}
/* Tablets in portrait: plain cover so the art fills the width. */
@media (min-aspect-ratio: 2/3) and (max-aspect-ratio: 9/10) {
  .title-bg { background-size: cover, 100% 100%, auto 92%; }
}
/* Short portrait phones: more compact PLAY and menu so the car stays visible. */
@media (max-height: 720px) and (max-aspect-ratio: 9/10) {
  .logo { width: min(78vw, 400px); top: calc(env(safe-area-inset-top) + 64px); }
  .title-bottom { gap: 7px; bottom: calc(env(safe-area-inset-bottom) + 12px); }
  .play-btn { height: 64px; font-size: 34px; border-radius: 22px; }
  .play-tri { border-top-width: 14px; border-bottom-width: 14px; border-left-width: 22px; }
  .menu-icon { width: 52px; height: 52px; border-radius: 15px; }
  .menu-icon svg { width: 28px; height: 28px; }
}

/* ---------- Combo banner ("DRIFT COMBO ×N") and trick feed ---------- */
#comboBanner {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 92px); z-index: 4;
  display: flex; flex-direction: column; align-items: center; pointer-events: none;
  transform: translateX(-50%) rotate(-7deg) skewX(-10deg) scale(0); opacity: 0;
  transition: transform .25s cubic-bezier(.3, 1.6, .5, 1), opacity .2s;
  font-family: 'Fredoka', ui-rounded, system-ui, sans-serif; font-weight: 700; line-height: .9;
}
#comboBanner.show { transform: translateX(-50%) rotate(-7deg) skewX(-10deg) scale(1); opacity: 1; }
#comboBanner.pop { animation: comboPop .4s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes comboPop {
  0% { transform: translateX(-50%) rotate(-12deg) skewX(-10deg) scale(1.55); }
  60% { transform: translateX(-50%) rotate(-5deg) skewX(-10deg) scale(.95); }
  100% { transform: translateX(-50%) rotate(-7deg) skewX(-10deg) scale(1); }
}
#comboBanner.bank { animation: comboBank .7s ease-in forwards; }
@keyframes comboBank {
  0% { transform: translateX(-50%) rotate(-7deg) skewX(-10deg) scale(1.15); opacity: 1; filter: brightness(1.6); }
  100% { transform: translateX(-50%) translateY(-60px) rotate(-7deg) skewX(-10deg) scale(.6); opacity: 0; }
}
.cb-burst {
  position: absolute; left: 50%; top: 46%; width: 360px; height: 240px; margin: -120px 0 0 -180px; z-index: -1;
  background: repeating-conic-gradient(from 0deg, rgba(255, 220, 70, 1) 0deg 5deg, rgba(255, 140, 20, 0) 5deg 14deg),
    radial-gradient(ellipse at center, rgba(255, 190, 40, .55), rgba(255, 140, 20, 0) 60%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 70%);
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 70%);
  animation: burstSpin 2.4s linear infinite;
}
@keyframes burstSpin { to { transform: rotate(360deg); } }
/* Heavy lettering: the word itself is drawn as a thick dark outline with a 3D shadow, and an
   ::after copy (from data-text) lays the gradient fill exactly on top. */
#comboBanner { font-family: 'Lilita One', 'Fredoka', ui-rounded, system-ui, sans-serif; font-weight: 400; }
.cb-top, .cb-word, .cb-x {
  position: relative; letter-spacing: 1px;
  color: #13234a; -webkit-text-stroke: 12px #13234a;
  text-shadow: 0 6px 0 #0b1530, 0 9px 0 #0b1530, 0 14px 18px rgba(0, 0, 0, .45);
}
.cb-top::after, .cb-word::after, .cb-x::after {
  content: attr(data-text); position: absolute; left: 0; top: 0;
  -webkit-text-stroke: 0; text-shadow: none;
}
.cb-top { font-size: 32px; margin-bottom: -4px; -webkit-text-stroke-width: 9px; }
.cb-top::after { color: #fff; }
.cb-main { display: flex; align-items: flex-end; gap: 6px; filter: drop-shadow(0 0 14px rgba(255, 170, 0, .5)); }
.cb-word::after, .cb-x::after {
  background: linear-gradient(#fffbd0 8%, #ffd21f 42%, #ff8a14 88%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.cb-word { font-size: 58px; }
.cb-x { font-size: 84px; line-height: .85; }
.cb-total {
  margin-top: 8px; padding: 5px 26px 7px; font-size: 32px; color: #fff; letter-spacing: 1px;
  background: #13234a; clip-path: polygon(4% 8%, 100% 0, 96% 92%, 0 100%);
  text-shadow: 0 3px 0 rgba(0, 0, 0, .45); font-variant-numeric: tabular-nums;
}
/* Hotter colours as the combo climbs */
#comboBanner.hot .cb-word::after, #comboBanner.hot .cb-x::after { background-image: linear-gradient(#fff1a8 10%, #ffab2e 45%, #ff4b2b 90%); }
#comboBanner.fire .cb-word::after, #comboBanner.fire .cb-x::after { background-image: linear-gradient(#ffe0ff 10%, #ff6ad5 45%, #b02cff 90%); }
#comboBanner.fire .cb-burst { background: repeating-conic-gradient(from 0deg, rgba(255, 106, 213, .95) 0deg 4deg, rgba(176, 44, 255, 0) 4deg 16deg); }

#comboFeed {
  position: fixed; right: calc(env(safe-area-inset-right) + 10px); top: 47%; z-index: 4; pointer-events: none;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px; max-width: 62%;
}
.feed-item {
  display: flex; gap: 6px; align-items: baseline; white-space: nowrap;
  font-family: 'Fredoka', ui-rounded, system-ui, sans-serif; font-weight: 700; font-size: 17px; letter-spacing: .3px;
  transform: skewX(-12deg); padding: 1px 10px 2px 8px;
  background: linear-gradient(90deg, rgba(19, 35, 74, .78), rgba(19, 35, 74, 0));
  animation: feedIn .28s cubic-bezier(.3, 1.6, .5, 1), feedOut .5s ease-in 2.4s forwards;
}
.feed-item .lbl { color: #fff; -webkit-text-stroke: 3px #13234a; paint-order: stroke fill; }
.feed-item .pts { color: #ffd84a; font-size: 19px; -webkit-text-stroke: 3px #13234a; paint-order: stroke fill; }
.feed-item.great .pts { color: #ffb347; }
.feed-item.insane .lbl, .feed-item.insane .pts { color: #ff6ad5; }
.feed-item.perfect .lbl { color: #ffe066; }
.feed-item.zone .lbl { color: #5ff0ff; }
.feed-item.coins .lbl { color: #ffe9a8; }
@keyframes feedIn { from { transform: translateX(60px) skewX(-12deg); opacity: 0; } }
@keyframes feedOut { to { transform: translateX(30px) skewX(-12deg); opacity: 0; } }

@media (max-height: 500px) {
  #comboBanner { top: calc(env(safe-area-inset-top) + 52px); }
  .cb-top { font-size: 22px; }
  .cb-word { font-size: 40px; }
  .cb-x { font-size: 58px; }
  .cb-word, .cb-x { -webkit-text-stroke-width: 9px; }
  .cb-top { -webkit-text-stroke-width: 7px; }
  .cb-total { font-size: 22px; }
  .cb-burst { width: 220px; height: 140px; margin: -70px 0 0 -110px; }
  #comboFeed { top: 28%; max-width: 40%; }
  .feed-item { font-size: 14px; }
  .feed-item .pts { font-size: 16px; }
}

/* ---------- Loading screen (plain HTML, visible before any script runs) ---------- */
#loading {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  background: linear-gradient(#1f74de, #5aa9f2 55%, #8fcaf8);
  transition: opacity .45s;
}
#loading.done { opacity: 0; pointer-events: none; }
.load-logo { width: min(80vw, 420px); filter: drop-shadow(0 8px 0 rgba(20, 35, 70, .35)); }
.load-bar {
  width: min(70vw, 300px); height: 18px; padding: 3px; box-sizing: border-box;
  background: #22304d; border: 3px solid #3b4d75; border-radius: 12px; box-shadow: 0 4px 0 #121b2e;
}
#loadFill {
  height: 100%; width: 8%; border-radius: 6px;
  background: linear-gradient(#ffd27a, #ff8a14); transition: width .25s;
}
@media (max-height: 500px) { .load-logo { width: min(50vw, 340px); } }
