/* =====================================================================
   Space Rover Coding Game Styles (Ages 5-7)
   Martian Exploration Grid, Program Tape & Animated Rover
   ===================================================================== */

:root {
  --mars-dust: #b45309;
  --mars-ground: #d97706;
  --mars-light: #fef3c7;
  --space-sky: #090d16;
  --space-deep: #111827;
  --rover-x: 0px;
  --rover-y: 0px;
  --rover-rot: 0deg;
  --cell-size: 56px;
}

body {
  background: radial-gradient(circle at 50% 20%, #1e1b4b 0%, var(--space-sky) 85%);
  color: #ffffff;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

.game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------------
   Workspace Layout
   --------------------------------------------------------------------- */

.space-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 6px 14px 12px;
  box-sizing: border-box;
  position: relative;
}

/* ---------------------------------------------------------------------
   Status Bar
   --------------------------------------------------------------------- */

.mission-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 12px;
  margin-bottom: 4px;
}

.mission-badge,
.crystals-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 4px 12px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fef08a;
}

.badge-icon {
  font-size: 1.25rem;
}

/* ---------------------------------------------------------------------
   Planet Map & Grid
   --------------------------------------------------------------------- */

.planet-map-container {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1 / 1;
  max-height: 340px;
  background: linear-gradient(135deg, #7c2d12 0%, #9a3412 50%, #c2410c 100%);
  border: 4px solid #f97316;
  border-radius: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), inset 0 0 25px rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.planet-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  width: 92%;
  height: 92%;
  gap: 4px;
}

.grid-cell {
  background: rgba(254, 215, 170, 0.18);
  border: 1px dashed rgba(255, 237, 213, 0.35);
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.7rem;
  position: relative;
  transition: background 0.2s;
}

.grid-cell.cell-base {
  background: rgba(16, 185, 129, 0.3);
  border-color: #10b981;
  box-shadow: inset 0 0 12px rgba(16, 185, 129, 0.4);
}

.grid-cell.cell-crystal {
  animation: crystalPulse 2s infinite ease-in-out;
}

.grid-cell.cell-rock {
  background: rgba(0, 0, 0, 0.3);
}

@keyframes crystalPulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 4px #38bdf8); }
  50% { transform: scale(1.15); filter: drop-shadow(0 0 10px #38bdf8); }
}

/* ---------------------------------------------------------------------
   Animated Rover Sprite
   --------------------------------------------------------------------- */

.rover-sprite {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transform: translate(var(--rover-x), var(--rover-y)) rotate(var(--rover-rot));
  transform-origin: center center;
  transition: transform 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  z-index: 20;
}

.rover-body {
  width: 38px;
  height: 38px;
  background: radial-gradient(circle at 40% 30%, #60a5fa 0%, #2563eb 60%, #1e40af 100%);
  border: 2px solid #bfdbfe;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.rover-face {
  font-size: 1.5rem;
  line-height: 1;
}

.rover-antenna {
  font-size: 0.9rem;
  margin-bottom: -5px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
}

.rover-wheels {
  font-size: 0.75rem;
  margin-top: -3px;
  display: flex;
  justify-content: space-between;
  width: 32px;
}

.rover-sprite.bump {
  animation: roverBump 0.45s ease-in-out;
}

@keyframes roverBump {
  0%, 100% { transform: translate(var(--rover-x), var(--rover-y)) rotate(var(--rover-rot)) scale(1); }
  25% { transform: translate(var(--rover-x), var(--rover-y)) rotate(calc(var(--rover-rot) - 12deg)) scale(0.9); }
  75% { transform: translate(var(--rover-x), var(--rover-y)) rotate(calc(var(--rover-rot) + 12deg)) scale(0.9); }
}

/* ---------------------------------------------------------------------
   Program Tape (Command Queue)
   --------------------------------------------------------------------- */

.program-section {
  width: 100%;
  margin: 4px 0;
}

.program-strip-wrapper {
  background: rgba(15, 23, 42, 0.75);
  border: 2px solid rgba(148, 163, 184, 0.3);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
  overflow-x: auto;
  min-height: 54px;
  display: flex;
  align-items: center;
}

.program-strip {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 100%;
}

.program-step-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}

.program-step-pill:hover {
  transform: translateY(-2px) scale(1.05);
}

.program-step-pill.step-forward {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border: 2px solid #38bdf8;
}

.program-step-pill.step-left {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  border: 2px solid #c084fc;
}

.program-step-pill.step-right {
  background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  border: 2px solid #818cf8;
}

.program-step-pill.active-step {
  transform: scale(1.22);
  box-shadow: 0 0 16px #facc15, 0 4px 10px rgba(0, 0, 0, 0.4);
  border-color: #facc15;
  z-index: 10;
}

.empty-tape-hint {
  color: #94a3b8;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0 8px;
}

/* ---------------------------------------------------------------------
   Controls Section
   --------------------------------------------------------------------- */

.controls-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.command-buttons-tray {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.cmd-btn {
  flex: 1;
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  padding: 10px 8px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, filter 0.15s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #ffffff;
}

.cmd-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.cmd-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.cmd-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.6);
}

.btn-forward {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border-bottom: 3px solid #075985;
}

.btn-left {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  border-bottom: 3px solid #5b21b6;
}

.btn-right {
  background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  border-bottom: 3px solid #3730a3;
}

/* Execution Action Buttons */
.execution-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.action-btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 8px 14px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s ease, filter 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.action-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.run-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-bottom: 3px solid #047857;
  flex: 1.5;
  font-size: 1.1rem;
}

.undo-btn {
  background: #475569;
  flex: 1;
}

.clear-btn {
  background: #334155;
  flex: 1;
}

.next-btn {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  border-bottom: 3px solid #b45309;
  font-size: 1.1rem;
  flex: 2;
}

.primary-btn {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  padding: 12px 28px;
  font-size: 1.15rem;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------------
   Celebration Overlay & Sparks
   --------------------------------------------------------------------- */

.celebration-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 13, 22, 0.75);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 16px;
}

.celebration-card {
  background: #1e293b;
  border: 3px solid #f59e0b;
  padding: 24px 30px;
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
  max-width: 420px;
  width: 100%;
  animation: cardBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.celebration-icon {
  font-size: 3.2rem;
  margin-bottom: 8px;
}

.celebration-text {
  font-size: 1.25rem;
  font-weight: 800;
  color: #fef08a;
  margin-bottom: 20px;
  line-height: 1.4;
}

.sparks-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.sparkle {
  position: absolute;
  font-size: 1.5rem;
  animation: sparkBurst 0.8s ease-out forwards;
}

/* ---------------------------------------------------------------------
   Keyframes
   --------------------------------------------------------------------- */

@keyframes cardBounce {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes sparkBurst {
  0% { transform: translate(0, 0) scale(0.5); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.3); opacity: 0; }
}

/* ---------------------------------------------------------------------
   Mobile Responsive
   --------------------------------------------------------------------- */

@media (max-width: 480px) {
  :root {
    --cell-size: 46px;
  }
  .planet-map-container {
    max-height: 270px;
  }
  .grid-cell {
    font-size: 1.4rem;
  }
  .rover-body {
    width: 32px;
    height: 32px;
  }
  .rover-face {
    font-size: 1.25rem;
  }
  .cmd-btn {
    font-size: 0.88rem;
    padding: 8px 4px;
  }
  .action-btn {
    font-size: 0.85rem;
    padding: 6px 10px;
  }
}

/* ---------------------------------------------------------------------
   Reduced Motion
   --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .rover-sprite,
  .rover-sprite.bump,
  .grid-cell.cell-crystal,
  .celebration-card {
    transition: none !important;
    animation: none !important;
  }
}
