/* Settings screen + mobile joystick HUD */

#settingsOverlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  pointer-events: auto;
  background: rgba(0, 8, 20, 0.55);
  touch-action: auto;
}
#settingsScreen {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 16px 16px 14px;
  pointer-events: auto;
  width: min(420px, 94vw);
  max-height: min(92vh, 760px);
  overflow-y: auto;
  box-sizing: border-box;
  touch-action: pan-y;
  background: rgba(7, 17, 36, 0.88);
  border: 1px solid rgba(120, 180, 255, 0.16);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#settingsScreen h2 { margin: 0 0 6px; font-size: clamp(1.15rem, 3.6vw, 1.4rem); }
#settingsScreen h3 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}
.settings-hint {
  margin: 0 0 8px;
  font-size: 12px;
  opacity: 0.72;
  line-height: 1.35;
}
.settings-desktop-note {
  display: none;
  margin: 6px 0 10px;
  font-size: 12px;
  opacity: 0.7;
}
body:not(.touch-play) #playModeSection { display: none; }
body:not(.touch-play) #settingsDesktopNote { display: block; }
.play-mode-section { margin-bottom: 4px; }
.mode-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  text-align: center;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px 7px;
  min-height: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  text-align: center;
  font-weight: 500;
  position: relative;
}
.mode-card:hover { filter: none; background: rgba(255, 255, 255, 0.08); }
.mode-card .mode-icon { font-size: 20px; line-height: 1.1; }
.mode-card strong {
  font-size: 12px;
  line-height: 1.15;
  font-weight: 700;
}
.mode-card > span:last-child {
  font-size: 10px;
  opacity: 0.72;
  line-height: 1.2;
  font-weight: 500;
}
.mode-card.selected {
  border-color: rgba(155, 89, 182, 0.95);
  background: rgba(155, 89, 182, 0.2);
  box-shadow: 0 0 0 1px rgba(155, 89, 182, 0.4);
}
.mode-card.selected::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  opacity: 0.95;
}
#modeCardJoy.selected {
  border-color: rgba(74, 215, 255, 0.95);
  background: rgba(74, 215, 255, 0.16);
  box-shadow: 0 0 0 1px rgba(74, 215, 255, 0.35);
}
#modeCardFree.selected {
  border-color: rgba(126, 217, 87, 0.95);
  background: rgba(126, 217, 87, 0.16);
  box-shadow: 0 0 0 1px rgba(126, 217, 87, 0.35);
}
.settings-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  margin: 8px 0 2px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.settings-toggle-copy { min-width: 0; flex: 1; }
.settings-toggle-copy h3 { margin: 0 0 4px; }
.settings-toggle-copy .settings-hint { margin: 0; }
.settings-toggle {
  flex: none;
  min-width: 64px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 13px;
  font-weight: 700;
}
.settings-toggle.on {
  background: rgba(74, 215, 255, 0.28);
  border-color: rgba(74, 215, 255, 0.75);
}
.settings-back-row { margin-top: 14px; }

#hudSettingsBtn {
  padding: clamp(5px, 1.2vw, 7px) clamp(8px, 1.6vw, 10px);
  font-size: clamp(12px, 2.8vw, 14px);
  border-radius: 999px;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  line-height: 1;
}

#joystickHud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  display: none;
}
#joystickHud.visible { display: block; }
#joystickHud.freestyle .joy-pad {
  display: none;
  pointer-events: none;
  right: auto;
  bottom: auto;
  opacity: 0.48;
}
#joystickHud.freestyle .joy-pad.floating { display: block; }
#joystickHud.freestyle .joy-pad.floating .joy-pad-face {
  background: rgba(8, 18, 36, 0.16);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 12px rgba(74, 215, 255, 0.08), 0 4px 12px rgba(0, 0, 0, 0.18);
}
#joystickHud.freestyle .joy-pad.floating.active .joy-pad-face {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(8, 22, 44, 0.24);
}
#joystickHud.freestyle .joy-pad.floating .joy-knob { opacity: 0.72; }

.joy-pad, .joy-action {
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  position: absolute;
}

.joy-pad {
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  width: clamp(96px, 26vmin, 140px);
  height: clamp(96px, 26vmin, 140px);
  border-radius: 50%;
}
.joy-pad-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(8, 18, 36, 0.38);
  border: 3px solid rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 0 18px rgba(74, 215, 255, 0.12), 0 6px 18px rgba(0, 0, 0, 0.35);
}
.joy-pad.active .joy-pad-face {
  border-color: rgba(74, 215, 255, 0.85);
  background: rgba(8, 22, 44, 0.5);
}
.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  height: 38%;
  margin: -19% 0 0 -19%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #e8fbff, #4ad7ff 58%, #2a8fad);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  will-change: transform;
}

.joy-action {
  left: max(16px, env(safe-area-inset-left, 0px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  width: clamp(72px, 18vmin, 96px);
  height: clamp(72px, 18vmin, 96px);
  border-radius: 50%;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: radial-gradient(circle at 35% 30%, #c084fc, #9b59b6 55%, #6f4bd8);
  border: 3px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}
.joy-action.pressed {
  transform: scale(0.94);
  filter: brightness(1.15);
}
.joy-action-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(255, 210, 74, 0);
  pointer-events: none;
}
.joy-action.pressed .joy-action-ring {
  border-color: rgba(255, 210, 74, 0.8);
}
.joy-action-icon { font-size: clamp(18px, 5vmin, 22px); line-height: 1; }
.joy-action-label {
  font-size: clamp(9px, 2.4vmin, 11px);
  letter-spacing: 0.08em;
  margin-top: 2px;
}

/* Mobile: radar top-left, room/leave chips beside it, score bottom-center */
body.touch-play.playing #hudCluster {
  display: flex;
  position: absolute;
  top: max(8px, env(safe-area-inset-top, 0px));
  left: max(8px, env(safe-area-inset-left, 0px));
  right: auto;
  bottom: auto;
  align-items: flex-start;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
  width: auto;
  height: auto;
}
body.touch-play.playing #minimapWrap,
body.touch-play.playing #hudTopLeft {
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  pointer-events: auto;
}
body.touch-play.playing #hudTopLeft {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: min(160px, 42vw);
}
body.touch-play.playing #scoreBoard {
  top: auto;
  bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 10px));
  left: 50%;
  transform: translateX(-50%);
}
body.touch-play.playing.joystick-hud #scoreBoard,
body.touch-play.playing.freestyle-hud #scoreBoard {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 36px);
}
body.touch-play.playing #trackChip {
  top: max(8px, env(safe-area-inset-top, 0px));
}

@media (max-width: 640px) {
  .mode-cards { grid-template-columns: repeat(3, 1fr); }
  #settingsScreen { padding: 14px 12px 12px; }
}
@media (max-height: 430px) {
  .mode-cards { grid-template-columns: repeat(3, 1fr); }
  .joy-pad {
    width: clamp(78px, 22vmin, 110px);
    height: clamp(78px, 22vmin, 110px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  }
  .joy-action {
    width: clamp(58px, 16vmin, 76px);
    height: clamp(58px, 16vmin, 76px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  }
}
@media (max-width: 400px) {
  .joy-pad {
    right: max(10px, env(safe-area-inset-right, 0px));
  }
  .joy-action {
    left: max(10px, env(safe-area-inset-left, 0px));
  }
}
