* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0b111e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  touch-action: none !important;
  overscroll-behavior: none !important;
}

#game-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none !important;
  overscroll-behavior: none !important;
}

#c {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none !important;
}

/* Speed Lines Overlay */
#speed-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease-out;
  background:
    repeating-conic-gradient(from 0deg at 50% 50%, transparent 0deg 5deg, rgba(80, 255, 170, 0.12) 5.4deg 5.7deg),
    radial-gradient(circle at center, transparent 38%, rgba(65, 255, 155, 0.18) 78%, rgba(0, 15, 8, 0.48) 100%);
  mix-blend-mode: screen;
}

#speed-lines.active {
  opacity: 0.8;
}

/* Impact Flash */
#impact-flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  background-color: #fff;
  transition: opacity 0.05s ease-in;
}

#impact-flash.flash-red {
  background-color: #ff2a55;
  opacity: 0.65;
}

#impact-flash.flash-white {
  background-color: #ffffff;
  opacity: 0.85;
}

/* HUD Overlay */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  padding: env(safe-area-inset-top, 12px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 14px) env(safe-area-inset-left, 16px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Top Bar: Pause & Restart */
.hud-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: auto;
  width: 100%;
  z-index: 50;
}

.top-left-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(15, 22, 38, 0.75);
  backdrop-filter: blur(10px);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  color: #ffffff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: transform 0.1s, background 0.1s;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.hud-icon-btn:active {
  transform: scale(0.9);
  background: rgba(255, 42, 85, 0.85);
}

.track-name-badge {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
  background: rgba(15, 25, 45, 0.85);
  border: 1.5px solid rgba(57, 255, 143, 0.6);
  color: #8affbd;
  padding: 6px 14px;
  border-radius: 18px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
}

.track-name-badge:hover {
  border-color: #00f0ff;
  background: rgba(0, 240, 255, 0.2);
}

.track-name-badge:active {
  transform: scale(0.95);
}

.target-dist-badge {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
  background: rgba(255, 59, 48, 0.2);
  border: 1.5px solid #ff3b30;
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 18px;
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 0 14px rgba(255, 59, 48, 0.35);
}

.reticle-lock-text {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #00d2d3;
  text-shadow: 0 0 8px rgba(0, 210, 211, 0.9), 1px 1px 2px #000;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease-out;
  pointer-events: none;
}

#reticle.grapple-ready .reticle-lock-text {
  opacity: 1;
}

/* Edit Mode Top Panel */
#edit-mode-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.85);
  border: 1.5px solid #2ed573;
  padding: 6px 14px;
  border-radius: 24px;
  box-shadow: 0 0 16px rgba(46, 213, 115, 0.4);
}

#edit-mode-panel.hidden {
  display: none;
}

.edit-hint-text {
  color: #2ed573;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
}

.hud-edit-btn {
  border: none;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 6px 12px;
  border-radius: 14px;
  cursor: pointer;
}

.save-btn {
  background: #2ed573;
  color: #0b111e;
  box-shadow: 0 2px 8px rgba(46, 213, 115, 0.6);
}

.reset-layout-btn {
  background: #ff4757;
  color: #fff;
}

/* Dynamic Reticle with Grapple Lock */
#reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 52px;
  height: 52px;
  pointer-events: none;
  transition: transform 0.05s ease-out;
}

.reticle-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-top: -2px;
  margin-left: -2px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 6px #ffffff;
}

.reticle-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 2px dashed rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  animation: spinRing 14s linear infinite;
  transition: border-color 0.15s, transform 0.15s;
}

@keyframes spinRing {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.reticle-grapple-lock {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin-top: -11px;
  margin-left: -11px;
  border: 2.5px solid transparent;
  transform: rotate(45deg);
  transition: border-color 0.15s, transform 0.2s;
}

#reticle.grapple-ready .reticle-grapple-lock {
  border-color: #00d2d3;
  box-shadow: 0 0 12px #00d2d3;
  transform: rotate(45deg) scale(1.25);
}

#reticle.grapple-attached .reticle-ring {
  border-color: #ff9f43;
  border-style: solid;
}

.reticle-bars span {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 2px;
  background: rgba(255, 255, 255, 0.6);
  margin-top: -1px;
}

.reticle-bars .bar-l { left: -14px; }
.reticle-bars .bar-r { right: -14px; }

/* Mobile Controls Layer */
#controls-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Draggable Control Wrapper */
.draggable-control {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  transition: box-shadow 0.15s;
}

.drag-tag {
  display: none;
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

/* Edit Mode Visual Highlights */
.edit-mode-active .draggable-control {
  outline: 2.5px dashed #2ed573;
  outline-offset: 6px;
  cursor: grab;
}

.edit-mode-active .drag-tag {
  display: block;
}

/* 1. GREEN JOYSTICK (Clean Roblox / Brawl Stars Style) */
#ctrl-joystick {
  left: 60px;
  bottom: 50px;
}

.joystick-base {
  width: 136px;
  height: 136px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(46, 213, 115, 0.22) 0%, rgba(15, 45, 28, 0.72) 70%, rgba(8, 28, 16, 0.9) 100%);
  border: 3.5px solid #2ed573;
  box-shadow: 0 0 22px rgba(46, 213, 115, 0.45), inset 0 0 15px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.joystick-stick {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7bed9f 0%, #2ed573 50%, #10ac84 100%);
  border: 2.5px solid #ffffff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6), 0 0 14px rgba(46, 213, 115, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  transition: transform 0.05s ease-out;
  pointer-events: none;
}

.joystick-arrows-svg {
  width: 34px;
  height: 34px;
}

/* 2. BRAWL STARS ACTION BUTTONS (Grapple & Boost) */
.brawl-btn {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.35);
  transition: transform 0.08s, filter 0.08s;
}

.brawl-btn:active {
  transform: scale(0.92);
}

.btn-svg-container {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brawl-icon-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.brawl-btn-label {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.8px;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  margin-top: 2px;
}

/* BLUE GRAPPLE BUTTON (СИНИЙ ФОН + ПРИЦЕЛ) */
#ctrl-grapple {
  right: 140px;
  bottom: 55px;
}

.btn-grapple-blue {
  background: radial-gradient(circle at 35% 35%, #54a0ff 0%, #1e90ff 50%, #0033cc 100%);
  border: 3.5px solid #70a1ff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5), 0 0 18px rgba(30, 144, 255, 0.6);
}

.btn-grapple-blue.attached {
  border-color: #2ed573;
  box-shadow: 0 0 25px rgba(46, 213, 115, 0.85);
  animation: pulseGrapple 0.5s alternate infinite;
}

@keyframes pulseGrapple {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.brawl-cooldown-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: rgba(0, 0, 0, 0.65);
  transition: height 0.1s linear;
}

/* YELLOW BOOST BUTTON (ЖЕЛТОЕ + МОЛНИЯ) */
#ctrl-boost {
  right: 35px;
  bottom: 65px;
}

.btn-boost-yellow {
  width: 90px;
  height: 90px;
  background: radial-gradient(circle at 35% 35%, #ffeaa7 0%, #ffaa00 50%, #e67e22 100%);
  border: 3.5px solid #ffda79;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 170, 0, 0.7);
}

.btn-boost-yellow.active {
  transform: scale(1.05);
  box-shadow: 0 0 28px rgba(255, 170, 0, 0.95);
}

/* PAUSE MENU MODAL */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 10, 20, 0.75);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.2s ease-out;
}

.modal-backdrop.hidden {
  display: none;
}

.pause-card {
  width: 90%;
  max-width: 360px;
  background: rgba(18, 26, 45, 0.92);
  border: 2px solid rgba(0, 210, 211, 0.4);
  border-radius: 24px;
  padding: 26px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7), 0 0 25px rgba(0, 210, 211, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.pause-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffffff;
  text-shadow: 0 0 14px rgba(0, 210, 211, 0.8);
}

.pause-buttons-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.pause-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px;
  border-radius: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  outline: none;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  transition: transform 0.1s, background 0.1s, box-shadow 0.1s;
}

.pause-menu-btn:active {
  transform: scale(0.96);
}

.resume-btn {
  background: linear-gradient(90deg, #2ed573, #10ac84);
  color: #0b111e;
  border-color: #2ed573;
  box-shadow: 0 4px 14px rgba(46, 213, 115, 0.4);
}

.restart-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.next-track-btn {
  background: linear-gradient(90deg, #9c88ff, #8c7ae6);
  color: #ffffff;
  border-color: #a29bfe;
  box-shadow: 0 4px 14px rgba(156, 136, 255, 0.4);
}

.edit-btn {
  background: linear-gradient(90deg, #1e90ff, #0984e3);
  color: #ffffff;
  border-color: #70a1ff;
  box-shadow: 0 4px 14px rgba(30, 144, 255, 0.4);
}

.reset-btn {
  background: rgba(255, 71, 87, 0.18);
  color: #ff4757;
  border-color: rgba(255, 71, 87, 0.4);
}

/* Toast Banner */
#track-toast {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  text-align: center;
  pointer-events: none;
  opacity: 1;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease-out;
  z-index: 100;
}

#track-toast.hidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.7);
}

.toast-title {
  font-size: 30px;
  font-weight: 900;
  color: #2ed573;
  text-shadow: 0 0 24px rgba(46, 213, 115, 0.9), 2px 2px 0px #000;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.toast-sub {
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 2px;
  margin-top: 4px;
  text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.8);
}

/* Rotate Screen Overlay */
#rotate-device-screen {
  display: none !important;
}

@media (orientation: portrait) {
  #rotate-device-screen {
    display: none !important;
  }
}

.phone-rotate-icon {
  position: relative;
  width: 70px;
  height: 120px;
  margin-bottom: 30px;
}

.phone-shape {
  width: 60px;
  height: 100px;
  border: 3px solid #00f0ff;
  border-radius: 12px;
  margin: 0 auto;
  animation: phoneRotateAnim 2.5s ease-in-out infinite;
}

@keyframes phoneRotateAnim {
  0%, 20% { transform: rotate(0deg); }
  50%, 80% { transform: rotate(90deg); }
  100% { transform: rotate(90deg); }
}

.rotate-arrow {
  position: absolute;
  top: 35%;
  right: -10px;
  font-size: 32px;
  color: #2ed573;
}

.rotate-text {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #00f0ff;
  margin-bottom: 8px;
}

.rotate-sub {
  font-size: 13px;
  color: #8b9bb4;
  margin-bottom: 24px;
}

.dismiss-rotate-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(0, 240, 255, 0.6);
  color: #00f0ff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.dismiss-rotate-btn:active {
  background: rgba(0, 240, 255, 0.25);
  transform: scale(0.96);
}

#rotate-device-screen.dismissed {
  display: none !important;
}

/* Construction free-flight mode and scrollable mobile pause menu. */
.pause-card {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.free-map-btn {
  background: linear-gradient(110deg, #e6b94d, #bc7f2c);
  color: #202b2c;
  border-color: #f4d688;
}
.free-map-copy { display: flex; flex-direction: column; gap: 5px; }
.free-map-copy small { font-size: 9px; letter-spacing: 0.6px; line-height: 1.4; }
@media (max-height: 500px) {
  .pause-card { padding: 14px 18px; gap: 10px; }
  .pause-title { font-size: 20px; }
  .pause-buttons-list { gap: 7px; }
  .pause-menu-btn { padding: 10px; font-size: 12px; }
}
