/* Mobile Optimizations for SimCit */

/* ============================================
   Mobile Toolbar Toggle Button
   ============================================ */
#mobileToolbarToggle {
  display: none;
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: #2196F3;
  color: white;
  border: none;
  font-size: 28px;
  font-weight: bold;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 100;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
  /* Center the + symbol */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#mobileToolbarToggle:active {
  transform: scale(0.95);
  background-color: #1976D2;
}

#mobileToolbarToggle.active {
  background-color: #f44336;
}

/* ============================================
   Mobile Tool Palette
   ============================================ */
#mobileToolPalette {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(255, 255, 255, 0.98);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
  z-index: 99;
  max-height: 50vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
  padding-bottom: env(safe-area-inset-bottom);
}

#mobileToolPalette.open {
  transform: translateY(0);
}

#mobileToolPalette .tool-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 15px;
}

#mobileToolPalette .mobile-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  border: 2px solid transparent;
  border-radius: 12px;
  background-color: #f5f5f5;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 70px;
}

#mobileToolPalette .mobile-tool-btn .tool-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  margin-bottom: 6px;
}

#mobileToolPalette .mobile-tool-btn.selected {
  border-color: #2196F3;
  background-color: #e3f2fd;
}

#mobileToolPalette .mobile-tool-btn:active {
  transform: scale(0.95);
}

/* Tool colors for mobile palette */
.mobile-tool-btn[data-tool="residential"] .tool-icon { background-color: lime; }
.mobile-tool-btn[data-tool="commercial"] .tool-icon { background-color: blue; }
.mobile-tool-btn[data-tool="industrial"] .tool-icon { background-color: yellow; }
.mobile-tool-btn[data-tool="road"] .tool-icon { background-color: black; }
.mobile-tool-btn[data-tool="rail"] .tool-icon { background-color: brown; }
.mobile-tool-btn[data-tool="wire"] .tool-icon { background-color: khaki; }
.mobile-tool-btn[data-tool="bulldozer"] .tool-icon { background-color: salmon; }
.mobile-tool-btn[data-tool="park"] .tool-icon { background-color: darkgreen; }
.mobile-tool-btn[data-tool="police"] .tool-icon { background-color: darkblue; }
.mobile-tool-btn[data-tool="fire"] .tool-icon { background-color: red; }
.mobile-tool-btn[data-tool="stadium"] .tool-icon { background-color: indigo; }
.mobile-tool-btn[data-tool="port"] .tool-icon { background-color: dodgerblue; }
.mobile-tool-btn[data-tool="airport"] .tool-icon { background-color: violet; }
.mobile-tool-btn[data-tool="coal"] .tool-icon { background-color: gray; }
.mobile-tool-btn[data-tool="nuclear"] .tool-icon { background-color: mistyrose; }
.mobile-tool-btn[data-tool="query"] .tool-icon { background-color: cyan; }

/* ============================================
   Mobile Info Bar (top)
   ============================================ */
#mobileInfoBar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background-color: rgba(47, 79, 79, 0.95);
  color: white;
  padding: 8px 15px;
  padding-top: calc(8px + env(safe-area-inset-top));
  z-index: 50;
  font-family: 'Open Sans', sans-serif;
  font-size: 12px;
}

#mobileInfoBar .info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#mobileInfoBar .info-item {
  text-align: center;
}

#mobileInfoBar .info-label {
  font-size: 10px;
  opacity: 0.8;
}

#mobileInfoBar .info-value {
  font-weight: 600;
}

/* ============================================
   Mobile Quick Actions
   ============================================ */
#mobileQuickActions {
  display: none;
  position: fixed;
  top: calc(50px + env(safe-area-inset-top));
  right: 10px;
  z-index: 50;
  flex-direction: column;
  gap: 8px;
}

#mobileQuickActions button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#mobileQuickActions .undo-btn {
  background-color: #9c27b0;
  color: white;
}

#mobileQuickActions .undo-btn:disabled {
  background-color: #ccc;
  color: #999;
}

#mobileQuickActions .pause-btn {
  background-color: #ff9800;
  color: white;
}

#mobileQuickActions .menu-btn {
  background-color: #607d8b;
  color: white;
}

/* ============================================
   Mobile Menu Overlay
   ============================================ */
#mobileMenuOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.5);
  z-index: 150;
}

#mobileMenu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  border-radius: 16px;
  padding: 20px;
  min-width: 280px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

#mobileMenu h3 {
  text-align: center;
  margin-bottom: 15px;
  font-family: 'Chunk', serif;
}

#mobileMenu button {
  display: block;
  width: 100%;
  padding: 15px;
  margin: 8px 0;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#mobileMenu .menu-close {
  background-color: #f5f5f5;
  color: #333;
}

/* ============================================
   Touch Feedback
   ============================================ */
.touch-feedback {
  position: fixed;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(33, 150, 243, 0.3);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0);
  animation: touch-ripple 0.4s ease-out forwards;
  z-index: 1000;
}

@keyframes touch-ripple {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
}

/* ============================================
   Zoom Controls - DISABLED (CSS zoom breaks canvas)
   ============================================ */
#zoomControls {
  display: none !important;
}

#zoomControls button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: none;
  background-color: white;
  font-size: 20px;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  cursor: pointer;
}

#zoomControls button:active {
  background-color: #e0e0e0;
}

#zoomLevel {
  font-size: 11px;
  color: #333;
  background-color: white;
  padding: 4px 8px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  margin-top: 5px;
}

/* ============================================
   Mobile Media Queries
   ============================================ */
@media (max-width: 768px) {
  /* Hide desktop UI elements */
  #header,
  #footer,
  #controls,
  #infobar,
  #miscButtons,
  #RCIContainer,
  #tw,
  #debug,
  #tooSmall {
    display: none !important;
  }

  /* Show mobile UI elements */
  #mobileToolbarToggle,
  #mobileInfoBar,
  #mobileQuickActions {
    display: flex;
  }

  #mobileToolPalette {
    display: block;
  }

  /* Adjust main canvas area - main IS #canvasContainer */
  main#canvasContainer {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }

  #wrapper {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  /* Adjust notifications for mobile */
  #notifications {
    bottom: auto;
    top: calc(55px + env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    width: auto;
    transform: none;
    font-size: 12px;
  }

  /* Make modals mobile-friendly */
  .modal {
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
  }

  .centred, #splash, #start {
    width: 90%;
    max-width: 400px;
  }

  /* Position name input form at top so it's above keyboard */
  #start {
    position: fixed !important;
    top: 10px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    margin: 0 !important;
    max-height: 45vh;
    overflow-y: auto;
  }

  #splash {
    height: auto;
    max-height: 80vh;
    overflow-y: auto;
  }

  #splashButtonContainer {
    position: relative;
    top: auto;
    left: auto;
    margin-top: 20px;
  }

  #splashButtons {
    position: relative;
    top: auto;
    left: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  #splashContainer {
    position: relative;
    top: auto;
    left: auto;
  }

  /* Touch-friendly button sizes */
  button, input[type="submit"] {
    min-height: 44px;
    font-size: 16px;
  }

  .splashButton {
    width: 100%;
    max-width: 200px;
    margin: 5px auto;
  }

  /* Disable text selection on game elements */
  #canvasContainer,
  #gameCanvas {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
  }
}

@media (max-width: 480px) {
  #mobileToolPalette .tool-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  #mobileInfoBar {
    font-size: 11px;
  }

  #mobileInfoBar .info-label {
    font-size: 9px;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #mobileToolPalette {
    max-height: 60vh;
  }

  #mobileToolPalette .tool-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  #mobileInfoBar {
    padding: 5px 15px;
  }

  #mobileToolbarToggle {
    bottom: 20px;
    width: 50px;
    height: 50px;
  }
}

/* Touch warning removal for mobile */
@media (pointer: coarse) {
  #touchWarnWindow {
    display: none !important;
  }
}
