/* ==========================================================================
   COSMIC GRIDLOCK - SCI-FI "UNBLOCK ME / RUSH HOUR" PUZZLE STYLESHEET
   Touch-Friendly, Holographic Grid, Glowing Warp Exit, Fluid Pointer Physics
   ========================================================================== */

.cgl-arena-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 20px 40px;
  font-family: 'Space Grotesk', -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

/* Top HUD Bar */
.cgl-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.cgl-hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cgl-stat-pill {
  background: #111a2e;
  border: 1px solid #3b82f6;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 13.5px;
  font-weight: 700;
  color: #93c5fd;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.cgl-tier-badge {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #ffffff;
  padding: 5px 12px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

/* Header Box */
.cgl-header-box {
  text-align: center;
  margin-bottom: 14px;
}

.cgl-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #f87171, #fbbf24, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 2px;
}

.cgl-subtitle {
  font-size: 13.5px;
  color: #94a3b8;
}

/* Board Outer Frame & Exit Gate Alignment */
.cgl-board-wrapper {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin-bottom: 18px;
}

.cgl-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #090e1a;
  border: 3px solid #1e293b;
  border-radius: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0, 0, 0, 0.6);
  touch-action: none; /* Crucial for iPad dragging */
  overflow: hidden;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: calc(100% / 6) calc(100% / 6);
}

/* Warp Exit Gate on Row 2 (33.33% from top) */
.cgl-exit-gate {
  position: absolute;
  right: -12px;
  top: calc(100% / 6 * 2);
  height: calc(100% / 6);
  width: 18px;
  background: linear-gradient(90deg, #ef4444, #f59e0b);
  border-radius: 0 8px 8px 0;
  box-shadow: 0 0 20px #ef4444, 0 0 35px #f59e0b;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
  z-index: 10;
  animation: pulseExit 1.5s infinite alternate;
}

@keyframes pulseExit {
  0% { box-shadow: 0 0 12px #ef4444; }
  100% { box-shadow: 0 0 28px #f59e0b, 0 0 45px #ef4444; }
}

/* Spaceship Block Pieces */
.cgl-piece {
  position: absolute;
  padding: 4px;
  box-sizing: border-box;
  cursor: grab;
  touch-action: none;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  z-index: 2;
}

.cgl-piece.dragging {
  cursor: grabbing;
  z-index: 10;
  transform: scale(1.03);
}

.cgl-piece-inner {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.25), 0 4px 10px rgba(0, 0, 0, 0.5);
}

/* Target Red Flagship */
.cgl-piece.target-ship .cgl-piece-inner {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border: 2px solid #fca5a5;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.6), inset 0 2px 4px rgba(255, 255, 255, 0.4);
}

.cgl-piece.target-ship.dragging .cgl-piece-inner {
  box-shadow: 0 0 25px rgba(239, 68, 68, 0.9), inset 0 2px 4px rgba(255, 255, 255, 0.6);
}

/* Obstacle Cruisers (Length 3) */
.cgl-piece.cruiser .cgl-piece-inner {
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  border: 2px solid #818cf8;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

/* Obstacle Scouts (Length 2) */
.cgl-piece.scout .cgl-piece-inner {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  border: 2px solid #38bdf8;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.cgl-piece-label {
  font-size: 18px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* Optimal Hint Indicator */
.cgl-hint-indicator {
  position: absolute;
  border: 2px dashed #f59e0b;
  border-radius: 12px;
  background: rgba(245, 158, 11, 0.2);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.5);
  pointer-events: none;
  z-index: 5;
  animation: hintPulse 1.2s infinite ease-in-out;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.96); }
  50% { opacity: 0.9; transform: scale(1.02); }
}

/* Control Actions Bar */
.cgl-actions-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.cgl-action-btn {
  padding: 11px 18px;
  border-radius: 9999px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  border: none;
  min-height: 48px;
  touch-action: manipulation;
}

.cgl-action-btn.undo, .cgl-action-btn.reset {
  background: #1e293b;
  border: 1px solid #475569;
  color: #f1f5f9;
}

.cgl-action-btn.undo:hover, .cgl-action-btn.reset:hover {
  background: #334155;
  border-color: #94a3b8;
}

.cgl-action-btn.hint {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid #f59e0b;
  color: #fcd34d;
}

.cgl-action-btn.select {
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #ffffff;
}

/* Level Select Modal */
.cgl-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.cgl-modal-card {
  background: linear-gradient(145deg, #0f172a, #1e1b4b);
  border: 2px solid #6366f1;
  border-radius: 28px;
  padding: 28px;
  max-width: 540px;
  width: 100%;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.9);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.cgl-modal-title {
  font-size: 24px;
  font-weight: 800;
  color: #a5b4fc;
  margin-bottom: 16px;
}

.cgl-level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  overflow-y: auto;
  padding: 10px 4px;
  max-height: 380px;
}

@media (max-width: 500px) {
  .cgl-level-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.cgl-level-card {
  background: #111a2e;
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 10px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cgl-level-card.unlocked:hover {
  transform: translateY(-2px);
  border-color: #60a5fa;
  background: #1e293b;
}

.cgl-level-card.current {
  border-color: #fbbf24;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.4);
}

.cgl-level-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.cgl-level-num {
  font-size: 13px;
  font-weight: 800;
  color: #ffffff;
}

.cgl-level-name {
  font-size: 10px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90%;
  margin: 2px 0;
}

.cgl-level-tier {
  font-size: 9px;
  font-weight: 700;
  color: #818cf8;
}

.cgl-level-stars {
  font-size: 11px;
  margin-top: 4px;
}

.cgl-modal-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border: none;
  border-radius: 9999px;
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
  cursor: pointer;
  margin-top: 14px;
  min-height: 52px;
}
