:root {
  --blue: #5aa0ff;
  --orange: #ff9b50;
  --green: #26d07c;
  --red: #ff5d4a;
  --bug-green: #4ade80;
  --bug-purple: #a78bfa;
  --bug-cyan: #22d3ee;

  --ink: #e6ecff;
  --ink-dim: #aeb9d9;
  --bg: #1a2845;
  --panel: #0f172a;
  --tile: #1a2742;
  --tile-border: #2d4366;
  --grid-border: #4a7fc4;
}

html, body {
  min-height: 100%;
  background: linear-gradient(180deg, #1a2845 0%, #0d1220 100%);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.game-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(8px, 2vh, 16px) clamp(8px, 2vw, 16px);
  gap: clamp(8px, 1.5vh, 12px);
  box-sizing: border-box;
  overflow-y: auto;
}

/* ========================================
   MULTIPLAYER MENU
   ======================================== */

.multiplayer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 2000;
  display: block;
}

.multiplayer-menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #1a2845 0%, #0f172a 100%);
  border: 3px solid var(--grid-border);
  border-radius: 20px;
  padding: clamp(24px, 5vh, 40px) clamp(20px, 4vw, 32px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  z-index: 2001;
  min-width: min(90vw, 400px);
  max-width: 500px;
}

.multiplayer-menu h2 {
  margin: 0 0 8px 0;
  font-size: clamp(24px, 5vw, 32px);
  color: #7eb3ff;
  text-align: center;
  font-weight: 800;
}

.menu-subtitle {
  text-align: center;
  color: var(--ink-dim);
  margin: 0 0 24px 0;
  font-size: clamp(14px, 3vw, 16px);
}

.menu-btn {
  appearance: none;
  width: 100%;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: clamp(16px, 3.5vw, 18px);
  padding: clamp(12px, 2.5vh, 16px);
  border-radius: 12px;
  border: 2px solid;
  margin-bottom: 12px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.create-btn {
  background: linear-gradient(180deg, #32e590 0%, #26d07c 100%);
  border-color: #1fb868;
  color: #0d1220;
  box-shadow: 0 4px 16px rgba(38, 208, 124, 0.3);
}

.create-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(38, 208, 124, 0.4);
}

.btn-icon {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.join-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.room-code-input {
  appearance: none;
  background: #0d1a2e;
  border: 2px solid var(--tile-border);
  border-radius: 12px;
  padding: clamp(10px, 2vh, 12px);
  color: var(--ink);
  font-size: clamp(14px, 3vw, 16px);
  font-weight: 700;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.room-code-input::placeholder {
  color: var(--ink-dim);
  opacity: 0.5;
  letter-spacing: 1px;
}

.room-code-input:focus {
  outline: none;
  border-color: var(--grid-border);
  box-shadow: 0 0 0 3px rgba(74, 127, 196, 0.2);
}

.join-btn {
  background: linear-gradient(180deg, #5aa0ff 0%, #4890e8 100%);
  border-color: #3d7fc4;
  color: #fff;
  box-shadow: 0 4px 16px rgba(90, 160, 255, 0.3);
}

.join-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(90, 160, 255, 0.4);
}

/* Level Selection in Multiplayer Menu */
.level-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--tile-border);
}

.level-label {
  margin: 0 0 8px 0;
  font-size: clamp(12px, 2.5vw, 14px);
  color: var(--ink-dim);
  text-align: center;
  font-weight: 600;
}

.level-options {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.level-option-btn {
  appearance: none;
  cursor: pointer;
  background: var(--tile);
  border: 2px solid var(--tile-border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--ink);
  font-size: clamp(11px, 2.5vw, 13px);
  font-weight: 600;
  transition: all 0.2s ease;
  flex: 1;
  min-width: 0;
}

.level-option-btn:hover {
  background: #1e2d4a;
  border-color: var(--grid-border);
  transform: translateY(-1px);
}

.level-option-btn.active {
  background: linear-gradient(135deg, #5aa0ff 0%, #4890e8 100%);
  border-color: #3d7fc4;
  color: #fff;
  box-shadow: 0 2px 8px rgba(90, 160, 255, 0.3);
}

/* ========================================
   TOP BAR CONTAINER (Room Info + Bug Fleet)
   ======================================== */

.top-bar-container {
  display: flex;
  gap: clamp(12px, 2vw, 16px);
  width: 100%;
  max-width: 1200px;
  box-sizing: border-box;
  align-items: stretch;
}

/* Stack vertically on very small screens */
@media (max-width: 600px) {
  .top-bar-container {
    flex-direction: column;
  }

  .room-info {
    width: 100%;
  }
}

/* ========================================
   ROOM INFO BAR
   ======================================== */

.room-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  background: #0d1a2e;
  border: 2px solid var(--grid-border);
  border-radius: 12px;
  padding: clamp(8px, 1.5vh, 12px) clamp(12px, 2.5vw, 16px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  flex-shrink: 0;
  min-width: 200px;
  position: relative;
}

.room-code-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-label {
  font-size: clamp(11px, 2.5vw, 14px);
  color: #7eb3ff;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.room-code {
  font-size: clamp(20px, 4.5vw, 28px);
  font-weight: 900;
  color: #7eb3ff;
  letter-spacing: 3px;
  background: rgba(74, 127, 196, 0.25);
  padding: clamp(6px, 1.5vh, 10px) clamp(12px, 3vw, 18px);
  border-radius: 8px;
  border: 2px solid rgba(74, 127, 196, 0.5);
  box-shadow: 0 0 20px rgba(74, 127, 196, 0.3);
  animation: pulse-code 2s ease-in-out infinite;
}

@keyframes pulse-code {
  0%, 100% {
    box-shadow: 0 0 20px rgba(74, 127, 196, 0.3);
  }
  50% {
    box-shadow: 0 0 30px rgba(74, 127, 196, 0.5);
  }
}

.connection-status {
  font-size: clamp(10px, 2.2vw, 12px);
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid;
}

.connection-status.waiting {
  background: rgba(255, 155, 80, 0.15);
  border-color: rgba(255, 155, 80, 0.4);
  color: var(--orange);
}

.connection-status.connected {
  background: rgba(38, 208, 124, 0.15);
  border-color: rgba(38, 208, 124, 0.4);
  color: var(--green);
}

.leave-btn {
  appearance: none;
  background: transparent;
  border: 2px solid var(--red);
  color: var(--red);
  width: clamp(24px, 5vw, 30px);
  height: clamp(24px, 5vw, 30px);
  border-radius: 50%;
  font-size: clamp(16px, 3.5vw, 20px);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  position: absolute;
  top: clamp(6px, 1vh, 8px);
  right: clamp(6px, 1vw, 8px);
}

.leave-btn:hover {
  background: rgba(255, 93, 74, 0.2);
  transform: scale(1.1);
}

/* ========================================
   PHASE AND TURN INDICATORS
   ======================================== */

.phase-indicator {
  text-align: center;
  font-size: clamp(16px, 3.5vw, 24px);
  font-weight: 800;
  padding: clamp(8px, 1.5vh, 12px) clamp(16px, 3vw, 24px);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(74, 127, 196, 0.2) 0%, rgba(74, 127, 196, 0.1) 100%);
  border: 2px solid var(--grid-border);
  color: #7eb3ff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.5px;
}

/* ========================================
   BUG FLEET SELECTOR
   ======================================== */

.bug-fleet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: #0d1a2e;
  border: 2px solid var(--grid-border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  flex: 1;
  box-sizing: border-box;
}

.fleet-title {
  font-size: clamp(14px, 3vw, 16px);
  font-weight: 700;
  color: #7eb3ff;
  letter-spacing: 0.5px;
  margin: 0;
}

.fleet-controls {
  display: flex;
  gap: clamp(8px, 2vw, 12px);
  align-items: center;
  justify-content: center;
  width: 100%;
  flex-wrap: wrap;
}

/* Shooting Panel (replaces bug fleet during gameplay) */
.shooting-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: #0d1a2e;
  border: 2px solid var(--grid-border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  flex: 1;
  box-sizing: border-box;
}

.turn-indicator-panel {
  text-align: center;
  font-size: clamp(16px, 3.5vw, 20px);
  font-weight: 800;
  padding: clamp(8px, 1.5vh, 12px) clamp(12px, 2.5vw, 18px);
  border-radius: 8px;
  letter-spacing: 0.5px;
  border: 2px solid;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  display: inline-block;
  align-self: center;
}

.turn-indicator-panel.my-turn {
  background: linear-gradient(135deg, rgba(38, 208, 124, 0.2) 0%, rgba(38, 208, 124, 0.1) 100%);
  border-color: var(--green);
  color: var(--green);
  animation: pulse-green-panel 2s ease-in-out infinite;
}

@keyframes pulse-green-panel {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(38, 208, 124, 0.4);
  }
  50% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 8px rgba(38, 208, 124, 0);
  }
}

.turn-indicator-panel.their-turn {
  background: rgba(174, 185, 217, 0.1);
  border-color: var(--tile-border);
  color: var(--ink-dim);
}

.shooting-controls-panel {
  display: flex;
  gap: clamp(8px, 2vw, 12px);
  align-items: center;
  justify-content: center;
  width: 100%;
  position: relative;
}

/* Numeric Keypad */
.numeric-keypad {
  position: absolute;
  right: calc(50% + 235px);
  top: 50%;
  transform: translateY(-50%);
  background: #0d1a2e;
  border: 3px solid var(--grid-border);
  border-radius: 12px;
  padding: clamp(8px, 1.5vw, 12px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
  z-index: 100;
  animation: keypad-appear 0.2s ease-out;
}

/* Arrow connecting keypad to input - positioned at middle row */
.numeric-keypad::after {
  content: "";
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 12px solid var(--grid-border);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

.numeric-keypad::before {
  content: "";
  position: absolute;
  right: -9px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 9px solid #0d1a2e;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  z-index: 1;
}

@keyframes keypad-appear {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(6px, 1.2vw, 8px);
}

.keypad-btn {
  appearance: none;
  background: var(--tile);
  border: 2px solid var(--tile-border);
  border-radius: 8px;
  color: var(--ink);
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 700;
  width: clamp(36px, 7vw, 46px);
  height: clamp(36px, 7vw, 46px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.keypad-btn:hover {
  background: #243555;
  border-color: var(--grid-border);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.keypad-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.keypad-btn-delete {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  border-color: #b91c1c;
  color: #fff;
  grid-column: span 5;
  font-size: clamp(18px, 3.5vw, 22px);
}

.keypad-btn-delete:hover {
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
  border-color: #dc2626;
}

.keypad-btn-special {
  background: linear-gradient(135deg, #5aa0ff 0%, #4890e8 100%);
  border-color: #3d7fc4;
  color: #fff;
}

.keypad-btn-special:hover {
  background: linear-gradient(135deg, #7eb3ff 0%, #5aa0ff 100%);
  border-color: #5aa0ff;
}

/* Adjust keypad position on mobile */
@media (max-width: 600px) {
  .numeric-keypad {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    top: auto;
    bottom: calc(100% + 8px);
  }

  @keyframes keypad-appear {
    from {
      opacity: 0;
      transform: translateX(-50%) translateY(-10px);
    }
    to {
      opacity: 1;
      transform: translateX(-50%);
    }
  }

  .numeric-keypad::after {
    right: auto;
    left: 50%;
    top: auto;
    transform: translateX(-50%);
    bottom: -12px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 12px solid var(--grid-border);
    border-bottom: none;
  }

  .numeric-keypad::before {
    right: auto;
    left: 50%;
    top: auto;
    transform: translateX(-50%);
    bottom: -9px;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 9px solid #0d1a2e;
    border-bottom: none;
  }
}

.bugs-container {
  display: flex;
  gap: clamp(6px, 1.5vw, 10px);
  flex-wrap: nowrap;
  justify-content: center;
  width: 100%;
  overflow-x: auto;
}

.bug-btn {
  appearance: none;
  background: var(--tile);
  border: 2px solid var(--tile-border);
  border-radius: 8px;
  padding: clamp(6px, 1.2vh, 10px);
  cursor: grab;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  user-select: none;
}

.bug-btn:active {
  cursor: grabbing;
}

.bug-btn:hover {
  background: #243555;
  border-color: var(--grid-border);
  transform: translateY(-2px);
}

.bug-btn.selected {
  background: rgba(74, 127, 196, 0.3);
  border-color: var(--grid-border);
  box-shadow: 0 0 0 2px var(--grid-border), 0 4px 12px rgba(74, 127, 196, 0.4);
}

.bug-btn[data-placed="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  background: #0d1220;
}

.bug-btn[data-placed="true"]:hover {
  transform: none;
  background: #0d1220;
}

.bug-name {
  display: none;
}

.bug-preview {
  position: relative;
  display: flex;
  gap: clamp(8px, 2vw, 12px);
  padding: clamp(8px, 2vw, 12px);
  border-radius: clamp(8px, 2vw, 12px);
}

/* Different colored ellipse backgrounds for each bug type */
.bug-btn[data-size="5"] .bug-preview {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.bug-btn[data-size="4"] .bug-preview {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

.bug-btn[data-size="3"]:nth-of-type(3) .bug-preview {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.bug-btn[data-size="3"]:nth-of-type(4) .bug-preview {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
}

.bug-btn[data-size="2"] .bug-preview {
  background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.4);
}

.bug-cell {
  width: clamp(12px, 3vw, 16px);
  height: clamp(12px, 3vw, 16px);
  background: transparent;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

/* Drag preview */
.drag-preview {
  opacity: 0.9;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

.bug-preview-drag {
  display: flex;
  gap: clamp(8px, 2vw, 12px);
  padding: clamp(8px, 2vw, 12px);
  border-radius: clamp(8px, 2vw, 12px);
  background: rgba(74, 127, 196, 0.3);
  border: 2px solid var(--grid-border);
  transition: flex-direction 0.2s ease;
}

.bug-cell-drag {
  width: clamp(16px, 3.5vw, 24px);
  height: clamp(16px, 3.5vw, 24px);
  background: transparent;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

@keyframes flash-red {
  0%, 100% { background: rgba(74, 127, 196, 0.3); }
  50% { background: rgba(239, 68, 68, 0.6); }
}


.ready-btn {
  appearance: none;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.8px;
  font-size: clamp(14px, 3vw, 18px);
  padding: clamp(10px, 2vh, 12px) clamp(24px, 6vw, 36px);
  border-radius: 12px;
  border: none;
  color: #0d1220;
  background: linear-gradient(180deg, #32e590 0%, #26d07c 100%);
  box-shadow: 0 6px 20px rgba(38, 208, 124, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.1s ease;
  flex: 1;
  min-width: 150px;
}

.ready-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(38, 208, 124, 0.4);
}

.ready-btn:active:not(:disabled) {
  transform: translateY(0);
}

.ready-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: linear-gradient(180deg, #2d4366 0%, #1a2742 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ========================================
   GRIDS CONTAINER
   ======================================== */

.grids-container {
  display: flex;
  gap: clamp(16px, 3vw, 32px);
  align-items: center;
  justify-content: center;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  overflow: visible;
}

/* Portrait mode: stack vertically */
@media (max-width: 900px) and (orientation: portrait) {
  .grids-container {
    flex-direction: column;
    gap: clamp(8px, 1.5vh, 12px);
  }

  .grid-wrapper {
    width: 100%;
    max-width: 100%;
  }
}

/* Landscape mode: side by side */
@media (max-width: 900px) and (orientation: landscape) {
  .grids-container {
    flex-direction: row;
    gap: clamp(8px, 2vw, 16px);
  }

  .grid-wrapper {
    flex: 1;
    max-width: 50%;
  }
}

.grid-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  max-width: 550px;
  overflow: visible;
}

.grid-title {
  text-align: center;
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 700;
  color: #7eb3ff;
  letter-spacing: 0.5px;
}

.grid-border {
  background: #0d1a2e;
  border: 3px solid var(--grid-border);
  border-radius: 12px;
  padding: clamp(8px, 1.5vw, 12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  position: relative;
  overflow: visible;
}

.grid-border::before {
  content: "";
  position: absolute;
  inset: clamp(8px, 1.5vw, 12px);
  background: radial-gradient(circle at 50% 50%, rgba(94, 156, 255, 0.08) 0%, transparent 70%);
  pointer-events: none;
  border-radius: 8px;
  z-index: 0;
}

.grid-labels-bottom {
  display: grid;
  grid-template-columns: clamp(20px, 4vw, 24px) 1fr;
  margin-top: clamp(4px, 0.8vw, 6px);
  font-size: clamp(10px, 2.2vw, 13px);
  font-weight: 700;
  color: #7eb3ff;
  position: relative;
  height: clamp(14px, 3vw, 18px);
}

.grid-labels-bottom > span:first-child {
  /* Empty spacer for left margin */
}

.grid-labels-bottom > span:nth-child(n+2) {
  position: absolute;
  transform: translateX(-50%);
}

/* Position each number label at exact grid line percentages (0%, 10%, 20%, ..., 100%) */
.grid-labels-bottom > span:nth-child(2) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 0 / 10); }
.grid-labels-bottom > span:nth-child(3) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 1 / 10); }
.grid-labels-bottom > span:nth-child(4) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 2 / 10); }
.grid-labels-bottom > span:nth-child(5) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 3 / 10); }
.grid-labels-bottom > span:nth-child(6) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 4 / 10); }
.grid-labels-bottom > span:nth-child(7) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 5 / 10); }
.grid-labels-bottom > span:nth-child(8) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 6 / 10); }
.grid-labels-bottom > span:nth-child(9) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 7 / 10); }
.grid-labels-bottom > span:nth-child(10) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 8 / 10); }
.grid-labels-bottom > span:nth-child(11) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 9 / 10); }
.grid-labels-bottom > span:nth-child(12) { left: calc(clamp(20px, 4vw, 24px) + (100% - clamp(20px, 4vw, 24px)) * 10 / 10); }

.grid-with-labels {
  display: grid;
  grid-template-columns: clamp(20px, 4vw, 24px) 1fr;
  gap: 0;
  position: relative;
  z-index: 1;
  overflow: visible;
  margin-bottom: 0;
}

.grid-labels-left {
  position: relative;
  font-size: clamp(10px, 2.2vw, 13px);
  font-weight: 700;
  color: #7eb3ff;
}

.grid-labels-left > span {
  position: absolute;
  width: 100%;
  text-align: center;
  transform: translateY(-50%);
}

/* Position each number label at exact grid line percentages (0%, 10%, 20%, ..., 100%) */
/* Labels go from top to bottom as: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 */
.grid-labels-left > span:nth-child(1) { top: 0%; }    /* 10 */
.grid-labels-left > span:nth-child(2) { top: 10%; }   /* 9 */
.grid-labels-left > span:nth-child(3) { top: 20%; }   /* 8 */
.grid-labels-left > span:nth-child(4) { top: 30%; }   /* 7 */
.grid-labels-left > span:nth-child(5) { top: 40%; }   /* 6 */
.grid-labels-left > span:nth-child(6) { top: 50%; }   /* 5 */
.grid-labels-left > span:nth-child(7) { top: 60%; }   /* 4 */
.grid-labels-left > span:nth-child(8) { top: 70%; }   /* 3 */
.grid-labels-left > span:nth-child(9) { top: 80%; }   /* 2 */
.grid-labels-left > span:nth-child(10) { top: 90%; }  /* 1 */
.grid-labels-left > span:nth-child(11) { top: 100%; } /* 0 */

.grid {
  position: relative;
  background: #0d1a2e;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  /* Draw 11 grid lines (0-10) */
  background-image:
    repeating-linear-gradient(to right, #4a7fc4 0, #4a7fc4 2px, transparent 2px, transparent calc(100% / 10)),
    repeating-linear-gradient(to bottom, #4a7fc4 0, #4a7fc4 2px, transparent 2px, transparent calc(100% / 10));
  background-size: 100% 100%;
  background-position: 0 0;
  /* Add final grid lines at right and bottom edges */
  border-right: 2px solid #4a7fc4;
  border-bottom: 2px solid #4a7fc4;
  overflow: visible;
}

/* Bug rounded rectangle backgrounds */
.bug-ellipse {
  position: absolute;
  border-radius: clamp(12px, 3vw, 20px);
  pointer-events: auto;
  z-index: 1;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.4);
  cursor: grab;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.bug-ellipse:hover {
  transform: translate(-50%, -50%) scale(1.02);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
}

.bug-ellipse:active {
  cursor: grabbing;
}

.bug-ellipse.beetle { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); }
.bug-ellipse.spider { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); }
.bug-ellipse.ant { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }
.bug-ellipse.wasp { background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%); }
.bug-ellipse.fly { background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%); }

.cell {
  position: absolute;
  background: transparent;
  border: none;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  cursor: pointer;
  transition: transform 0.06s ease;
  /* Make cells small clickable areas around intersection points */
  width: clamp(24px, 5vw, 36px);
  height: clamp(24px, 5vw, 36px);
  transform: translate(-50%, -50%);
  z-index: 2;
}

/* Intersection point indicator */
.cell::before {
  content: "";
  position: absolute;
  width: clamp(8px, 2vw, 12px);
  height: clamp(8px, 2vw, 12px);
  background: transparent;
  border: 2px solid transparent;
  border-radius: 50%;
  transition: all 0.2s ease;
  pointer-events: none;
}

@media (hover: hover) {
  .cell:hover::before {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
  }

  /* Don't show hover indicator on cells covered by shapes */
  .cell.shape:hover::before {
    background: transparent;
    border-color: transparent;
  }
}

/* Bug states - show as transparent dots with white borders */
.cell.bug {
  pointer-events: none;
}

/* Shape-covered cells should not show pointer cursor */
.cell.shape {
  cursor: default;
  pointer-events: none;
}

.cell.bug::before {
  background: transparent;
  border: 3px solid #fff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.5), 0 0 0 1px rgba(0, 0, 0, 0.3);
  width: clamp(14px, 3.5vw, 20px);
  height: clamp(14px, 3.5vw, 20px);
}

.cell.preview::before {
  background: transparent;
  border: 3px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
  animation: pulse-preview 1s ease-in-out infinite;
  width: clamp(14px, 3.5vw, 20px);
  height: clamp(14px, 3.5vw, 20px);
}

.cell.invalid::before {
  background: rgba(255, 93, 74, 0.4);
  border-color: var(--red);
  width: clamp(12px, 3vw, 18px);
  height: clamp(12px, 3vw, 18px);
}

@keyframes pulse-preview {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}

/* Shot states */
.cell.hit::before {
  background: var(--red);
  border-color: #e84936;
  box-shadow: 0 0 12px rgba(255, 93, 74, 0.8), inset 0 0 0 2px rgba(255, 255, 255, 0.3);
  width: clamp(14px, 3.5vw, 20px);
  height: clamp(14px, 3.5vw, 20px);
  animation: hit-flash 0.5s ease;
  z-index: 10;
}

.cell.hit::after {
  content: "💥";
  position: absolute;
  font-size: clamp(16px, 3.5vw, 24px);
  z-index: 10;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
}

@keyframes hit-flash {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.cell.strike::before {
  background: #64748b;
  border-color: #94a3b8;
  box-shadow: 0 0 12px rgba(100, 116, 139, 0.8), inset 0 0 0 2px rgba(255, 255, 255, 0.3);
  width: clamp(12px, 3vw, 18px);
  height: clamp(12px, 3vw, 18px);
  animation: strike-flash 0.5s ease;
  z-index: 10;
}

.cell.strike::after {
  content: "💨";
  position: absolute;
  font-size: clamp(14px, 3vw, 20px);
  z-index: 10;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
}

@keyframes strike-flash {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.cell.miss::before {
  background: var(--ink-dim);
  border-color: #7eb3ff;
  width: clamp(6px, 1.5vw, 10px);
  height: clamp(6px, 1.5vw, 10px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  z-index: 10;
}

.cell.sunk::before {
  background: #6b21a8;
  border-color: #a78bfa;
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.8), inset 0 0 0 2px rgba(255, 255, 255, 0.3);
  width: clamp(14px, 3.5vw, 20px);
  height: clamp(14px, 3.5vw, 20px);
}

/* ========================================
   CONTROL BUTTONS
   ======================================== */

.control-btn {
  appearance: none;
  background: var(--tile);
  border: 2px solid var(--tile-border);
  border-radius: 12px;
  width: clamp(42px, 10vw, 52px);
  height: clamp(42px, 10vw, 52px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.2s ease;
  padding: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.control-btn:hover {
  background: #243555;
  border-color: var(--grid-border);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.control-btn:active {
  transform: translateY(0);
}

.game-status {
  width: 100%;
  text-align: center;
  font-size: clamp(13px, 3vw, 16px);
  font-weight: 700;
  color: #7eb3ff;
  background: rgba(74, 127, 196, 0.15);
  padding: clamp(10px, 2vh, 14px) clamp(16px, 3vw, 20px);
  border-radius: 12px;
  border: 2px solid rgba(74, 127, 196, 0.3);
  letter-spacing: 0.3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.coordinate-input {
  appearance: none;
  background: #0d1a2e;
  border: 2px solid var(--tile-border);
  border-radius: 8px;
  padding: clamp(10px, 2vh, 14px) clamp(14px, 3vw, 18px);
  color: var(--ink);
  font-size: clamp(16px, 3.5vw, 20px);
  font-weight: 700;
  text-align: center;
  letter-spacing: 1px;
  text-transform: uppercase;
  flex: 1;
  max-width: 150px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: opacity 0.3s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.coordinate-input::placeholder {
  color: var(--ink-dim);
  opacity: 0.5;
}

.coordinate-input:focus {
  outline: none;
  border-color: var(--grid-border);
  box-shadow: 0 0 0 3px rgba(74, 127, 196, 0.2);
}

.fire-btn {
  appearance: none;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.5px;
  font-size: clamp(16px, 3.5vw, 20px);
  padding: clamp(10px, 2vh, 14px) clamp(20px, 4vw, 32px);
  border-radius: 8px;
  border: none;
  color: #fff;
  background: linear-gradient(180deg, #ff6b6b 0%, var(--red) 100%);
  box-shadow: 0 4px 12px rgba(255, 93, 74, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 0.1s ease, opacity 0.3s ease;
  white-space: nowrap;
  flex: 1;
  max-width: 200px;
}

.fire-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 93, 74, 0.4);
}

.fire-btn:active:not(:disabled) {
  transform: translateY(0);
}

.fire-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.coordinate-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ========================================
   GAME STATES
   ======================================== */

/* Inactive grid styling */
.grid-wrapper.inactive-grid {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.grid-wrapper:not(.inactive-grid) {
  opacity: 1;
  transition: opacity 0.3s ease;
}

/* Hide bug fleet during gameplay */
.game-container[data-phase="playing"] .bug-fleet {
  display: none;
}

/* Disable bug interaction after clicking ready or during gameplay */
.game-container.player-ready .bug-ellipse,
.game-container[data-phase="playing"] .bug-ellipse {
  cursor: default;
  pointer-events: none;
}

/* Hide enemy grid during placement */
.game-container[data-phase="placing"] .grid-wrapper:nth-child(2) {
  opacity: 0.3;
  pointer-events: none;
}

/* ========================================
   VICTORY/DEFEAT OVERLAY
   ======================================== */

.game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 0.5s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.game-over-content {
  background: linear-gradient(180deg, #1a2845 0%, #0f172a 100%);
  border: 4px solid var(--grid-border);
  border-radius: 24px;
  padding: clamp(32px, 6vh, 60px) clamp(24px, 5vw, 48px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  text-align: center;
  max-width: 90vw;
  animation: scale-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scale-in {
  from {
    transform: scale(0.5);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.game-over-title {
  font-size: clamp(48px, 10vw, 96px);
  font-weight: 900;
  margin-bottom: clamp(16px, 3vh, 24px);
  letter-spacing: 2px;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}

.game-over-title.victory {
  color: #26d07c;
  animation: victory-glow 2s ease-in-out infinite;
}

.game-over-title.defeat {
  color: #ff5d4a;
}

@keyframes victory-glow {
  0%, 100% {
    text-shadow: 0 4px 16px rgba(38, 208, 124, 0.6),
                 0 0 40px rgba(38, 208, 124, 0.4);
  }
  50% {
    text-shadow: 0 4px 16px rgba(38, 208, 124, 0.9),
                 0 0 60px rgba(38, 208, 124, 0.6),
                 0 0 80px rgba(38, 208, 124, 0.3);
  }
}

.game-over-message {
  font-size: clamp(18px, 4vw, 28px);
  color: var(--ink);
  margin-bottom: clamp(24px, 4vh, 32px);
  font-weight: 600;
}

.game-over-emoji {
  font-size: clamp(64px, 12vw, 120px);
  margin-bottom: clamp(20px, 3vh, 32px);
  display: block;
  animation: emoji-bounce 1s ease-in-out infinite;
}

@keyframes emoji-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.play-again-btn {
  appearance: none;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 1px;
  font-size: clamp(18px, 4vw, 24px);
  padding: clamp(14px, 2.5vh, 18px) clamp(32px, 6vw, 48px);
  border-radius: 16px;
  border: none;
  color: #0d1220;
  background: linear-gradient(180deg, #32e590 0%, #26d07c 100%);
  box-shadow: 0 8px 24px rgba(38, 208, 124, 0.4);
  transition: transform 0.2s ease;
  margin-top: 12px;
}

.play-again-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(38, 208, 124, 0.5);
}

/* Confetti */
.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  pointer-events: none;
  z-index: 3001;
  animation: confetti-fall 3s linear forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotateZ(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotateZ(720deg);
    opacity: 0;
  }
}

/* ========================================
   SHOT FEEDBACK ANIMATIONS
   ======================================== */

.shot-feedback {
  position: absolute;
  font-weight: 900;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 100;
  transform: translate(-50%, -50%);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  letter-spacing: 1px;
}

.shot-feedback.miss {
  color: #7eb3ff;
  font-size: clamp(18px, 4vw, 28px);
  animation: miss-pop 1.2s ease-out forwards;
}

.shot-feedback.hit {
  color: #ff5d4a;
  font-size: clamp(24px, 5vw, 36px);
  animation: hit-pop 1s ease-out forwards;
}

.shot-feedback.strike {
  color: #94a3b8;
  font-size: clamp(20px, 4.5vw, 32px);
  animation: strike-pop 1.1s ease-out forwards;
}

@keyframes miss-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.2);
  }
  50% {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(0.7);
  }
}

@keyframes hit-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(-10deg);
  }
  25% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.3) rotate(5deg);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1) rotate(-3deg);
  }
  75% {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -65%) scale(0.5) rotate(0deg);
  }
}

@keyframes strike-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.2);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(0.6);
  }
}

/* Sunk bug outline */
.sunk-bug-outline {
  position: absolute;
  border-radius: clamp(12px, 3vw, 20px);
  pointer-events: none;
  z-index: 3;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, 0.4);
  background: transparent;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.3),
              inset 0 0 20px rgba(255, 255, 255, 0.1);
  animation: sunk-outline-appear 0.6s ease-out;
}

@keyframes sunk-outline-appear {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7);
    border-color: rgba(255, 255, 255, 0);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.05);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    border-color: rgba(255, 255, 255, 0.4);
  }
}

/* ========================================
   MOBILE LANDSCAPE SCALING
   ======================================== */

/* Scale down everything on mobile landscape to fit comfortably */
@media (max-height: 700px) and (orientation: landscape) {
  .game-container {
    transform: scale(0.75);
    transform-origin: top center;
    min-height: auto;
  }

  html, body {
    overflow-y: auto;
  }
}
