/* Title screen, starting lights and the phone's landscape prompt. */
body[data-screen='menu'] #backdrop {
  isolation: isolate;
  overflow: hidden;
  overflow: clip;
  pointer-events: none;
  background-position: 55% 50%;
}
body[data-screen='menu'] #backdrop::after {
  background:
    linear-gradient(90deg, #0d3149f2 1%, #123650da 8%, #0e455d8c 24%, #184c5922 43%, transparent 53%),
    linear-gradient(0deg, #11223770, transparent 18%);
}
body[data-screen='menu'] #backdrop::before {
  content: '';
  position: absolute;
  z-index: 1;
  inset: 0 59% 0 0;
  background:
    repeating-conic-gradient(#61c8d9 0 25%, transparent 0 50%) 2px 2px / 28px 28px;
  opacity: .12;
  transform: skewX(-12deg);
  transform-origin: bottom;
  mask-image: linear-gradient(110deg, #0009, transparent 48%, transparent 70%, #000 110%);
}
body[data-screen='menu'] #top {
  margin-inline: max(var(--rail), env(safe-area-inset-left)) max(var(--rail), env(safe-area-inset-right));
  padding-top: max(14px, env(safe-area-inset-top));
  justify-content: flex-end;
}
body[data-screen='menu'] #home { display: none; }
body[data-screen='menu'] .icon-button {
  background: #14374af2;
  border: 2px solid #fffae8;
  box-shadow: 0 3px 0 #152737;
}
#play-music {
  width: auto;
  padding-inline: .85em;
  font: 700 16px/1 Barlow, sans-serif;
  white-space: nowrap;
}
body[data-screen='menu'] .icon-button:hover { background: #215c6d; }
@media (pointer: coarse) {
  body[data-screen='menu'] :is(#mute, #fullscreen) { width: 44px; height: 44px; }
}
#menu.home {
  padding-left: max(var(--rail), env(safe-area-inset-left));
  padding-bottom: max(5vh, env(safe-area-inset-bottom));
}
#menu .home-group {
  display: block;
  width: clamp(245px, 29vw, 460px);
  position: relative;
  isolation: isolate;
}
.rally-badge {
  width: max-content;
  max-width: 100%;
  position: relative;
  isolation: isolate;
  transform: rotate(-7deg);
  margin: 0 0 clamp(26px, 5vh, 62px);
}
.rally-badge::before {
  content: '';
  position: absolute;
  inset: 27% -9% -1% -7%;
  z-index: -1;
  background: linear-gradient(118deg, transparent 83%, #2e93a0 83% 85%, transparent 85% 88%, #123947 88%), linear-gradient(151deg, #218aa1, #14596f 47%, #183540 47.3%);
  clip-path: polygon(3% 26%, 100% 0, 93% 76%, 12% 100%, 15% 83%, 0 83%, 7% 69%, 1% 69%, 9% 53%, 0 53%);
}
#menu h1 {
  width: max-content;
  max-width: 100%;
  margin: 0;
  transform: none;
  position: relative;
  z-index: 1;
  font-size: clamp(78px, min(9vw, 15.8vh), 156px);
  line-height: .79;
  letter-spacing: -.045em;
  color: #fffdf0;
  -webkit-text-stroke: 1px #fffdf0;
  paint-order: stroke fill;
  filter: drop-shadow(1px 2px 0 #163142) drop-shadow(2px 3px 0 #173646);
}
#menu h1 span { margin-left: 5%; text-shadow: 0 .034em #9cddd9; }
#menu h1 strong {
  color: #ffe349;
  -webkit-text-stroke: 1px #ffe349;
  margin: .045em 0 0 -.01em;
  text-shadow: 0 .033em #f4a52c, 0 .057em #e45830;
  font-size: 1.19em;
}
.badge-wing {
  position: absolute;
  top: -9%;
  right: -6%;
  width: 34%;
  height: 25%;
  transform: skewX(-26deg) rotate(-8deg);
  background: repeating-conic-gradient(#fff8db 0 25%, #183d50 0 50%) 0 0/20px 20px;
  clip-path: polygon(0 18%, 100% 0, 83% 69%, 0 100%);
}
.badge-stripe {
  position: absolute;
  left: 5%;
  right: 2%;
  height: 12%;
  bottom: -9%;
  transform: skewX(-28deg);
  background: linear-gradient(0deg, #173747 0 12%, #fd654f 12% 37%, #ffe7a4 37% 47%, #f14339 47% 100%);
  clip-path: polygon(0 50%, 100% 0%, 93% 67%, 0 100%);
}
#menu .mode-list {
  width: 91%;
  max-width: 365px;
  gap: 10px;
  margin: 0;
}
#menu .mode {
  --plate: #ffde45;
  --bevel: #df8d23;
  --button-ink: #372c28;
  gap: .48em;
  position: relative;
  isolation: isolate;
  min-height: 52px;
  padding: .22em .42em .24em .27em;
  color: var(--button-ink);
  font: 700 clamp(22px, 2.15vw, 34px)/.98 Barlow, sans-serif;
  letter-spacing: -.01em;
  text-transform: uppercase;
  border: 2px solid #173248;
  border-radius: 8px 15px 7px 13px;
  background: linear-gradient(180deg, #fff8 0 2px, transparent 2px 87%, #0001 87%), var(--plate);
  box-shadow: 0 3px 0 var(--bevel), 0 5px 0 #173248, 0 8px 12px #0003;
  text-shadow: 0 1px #fff5;
  transform: skewX(-7deg);
}
#menu .mode.secondary { --plate: #a0f3dd; --bevel: #36a69e; --button-ink: #163d48; }
#menu .mode > * { transform: skewX(7deg); }
#menu .mode > i:first-child {
  align-self: stretch;
  display: grid;
  place-items: center;
  width: 1.5em;
  min-height: 1.2em;
  color: var(--plate);
  background: #183a47;
  border-radius: 5px 9px 4px 8px;
}
#menu .mode > i:first-child svg { width: .93em; height: .93em; }
#menu .mode > i:last-child {
  color: var(--button-ink);
  padding: .12em;
  border-right: .18em solid var(--bevel);
  border-radius: 2px;
}
#menu .mode > i:last-child svg { stroke-width: 3.6; }
#menu .mode:hover, #menu .mode:focus-visible { transform: translateX(4px) skewX(-7deg); }
#menu .mode:active { transform: translate(4px,3px) skewX(-7deg); }
#menu #menu-help {
  margin: 18px 0 0;
  padding: 6px 13px;
  border-radius: 100px;
  background: #16384ce8;
  color: #fff9dc;
  border: 1px solid #cce9deaa;
  font: 700 16px/1 Barlow, sans-serif;
}
#menu #menu-help:hover { background: #24566a; }

#loader, #rotate {
  overflow: hidden;
  isolation: isolate;
  color: #fffbea;
  background: #133746;
  --course-art: url('../assets/ui/course-paddock.webp');
  --phone-art: url('../assets/ui/clockwork-crossing.webp');
}
#loader::before, #rotate::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(12deg, #0b283df5 4%, #12364bcc 58%, #16465bd9),
    var(--course-art) 50% 53%/cover;
}
#loader::after, #rotate::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  opacity: .12;
  background: repeating-conic-gradient(#a9e6d9 0 25%, transparent 0 50%) center / 30px 30px;
  mask-image: linear-gradient(155deg, #000 0%, transparent 25%, transparent 76%, #000 100%);
}
#loader {
  --loader-rail: max(6vw, env(safe-area-inset-left));
  place-items: end start;
  padding: 0 var(--loader-rail) max(7vh, env(safe-area-inset-bottom));
}
#game:has(#courses [data-course='ribbon'].selected) :is(#loader,#rotate) {
  --phone-art: url('../assets/ui/ribbon-run.webp');
  --course-art: url('../assets/ui/course-ribbon.webp');
}
#game:has(#courses [data-course='bubble'].selected) :is(#loader,#rotate) {
  --phone-art: url('../assets/ui/bubbleworks.webp');
  --course-art: url('../assets/ui/course-bubble.webp');
}
#loader::before {
  background: linear-gradient(0deg, #0e3046b8, transparent 56%), var(--course-art) center 47%/cover;
}
#loader .loader-body {
  width: min(420px, 79vw);
  isolation: isolate;
  padding: 17px 18px 13px;
}
#loader .loader-body::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  transform: skewX(-6deg);
  border-radius: 10px 21px 9px 20px;
  border: 2px solid #e0f4e5;
  border-bottom: 4px solid #60c7bd;
  box-shadow: 0 6px 0 #17364a, 0 9px 14px #0003;
  background: linear-gradient(117deg, transparent 70%, #18394b80 71%), #103346ed;
}
#loader .loader-body {
  text-align: center;
  position: relative;
}
.start-lights {
  display: flex;
  width: max-content;
  gap: 10px;
  margin: -33px auto 12px;
  padding: 8px 16px;
  border: 2px solid #9ad3c4;
  background: #153444;
  box-shadow: 0 4px #081f2b;
  border-radius: 6px 15px;
}
.start-lights i {
  display: block;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 34% 30%, #fff8cb 0 13%, #ffb65c 18% 44%, #fa6b44 65%, #bd352b 82%);
  border: 1px solid #0c2434;
  animation: start-light 1.5s ease-in-out infinite;
}
.start-lights i:nth-child(2) { animation-delay: .18s; }
.start-lights i:nth-child(3) { animation-delay: .36s; }
@keyframes start-light { 0%, 76%, 100% { opacity: .49; } 25%, 56% { opacity: 1; } }
#loader .loader-body strong {
  font-size: clamp(38px, min(6.4vw,16vh), 65px);
  line-height: 1;
  letter-spacing: -.045em;
  transform: rotate(-5deg);
  text-shadow: 0 .045em #174156, 0 .075em #082636;
}
#loader .loader-body em { color: #ffe04a; font: inherit; }
#loader .load-track {
  --lanes: repeating-linear-gradient(115deg, #fff4 0 2px, transparent 2px 14px);
  width: min(320px, 80%);
  height: 13px;
  border: 2px solid #a7d5cb;
  background: #103346;
  border-radius: 3px;
  transform: skewX(-12deg);
  padding: 1px;
  margin: clamp(12px, 2.8vh, 26px) auto 8px;
}
#loader .load-track i { background: var(--lanes), linear-gradient(90deg, #49dab6, #c7ea77, #ffda50); }
#loader .loader-body p { margin: 0; }
#loader .loader-body p, #rotate small { color: #dcf2e8; font-size: clamp(13px,1.5vw,16px); }
#rotate {
  gap: 12px;
  padding: max(25px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(25px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
#rotate strong {
  max-width: 11em;
  text-transform: uppercase;
  font: italic 900 clamp(30px, 9vw, 56px)/.98 Race,sans-serif;
  text-shadow: 0 3px #102c3d;
}
.tilt-device {
  width: min(212px, 60vw);
  aspect-ratio: 2 / 1;
  padding: 7px 15px;
  border: 3px solid #ffdc56;
  border-radius: 21px;
  background: #0e2d3c;
  box-shadow: 1px 4px 0 #e49035, 1px 7px 0 #0c2232;
  position: relative;
  margin: 0 0 26px;
  transform: rotate(-6deg);
  animation: tilt-handset 3.8s ease-in-out infinite;
}
.tilt-screen {
  display: block;
  height: 100%;
  border-radius: 9px;
  background: #69a1a2 var(--phone-art) 50% 56%/cover;
}
.tilt-direction {
  position: absolute;
  right: -16px;
  bottom: -13px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 2px solid #163548;
  border-radius: 50%;
  background: #9ce9c8;
  box-shadow: 1px 2px #153545;
}
.tilt-direction::before, .tilt-direction::after {
  content: '';
  position: absolute;
}
.tilt-direction::before {
  width: 14px;
  height: 14px;
  border: 3px solid #153545;
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
  transform: rotate(-44deg);
}
.tilt-direction::after {
  width: 0;
  height: 0;
  margin: 0 0 -2px 15px;
  border-style: solid;
  border-width: 6px 4px 0;
  border-color: #153545 transparent transparent;
}
@keyframes tilt-handset {
  0%, 14% { transform: rotate(-82deg) scale(.82); }
  40%, 84% { transform: rotate(-5deg); }
  100% { transform: rotate(-82deg) scale(.82); }
}

@media (orientation: portrait) {
  body[data-screen='menu'] #backdrop {
    background-color: #11394f;
    background-size: auto 72%;
    background-position: 74% top;
  }
  body[data-screen='menu'] #backdrop::after {
    background: linear-gradient(0deg, #0b2c41 3%, #124454 24%, #144457d6 36%, #0c304440 57%, transparent 75%);
  }
  body[data-screen='menu'] #backdrop::before { inset: 47% 0 0 0; transform: none; }
  #menu.home {
    align-items: flex-end;
    padding: 0 max(7vw,env(safe-area-inset-right)) max(4.6vh,env(safe-area-inset-bottom)) max(7vw,env(safe-area-inset-left));
  }
  #menu .home-group { width: min(100%, 490px); }
  #menu .rally-badge { margin: 0 0 3.2vh; }
  #menu h1 { font-size: clamp(62px,min(17.5vw,10vh),105px); }
  #menu .mode-list { width: 100%; max-width: 400px; }
}
@media (max-height: 550px) and (orientation: landscape) {
  body[data-screen='menu'] #top { padding: max(8px,env(safe-area-inset-top)) 0 6px; }
  #menu.home { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  #menu .home-group { width: clamp(210px,31vw,310px); }
  #menu .rally-badge { margin-bottom: 4.4vh; }
  #menu h1 { font-size: min(8.55vw, 15.9vh); }
  #menu .mode { min-height: 39px; font-size: 20px; }
  #menu .mode-list { gap: 8px; }
  #menu #menu-help { margin-top: 10px; font-size: 14px; padding: 4px 10px; }
}
@media (max-height: 350px) and (orientation: landscape) {
  #menu.home { padding-bottom: max(9px, env(safe-area-inset-bottom)); }
  #menu .rally-badge { margin-bottom: 15px; }
  #menu .mode { min-height: 40px; font-size: 18px; }
  #menu .mode-list { gap: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  #menu .home-group, .tilt-device, .start-lights i { animation: none; }
  #menu .mode, #loader .load-track i { transition: none; }
}
