/* Mega Cube Clash — Battle UI (arena blue theme) */

:root {
  --arena: #071530;
  --arena-mid: #14539a;
  --font: "Nunito", system-ui, sans-serif;
  --display: "Fredoka", "Nunito", system-ui, sans-serif;

  --hud-bg: rgba(6, 18, 42, 0.78);
  --hud-border: rgba(120, 180, 255, 0.32);
  --hud-text: #e8f1ff;
  --hud-muted: #9bb8d8;
  --hud-gold: #ffe066;
  --hud-cyan: #7ec8ff;
  --hud-you: rgba(77, 163, 255, 0.28);
  --accent-blue: #3d9cff;
  --accent-blue-deep: #1e6fd4;
  --accent-hot: #ffb020;

  --space: clamp(10px, 2.4vw, 20px);
  --panel-pad-x: clamp(18px, 4.5vw, 28px);
  --panel-pad-y: clamp(20px, 3.8vh, 32px);
  --hud-gap: clamp(8px, 1.8vw, 12px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--arena);
  font-family: var(--font);
  color: var(--hud-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

#game-root {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#game-renderer {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  z-index: 0;
  touch-action: none;
  cursor: crosshair;
}

/* ── Menu overlays (match arena) ──────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(var(--space), var(--safe-t))
    max(var(--space), var(--safe-r))
    max(var(--space), var(--safe-b))
    max(var(--space), var(--safe-l));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.overlay-menu {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(61, 156, 255, 0.34), transparent 50%),
    radial-gradient(ellipse at 15% 70%, rgba(240, 101, 149, 0.12), transparent 40%),
    radial-gradient(ellipse at 85% 75%, rgba(255, 217, 61, 0.1), transparent 42%),
    linear-gradient(180deg, rgba(5, 14, 36, 0.55), rgba(7, 21, 48, 0.78));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.menu-glow {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.orb {
  position: absolute;
  border-radius: 22%;
  filter: blur(18px);
  opacity: 0.45;
  animation: orb-float 9s ease-in-out infinite;
  will-change: transform;
}

.orb-a {
  width: clamp(70px, 18vw, 120px);
  height: clamp(70px, 18vw, 120px);
  left: 8%;
  top: 18%;
  background: #f06595;
}

.orb-b {
  width: clamp(56px, 14vw, 90px);
  height: clamp(56px, 14vw, 90px);
  right: 12%;
  top: 22%;
  background: #4dabf7;
  animation-delay: -2s;
}

.orb-c {
  width: clamp(80px, 20vw, 140px);
  height: clamp(80px, 20vw, 140px);
  left: 18%;
  bottom: 14%;
  background: #ffd93d;
  animation-delay: -4s;
}

.orb-d {
  width: clamp(60px, 15vw, 100px);
  height: clamp(60px, 15vw, 100px);
  right: 16%;
  bottom: 20%;
  background: #51cf66;
  animation-delay: -1s;
}

.orb-e {
  width: clamp(48px, 12vw, 70px);
  height: clamp(48px, 12vw, 70px);
  left: 42%;
  top: 10%;
  background: #cc5de8;
  opacity: 0.35;
  animation-delay: -3s;
}

.orb-f {
  width: clamp(52px, 13vw, 80px);
  height: clamp(52px, 13vw, 80px);
  right: 38%;
  bottom: 10%;
  background: #ff9f43;
  opacity: 0.4;
  animation-delay: -5s;
}

.float-cube {
  position: absolute;
  display: grid;
  place-items: center;
  width: clamp(42px, 9vw, 64px);
  height: clamp(42px, 9vw, 64px);
  border-radius: 14px;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(0.85rem, 2.4vw, 1.15rem);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.28);
  animation: cube-drift 7.5s ease-in-out infinite;
  opacity: 0.88;
}

.fc-a {
  left: 7%;
  top: 28%;
  background: linear-gradient(160deg, #ff6b9d, #e64980);
  animation-delay: 0s;
}

.fc-b {
  right: 8%;
  top: 24%;
  background: linear-gradient(160deg, #4dabf7, #228be6);
  animation-delay: -1.4s;
}

.fc-c {
  left: 12%;
  bottom: 22%;
  background: linear-gradient(160deg, #69db7c, #2f9e44);
  animation-delay: -2.8s;
}

.fc-d {
  right: 11%;
  bottom: 26%;
  background: linear-gradient(160deg, #ffd43b, #f59f00);
  animation-delay: -4.2s;
}

.fc-e {
  left: 48%;
  top: 12%;
  background: linear-gradient(160deg, #da77f2, #9c36b5);
  animation-delay: -3.5s;
  opacity: 0.7;
}

@keyframes cube-drift {
  0%,
  100% {
    transform: translateY(0) rotate(-6deg);
  }
  50% {
    transform: translateY(-14px) rotate(8deg);
  }
}

@keyframes orb-float {
  0%,
  100% {
    transform: translateY(0) rotate(8deg) scale(1);
  }
  50% {
    transform: translateY(-18px) rotate(-6deg) scale(1.06);
  }
}

.panel {
  position: relative;
  z-index: 1;
  width: min(380px, 100%);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.6vh, 12px);
  padding: var(--panel-pad-y) var(--panel-pad-x);
  margin: auto;
  background:
    linear-gradient(180deg, rgba(14, 36, 72, 0.82), rgba(8, 22, 48, 0.9));
  border: 1px solid rgba(140, 190, 255, 0.28);
  border-radius: clamp(20px, 5vw, 28px);
  box-shadow:
    0 0 0 1px rgba(126, 200, 255, 0.06) inset,
    0 24px 60px rgba(0, 0, 0, 0.45),
    0 0 50px rgba(61, 156, 255, 0.1);
  text-align: center;
  animation: panel-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.start-panel {
  gap: clamp(8px, 1.5vh, 12px);
  padding-top: clamp(22px, 3.5vh, 30px);
  padding-bottom: clamp(20px, 3vh, 28px);
}

.logo-stack {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  margin-bottom: 2px;
  animation: logo-pop 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.08s both;
}

.logo-stack-sm {
  gap: 6px;
  margin-bottom: 0;
}

.logo-cube {
  display: grid;
  place-items: center;
  width: clamp(36px, 9vw, 48px);
  height: clamp(36px, 9vw, 48px);
  border-radius: 12px;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(0.78rem, 2.2vw, 1rem);
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.28);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.3);
  transform: rotate(-4deg);
}

.logo-stack-sm .logo-cube {
  width: 30px;
  height: 30px;
  font-size: 0.72rem;
  border-radius: 9px;
}

.lc-pink {
  background: linear-gradient(160deg, #ff6b9d, #e64980);
  transform: rotate(-8deg) translateY(4px);
}

.lc-blue {
  background: linear-gradient(160deg, #4dabf7, #1c7ed6);
  width: clamp(44px, 11vw, 58px);
  height: clamp(44px, 11vw, 58px);
  font-size: clamp(0.95rem, 2.6vw, 1.2rem);
  transform: rotate(2deg) translateY(-2px);
  z-index: 1;
}

.logo-stack-sm .lc-blue {
  width: 36px;
  height: 36px;
  font-size: 0.85rem;
}

.lc-gold {
  background: linear-gradient(160deg, #ffd43b, #f59f00);
  transform: rotate(7deg) translateY(6px);
}

@keyframes logo-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.brand {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(0.7rem, 2.4vw, 0.82rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--hud-muted);
}

.brand-hero {
  margin: 4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 0.92;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.02em;
  animation: brand-in 0.65s cubic-bezier(0.22, 1, 0.36, 1) 0.12s both;
}

.brand-line {
  font-size: clamp(2.4rem, 11vw, 3.5rem);
  color: #f4f8ff;
  text-shadow: 0 4px 24px rgba(61, 156, 255, 0.25);
}

.brand-line-accent {
  font-size: clamp(2.1rem, 9.5vw, 3.05rem);
  background: linear-gradient(180deg, #ffe066 0%, #ffb020 55%, #ff8a3d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 20px rgba(255, 176, 32, 0.35));
}

@keyframes brand-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tagline {
  margin: 4px 0 0;
  font-size: clamp(0.95rem, 3.2vw, 1.1rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--hud-cyan);
}

.hint {
  margin: 0 0 4px;
  font-size: clamp(0.8rem, 2.6vw, 0.9rem);
  font-weight: 700;
  color: var(--hud-muted);
}

.name-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  width: 100%;
  margin: 6px 0 2px;
  text-align: left;
}

.name-field span {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--hud-muted);
}

.name-field input {
  width: 100%;
  min-height: 48px;
  padding: clamp(11px, 2vh, 13px) 15px;
  border: 1px solid rgba(120, 180, 255, 0.28);
  border-radius: 14px;
  background: rgba(12, 36, 72, 0.9);
  color: var(--hud-text);
  font-size: clamp(1rem, 3.2vw, 1.05rem);
  font-weight: 800;
  outline: none;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.25);
  transition:
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.name-field input:focus {
  border-color: var(--hud-cyan);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.2),
    0 0 0 3px rgba(61, 156, 255, 0.28);
}

.controls-hint {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 8px;
  font-size: clamp(0.7rem, 2.4vw, 0.78rem);
  font-weight: 700;
  line-height: 1.35;
  color: var(--hud-muted);
}

.hint-touch {
  display: none;
}

.touch-ui .hint-desktop {
  display: none;
}

.touch-ui .hint-touch {
  display: inline;
}

.music-hint {
  margin-top: 6px;
  color: var(--hud-gold);
  letter-spacing: 0.04em;
}

.panel h2 {
  margin: 2px 0 10px;
  font-family: var(--display);
  font-size: clamp(1.6rem, 6vw, 2.1rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--hud-text);
}

.go-score-label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--hud-muted);
}

.go-score {
  margin: 0;
  font-size: clamp(2.4rem, 10vw, 3.1rem);
  font-weight: 900;
  line-height: 1;
  color: var(--hud-gold);
}

.go-rank {
  margin: 0 0 10px;
  font-size: clamp(0.9rem, 3vw, 1rem);
  font-weight: 800;
  color: var(--hud-cyan);
}

.campaign-progress {
  margin: 2px 0 0;
  font-size: clamp(0.72rem, 2.4vw, 0.82rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--hud-cyan);
}

.level-panel {
  width: min(480px, 100%);
  max-height: min(92vh, 780px);
  overflow: hidden;
}

.level-heading {
  margin: 2px 0 4px !important;
  font-family: var(--display) !important;
  font-size: clamp(1.45rem, 5vw, 1.9rem) !important;
  letter-spacing: 0.06em !important;
}

.level-hint {
  margin: 0 0 8px;
  font-size: clamp(0.72rem, 2.4vw, 0.82rem);
  font-weight: 700;
  color: var(--hud-muted);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 1.2vw, 7px);
  width: 100%;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 4px 2px 8px;
  margin-bottom: 4px;
  scrollbar-width: thin;
}

.level-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: clamp(58px, 14vw, 70px);
  padding: 6px 4px;
  border: 1px solid var(--hud-border);
  border-radius: 12px;
  background: rgba(18, 48, 92, 0.75);
  color: var(--hud-text);
  cursor: pointer;
  transition:
    transform 0.12s ease,
    background 0.15s ease,
    border-color 0.15s ease,
    filter 0.12s ease;
}

.level-btn:hover:not(:disabled) {
  filter: brightness(1.08);
  border-color: rgba(126, 200, 255, 0.55);
}

.level-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.level-btn .lv-num {
  font-size: clamp(0.95rem, 3.2vw, 1.1rem);
  font-weight: 900;
  line-height: 1;
}

.level-btn .lv-goal {
  font-size: clamp(0.55rem, 1.8vw, 0.62rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--hud-gold);
}

.level-btn .lv-tier {
  font-size: clamp(0.48rem, 1.6vw, 0.55rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--hud-muted);
}

.level-btn.tier-easy .lv-tier {
  color: #7dffb0;
}

.level-btn.tier-medium .lv-tier {
  color: #ffe066;
}

.level-btn.tier-hard .lv-tier {
  color: #ff8a7a;
}

.level-btn.tier-easy:not(.locked) {
  border-color: rgba(125, 255, 176, 0.28);
}

.level-btn.tier-medium:not(.locked) {
  border-color: rgba(255, 224, 102, 0.28);
}

.level-btn.tier-hard:not(.locked) {
  border-color: rgba(255, 138, 122, 0.32);
}

#hud-tier[data-tier="easy"] {
  color: #7dffb0;
}

#hud-tier[data-tier="medium"] {
  color: #ffe066;
}

#hud-tier[data-tier="hard"] {
  color: #ff8a7a;
}

.level-btn.current {
  border-color: rgba(255, 224, 102, 0.65);
  box-shadow: 0 0 0 2px rgba(255, 196, 64, 0.25);
  background: rgba(61, 156, 255, 0.28);
}

.level-btn.cleared {
  background: rgba(61, 180, 120, 0.22);
  border-color: rgba(81, 207, 102, 0.4);
}

.level-btn:disabled,
.level-btn.locked {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

.level-btn .lv-lock {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  font-size: 0;
  background: rgba(155, 184, 216, 0.55);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}

.level-btn .lv-lock::before {
  content: "";
  position: absolute;
  left: 2px;
  top: -4px;
  width: 8px;
  height: 6px;
  border: 2px solid rgba(155, 184, 216, 0.7);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}

/* ── Buttons ──────────────────────────────────────────── */

.btn {
  width: 100%;
  min-height: clamp(46px, 7vh, 52px);
  padding: 14px 18px;
  border: none;
  border-radius: 16px;
  font-size: clamp(0.95rem, 3.2vw, 1.08rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    filter 0.12s ease;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  transform: translateY(3px);
}

.btn-primary {
  color: #071428;
  background: linear-gradient(180deg, #ffe66d 0%, #ffc83d 45%, #ffb020 100%);
  box-shadow:
    0 6px 0 #c98910,
    0 12px 28px rgba(255, 196, 64, 0.32);
  font-family: var(--display);
  letter-spacing: 0.14em;
}

.btn-primary:active {
  box-shadow:
    0 2px 0 #c98910,
    0 4px 12px rgba(255, 196, 64, 0.22);
}

.btn-ghost {
  color: var(--hud-text);
  background: rgba(30, 70, 130, 0.55);
  border: 1px solid var(--hud-border);
  box-shadow: 0 4px 0 rgba(20, 50, 100, 0.8);
}

.btn-ghost:active {
  box-shadow: 0 1px 0 rgba(20, 50, 100, 0.8);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(40px, 10vw, 46px);
  height: clamp(40px, 10vw, 46px);
  padding: 0;
  border: 1px solid var(--hud-border);
  border-radius: 50%;
  color: var(--hud-text);
  background: var(--hud-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  flex-shrink: 0;
}

.btn-icon:active {
  transform: scale(0.94);
}

.btn-icon svg {
  width: clamp(18px, 4.5vw, 22px);
  height: clamp(18px, 4.5vw, 22px);
}

/* ── HUD ──────────────────────────────────────────────── */

#hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

#hud .score-card,
#hud .hud-actions,
#hud .leaderboard,
#hud .btn-icon,
#hud .touch-controls,
#hud .btn-action,
#hud .joystick {
  pointer-events: auto;
}

.hud-top {
  position: absolute;
  top: max(var(--hud-gap), var(--safe-t));
  left: max(var(--hud-gap), var(--safe-l));
  right: max(var(--hud-gap), var(--safe-r));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--hud-gap);
}

.score-card {
  min-width: min(132px, 38vw);
  max-width: min(200px, 46vw);
  padding: clamp(8px, 1.6vw, 10px) clamp(12px, 3vw, 16px) clamp(10px, 1.8vw, 12px);
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: clamp(12px, 3vw, 16px);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  text-align: left;
}

.score-label {
  font-size: clamp(0.58rem, 2vw, 0.68rem);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--hud-muted);
}

.cube-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 2px;
}

.cube-label {
  font-size: clamp(0.58rem, 2vw, 0.68rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--hud-muted);
}

.score-value {
  font-size: clamp(1.35rem, 5vw, 1.9rem);
  font-weight: 900;
  line-height: 1.05;
  color: var(--hud-gold);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-row {
  margin-top: 2px;
  font-size: clamp(0.68rem, 2.2vw, 0.78rem);
  font-weight: 800;
  color: var(--hud-cyan);
}

.hud-actions {
  display: flex;
  gap: clamp(6px, 1.5vw, 8px);
}

.leaderboard {
  position: absolute;
  top: calc(max(var(--hud-gap), var(--safe-t)) + clamp(52px, 12vw, 58px));
  right: max(var(--hud-gap), var(--safe-r));
  width: min(196px, 38vw);
  max-height: min(38vh, 300px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(8px, 1.5vw, 10px) clamp(10px, 2vw, 12px) clamp(10px, 1.8vw, 12px);
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: clamp(12px, 3vw, 16px);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  scrollbar-width: thin;
  /* Keep clear of the centered player */
  max-width: calc(50vw - 48px);
}

/* ── Touch controls (joystick + actions) ──────────────── */

.touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 22;
  pointer-events: none;
}

.touch-ui #hud:not(.hidden) .touch-controls,
body.show-touch-controls #hud:not(.hidden) .touch-controls {
  display: block;
}

.joystick {
  position: absolute;
  left: max(12px, var(--safe-l));
  bottom: max(16px, calc(var(--safe-b) + 8px));
  width: clamp(112px, 28vw, 140px);
  height: clamp(112px, 28vw, 140px);
  pointer-events: auto;
  touch-action: none;
  z-index: 23;
}

.joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(8, 24, 52, 0.45);
  border: 2px solid rgba(126, 200, 255, 0.35);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.3),
    inset 0 0 24px rgba(61, 156, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  margin: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #7ec8ff 0%, #3d9cff 100%);
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  will-change: transform;
  pointer-events: none;
}

.action-buttons {
  position: absolute;
  right: max(12px, var(--safe-r));
  bottom: max(20px, calc(var(--safe-b) + 12px));
  display: flex;
  flex-direction: column-reverse;
  gap: clamp(12px, 3vw, 16px);
  pointer-events: auto;
  z-index: 23;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(64px, 16vw, 76px);
  height: clamp(64px, 16vw, 76px);
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  color: #071428;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    0 6px 0 rgba(0, 0, 0, 0.28),
    0 10px 22px rgba(0, 0, 0, 0.32);
  transition:
    transform 0.1s ease,
    filter 0.12s ease,
    opacity 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn-action:active,
.btn-action.is-pressed {
  transform: translateY(3px) scale(0.96);
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.28),
    0 4px 10px rgba(0, 0, 0, 0.28);
}

.btn-action:disabled,
.btn-action.on-cooldown {
  opacity: 0.42;
  filter: grayscale(0.35);
  pointer-events: none;
}

.btn-boost {
  background: linear-gradient(180deg, #ffe66d 0%, #ffb020 100%);
  color: #5a3a00;
}

.btn-shield {
  background: linear-gradient(180deg, #8ce8ff 0%, #3d9cff 100%);
  color: #063056;
}

.btn-action svg {
  width: clamp(26px, 7vw, 32px);
  height: clamp(26px, 7vw, 32px);
  pointer-events: none;
}

.lb-title {
  margin-bottom: 6px;
  font-size: clamp(0.58rem, 2vw, 0.68rem);
  font-weight: 900;
  letter-spacing: 0.14em;
  color: var(--hud-muted);
}

#lb-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

#lb-list li {
  display: grid;
  grid-template-columns: clamp(18px, 4vw, 22px) minmax(0, 1fr) auto;
  gap: clamp(4px, 1.2vw, 6px);
  align-items: center;
  padding: clamp(4px, 1vw, 5px) clamp(4px, 1.2vw, 6px);
  border-radius: 8px;
  font-size: clamp(0.7rem, 2.4vw, 0.82rem);
  font-weight: 800;
  color: var(--hud-text);
}

#lb-list li.you {
  background: var(--hud-you);
}

#lb-list .pos {
  color: var(--hud-muted);
  font-variant-numeric: tabular-nums;
}

#lb-list .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  min-width: 0;
}

#lb-list .sc {
  font-variant-numeric: tabular-nums;
  color: var(--hud-gold);
}

.powerup-toast {
  position: absolute;
  left: 50%;
  bottom: max(22%, calc(var(--safe-b) + 18%));
  z-index: 25;
  max-width: min(90vw, 360px);
  padding: clamp(8px, 2vw, 10px) clamp(14px, 4vw, 22px);
  border-radius: 999px;
  background: rgba(6, 18, 42, 0.88);
  border: 1px solid var(--hud-border);
  color: var(--hud-gold);
  font-size: clamp(0.9rem, 3.5vw, 1.15rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
  animation: toast-pop 1.4s ease forwards;
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.show-touch-controls .powerup-toast,
.touch-ui .powerup-toast {
  bottom: max(28%, calc(var(--safe-b) + 160px));
}

@keyframes toast-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(12px) scale(0.92);
  }
  15% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  75% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px) scale(0.98);
  }
}

/* Phones — compact HUD, clear center for player */
@media (max-width: 720px) {
  .leaderboard {
    width: min(150px, 36vw);
    max-height: min(28vh, 200px);
    top: calc(max(var(--hud-gap), var(--safe-t)) + clamp(48px, 14vw, 56px));
  }

  .lb-title {
    letter-spacing: 0.1em;
  }

  #lb-list li {
    font-size: clamp(0.65rem, 2.2vw, 0.75rem);
    padding: 3px 4px;
  }

  .score-card {
    max-width: min(168px, 48vw);
  }

  .joystick {
    width: clamp(108px, 30vw, 132px);
    height: clamp(108px, 30vw, 132px);
  }
}

/* Narrow phones */
@media (max-width: 420px) {
  .panel {
    width: min(320px, 100%);
  }

  .leaderboard {
    width: min(128px, 40vw);
    max-height: min(26vh, 170px);
  }

  .lb-title {
    font-size: 0.55rem;
  }

  .level-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-height: min(48vh, 360px);
  }

  .orb {
    filter: blur(22px);
    opacity: 0.32;
  }

  .action-buttons {
    gap: 10px;
  }

  .btn-action {
    width: 64px;
    height: 64px;
  }
}

/* Very narrow */
@media (max-width: 340px) {
  .controls-hint span:not(.music-hint):not(.hint-touch):not(.hint-desktop) {
    display: none;
  }

  .leaderboard {
    width: min(112px, 42vw);
  }

  #lb-list .nm {
    max-width: 3.8em;
  }

  .score-label {
    font-size: 0.52rem;
  }
}

/* Tablet portrait / large phones */
@media (min-width: 600px) and (max-width: 1024px) {
  .leaderboard {
    width: min(180px, 28vw);
    max-height: min(34vh, 260px);
  }

  .joystick {
    width: 128px;
    height: 128px;
  }

  .btn-action {
    width: 72px;
    height: 72px;
  }
}

/* Short / landscape phones — keep menus + HUD usable */
@media (max-height: 520px) {
  .overlay {
    align-items: flex-start;
  }

  .panel {
    gap: 6px;
    padding: 14px 18px 16px;
  }

  .start-panel {
    padding-top: 14px;
  }

  .brand-hero .brand-line {
    font-size: clamp(1.8rem, 10vh, 2.6rem);
  }

  .brand-hero .brand-line-accent {
    font-size: clamp(1.55rem, 8.5vh, 2.2rem);
  }

  .float-cube,
  .logo-stack {
    display: none;
  }

  .hint,
  .controls-hint,
  .campaign-progress {
    display: none;
  }

  .name-field {
    margin: 2px 0;
  }

  .name-field input {
    min-height: 42px;
    padding: 9px 12px;
  }

  .btn {
    min-height: 42px;
    padding: 10px 14px;
  }

  .menu-glow {
    opacity: 0.45;
  }

  .leaderboard {
    max-height: min(32vh, 140px);
    top: calc(max(8px, var(--safe-t)) + 46px);
    width: min(140px, 30vw);
  }

  .powerup-toast {
    bottom: max(14%, calc(var(--safe-b) + 10%));
  }

  body.show-touch-controls .powerup-toast,
  .touch-ui .powerup-toast {
    bottom: max(18%, calc(var(--safe-b) + 96px));
  }

  .level-grid {
    max-height: min(38vh, 220px);
  }

  .level-btn {
    min-height: 46px;
  }

  .joystick {
    width: 96px;
    height: 96px;
    bottom: max(8px, var(--safe-b));
  }

  .action-buttons {
    bottom: max(10px, var(--safe-b));
    flex-direction: row;
    gap: 10px;
  }

  .btn-action {
    width: 56px;
    height: 56px;
  }
}

/* Ultra-short landscape */
@media (max-height: 380px) and (orientation: landscape) {
  .brand {
    display: none;
  }

  .tagline {
    margin: 2px 0 0;
    font-size: 0.95rem;
  }

  .panel h2 {
    margin: 0 0 6px;
    font-size: 1.4rem;
  }

  .go-score {
    font-size: 2rem;
  }

  .leaderboard {
    max-height: min(40vh, 120px);
  }

  .score-card {
    padding: 6px 10px 8px;
  }

  .score-value {
    font-size: 1.2rem;
  }
}

/* Wide desktops — keep HUD readable, not oversized */
@media (min-width: 1100px) {
  .leaderboard {
    width: 210px;
    max-width: none;
  }

  .score-card {
    min-width: 140px;
  }
}

/* Prefer showing touch UI whenever the primary input is coarse */
@media (pointer: coarse) {
  .hint-desktop {
    display: none;
  }

  .hint-touch {
    display: inline;
  }
}

@media (pointer: fine) and (hover: hover) {
  body:not(.force-touch-ui) .hint-touch {
    display: none;
  }

  body:not(.force-touch-ui) .hint-desktop {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  .orb,
  .float-cube,
  .panel,
  .logo-stack,
  .brand-hero,
  .powerup-toast {
    animation: none !important;
  }
}

@media (max-width: 520px) {
  .float-cube {
    opacity: 0.55;
    filter: saturate(0.95);
  }

  .fc-e {
    display: none;
  }
}
