/* ===== GAME BODY & BACKGROUND ===== */
.game-body {
  font-family: "Inter", sans-serif;
  background: #101827;
  color: #ffffff;
  touch-action: manipulation;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  box-sizing: border-box;
}

.game-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(
      circle at 20% 20%,
      rgba(99, 179, 237, 0.15) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(159, 122, 234, 0.12) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 40% 60%,
      rgba(56, 178, 172, 0.08) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 60% 40%,
      rgba(237, 137, 54, 0.06) 0%,
      transparent 50%
    ),
    linear-gradient(135deg, #101827 0%, #0f1419 30%, #1a1d29 70%, #101827 100%);
  animation: backgroundShift 20s ease-in-out infinite;
}

.game-background::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
      2px 2px at 20px 30px,
      rgba(255, 255, 255, 0.4),
      transparent
    ),
    radial-gradient(2px 2px at 40px 70px, rgba(99, 179, 237, 0.3), transparent),
    radial-gradient(1px 1px at 90px 40px, rgba(159, 122, 234, 0.4), transparent),
    radial-gradient(1px 1px at 130px 80px, rgba(56, 178, 172, 0.3), transparent),
    radial-gradient(2px 2px at 160px 30px, rgba(237, 137, 54, 0.2), transparent);
  background-repeat: repeat;
  background-size: 400px 300px;
  animation: starField 25s linear infinite;
  opacity: 0.6;
}

.game-background::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
      1px 1px at 30px 20px,
      rgba(255, 255, 255, 0.2),
      transparent
    ),
    radial-gradient(1px 1px at 60px 80px, rgba(99, 179, 237, 0.25), transparent),
    radial-gradient(
      1px 1px at 100px 50px,
      rgba(159, 122, 234, 0.2),
      transparent
    ),
    radial-gradient(
      1px 1px at 150px 90px,
      rgba(56, 178, 172, 0.15),
      transparent
    );
  background-repeat: repeat;
  background-size: 500px 350px;
  animation: starField 35s linear infinite reverse;
  opacity: 0.4;
}

.stars,
.stars2,
.stars3 {
  display: none;
}

@keyframes backgroundShift {
  0%,
  100% {
    background: radial-gradient(
        circle at 20% 20%,
        rgba(99, 179, 237, 0.15) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 80% 80%,
        rgba(159, 122, 234, 0.12) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 40% 60%,
        rgba(56, 178, 172, 0.08) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 60% 40%,
        rgba(237, 137, 54, 0.06) 0%,
        transparent 50%
      ),
      linear-gradient(
        135deg,
        #101827 0%,
        #0f1419 30%,
        #1a1d29 70%,
        #101827 100%
      );
  }
  25% {
    background: radial-gradient(
        circle at 30% 10%,
        rgba(99, 179, 237, 0.18) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 70% 90%,
        rgba(159, 122, 234, 0.15) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 50% 70%,
        rgba(56, 178, 172, 0.1) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 70% 30%,
        rgba(237, 137, 54, 0.08) 0%,
        transparent 50%
      ),
      linear-gradient(
        135deg,
        #101827 0%,
        #0f1419 30%,
        #1a1d29 70%,
        #101827 100%
      );
  }
  50% {
    background: radial-gradient(
        circle at 40% 30%,
        rgba(99, 179, 237, 0.12) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 60% 70%,
        rgba(159, 122, 234, 0.18) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 30% 50%,
        rgba(56, 178, 172, 0.12) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 80% 20%,
        rgba(237, 137, 54, 0.1) 0%,
        transparent 50%
      ),
      linear-gradient(
        135deg,
        #101827 0%,
        #0f1419 30%,
        #1a1d29 70%,
        #101827 100%
      );
  }
  75% {
    background: radial-gradient(
        circle at 10% 40%,
        rgba(99, 179, 237, 0.2) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 90% 60%,
        rgba(159, 122, 234, 0.1) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 60% 40%,
        rgba(56, 178, 172, 0.15) 0%,
        transparent 50%
      ),
      radial-gradient(
        circle at 40% 80%,
        rgba(237, 137, 54, 0.12) 0%,
        transparent 50%
      ),
      linear-gradient(
        135deg,
        #101827 0%,
        #0f1419 30%,
        #1a1d29 70%,
        #101827 100%
      );
  }
}

@keyframes starField {
  from {
    transform: translateY(0px) translateX(0px);
  }
  to {
    transform: translateY(-100px) translateX(-50px);
  }
}

/* ===== GAME BUTTONS ===== */
.game-button {
  position: relative;
  background: linear-gradient(145deg, #2d3748, #1a202c);
  border: 2px solid #4a5568;
  border-radius: 12px;
  padding: 12px 20px;
  color: #ffffff;
  font-family: "Orbitron", monospace;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.game-button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.game-button:hover::before {
  left: 100%;
}

.game-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
  border-color: #63b3ed;
}

.game-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.button-icon {
  font-size: 16px;
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.5));
}

.button-text {
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Button variants */
.home-button {
  background: linear-gradient(145deg, #4a5568, #2d3748);
  border-color: #718096;
}

.solution-button {
  background: linear-gradient(145deg, #d69e2e, #b7791f);
  border-color: #f6e05e;
}

.restart-button {
  background: linear-gradient(145deg, #e53e3e, #c53030);
  border-color: #fc8181;
}

/* ===== GAME MODAL ===== */
.game-modal {
  background: linear-gradient(
    145deg,
    rgba(26, 32, 44, 0.95),
    rgba(45, 55, 72, 0.95)
  );
  border: 2px solid #4a5568;
  border-radius: 20px;
  padding: 40px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  transform: scale(0.95);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  margin: 0 auto;
  display: block;
  box-sizing: border-box;
}

.game-modal::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, #63b3ed, #9f7aea, #ed8936, #38b2ac);
  border-radius: 22px;
  z-index: -1;
  opacity: 0.3;
}

/* ===== STARTUP MODAL ===== */
.startup-modal {
  max-width: 600px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.7);
  border: 3px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(20px);
}

.logo-section {
  margin-bottom: 40px;
}

.game-logo {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-glow {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, #63b3ed, #9f7aea, #ed8936, #38b2ac);
  border-radius: 50%;
  filter: blur(20px);
  opacity: 0.6;
  animation: logoGlow 3s ease-in-out infinite alternate;
}

.logo-text {
  position: relative;
  font-family: "Orbitron", monospace;
  font-size: 48px;
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 0 20px rgba(99, 179, 237, 0.8);
  z-index: 1;
}

@keyframes logoGlow {
  from {
    transform: scale(1);
    opacity: 0.6;
  }
  to {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

.game-title {
  font-family: "Orbitron", monospace;
  font-size: 42px;
  font-weight: 900;
  color: #ffffff;
  margin: 0 0 10px 0;
  text-shadow: 0 0 20px rgba(99, 179, 237, 0.6);
  background: linear-gradient(45deg, #63b3ed, #9f7aea, #ed8936, #38b2ac);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-subtitle {
  font-size: 18px;
  color: #a0aec0;
  margin: 0;
  font-weight: 300;
}

.info-section {
  margin-bottom: 30px;
  text-align: left;
}

.section-title {
  font-family: "Orbitron", monospace;
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
  margin: 0 0 15px 0;
  text-shadow: 0 0 10px rgba(99, 179, 237, 0.5);
}

.section-text {
  color: #cbd5e0;
  line-height: 1.6;
  margin: 0;
  font-size: 16px;
}

.instructions-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #cbd5e0;
  font-size: 15px;
}

.instruction-icon {
  font-size: 20px;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
}

.start-game-button {
  position: relative;
  background: linear-gradient(145deg, #38b2ac, #2c7a7b);
  border: 2px solid #4fd1c7;
  border-radius: 15px;
  padding: 18px 40px;
  color: #ffffff;
  font-family: "Orbitron", monospace;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 8px 30px rgba(56, 178, 172, 0.3);
  text-align: center;
  white-space: nowrap;
  box-sizing: border-box;
}

.button-glow {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  transition: left 0.6s;
}

.start-game-button:hover .button-glow {
  left: 100%;
}

.start-game-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(56, 178, 172, 0.4);
  border-color: #68d391;
}

.start-game-button:active {
  transform: translateY(-1px);
}

/* ===== GAME CONTAINER ===== */
.game-container {
  max-width: 500px;
  margin: 0 auto;
  background: linear-gradient(145deg, #1a202c, #2d3748);
  border: 2px solid #4a5568;
  border-radius: 20px;
  padding: 15px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  position: relative;
  display: block;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

/* Make color palette match game container width exactly */
.controls-section {
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.game-container::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, #63b3ed, #9f7aea, #ed8936, #38b2ac);
  border-radius: 22px;
  z-index: -1;
  opacity: 0.2;
}

.level-section {
  text-align: center;
  margin-bottom: 20px;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(145deg, #4a5568, #2d3748);
  border: 2px solid #63b3ed;
  border-radius: 25px;
  padding: 12px 24px;
  box-shadow: 0 4px 15px rgba(99, 179, 237, 0.3);
}

/* Level badge in navigation area */
#navigation-buttons .level-badge {
  margin: 0;
}

.level-icon {
  font-size: 20px;
  filter: drop-shadow(0 0 5px rgba(99, 179, 237, 0.8));
}

.level-text {
  font-family: "Orbitron", monospace;
  font-size: 20px;
  font-weight: 700;
  color: #63b3ed;
  text-shadow: 0 0 10px rgba(99, 179, 237, 0.5);
}

.grid-section {
  margin-bottom: 30px;
}

.game-grid {
  display: grid;
  gap: 8px;
  aspect-ratio: 1;
}

/* ===== GRID CELLS ===== */
.grid-cell {
  background: linear-gradient(145deg, #4a5568, #2d3748);
  border: 2px solid #718096;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.grid-cell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.grid-cell:hover::before {
  opacity: 1;
}

.grid-cell:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  border-color: #a0aec0;
}

.next-cell {
  background: linear-gradient(145deg, #2b6cb0, #2c5282);
  border-color: #63b3ed;
  box-shadow: 0 0 20px rgba(99, 179, 237, 0.6),
    inset 0 0 20px rgba(99, 179, 237, 0.2);
  animation: nextCellPulse 2s ease-in-out infinite;
}

@keyframes nextCellPulse {
  0%,
  100% {
    box-shadow: 0 0 20px rgba(99, 179, 237, 0.6),
      inset 0 0 20px rgba(99, 179, 237, 0.2);
  }
  50% {
    box-shadow: 0 0 30px rgba(99, 179, 237, 0.8),
      inset 0 0 30px rgba(99, 179, 237, 0.3);
  }
}

/* ===== COLOR BALLS ===== */
.ball {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.ball::before {
  content: "";
  position: absolute;
  top: 20%;
  left: 20%;
  width: 30%;
  height: 30%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.4), transparent);
  border-radius: 50%;
  pointer-events: none;
}

.ball::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  pointer-events: none;
}

/* ===== COLOR PALETTE ===== */
.controls-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 20px;
}

.color-palette {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: linear-gradient(145deg, #2d3748, #1a202c);
  border: 2px solid #4a5568;
  border-radius: 15px;
  padding: 12px 20px;
  min-height: 80px;
  box-shadow: inset 0 4px 15px rgba(0, 0, 0, 0.3);
  gap: 8px;
  --ball-size: 50px;
  --ball-gap: 8px;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  box-sizing: border-box;
}

.color-palette .text-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  flex: 1;
  min-width: 0;
}

.color-palette .ball {
  width: var(--ball-size);
  height: var(--ball-size);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.color-palette .ball:hover {
  transform: scale(1.15);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.color-palette .ball:active {
  transform: scale(1.05);
}

.color-disabled {
  opacity: 0.3;
  pointer-events: none;
  cursor: not-allowed !important;
  filter: grayscale(100%);
}

.color-disabled .ball {
  transform: scale(0.8);
}

/* Color count styling */
.color-palette .text-center p {
  font-family: "Orbitron", monospace;
  font-weight: 700;
  font-size: 16px;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  margin: 0;
  min-width: 30px;
  text-align: center;
}

/* Ball count display on the ball itself */
.ball-count {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Orbitron", monospace;
  font-weight: 900;
  font-size: 18px;
  color: #ffffff;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.8), 0 0 4px rgba(255, 255, 255, 0.5);
  pointer-events: none;
  z-index: 10;
  user-select: none;
}

.color-palette .ball {
  position: relative;
}

/* ===== STATUS DISPLAY ===== */
.status-display {
  text-align: center;
  font-family: "Orbitron", monospace;
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
  min-height: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* ===== MODAL STYLES ===== */
.modal-icon {
  font-size: 64px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.5));
  animation: modalIconFloat 3s ease-in-out infinite;
}

@keyframes modalIconFloat {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

.modal-title {
  font-family: "Orbitron", monospace;
  font-size: 28px;
  font-weight: 700;
  color: #ffffff;
  margin: 0 0 15px 0;
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.modal-text {
  color: #cbd5e0;
  font-size: 16px;
  line-height: 1.6;
  margin: 0 0 30px 0;
}

.modal-button {
  position: relative;
  background: linear-gradient(145deg, #4a5568, #2d3748);
  border: 2px solid #718096;
  border-radius: 12px;
  padding: 15px 30px;
  color: #ffffff;
  font-family: "Orbitron", monospace;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.modal-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
  border-color: #a0aec0;
}

/* Modal button variants */
.close-button {
  background: linear-gradient(145deg, #4a5568, #2d3748);
  border-color: #718096;
}

.next-level-button {
  background: linear-gradient(145deg, #38a169, #2f855a);
  border-color: #68d391;
}

.restart-button {
  background: linear-gradient(145deg, #e53e3e, #c53030);
  border-color: #fc8181;
}

.play-again-button {
  background: linear-gradient(145deg, #d69e2e, #b7791f);
  border-color: #f6e05e;
}

.solution-complete-modal {
  border-color: #9f7aea;
}

.solution-complete-modal::before {
  background: linear-gradient(45deg, #9f7aea, #ed8936, #38b2ac, #63b3ed);
}

/* ===== ANIMATIONS ===== */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}

@keyframes ballPlace {
  0% {
    transform: scale(0) rotate(0deg);
  }
  50% {
    transform: scale(1.2) rotate(180deg);
  }
  100% {
    transform: scale(1) rotate(360deg);
  }
}

@keyframes ballGlow {
  0%,
  100% {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  }
  50% {
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
  }
}

/* ===== MOBILE-FIRST RESPONSIVE DESIGN ===== */

/* ===== GENERAL LANDSCAPE ORIENTATION ===== */
@media (orientation: landscape) {
  .startup-modal {
    max-width: 500px;
    max-height: 95vh;
    overflow-y: auto;
    padding: 25px 20px;
    margin: 15px auto;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
    -ms-overflow-style: none; /* Hide scrollbar for IE and Edge */
  }

  .startup-modal::-webkit-scrollbar {
    display: none; /* Hide scrollbar for WebKit browsers */
  }

  .logo-section {
    margin-bottom: 20px;
  }

  .game-title {
    font-size: 36px;
    margin-bottom: 4px;
  }

  .game-subtitle {
    font-size: 18px;
  }

  .info-section {
    margin-bottom: 22px;
  }

  .section-title {
    font-size: 22px;
    margin-bottom: 14px;
  }

  .section-text {
    font-size: 16px;
    line-height: 1.7;
  }

  .instructions-list {
    gap: 12px;
  }

  .instruction-item {
    font-size: 15px;
    gap: 12px;
  }

  .instruction-icon {
    font-size: 18px;
  }

  .start-game-button {
    padding: 18px 28px;
    font-size: 18px;
    min-height: 55px;
    margin-top: 18px;
  }

  .start-game-button .button-text {
    font-size: 18px;
  }
}

/* ===== LANDSCAPE MOBILE (orientation: landscape) ===== */
@media (orientation: landscape) and (max-height: 600px) {
  .game-body {
    overflow-y: auto;
  }

  .game-container {
    margin: 5px auto;
    padding: 10px;
    max-width: 90vw;
    display: block;
  }

  .controls-section {
    max-width: 90vw;
  }

  .game-modal {
    margin: 5px;
    padding: 20px 15px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .startup-modal {
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 22px 18px;
    margin: 10px auto;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
    -ms-overflow-style: none; /* Hide scrollbar for IE and Edge */
  }

  .startup-modal::-webkit-scrollbar {
    display: none; /* Hide scrollbar for WebKit browsers */
  }

  .logo-section {
    margin-bottom: 18px;
  }

  .game-title {
    font-size: 28px;
    margin-bottom: 3px;
  }

  .game-subtitle {
    font-size: 14px;
  }

  .info-section {
    margin-bottom: 18px;
  }

  .section-title {
    font-size: 18px;
    margin-bottom: 10px;
  }

  .section-text {
    font-size: 14px;
    line-height: 1.5;
  }

  .instructions-list {
    gap: 8px;
  }

  .instruction-item {
    font-size: 13px;
    gap: 8px;
  }

  .instruction-icon {
    font-size: 16px;
  }

  .start-game-button {
    padding: 14px 20px;
    font-size: 16px;
    min-height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
    margin-top: 12px;
  }

  .start-game-button .button-text {
    font-size: 16px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }

  .level-section {
    margin-bottom: 10px;
  }

  .level-badge {
    padding: 8px 16px;
  }

  .level-text {
    font-size: 16px;
  }

  .grid-section {
    margin-bottom: 15px;
  }

  .game-grid {
    gap: 4px;
  }

  .controls-section {
    gap: 15px;
    margin-top: 10px;
  }

  .color-palette {
    padding: 8px 12px;
    min-height: 60px;
    --ball-size: 35px;
    --ball-gap: 6px;
    gap: var(--ball-gap);
    max-width: 90vw;
  }

  .color-palette .ball {
    width: var(--ball-size);
    height: var(--ball-size);
  }

  .color-palette .text-center p {
    font-size: 12px;
  }

  .ball-count {
    font-size: 14px;
  }

  .status-display {
    font-size: 14px;
    min-height: 0;
    display: none;
  }

  .modal-icon {
    font-size: 48px;
    margin-bottom: 15px;
  }

  .modal-title {
    font-size: 20px;
    margin-bottom: 10px;
  }

  .modal-text {
    font-size: 14px;
    margin-bottom: 20px;
  }

  .modal-button {
    padding: 12px 24px;
    font-size: 14px;
  }

  .game-button {
    padding: 8px 12px;
    font-size: 12px;
    min-width: 80px;
  }

  .game-button .button-text {
    display: none;
  }

  .start-game-button .button-text {
    display: inline;
  }

  .navigation-buttons {
    top: 4px;
    left: 4px;
    right: 4px;
    gap: 8px;
  }

  .navigation-buttons .flex {
    gap: 6px;
  }

  #navigation-buttons .level-badge {
    padding: 8px 16px;
  }

  #navigation-buttons .level-text {
    font-size: 14px;
  }

  /* Make game elements smaller for small landscape screens */
  .game-container {
    max-width: 350px;
    padding: 10px;
    margin: 8px auto;
  }

  .controls-section {
    max-width: 350px;
    margin: 12px auto;
  }

  .color-palette {
    max-width: 350px;
    padding: 8px 12px;
    min-height: 60px;
    --ball-size: 40px;
    --ball-gap: 5px;
    gap: var(--ball-gap);
  }

  .color-palette .ball {
    width: var(--ball-size);
    height: var(--ball-size);
  }

  .level-section {
    margin-bottom: 12px;
  }

  .level-badge {
    padding: 8px 15px;
  }

  .level-text {
    font-size: 16px;
  }

  .game-grid {
    gap: 5px;
  }

  .game-button {
    padding: 8px 12px;
    font-size: 12px;
    min-width: 80px;
  }
}

/* ===== EXTRA SMALL LANDSCAPE (very compact) ===== */
@media (orientation: landscape) and (max-height: 480px) {
  .startup-modal {
    max-width: 380px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 18px 15px;
    margin: 8px auto;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
    -ms-overflow-style: none; /* Hide scrollbar for IE and Edge */
  }

  .startup-modal::-webkit-scrollbar {
    display: none; /* Hide scrollbar for WebKit browsers */
  }

  .logo-section {
    margin-bottom: 12px;
  }

  .game-title {
    font-size: 24px;
    margin-bottom: 2px;
  }

  .game-subtitle {
    font-size: 12px;
  }

  .info-section {
    margin-bottom: 12px;
  }

  .section-title {
    font-size: 16px;
    margin-bottom: 8px;
  }

  .section-text {
    font-size: 12px;
    line-height: 1.4;
  }

  .instructions-list {
    gap: 6px;
  }

  .instruction-item {
    font-size: 11px;
    gap: 6px;
  }

  .instruction-icon {
    font-size: 14px;
  }

  .start-game-button {
    padding: 12px 16px;
    font-size: 14px;
    min-height: 38px;
    margin-top: 8px;
  }

  .start-game-button .button-text {
    font-size: 14px;
  }

  /* Make game elements even smaller for extra small landscape screens */
  .game-container {
    max-width: 300px;
    padding: 8px;
    margin: 5px auto;
  }

  .controls-section {
    max-width: 300px;
    margin: 10px auto;
  }

  .color-palette {
    max-width: 300px;
    padding: 6px 10px;
    min-height: 50px;
    --ball-size: 35px;
    --ball-gap: 4px;
    gap: var(--ball-gap);
  }

  .color-palette .ball {
    width: var(--ball-size);
    height: var(--ball-size);
  }

  .level-section {
    margin-bottom: 10px;
  }

  .level-badge {
    padding: 6px 12px;
  }

  .level-text {
    font-size: 14px;
  }

  .game-grid {
    gap: 4px;
  }

  .game-button {
    padding: 6px 10px;
    font-size: 11px;
    min-width: 70px;
  }

  /* Navigation adjustments for extra small landscape */
  .navigation-buttons {
    top: 2px;
    left: 2px;
    right: 2px;
    gap: 6px;
  }

  .navigation-buttons .flex {
    gap: 4px;
  }

  #navigation-buttons .level-badge {
    padding: 6px 12px;
  }

  #navigation-buttons .level-text {
    font-size: 12px;
  }
}

/* ===== EXTRA SMALL MOBILE (≤360px) ===== */
@media (max-width: 360px) {
  .game-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 6px;
    min-height: 100vh;
  }

  .start-game-button .button-text {
    font-size: 14px;
  }

  .start-game-button {
    padding: 14px 16px;
    font-size: 14px;
  }

  .controls-section {
    margin: 15px auto 0 auto;
  }

  /* Mobile level indicator - hide icon and background, show only text */
  #navigation-buttons .level-badge {
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
  }

  #navigation-buttons .level-icon {
    display: none;
  }

  #navigation-buttons .level-text {
    font-size: 14px;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  }
}

/* ===== SMALL MOBILE (≤480px) ===== */
@media (max-width: 480px) {
  .game-body {
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 8px;
    min-height: 100vh;
  }

  .game-container {
    margin: 0 auto;
    padding: 8px;
    border-radius: 15px;
    display: block;
    max-width: calc(100vw - 16px);
    width: calc(100vw - 16px);
  }

  .controls-section {
    max-width: calc(100vw - 16px);
    width: calc(100vw - 16px);
    margin: 20px auto 0 auto;
  }

  .game-container::before {
    border-radius: 17px;
  }

  .game-modal {
    margin: 8px;
    padding: 24px 16px;
    border-radius: 15px;
  }

  .game-modal::before {
    border-radius: 17px;
  }

  .startup-modal {
    max-width: 95vw;
  }

  .game-title {
    font-size: 28px;
    margin-bottom: 8px;
  }

  .game-subtitle {
    font-size: 14px;
  }

  .section-title {
    font-size: 18px;
    margin-bottom: 12px;
  }

  .section-text {
    font-size: 14px;
    line-height: 1.5;
  }

  .instructions-list {
    gap: 10px;
  }

  .instruction-item {
    font-size: 13px;
    gap: 10px;
  }

  .instruction-icon {
    font-size: 16px;
  }

  .start-game-button {
    padding: 16px 20px;
    font-size: 16px;
    border-radius: 12px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
  }

  .start-game-button .button-text {
    font-size: 16px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  }

  .level-section {
    margin-bottom: 15px;
  }

  .level-badge {
    padding: 10px 20px;
    border-radius: 20px;
  }

  .level-text {
    font-size: 16px;
  }

  /* Mobile level indicator - hide icon and background, show only text */
  #navigation-buttons .level-badge {
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
  }

  #navigation-buttons .level-icon {
    display: none;
  }

  #navigation-buttons .level-text {
    font-size: 16px;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  }

  .grid-section {
    margin-bottom: 20px;
  }

  .game-grid {
    gap: 2px;
    max-width: 100%;
    overflow: hidden;
  }

  .grid-cell {
    border-radius: 6px;
    border-width: 1px;
    min-width: 0;
    min-height: 0;
  }

  .ball {
    width: 70%;
    height: 70%;
  }

  /* For large grids (10+ columns), make everything even smaller */
  .game-grid[style*="repeat(10"] .grid-cell,
  .game-grid[style*="repeat(11"] .grid-cell,
  .game-grid[style*="repeat(12"] .grid-cell,
  .game-grid[style*="repeat(13"] .grid-cell {
    border-radius: 4px;
    border-width: 0.5px;
  }

  .game-grid[style*="repeat(10"] .ball,
  .game-grid[style*="repeat(11"] .ball,
  .game-grid[style*="repeat(12"] .ball,
  .game-grid[style*="repeat(13"] .ball {
    width: 60%;
    height: 60%;
  }

  .controls-section {
    gap: 16px;
    margin-top: 15px;
  }

  .color-palette {
    padding: 6px 8px;
    min-height: 60px;
    border-radius: 12px;
    --ball-size: 35px;
    --ball-gap: 4px;
    gap: var(--ball-gap);
    max-width: calc(100vw - 16px);
    width: calc(100vw - 16px);
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .color-palette .ball {
    width: var(--ball-size);
    height: var(--ball-size);
  }

  .color-palette .text-center p {
    font-size: 13px;
  }

  .ball-count {
    font-size: 15px;
  }

  .status-display {
    font-size: 14px;
    min-height: 0;
    display: none;
  }

  /* Dynamic grid sizing for very large grids on mobile */
  .game-grid[style*="repeat(13"] {
    gap: 1px;
  }

  .game-grid[style*="repeat(12"] {
    gap: 1.5px;
  }

  .game-grid[style*="repeat(11"] {
    gap: 2px;
  }

  .game-grid[style*="repeat(10"] {
    gap: 2.5px;
  }

  .modal-icon {
    font-size: 48px;
    margin-bottom: 16px;
  }

  .modal-title {
    font-size: 20px;
    margin-bottom: 12px;
  }

  .modal-text {
    font-size: 14px;
    margin-bottom: 24px;
  }

  .modal-button {
    padding: 12px 20px;
    font-size: 14px;
    border-radius: 10px;
  }

  .game-button {
    padding: 8px 12px;
    font-size: 12px;
    min-width: 70px;
    border-radius: 8px;
  }

  .game-button .button-text {
    display: none;
  }

  .start-game-button .button-text {
    display: inline;
  }

  .button-icon {
    font-size: 14px;
  }

  .navigation-buttons {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 8px;
  }

  .navigation-buttons .flex {
    gap: 8px;
  }
}

/* ===== MOBILE (≤640px) ===== */
@media (max-width: 640px) {
  .game-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 10px;
    min-height: 100vh;
  }

  .game-container {
    margin: 0 auto;
    padding: 10px;
    display: block;
    max-width: calc(100vw - 20px);
    width: calc(100vw - 20px);
  }

  .controls-section {
    max-width: calc(100vw - 20px);
    width: calc(100vw - 20px);
    margin: 25px auto 0 auto;
  }

  .game-modal {
    margin: 10px;
    padding: 30px 20px;
  }

  .game-title {
    font-size: 32px;
  }

  .game-subtitle {
    font-size: 16px;
  }

  .section-title {
    font-size: 20px;
  }

  .modal-title {
    font-size: 24px;
  }

  .game-button {
    padding: 10px 16px;
    font-size: 13px;
    min-width: 100px;
  }

  .game-button .button-text {
    display: none;
  }

  .start-game-button .button-text {
    display: inline;
  }

  .game-button {
    min-width: 50px;
  }

  /* Mobile level indicator - hide icon and background, show only text */
  #navigation-buttons .level-badge {
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
  }

  #navigation-buttons .level-icon {
    display: none;
  }

  #navigation-buttons .level-text {
    font-size: 18px;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  }

  .color-palette {
    padding: 6px 10px;
    min-height: 65px;
    --ball-size: 40px;
    --ball-gap: 5px;
    gap: var(--ball-gap);
    max-width: calc(100vw - 20px);
    width: calc(100vw - 20px);
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .color-palette .ball {
    width: var(--ball-size);
    height: var(--ball-size);
  }

  .color-palette .text-center p {
    font-size: 14px;
  }

  .ball-count {
    font-size: 16px;
  }

  .status-display {
    font-size: 16px;
    display: none;
  }

  /* Dynamic grid sizing for very large grids on mobile */
  .game-grid[style*="repeat(13"] {
    gap: 1.5px;
  }

  .game-grid[style*="repeat(12"] {
    gap: 2px;
  }

  .game-grid[style*="repeat(11"] {
    gap: 2.5px;
  }

  .game-grid[style*="repeat(10"] {
    gap: 3px;
  }

  .level-text {
    font-size: 18px;
  }

  .game-grid {
    gap: 3px;
    max-width: 100%;
    overflow: hidden;
  }

  .grid-cell {
    min-width: 0;
    min-height: 0;
  }

  .ball {
    width: 75%;
    height: 75%;
  }

  /* For large grids (10+ columns), make everything even smaller */
  .game-grid[style*="repeat(10"] .grid-cell,
  .game-grid[style*="repeat(11"] .grid-cell,
  .game-grid[style*="repeat(12"] .grid-cell,
  .game-grid[style*="repeat(13"] .grid-cell {
    border-radius: 6px;
    border-width: 1px;
  }

  .game-grid[style*="repeat(10"] .ball,
  .game-grid[style*="repeat(11"] .ball,
  .game-grid[style*="repeat(12"] .ball,
  .game-grid[style*="repeat(13"] .ball {
    width: 65%;
    height: 65%;
  }
}

/* ===== TABLET PORTRAIT (641px-768px) ===== */
@media (min-width: 641px) and (max-width: 768px) {
  .game-container {
    margin: 20px auto;
    padding: 15px;
    max-width: 90vw;
  }

  .controls-section {
    max-width: 90vw;
  }

  .game-modal {
    margin: 20px;
    padding: 35px 25px;
    max-width: 90vw;
  }

  .startup-modal {
    max-width: 80vw;
  }

  .game-title {
    font-size: 36px;
  }

  .game-subtitle {
    font-size: 17px;
  }

  .section-title {
    font-size: 22px;
  }

  .section-text {
    font-size: 15px;
  }

  .instruction-item {
    font-size: 14px;
  }

  .start-game-button {
    padding: 16px 35px;
    font-size: 17px;
  }

  .level-text {
    font-size: 19px;
  }

  .game-grid {
    gap: 7px;
  }

  .color-palette {
    --ball-size: 52px;
    --ball-gap: 6px;
    gap: var(--ball-gap);
    padding: 10px 18px;
    min-height: 85px;
    max-width: 90vw;
  }

  .color-palette .ball {
    width: var(--ball-size);
    height: var(--ball-size);
  }

  .color-palette .text-center p {
    font-size: 15px;
  }

  .ball-count {
    font-size: 17px;
  }

  .status-display {
    font-size: 17px;
    display: none;
  }

  .modal-title {
    font-size: 26px;
  }

  .modal-text {
    font-size: 15px;
  }

  .modal-button {
    padding: 14px 28px;
    font-size: 15px;
  }

  .game-button {
    padding: 11px 18px;
    font-size: 14px;
    min-width: 110px;
  }

  .button-text {
    display: inline;
  }
}

/* ===== TABLET LANDSCAPE (769px-1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  .game-container {
    margin: 30px auto;
    padding: 15px;
    max-width: 85vw;
  }

  .controls-section {
    max-width: 85vw;
  }

  .game-modal {
    margin: 30px;
    padding: 40px 30px;
    max-width: 85vw;
  }

  .startup-modal {
    max-width: 70vw;
  }

  .game-title {
    font-size: 38px;
  }

  .game-subtitle {
    font-size: 18px;
  }

  .section-title {
    font-size: 24px;
  }

  .section-text {
    font-size: 16px;
  }

  .instruction-item {
    font-size: 15px;
  }

  .start-game-button {
    padding: 18px 40px;
    font-size: 18px;
  }

  .level-text {
    font-size: 20px;
  }

  .game-grid {
    gap: 8px;
  }

  .color-palette {
    --ball-size: 55px;
    --ball-gap: 6px;
    gap: var(--ball-gap);
    padding: 12px 20px;
    min-height: 90px;
    max-width: 85vw;
  }

  .color-palette .ball {
    width: var(--ball-size);
    height: var(--ball-size);
  }

  .color-palette .text-center p {
    font-size: 16px;
  }

  .ball-count {
    font-size: 18px;
  }

  .status-display {
    font-size: 18px;
    display: none;
  }

  .modal-title {
    font-size: 28px;
  }

  .modal-text {
    font-size: 16px;
  }

  .modal-button {
    padding: 15px 30px;
    font-size: 16px;
  }

  .game-button {
    padding: 12px 20px;
    font-size: 14px;
    min-width: 120px;
  }

  .button-text {
    display: inline;
  }

  .navigation-buttons {
    top: 20px;
    left: 20px;
    right: 20px;
  }
}

/* ===== DESKTOP (≥1025px) ===== */
@media (min-width: 1025px) {
  /* Keep original desktop styles - no changes needed */
  /* All desktop styles are already defined in the base CSS above */
}

/* ===== UTILITY CLASSES ===== */
.hidden {
  display: none !important;
}

.text-red-600 {
  color: #e53e3e !important;
}

.font-bold {
  font-weight: 700 !important;
}

/* ===== TOUCH-FRIENDLY ENHANCEMENTS ===== */
@media (hover: none) and (pointer: coarse) {
  /* Touch device optimizations */
  .game-button {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
  }

  .color-palette .ball {
    min-width: 44px;
    min-height: 44px;
    width: max(var(--ball-size), 44px);
    height: max(var(--ball-size), 44px);
  }

  .grid-cell {
    min-height: 44px;
    min-width: 44px;
  }

  .modal-button {
    min-height: 44px;
  }

  .start-game-button {
    min-height: 50px;
  }

  /* Remove hover effects on touch devices */
  .game-button:hover {
    transform: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  }

  .color-palette .ball:hover {
    transform: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  }

  .grid-cell:hover {
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }
}

/* ===== HIGH DPI DISPLAY OPTIMIZATIONS ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .game-button {
    border-width: 1px;
  }

  .grid-cell {
    border-width: 1px;
  }

  .game-modal {
    border-width: 1px;
  }

  .game-container {
    border-width: 1px;
  }
}

/* ===== REDUCED MOTION PREFERENCES ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .game-background {
    animation: none;
    background: #101827;
  }

  .game-background::before,
  .game-background::after {
    animation: none;
    display: none;
  }

  .nextCellPulse {
    animation: none;
  }

  .modalIconFloat {
    animation: none;
  }

  .ballGlow {
    animation: none;
  }
}

/* ===== DARK MODE PREFERENCES ===== */
@media (prefers-color-scheme: light) {
  /* Keep the dark theme as it's part of the game's aesthetic */
  /* This media query is here for future light mode implementation if needed */
}

/* ===== PRINT STYLES ===== */
@media print {
  .game-body {
    background: white;
    color: black;
  }

  .game-background {
    display: none;
  }

  .navigation-buttons {
    display: none;
  }

  .game-container {
    box-shadow: none;
    border: 1px solid #000;
  }

  .game-modal {
    box-shadow: none;
    border: 1px solid #000;
  }
}

/* ===== CUSTOM SCROLLBAR ===== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #2d3748;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(145deg, #4a5568, #2d3748);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(145deg, #718096, #4a5568);
}
