/* Arena shares the compact race instruments and the same account storefront. */
#menu-screen .mode-options { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
#menu-screen .mode-option span { font-size: 10px; }
#menu-screen[data-mode="arena"] .race-options { grid-column: 1 / -1; grid-template-columns: 1fr; }
.arena-mode-preview { margin: 0; text-align: center; color: #c6bea6; font-size: 10px; line-height: 1.5; }
.arena-mode-preview strong { display: block; color: #e4c47e; font: 700 10px/1.5 Georgia, serif; letter-spacing: .6px; }
.arena-mode-preview span { display: block; margin-top: 4px; }
.party-options.is-arena { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.arena-status {
  position: absolute; top: calc(101px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 280px); padding: 6px 12px; border: 1px solid #a99156;
  border-radius: 2px; background: #171b17d9; color: #e8d098; text-align: center;
  font: 700 11px/1.3 'Trebuchet MS', Arial, sans-serif; letter-spacing: .3px;
  pointer-events: none; text-wrap: balance;
}
.arena-status.danger { border-color: #da6c4e; color: #ffbea0; background: #3a1415e8; }
.arena-spectator {
  position: absolute; left: 50%; bottom: calc(25px + var(--safe-bottom)); transform: translateX(-50%);
  width: min(340px, calc(100vw - 24px)); padding: 10px 12px 8px; text-align: center;
  border: 2px ridge #a49b7f; background: linear-gradient(#29271ff2, #101610f5);
  box-shadow: 0 3px 15px #0008; pointer-events: auto;
}
.spectator-caption { color: #cbbb92; font: 700 10px/1.3 'Trebuchet MS', Arial, sans-serif; letter-spacing: 1px; }
.spectator-controls { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 8px; align-items: center; margin: 5px 0; }
.spectator-controls .icon-button { width: 44px; min-width: 44px; height: 44px; min-height: 44px; font-size: 32px; line-height: 1; }
.spectator-controls > div { min-width: 0; }
#spectator-name { display: block; color: #f2d694; font: 700 18px/1.2 Georgia, serif; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#spectator-health { display: block; margin-top: 5px; color: #aade94; font: 700 11px/1.2 'Trebuchet MS', Arial, sans-serif; }
.arena-spectator > small { display: block; color: #a7a38c; font-size: 9px; }
#hud[data-spectating="true"] .race-bottom-center,
#hud[data-spectating="true"] .speedometer,
#hud[data-spectating="true"] .touch-controls,
#hud[data-spectating="true"] .active-effects { display: none !important; }
#hud[data-arena="true"] .hud-timing #hud-best { font-size: 13px; }
#hud[data-arena="true"] .race-place { min-width: 0; }
.store-card.chromie { background: radial-gradient(ellipse at 50% 25%, #745d2b70, transparent 65%), #161b1e; }
.store-card.magni { background: radial-gradient(ellipse at 50% 25%, #235e7780, transparent 65%), #161b1e; }
.store-free-hero { max-width: 340px; }

@media (pointer: coarse), (max-width: 760px), (orientation: landscape) and (max-height: 560px) {
  #hud[data-arena="true"] .position-copy > span { font-size: 21px; }
  #hud[data-arena="true"] .race-place { gap: 3px; padding-right: 4px; }
  #hud[data-arena="true"] .hud-lap { padding-inline: 5px; }
  .arena-status { top: calc(106px + var(--safe-top)); max-width: calc(100vw - 265px); font-size: 9px; padding: 4px 7px; }
  .arena-spectator { bottom: calc(12px + var(--safe-bottom)); padding: 8px 10px 6px; }
  .arena-spectator > small { display: none; }
  #spectator-name { font-size: 16px; }
}
@media (max-width: 760px) and (orientation: portrait) {
  .arena-status { top: calc(200px + var(--safe-top)); width: max-content; max-width: calc(100vw - 30px); }
  #hud[data-arena="true"].hud .race-center { top: calc(228px + var(--safe-top)); }
}
@media (orientation: landscape) and (max-height: 560px) {
  #menu-screen .arena-mode-preview { display: none; }
  #hud[data-arena="true"] .race-center { top: calc(144px + var(--safe-top)); }
}
@media (max-width: 400px) {
  #menu-screen .mode-options { gap: 3px; }
  #menu-screen .mode-option span { font-size: 9px; }
}
@media (orientation: landscape) and (max-height: 560px) and (max-width: 720px) {
  #menu-screen { grid-template-columns: minmax(0, 1.4fr) minmax(215px, 1fr); column-gap: 12px; }
  #menu-screen .selected-kart { gap: 6px; }
  #menu-screen .selected-kart h2 { font-size: 19px; }
  #menu-screen .mode-option { gap: 3px; padding-inline: 3px; }
  #menu-screen .mode-option .icon { width: 15px; height: 15px; flex-shrink: 0; }
}
@media (pointer: coarse) and (orientation: portrait) and (max-width: 350px) {
  /* Leave a gap between the joystick and the right-hand spell/action cluster. */
  #hud.hud .touch-joystick { flex-basis: 88px; width: 88px; height: 88px; }
  #hud.hud .joystick-knob { width: 44px; height: 44px; }
  #hud.hud .touch-actions { grid-template-columns: repeat(2, 44px); column-gap: 4px; }
  #hud.hud .touch-controls .touch-actions button { width: 44px; }
  #hud.hud .touch-controls .touch-actions [data-control="reset"] { width: 100%; }
}

/* Let the name determine the desktop card width. On narrow screens, give its
   longest word room instead of breaking a surname into individual letters. */
@media (max-width: 360px) and (orientation: portrait) {
  #menu-screen .selected-kart { padding: 8px; gap: 8px; }
  #menu-screen .kart-portrait { width: 48px; height: 48px; }
  #menu-screen .kart-change { width: 44px; min-width: 44px; padding-left: 6px; }
}
@media (orientation: landscape) and (max-height: 560px) and (max-width: 900px) {
  #menu-screen .selected-kart {
    display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 6px 10px;
    min-width: 0; width: max-content; max-width: 100%;
  }
  #menu-screen .kart-portrait { width: 48px; height: 48px; }
  #menu-screen .selected-kart-copy { min-width: min-content; }
  #menu-screen .kart-change {
    grid-column: 1 / -1; width: 100%; min-height: 44px; padding: 6px 0 0;
    border-left: 0; border-top: 1px solid #77726765; flex-direction: row;
  }
}

/* Keep the icon-only spells beside Drift in one right-hand action cluster.
   Portrait Reset sits above Drift/Turbo; landscape puts it before the spells. */
@media (pointer: coarse) {
  #hud.hud { --touch-action-size: 52px; --touch-action-gap: 8px; }
  #hud.hud .touch-actions {
    grid-template-columns: repeat(2, var(--touch-action-size));
    grid-template-areas: 'reset reset' 'drift boost'; gap: var(--touch-action-gap);
  }
  #hud.hud .touch-controls .touch-actions button { width: var(--touch-action-size); height: 52px; }
  #hud.hud .touch-controls .touch-actions [data-control="reset"] { width: 100%; height: 44px; }
  #hud.hud[data-arena="true"] .touch-actions { grid-template-areas: 'drift boost'; }
  #hud.hud .race-bottom-center, #hud.hud .race-bottom-center:has(.hero-slot:not([hidden])) {
    left: auto; right: calc(12px + var(--safe-right) + 2 * var(--touch-action-size) + var(--touch-action-gap) + var(--spell-gap));
    bottom: calc(12px + var(--safe-bottom)); width: max-content; transform: none;
  }
}
@media (pointer: coarse) and (orientation: landscape) {
  #hud.hud { --touch-spells: 1; }
  #hud.hud:has(.hero-slot:not([hidden])) { --touch-spells: 2; }
  #hud.hud .touch-actions { grid-template-areas: 'drift boost'; }
  #hud.hud .touch-controls .touch-actions [data-control="reset"] {
    position: fixed; bottom: calc(12px + var(--safe-bottom));
    right: calc(12px + var(--safe-right) + 2 * var(--touch-action-size) + var(--touch-action-gap) + (var(--touch-spells) + 1) * var(--spell-gap) + var(--touch-spells) * var(--spell-size));
    width: var(--touch-action-size); height: 52px;
  }
  #hud.hud .drift-indicator {
    position: fixed; left: 50%; bottom: calc(88px + var(--safe-bottom));
    transform: translateX(-50%); width: 216px;
  }
}
@media (pointer: coarse) and (orientation: portrait) and (max-width: 350px) {
  #hud.hud { --touch-action-size: 44px; --touch-action-gap: 4px; }
}
