/* Base styles */
body {
  margin: 0;
  overflow: hidden;
  font-family: 'Roboto', sans-serif;
  background: linear-gradient(135deg,
      #0c0921 0%,
      #292552 50%,
      #24243e 100%);
  background-size: 400% 400%;
  background-attachment: fixed;
  color: #e6e6e6;
  animation: gradientShift 30s ease infinite;
  position: relative;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  transform: translateZ(0);
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

/* Static stars in the background */
body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(1px 1px at 25% 15%, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(1px 1px at 50% 50%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(2px 2px at 75% 25%, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(2px 2px at 20% 60%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1px 1px at 40% 80%, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(1px 1px at 90% 35%, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(2px 2px at 5% 70%, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(1px 1px at 60% 95%, rgba(255, 255, 255, 0.8), transparent);
  background-size: 200% 200%;
  pointer-events: none;
  z-index: -2;
  animation: twinkling 20s ease-in-out infinite alternate;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  transform: translateZ(0);
}

@keyframes twinkling {
  0% {
    background-position: 0% 0%;
    opacity: 0.7;
  }

  50% {
    opacity: 0.9;
  }

  100% {
    background-position: 100% 100%;
    opacity: 0.7;
  }
}

#gameContainer {
  position: relative;
  width: 100%;
  height: calc(var(--vh, 1vh) * 100);
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: radial-gradient(circle at center,
      rgba(100, 100, 255, 0.03) 0%,
      rgba(0, 0, 0, 0) 70%);
  /* Add subtle floating effect */
  animation: subtleFloat 15s ease-in-out infinite alternate;
}

/* Add subtle floating animation for depth */
@keyframes subtleFloat {
  0% {
    background-position: center;
    transform: translateY(0px);
  }

  50% {
    transform: translateY(-5px);
  }

  100% {
    background-position: center 10%;
    transform: translateY(0px);
  }
}

/* Cosmic dust/nebula effect */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: -1;
  opacity: 0.3;
  filter: hue-rotate(240deg) brightness(0.8);
  animation: noisePan 30s linear infinite;
  -webkit-backface-visibility: hidden;
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  transform: translateZ(0);
}

/* Add missing noisePan animation */
@keyframes noisePan {
  0% {
    background-position: 0% 0%;
  }

  100% {
    background-position: 100% 100%;
  }
}

/* Fix for iOS background rendering */
@media only screen and (max-width: 844px) {
  body {
    background-attachment: scroll;
  }

  body::before, body::after {
    -webkit-backface-visibility: hidden;
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    transform: translateZ(0);
  }

  /* Fallback for iOS devices */
  @supports (-webkit-touch-callout: none) {
    body {
      /* Simpler gradient background for iOS */
      background: linear-gradient(135deg, #0c0921, #292552);
      background-attachment: scroll;
    }

    /* Simpler stars for iOS */
    body::after {
      background-image:
        radial-gradient(1px 1px at 25% 15%, rgba(255, 255, 255, 0.9), transparent),
        radial-gradient(1px 1px at 50% 50%, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(2px 2px at 75% 25%, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(1px 1px at 20% 60%, rgba(255, 255, 255, 0.7), transparent);
      background-size: 100% 100%;
      animation: none;
      opacity: 0.8;
    }

    /* Simpler noise for iOS */
    body::before {
      opacity: 0.2;
      animation: none;
    }
  }
}

/* Header styles */
#gameHeader {
  background: rgba(16, 16, 36, 0.8);
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  z-index: 100;
}

#gameHeader h1 {
  font-family: 'Orbitron', sans-serif;
  font-size: 28px;
  margin: 0 0 10px 0;
  color: #4ecca3;
  text-shadow: 0 0 10px rgba(78, 204, 163, 0.5);
}

/* Camera presets */
#cameraPresets {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 5px;
}

#cameraPresets::before {
  content: "Views:";
  color: #4ecca3;
  font-weight: bold;
  margin-right: 10px;
}

#cameraPresets button {
  background: #232350;
  border: 1px solid #4ecca3;
  color: #e6e6e6;
  padding: 8px 15px;
  border-radius: 4px;
  font-size: 14px;
  transition: all 0.2s ease;
  cursor: pointer;
}

#cameraPresets button:hover {
  background: #2d2d6b;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Game stats panel */
#gameStats {
  position: absolute;
  top: 120px;
  right: 20px;
  background: rgba(16, 16, 36, 0.8);
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
  border-left: 3px solid #4ecca3;
}

#score-container {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(78, 204, 163, 0.3);
}

#score-x, #score-o {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  padding: 8px 0;
  border-radius: 4px;
  transition: all 0.3s ease;
}

#score-x {
  background: rgba(255, 0, 0, 0.15);
  color: #ff6b6b;
}

#score-o {
  background: rgba(0, 0, 255, 0.15);
  color: #6b9fff;
}

#turn, #remaining {
  font-size: 16px;
  padding: 5px 0;
}

#turn {
  font-weight: bold;
  color: #4ecca3;
}

#soundToggle {
  margin-top: 5px;
  display: flex;
  align-items: center;
}

#soundToggle label {
  display: flex;
  align-items: center;
  cursor: pointer;
}

#soundToggle input {
  margin-right: 8px;
  cursor: pointer;
}

#aiControls {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 10px;
}

#aiControls label {
  display: flex;
  align-items: center;
}

#aiControls input,
#aiControls select {
  margin-right: 5px;
  cursor: pointer;
}

/* Instructions panel */
#gameInstructions {
  position: absolute;
  top: 120px;
  left: 20px;
  background: rgba(16, 16, 36, 0.8);
  padding: 15px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  max-width: 350px;
  z-index: 10;
  border-left: 3px solid #4ecca3;
  display: flex;
  flex-direction: column;
}

.instructions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  min-height: 30px;
}

#gameInstructions h2 {
  font-family: 'Orbitron', sans-serif;
  font-size: 18px;
  margin: 0;
  color: #4ecca3;
}

#toggleInstructions {
  background: none;
  border: none;
  color: #4ecca3;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  transition: background-color 0.2s ease;
}

#toggleInstructions:hover {
  background-color: rgba(78, 204, 163, 0.2);
}

.toggle-icon {
  transition: transform 0.3s ease;
}

.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

#instructionsContent {
  transition: max-height 0.3s ease, opacity 0.3s ease;
  max-height: 500px;
  opacity: 1;
  overflow: hidden;
}

.collapsed #instructionsContent {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

.instruction-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.instruction-icon {
  font-size: 18px;
  margin-right: 12px;
  min-width: 24px;
  text-align: center;
}

.instruction-text {
  font-size: 15px;
  line-height: 1.4;
}

.reset-zoom {
  margin-top: 15px;
  text-align: center;
}

#resetZoomButton {
  background: #232350;
  border: 1px solid #4ecca3;
  color: #e6e6e6;
  padding: 8px 15px;
  border-radius: 4px;
  font-size: 14px;
  transition: all 0.2s ease;
  cursor: pointer;
}

#resetZoomButton:hover {
  background: #2d2d6b;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Game over modal */
.hidden {
  display: none;
}

#gameOver {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(16, 16, 36, 0.95);
  color: white;
  padding: 30px;
  border-radius: 10px;
  text-align: center;
  font-size: 24px;
  z-index: 999;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 2px solid #4ecca3;
  min-width: 300px;
}

#winner {
  font-family: 'Orbitron', sans-serif;
  font-size: 28px;
  margin-bottom: 20px;
  color: #4ecca3;
}

#resetButton {
  background: #4ecca3;
  border: none;
  color: #1a1a2e;
  padding: 12px 25px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 10px 2px;
  cursor: pointer;
  border-radius: 5px;
  font-weight: bold;
  transition: all 0.2s ease;
}

#resetButton:hover {
  background: #3db893;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Animation for the pulse effect */
@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.pulse {
  animation: pulse 1.5s infinite;
}

/* Hover effect for cubes */
.cube-hover {
  opacity: 0.8 !important;
  filter: brightness(1.2);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  #gameHeader h1 {
    font-size: 22px;
    margin-bottom: 8px;
  }

  #gameStats {
    top: 110px;
    right: 10px;
    padding: 10px;
  }

  #score-container {
    gap: 5px;
  }

  #score-x, #score-o {
    font-size: 16px;
    padding: 6px 0;
  }

  #gameInstructions {
    position: absolute;
    top: 110px;
    left: 10px;
    max-width: 200px;
    padding: 10px 15px;
  }

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

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

@media (max-width: 380px) {
  #gameHeader {
    padding: 10px;
  }

  #gameHeader h1 {
    margin-bottom: 8px;
  }

  #cameraPresets {
    width: 100%;
    justify-content: center;
  }

  #gameContainer {
    padding-top: 1rem;
  }

  #gameStats {
    top: 140px;
    right: 10px;
    bottom: auto;
    max-width: 150px;
    font-size: 14px;
    padding: 8px 12px;
    z-index: 20;
  }

  #score-container {
    gap: 3px;
  }

  #score-x, #score-o {
    font-size: 14px;
    padding: 5px 0;
  }

  #turn, #remaining {
    font-size: 14px;
    padding: 3px 0;
  }

  #gameInstructions {
    top: 140px;
    left: 10px;
    max-width: 150px;
    padding: 8px 12px;
    z-index: 20;
    min-height: 40px;
    max-height: 60vh;
    overflow-y: auto;
  }

  #gameInstructions h2 {
    font-size: 18px;
  }

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

  .instruction-text {
    font-size: 12px;
  }

  .collapsed #gameInstructions {
    max-width: 150px;
    min-height: 40px;
  }

  #cameraPresets button {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 15px;
  }

  #resetZoomButton {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 15px;
  }

  #toggleInstructions {
    width: 44px;
    height: 44px;
  }

  .toggle-icon {
    font-size: 20px;
  }
}

@media (max-width: 320px) {
  #gameStats {
    top: 80px;
    right: 10px;
    bottom: auto;
    max-width: 120px;
    padding: 6px 10px;
  }

  #gameInstructions {
    max-width: 150px;
    padding: 6px 10px;
    min-height: 40px;
  }

  .collapsed #gameInstructions {
    max-width: 120px;
    min-height: 40px;
  }
}

@media (min-width: 381px) and (max-width: 420px) {
  #gameHeader {
    flex-direction: column;
    padding: 10px 15px;
  }

  #gameHeader h1 {
    font-size: 20px;
    margin-bottom: 8px;
  }

  #cameraPresets {
    gap: 5px;
  }

  #cameraPresets::before {
    content: "Views:";
    margin-right: 8px;
    color: #4ecca3;
    font-weight: bold;
  }

  #cameraPresets button {
    padding: 6px 10px;
    font-size: 12px;
  }

  #gameStats {
    top: 130px;
    right: 10px;
    max-width: 140px;
  }

  #gameContainer {
    padding-top: 1rem;
  }

  #gameInstructions {
    top: 130px;
    left: 10px;
    max-width: 150px;
    min-height: 40px;
    max-height: 60vh;
    overflow-y: auto;
  }
}

/* Score change animation */
@keyframes scoreChange {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.15);
  }

  100% {
    transform: scale(1);
  }
}

.score-changed {
  animation: scoreChange 0.5s ease;
}

/* Tutorial overlay */
#tutorialOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  color: #fff;
  text-align: center;
  padding: 20px;
  pointer-events: auto;
}

#tutorialBox {
  background: #222;
  padding: 20px;
  border-radius: 8px;
  max-width: 400px;
  width: 100%;
  pointer-events: auto;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

#tutorialBtns {
  margin-top: 15px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

#tutorialBtns button {
  background: #4ecca3;
  border: none;
  color: #1a1a2e;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  font-size: 1rem;
  transition: background 0.2s, color 0.2s, transform 0.1s;
}

#tutorialBtns button:hover, #tutorialBtns button:focus {
  background: #3bbf9b;
  color: #fff;
  outline: none;
  transform: translateY(-2px) scale(1.05);
}

@media (max-width: 600px) {
  #tutorialBox {
    max-width: 95vw;
    padding: 10px;
  }
  #tutorialBtns button {
    padding: 10px 10px;
    font-size: 0.95rem;
  }
}

#tutorialOverlay.hidden {
  display: none !important;
}