/* Global Responsive Styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  /* Prevent browser zoom on mobile */
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  max-width: 100vw;
  overflow-x: hidden;
}

/* Ensure all main containers are responsive */
main {
  width: 100%;
  max-width: 100%;
}

/* Placeholder de layouts */
.layout-box {
  aspect-ratio: 16/9;
  border: 2px dashed #94a3b8; /* slate-400 */
  border-radius: .75rem;
  display: grid;
  place-items: center;
  background: repeating-linear-gradient(
    45deg,
    #f1f5f9 0px,
    #f1f5f9 10px,
    #e2e8f0 10px,
    #e2e8f0 20px
  );
  font-weight: 600;
  color: #334155;
}

/* Overlay zoom */
.zoom-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.zoom-backdrop img {
  max-width: 95%;
  max-height: 95%;
  box-shadow: 0 10px 40px -5px rgba(0,0,0,.6);
  border-radius: 1rem;
  object-fit: contain;
}

.zoom-img {
  cursor: grab;
  touch-action: none;
}

.zoom-img:active {
  cursor: grabbing;
}

@keyframes dice-spin {
  0% {
    transform: rotate(0deg) scale(1);
  }
  50% {
    transform: rotate(180deg) scale(1.2);
  }
  100% {
    transform: rotate(360deg) scale(1);
  }
}

.animate-dice {
  animation: dice-spin .6s ease-in-out infinite;
}

/* ========================================
   Hit Template Calculator Styles
   ======================================== */

/* Battlefield container */
.battlefield-container {
  position: relative;
  background: white;
  border: 1px solid #cbd5e1; /* slate-300 */
  border-radius: 0.5rem;
  padding: 2rem;
  min-height: 500px;
  overflow: hidden;
}

/* SVG line overlay */
.battlefield-line {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 5;
}

/* Regiment grid */
.regiment-grid {
  display: grid;
  background: #444;
  border-radius: 4px;
  overflow: hidden;
  margin: 0 auto;
  position: relative;
  z-index: 2;
}

/* Base models */
.base-model {
  border: 1px solid #555;
  background: #f1f5f9; /* slate-100 */
  transition: background-color 0.2s;
}

/* Impact highlighting */
.base-model.impact-total {
  background: #e63946; /* red */
}

.base-model.impact-partial {
  background: #f4a261; /* orange */
}

/* Circular template */
.circular-template {
  position: absolute;
  pointer-events: auto;
  z-index: 10;
  border-radius: 50%;
  background-color: rgba(230, 57, 70, 0.3);
  border: 2px solid #e63946;
  cursor: grab;
  transition: opacity 0.2s;
}

.circular-template:active {
  cursor: grabbing;
  opacity: 0.8;
}

/* Center marker */
.center-marker {
  background: #e63946;
  border-radius: 50%;
  border: 2px solid white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .battlefield-container {
    padding: 1rem;
    min-height: 400px;
  }
}

/* ========================================
   Battlefield Planner Styles
   ======================================== */

/* Layout: Sidebar + Main */
.battlefield-layout {
  display: flex;
  gap: 0;
  height: 100%;
  min-height: calc(100vh - 200px);
  position: relative;
  background: #f8fafc;
}

.battlefield-sidebar {
  width: min(300px, 25vw);
  min-width: 250px;
  max-width: 350px;
  background: white;
  border-right: 2px solid #cbd5e1;
  overflow-y: auto;
  flex-shrink: 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
}

.sidebar-content {
  padding: min(1rem, 2.5vw);
}

.sidebar-section {
  margin-bottom: min(1rem, 2.5vh);
  padding-bottom: min(1rem, 2.5vh);
  border-bottom: 1px solid #e2e8f0;
}

.sidebar-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.sidebar-title {
  font-size: clamp(0.75rem, 2vw, 0.875rem);
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 0.5rem;
}

.unit-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: clamp(0.4rem, 1.2vw, 0.6rem);
  cursor: grab;
  transition: all 0.2s;
  gap: 0.5rem;
}

.unit-card:hover {
  background: #f1f5f9;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.unit-card:active {
  cursor: grabbing;
}

/* Optimized spacing for unit list */
.space-y-2 > * + * {
  margin-top: 0.4rem;
}

.space-y-1\.5 > * + * {
  margin-top: 0.375rem;
}

/* Scrollable units list container */
.units-list-container {
  max-height: min(calc(100vh - 420px), 500px);
  min-height: 150px;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 -0.5rem;
  padding: 0 0.5rem;
}

/* Custom scrollbar for units list */
.units-list-container::-webkit-scrollbar {
  width: 6px;
}

.units-list-container::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 3px;
}

.units-list-container::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.units-list-container::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.battlefield-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #e2e8f0;
  overflow: hidden;
  width: 100%;
  min-width: 0;
  position: relative; /* Needed for absolute positioning of floating controls */
}

.battlefield-header {
  padding: clamp(0.5rem, 1.5vw, 0.75rem) clamp(1rem, 2vw, 1.25rem);
  background: white;
  border-bottom: 2px solid #cbd5e1;
  flex-shrink: 0;
}

.battlefield-wrapper-full {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #f8fafc;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  /* Prevent browser zoom, capture all touch gestures */
  touch-action: none;
  -webkit-touch-callout: none;
}

.battlefield-wrapper-full:active {
  cursor: grabbing;
}

.battlefield-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Prevent browser zoom, allow only app-controlled gestures */
  touch-action: none;
  -webkit-touch-callout: none;
}

.battlefield-canvas {
  position: relative;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  margin: 1rem;
  min-width: fit-content;
  /* Prevent browser zoom on canvas */
  touch-action: none;
  min-height: fit-content;
}

/* Responsive adjustments */
@media (max-width: 1400px) {
  .battlefield-sidebar {
    width: min(280px, 23vw);
    min-width: 240px;
  }
}

@media (max-width: 1200px) {
  .battlefield-sidebar {
    width: min(260px, 22vw);
    min-width: 220px;
  }
  
  .sidebar-content {
    padding: 1rem;
  }
}

@media (max-width: 1024px) {
  .battlefield-layout {
    flex-direction: column;
    height: auto;
  }
  
  .battlefield-sidebar {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    border-right: none;
    border-bottom: 2px solid #cbd5e1;
    max-height: 50vh;
  }
  
  .battlefield-main {
    min-height: 60vh;
  }
}

@media (max-width: 768px) {
  .battlefield-sidebar {
    max-height: 40vh;
  }
  
  .sidebar-content {
    padding: 0.875rem;
  }
  
  .battlefield-main {
    min-height: 50vh;
  }
}

@media (max-width: 640px) {
  .battlefield-layout {
    min-height: calc(100vh - 150px);
  }
  
  .battlefield-sidebar {
    max-height: 35vh;
  }
  
  .sidebar-content {
    padding: 0.75rem;
  }
  
  .unit-card {
    padding: 0.5rem;
    font-size: 0.875rem;
  }
}

/* Battlefield canvas centering improvements */
.battlefield-canvas {
  /* Ensure canvas stays centered even with transform scale */
  display: inline-block;
}

/* When battlefield is smaller than container, center it */
@media (min-width: 1024px) {
  .battlefield-wrapper-full {
    /* Add some padding for better centering on large screens */
    padding: 1rem;
  }
}

/* Floating Control Buttons (Top-Right) */
.battlefield-controls {
  position: absolute;
  top: 70px; /* Below the header */
  right: 10px;
  z-index: 10000; /* Higher than maximized wrapper (9999) */
  display: flex;
  gap: 8px;
  touch-action: auto;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
}

/* When battlefield is maximized, position controls at the top */
.battlefield-main.maximized .battlefield-controls {
  position: fixed;
  top: 10px;
  right: 10px;
}

.control-button {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  touch-action: auto;
  pointer-events: auto;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  -webkit-user-select: none;
  user-select: none;
}

.control-button:hover {
  background: white;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.control-button:active {
  transform: translateY(0);
  background: #e2e8f0;
}

/* Zoom Controls (Bottom-Right) */
.zoom-controls {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  touch-action: auto;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
}

.zoom-button {
  width: 36px;
  height: 36px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: auto;
  pointer-events: auto;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  -webkit-user-select: none;
  user-select: none;
}

.zoom-button:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  transform: scale(1.05);
}

.zoom-button:active {
  transform: scale(0.95);
  background: #e2e8f0;
}

.zoom-level {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  padding: 4px 0;
  min-width: 36px;
}

/* Responsive controls for smaller screens */
@media (max-width: 768px) {
  .battlefield-controls {
    top: 60px; /* Adjust for smaller header */
    right: 8px;
    gap: 6px;
  }
  
  .control-button {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  
  .zoom-controls {
    bottom: 8px;
    right: 8px;
    padding: 6px;
  }
  
  .zoom-button {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  
  .zoom-level {
    font-size: 10px;
    min-width: 32px;
  }
}

@media (max-width: 640px) {
  .battlefield-controls {
    top: 55px; /* Adjust for even smaller header */
    right: 6px;
    gap: 4px;
  }
  
  .control-button {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
  
  .zoom-controls {
    bottom: 6px;
    right: 6px;
    padding: 4px;
    gap: 2px;
  }
  
  .zoom-button {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .zoom-level {
    font-size: 9px;
    min-width: 28px;
    padding: 2px 0;
  }
}

/* Deployment Zones Overlay */
.deployment-zones-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 5;
}

/* Drag and Drop from list */
.cursor-grab {
  cursor: grab;
}

.cursor-grabbing {
  cursor: grabbing;
}

.battlefield-grid {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
}

.placed-unit {
  position: absolute;
  cursor: move;
  z-index: 10;
  transition: opacity 0.2s;
}

.placed-unit:hover {
  opacity: 0.9;
}

.placed-unit.dragging {
  opacity: 0.6;
  z-index: 1000;
}

.placed-unit.rotating {
  opacity: 0.85;
  z-index: 100;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5);
  animation: rotatePulse 1s ease-in-out infinite;
}

@keyframes rotatePulse {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.5);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.3);
  }
}

.unit-base {
  position: relative;
  box-sizing: border-box;
  border-radius: 2px;
  transition: all 0.2s;
}

.placed-unit:hover .unit-base {
  opacity: 0.9;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.unit-front-indicator {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
  transition: all 0.2s ease-in-out;
  padding: 0px;
}

.unit-front-indicator svg {
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.9;
  transition: opacity 0.2s ease-in-out;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}

.placed-unit:hover {
  background: rgba(0, 0, 0, 0.7);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.placed-unit:hover .unit-front-indicator svg {
  opacity: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
}

.unit-label {
  position: absolute;
  bottom: -20px;
  left: 50%;
  background: rgba(0, 0, 0, 0.15);
  color: rgba(255, 255, 255, 0.25);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  transform-origin: center top;
  transition: all 0.2s ease-in-out;
}

.placed-unit:hover .unit-label {
  background: rgba(0, 0, 0, 0.8);
  color: rgba(255, 255, 255, 0.95);
}

/* Mobile: Make labels more visible since there's no hover */
@media (max-width: 1024px) {
  .unit-label {
    background: rgba(0, 0, 0, 0.6);
    color: rgba(255, 255, 255, 0.85);
  }
}

@media (max-width: 768px) {
  .unit-label {
    background: rgba(0, 0, 0, 0.65);
    color: rgba(255, 255, 255, 0.9);
    font-size: 10px;
  }
}

.rotation-indicator {
  position: absolute;
  top: -30px;
  left: 50%;
  background: rgba(59, 130, 246, 0.95);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1002;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  animation: rotationPulse 0.3s ease-in-out;
  transform-origin: center center;
  /* Transform is calculated inline to counter zoom effect */
}

@keyframes rotationPulse {
  0% { transform: translateX(-50%) scale(0.8); opacity: 0; }
  50% { transform: translateX(-50%) scale(1.1); }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Edit Modal */
.fixed {
  position: fixed;
}

.inset-0 {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* Modal responsive improvements */
@media (max-width: 768px) {
  /* Make modals full-width on mobile with some padding */
  .fixed .bg-white.rounded-xl {
    max-width: calc(100vw - 1rem) !important;
    margin: 0.5rem;
    max-height: calc(100vh - 1rem) !important;
  }
  
  /* Reduce modal padding on mobile */
  .fixed .bg-white.rounded-xl.p-6 {
    padding: 1rem !important;
  }
  
  /* Adjust grid columns in modals */
  .grid.grid-cols-1.sm\\:grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 640px) {
  /* Ultra-compact modals on very small screens */
  .fixed .bg-white.rounded-xl {
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0;
    border-radius: 0 !important;
  }
  
  /* Even smaller padding */
  .fixed .bg-white.rounded-xl.p-6 {
    padding: 0.75rem !important;
  }
  
  /* Smaller font sizes in modals */
  .fixed .text-xl {
    font-size: 1.125rem !important;
  }
  
  .fixed .text-sm {
    font-size: 0.8125rem !important;
  }
}

/* Improve text sizing across all battlefield components */
@media (max-width: 1024px) {
  .battlefield-header h3 {
    font-size: clamp(0.875rem, 2.5vw, 1rem);
  }
  
  .battlefield-header .text-xs {
    font-size: clamp(0.625rem, 1.5vw, 0.75rem);
  }
}

/* Global responsive improvements for all components */
@media (max-width: 1400px) {
  /* Ensure containers don't overflow */
  .bg-white.rounded-xl,
  .bg-slate-100.rounded-xl {
    max-width: 100%;
  }
}

@media (max-width: 1024px) {
  /* Make all sections stack nicely on tablets */
  section {
    width: 100%;
  }
  
  /* Reduce spacing on tablets */
  .mb-6 {
    margin-bottom: 1rem;
  }
  
  .p-6 {
    padding: 1rem;
  }
}

@media (max-width: 768px) {
  /* Compact layout for mobile */
  .rounded-xl {
    border-radius: 0.5rem;
  }
  
  /* Smaller shadows */
  .shadow-lg,
  .shadow-xl {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
}

@media (max-width: 640px) {
  /* Ultra-compact for small phones */
  .rounded-xl {
    border-radius: 0.375rem;
  }
  
  /* Minimal padding on small screens */
  .p-4 {
    padding: 0.75rem;
  }
  
  .p-6 {
    padding: 0.875rem;
  }
  
  /* Reduce all gaps */
  .gap-4 {
    gap: 0.75rem;
  }
  
  .gap-6 {
    gap: 1rem;
  }
}

/* Ensure images and media are responsive */
img,
video,
iframe {
  max-width: 100%;
  height: auto;
}

/* Prevent horizontal scroll */
html,
body {
  overflow-x: hidden;
  max-width: 100vw;
}

