#mobileControls {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

#rotatePrompt {
  display: none;
}

.touch-skill-pad {
  position: absolute;
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 54px);
  gap: 7px;
  pointer-events: auto;
}

.touch-skill {
  width: 54px;
  height: 54px;
  padding: 0;
  border: 1px solid #75dfffa8;
  border-radius: 12px;
  color: #eefaff;
  background: linear-gradient(145deg, #17314deF, #071326f2);
  box-shadow: 0 4px 14px #0009, inset 0 0 14px #55dfff14;
  font: 900 18px/1 system-ui, sans-serif;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-skill small {
  display: block;
  margin-top: 4px;
  color: #a9c6df;
  font: 700 8px/1 system-ui, sans-serif;
  letter-spacing: .3px;
}

.touch-skill[data-ability="R"] {
  border-color: #ca79ffb3;
  background: linear-gradient(145deg, #39214feF, #130d28f2);
}

.touch-skill.is-ready {
  box-shadow: 0 0 16px #d96bff70, inset 0 0 14px #d96bff2a;
}

.touch-skill.is-locked {
  opacity: .55;
}

.touch-joystick {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(15px + env(safe-area-inset-bottom));
  width: 116px;
  height: 116px;
  border: 1px solid #72dfff55;
  border-radius: 50%;
  background: radial-gradient(circle, #15334c99 0 45%, #08162caa 72%);
  box-shadow: 0 4px 18px #0009, inset 0 0 18px #46dfff20;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-joystick::before,
.touch-joystick::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.touch-joystick::before {
  inset: 12px;
  border: 1px dashed #9deaff42;
  border-radius: 50%;
}

.touch-joystick::after {
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #c4f6ff99;
  transform: translate(-50%, -50%);
}

.touch-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  border: 1px solid #b3f2ffcc;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #8cefff, #16749a 60%, #0a263e);
  box-shadow: 0 2px 13px #26d8ff70, inset 0 0 10px #ffffff66;
  transform: translate(-50%, -50%);
  transition: box-shadow .12s;
  pointer-events: none;
}

.touch-joystick.is-boosting .touch-stick {
  box-shadow: 0 0 22px #ffbd4e, inset 0 0 12px #fff;
}

.touch-boost-label {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(136px + env(safe-area-inset-bottom));
  width: 116px;
  color: #ffd88b;
  text-align: center;
  font: 900 9px/1.2 system-ui, sans-serif;
  letter-spacing: 1px;
  opacity: 0;
  text-shadow: 0 1px 6px #000;
  transition: opacity .12s;
  pointer-events: none;
}

.touch-boost-label.is-active {
  opacity: 1;
}

@media (min-width: 901px) and (pointer: fine) {
  .bottom {
    right: auto !important;
    left: 50% !important;
    top: auto !important;
    bottom: 14px !important;
    transform: translateX(-50%) !important;
    width: min(790px, 95vw) !important;
  }

  .abilityrow {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  .ability {
    display: block !important;
    min-height: 58px !important;
    padding: 9px !important;
    text-align: center !important;
  }

  .ability small {
    grid-row: auto !important;
    grid-column: auto !important;
    max-height: none !important;
    font-size: 10px !important;
  }

  .ability .muted {
    grid-column: auto !important;
    grid-row: auto !important;
  }

  .utility .key {
    display: block !important;
  }
}

@media (max-width: 900px), (pointer: coarse) {
  #mobileControls.is-active {
    display: block;
  }

  .bottom {
    display: none !important;
  }
}

@media (max-width: 900px) {
  .topbar {
    align-items: center !important;
    padding: 7px 8px !important;
  }

  .brand {
    max-width: 58vw;
    font-size: 11px !important;
    letter-spacing: .7px !important;
  }

  .brand span {
    display: block;
    font-size: 9px;
  }

  #modeChip {
    display: none !important;
  }

  #menuBtn {
    padding: 6px 9px !important;
    font-size: 11px;
  }

  .hud {
    top: 53px !important;
    left: 6px !important;
    width: calc(50vw - 12px) !important;
  }

  .hud.right {
    right: 6px !important;
    left: auto !important;
    width: calc(50vw - 12px) !important;
  }

  .hud .panel {
    padding: 7px !important;
    border-radius: 10px !important;
  }

  .hud .nameRow {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 3px !important;
    line-height: 1.15;
  }

  .hud.right .nameRow {
    justify-items: end;
  }

  .hud .nameRow span {
    overflow-wrap: anywhere;
    font-size: 10px;
  }

  .hud .nameRow span:last-child {
    color: var(--cyan);
    font-size: 9px;
  }

  .hud .muted {
    display: none !important;
  }

  .hud .bar {
    height: 6px !important;
    margin: 4px 0 5px !important;
  }

  .hud .statline {
    gap: 4px;
    font-size: 8px !important;
  }

  .hud .statline b {
    font-size: 9px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .hud {
    top: 53px !important;
    left: 8px !important;
    width: clamp(175px, 25vw, 300px) !important;
  }

  .hud.right {
    right: 8px !important;
    left: auto !important;
    width: clamp(175px, 25vw, 300px) !important;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  #rotatePrompt {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: #eef8ff;
    background: radial-gradient(ellipse at center, #0b1d35, #030711 78%);
    text-align: center;
  }

  .rotate-card {
    max-width: 320px;
  }

  .rotate-phone {
    width: 56px;
    height: 90px;
    margin: 0 auto 18px;
    border: 3px solid #65eaff;
    border-radius: 11px;
    box-shadow: 0 0 24px #38dfff66;
    transform: rotate(90deg);
  }

  .rotate-card strong {
    display: block;
    color: var(--cyan);
    font-size: 15px;
    letter-spacing: 2px;
  }

  .rotate-card p {
    margin: 8px 0 0;
    color: #b5cbe2;
    font-size: 13px;
  }
}

@media (max-width: 390px) {
  .touch-skill-pad {
    grid-template-columns: repeat(2, 50px);
    gap: 6px;
  }

  .touch-skill {
    width: 50px;
    height: 50px;
  }

  .touch-joystick {
    width: 108px;
    height: 108px;
  }

  .touch-boost-label {
    bottom: calc(128px + env(safe-area-inset-bottom));
    width: 108px;
  }
}

@media (max-height: 430px) and (pointer: coarse) {
  .touch-skill-pad {
    bottom: calc(7px + env(safe-area-inset-bottom));
  }

  .touch-joystick {
    bottom: calc(6px + env(safe-area-inset-bottom));
  }

  .touch-boost-label {
    bottom: calc(120px + env(safe-area-inset-bottom));
  }
}
