/* Base Styles */
body {
  margin: 0;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  touch-action: manipulation;
}

body.menu {
  background: radial-gradient(circle at top, #2a4a6a 0%, #0f1b28 45%, #0b0f16 100%);
  color: #f5f5f5;
  overflow-x: hidden;
  overflow-y: auto;
}

#menu {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  position: relative;
}

@media (max-height: 720px) {
  #menu {
    align-items: flex-start;
  }
}

#menu::before,
#menu::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  opacity: 0.35;
  background: radial-gradient(circle, rgba(92, 153, 255, 0.8), rgba(92, 153, 255, 0));
  filter: blur(10px);
}

#menu::before {
  width: 320px;
  height: 320px;
  top: 10%;
  left: 5%;
}

#menu::after {
  width: 420px;
  height: 420px;
  bottom: -10%;
  right: -5%;
}

.menu-panel {
  position: relative;
  z-index: 1;
  width: min(520px, 90vw);
  background: rgba(12, 20, 30, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
  border-radius: 18px;
  padding: 36px 32px;
  text-align: center;
}

.menu-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 1px;
}

.menu-subtitle {
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
}

.menu-actions {
  margin-top: 28px;
  display: grid;
  gap: 14px;
}

.menu-btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 14px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f3b04a, #e07b2d);
  color: #1a0f07;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 8px 18px rgba(224, 123, 45, 0.35);
}

.menu-btn.secondary {
  background: linear-gradient(135deg, #4aa0f3, #4ac3f3);
  color: #081421;
  box-shadow: 0 8px 18px rgba(74, 160, 243, 0.35);
}

.menu-btn:hover {
  transform: translateY(-2px);
}

.menu-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 3px;
}

.menu-hint {
  margin-top: 20px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
}

.menu-status {
  margin-top: 12px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
}

.menu-status.online {
  color: #7fe3a8;
}

.menu-status.offline {
  color: #f29b9b;
}

.menu-version {
  margin-top: 10px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.6px;
}

.menu-cards {
  margin-top: 24px;
  display: grid;
  gap: 12px;
}

.menu-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
}

.menu-card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(255, 255, 255, 0.7);
}

.menu-card-body {
  margin-top: 6px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
}

.menu-extras {
  margin-top: 20px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.menu-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  line-height: 1.4;
}

.preview-card {
  overflow: hidden;
}

.menu-preview {
  position: relative;
  margin-top: 10px;
  height: 120px;
  border-radius: 12px;
  background: radial-gradient(circle at 20% 20%, rgba(82, 160, 86, 0.55), rgba(15, 26, 18, 0.85));
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.preview-cloud {
  position: absolute;
  top: 12px;
  left: -30%;
  width: 70px;
  height: 24px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 50px;
  filter: blur(0.5px);
  animation: drift 10s linear infinite;
}

.preview-cloud::after {
  content: '';
  position: absolute;
  left: 14px;
  top: -8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}

.preview-cloud.two {
  top: 28px;
  width: 90px;
  height: 28px;
  animation-duration: 14s;
  animation-delay: -6s;
  opacity: 0.5;
}

.preview-ground {
  position: absolute;
  bottom: -10px;
  left: -10px;
  width: 140%;
  height: 50%;
  background: linear-gradient(135deg, #3d6b42, #1f3522);
  transform: rotate(-4deg);
  opacity: 0.9;
}

.preview-unit {
  position: absolute;
  bottom: 32px;
  left: 18%;
  width: 18px;
  height: 32px;
  background: #4aa0f3;
  border-radius: 6px;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.35);
  animation: bob 1.6s ease-in-out infinite;
}

.preview-unit.alt {
  left: 55%;
  bottom: 26px;
  background: #f3b04a;
  animation-delay: -0.8s;
}

.preview-tower {
  position: absolute;
  right: 14%;
  bottom: 30px;
  width: 22px;
  height: 46px;
  background: #6b7b3b;
  border-radius: 6px 6px 2px 2px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes drift {
  0% {
    transform: translateX(-10%);
  }
  100% {
    transform: translateX(160%);
  }
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

#app {
  width: 100vw;
  height: 100vh;
}

/* UI Layer */
#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Let clicks pass through to game */
  z-index: 10;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#ui-layer button,
#ui-layer a {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  touch-action: none;
}

#gold-counter {
  position: absolute;
  bottom: 90px;
  right: 20px;
  transform: translateX(calc(-100% - 10px));
  color: #ffd700;
  font-size: 24px;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  background: rgba(0, 0, 0, 0.3);
  padding: 10px 20px;
  border-radius: 8px;
  text-align: right;
  border: 2px solid rgba(255, 215, 0, 0.3);
}

#player-stats {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.5);
  padding: 10px;
  border-radius: 5px;
  text-align: right;
  pointer-events: none;
}

.hud-link {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(0, 0, 0, 0.5);
  color: #ffffff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  pointer-events: auto;
  transition: transform 0.2s ease, background 0.2s ease;
  touch-action: none;
}

.hud-link:hover {
  background: rgba(40, 40, 40, 0.7);
  transform: translateY(-1px);
}

.menu-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  pointer-events: auto;
}

.menu-overlay.hidden {
  display: none;
}

.overlay-panel {
  background: rgba(12, 18, 26, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 20px 24px;
  width: min(320px, 85vw);
  text-align: center;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
}

.overlay-title {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
}

.overlay-body {
  margin-top: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}

.overlay-actions {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.overlay-btn {
  background: linear-gradient(135deg, #f3b04a, #e07b2d);
  color: #1a0f07;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.overlay-btn.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.overlay-btn:active {
  transform: scale(0.98);
}

body.mode-single .multiplayer-only {
  display: none;
}

#match-status {
  position: absolute;
  top: 60px;
  left: 20px;
  color: #ffffff;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 12px;
  border-radius: 6px;
  text-align: left;
  pointer-events: none;
}

#player-list {
  position: absolute;
  top: 100px;
  left: 20px;
  color: #ffffff;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.45);
  padding: 8px 12px;
  border-radius: 6px;
  display: grid;
  gap: 6px;
  white-space: normal;
  pointer-events: none;
}

#player-list .player-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

#player-list .player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
  flex: 0 0 auto;
}

#countdown-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.98);
  color: #ffffff;
  font-size: 48px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: 0 6px 18px rgba(0, 0, 0, 0.7);
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.35);
  padding: 16px 28px;
  border-radius: 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#countdown-overlay.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#perf-metrics {
  position: absolute;
  bottom: 20px;
  left: 20px;
  color: #ffffff;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 10px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  white-space: pre-line;
  pointer-events: none;
}

.hud-version {
  position: absolute;
  bottom: 56px;
  left: 20px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 11px;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.6px;
  pointer-events: none;
}
#shop {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  pointer-events: auto;
  /* Enable clicks */
}

.touch-control {
  position: absolute;
  pointer-events: auto;
}

#touch-joystick {
  left: 20px;
  bottom: 80px;
}

#joystick {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.25);
  position: relative;
  touch-action: none;
}

#joystick-handle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: 2px solid rgba(0, 0, 0, 0.2);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.06s ease;
  touch-action: none;
}

#touch-actions {
  right: 20px;
  bottom: 190px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

#touch-dpad {
  right: 20px;
  bottom: 80px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
  width: 120px;
  height: 120px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dpad-btn {
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  border: 2px solid #888;
  border-radius: 10px;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  touch-action: none;
}

.dpad-btn:active {
  transform: scale(0.98);
}

.dpad-btn.up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-btn.left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-btn.right {
  grid-column: 3;
  grid-row: 2;
}

.dpad-btn.down {
  grid-column: 2;
  grid-row: 3;
}

.touch-btn {
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  border: 2px solid #888;
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: all 0.2s;
  touch-action: none;
}

.touch-btn:active {
  transform: scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  #touch-joystick,
  #touch-actions,
  #touch-dpad {
    display: none;
  }
}

@media (hover: none) and (pointer: coarse) {
  #touch-joystick {
    bottom: 100px;
  }

  #touch-actions {
    bottom: 220px;
  }

  #touch-dpad {
    bottom: 100px;
  }

  #perf-metrics {
    bottom: auto;
    top: 220px;
  }
}

.shop-btn {
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: 2px solid #888;
  padding: 10px 15px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.2s;
  touch-action: none;
}

.shop-btn:hover {
  background: rgba(50, 50, 50, 0.8);
  transform: scale(1.05);
}

.shop-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: #555;
  transform: none;
}

body.demo {
  background: radial-gradient(circle at top, #2a4a6a 0%, #0f1b28 45%, #0b0f16 100%);
}

#demo-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  width: min(360px, 90vw);
  background: rgba(12, 18, 26, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 16px 18px;
  color: rgba(255, 255, 255, 0.92);
  z-index: 15;
  pointer-events: auto;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.35);
}

.demo-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.6px;
}

.demo-subtitle {
  margin-top: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}

.demo-list {
  list-style: none;
  margin: 12px 0 14px;
  padding: 0;
  display: grid;
  gap: 8px;
  font-size: 13px;
  line-height: 1.3;
}

.demo-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.demo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
  flex: 0 0 auto;
}

.demo-dot.player {
  background: #4aa0ff;
}

.demo-dot.swordsman {
  background: #4078ff;
}

.demo-dot.archer {
  background: #40ff70;
}

.demo-dot.enemy {
  background: #ff6262;
}

.demo-dot.world {
  background: #9dd06d;
}

.demo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  transition: transform 0.15s ease, background 0.15s ease;
}

.demo-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.18);
}

@media (max-width: 720px) {
  #demo-panel {
    left: 20px;
    right: 20px;
    top: 12px;
  }
}
