* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: linear-gradient(135deg, #080312 0%, #0d0520 50%, #080312 100%);
  background-attachment: fixed;
  color: #0ff;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  text-align: center;
  margin: 0;
  padding: 20px;
  overflow-x: hidden;
  min-height: 100vh;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 80%, rgba(0, 255, 255, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 0, 255, 0.03) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

body > * {
  position: relative;
  z-index: 1;
}

h1 {
  font-size: 2.5rem;
  text-shadow: 0 0 5px #0ff, 0 0 10px #0ff, 0 0 20px #0ff, 0 0 40px #0ff;
  margin-bottom: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  animation: glow-pulse 2s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { 
    text-shadow: 0 0 5px #0ff, 0 0 10px #0ff, 0 0 20px #0ff, 0 0 40px #0ff;
  }
  50% { 
    text-shadow: 0 0 10px #0ff, 0 0 20px #0ff, 0 0 30px #0ff, 0 0 60px #0ff;
  }
}

.score {
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: #fff;
  font-family: 'Courier New', monospace;
}

#gameWrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  margin: 0 auto;
  max-width: 800px;
  flex-wrap: wrap;
}

#tetris {
  order: 2;
  border: 3px solid #0ff;
  box-shadow: 
    0 0 15px #0ff,
    0 0 30px rgba(0, 255, 255, 0.5),
    inset 0 0 20px rgba(0, 255, 255, 0.1);
  border-radius: 5px;
  position: relative;
  background: rgba(0, 0, 0, 0.5);
}

#gameCanvas {
  display: block;
  width: 240px;
  height: 400px;
}

#sidePanel {
  order: 3;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 160px;
  margin-left: 20px;
}

#highScoreWrapper {
  order: 1;
  text-align: center;
  margin-right: 20px;
  width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#highScoreWrapper p {
  margin: 0 0 5px 0;
  color: #ff0;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.8rem;
  text-shadow: 0 0 3px #ff0;
}

.high-score-display {
  background-color: #000;
  border: 2px solid #ff0;
  border-radius: 5px;
  padding: 10px;
  font-family: 'Press Start 2P', cursive;
  font-size: 1.2rem;
  color: #ff0;
  text-shadow: 0 0 5px #ff0, 0 0 10px #ff0;
  box-shadow: 
    0 0 10px rgba(255, 255, 0, 0.5),
    inset 0 0 10px rgba(255, 255, 0, 0.1);
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#nextWrapper {
  text-align: center;
  width: 160px;
}

#nextWrapper p {
  margin: 0 0 10px 0;
  color: #fff;
  font-weight: bold;
}

#nextCanvas {
  width: 120px;
  height: 120px;
  margin: 0 auto;
  background-color: #000;
  border: 2px solid #0ff;
  border-radius: 5px;
  box-shadow: 
    0 0 10px rgba(0, 255, 255, 0.5),
    inset 0 0 15px rgba(0, 255, 255, 0.1);
}

.controls-info {
  margin-top: 20px;
  padding: 15px;
  background: rgba(0,0,0,0.5);
  border: 1px solid #0ff;
  border-radius: 5px;
}

.controls-info h3 {
  margin: 0 0 10px 0;
  color: #ff0;
  font-size: 1rem;
}

.controls-info ul {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
  font-size: 0.9rem;
}

.controls-info li {
  margin: 5px 0;
  color: #fff;
}

canvas {
  display: block;
  background-color: #000;
  filter: drop-shadow(0 0 5px rgba(0, 255, 255, 0.5));
}

.ghost-piece {
  opacity: 0.3;
}

.controls {
  margin: 20px 0;
}

#highScoreWrapper .controls {
  margin: 20px 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

#highScoreWrapper .controls button {
  width: 100%;
  margin: 0;
  padding: 8px 0;
  font-size: 0.8rem;
}

button {
  padding: 10px 25px;
  margin: 0 10px;
  background: #0ff;
  color: #000;
  border: none;
  border-radius: 5px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  text-transform: uppercase;
  font-size: 0.9rem;
  letter-spacing: 1px;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
  position: relative;
  overflow: hidden;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

button span {
  position: relative;
  z-index: 2;
}

button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
  z-index: 0;
}

button:hover::before {
  width: 300px;
  height: 300px;
}

button:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.8), 0 0 30px rgba(0, 255, 255, 0.4);
}

#pauseBtn {
  background: #ff0;
}

.play-again-btn {
  background: #f0f;
  margin-top: 20px;
}

.controls-hint {
  color: #0ff;
  margin: 15px 0;
  font-size: 0.9rem;
  text-shadow: 0 0 3px #0ff;
}

#overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(3px);
  z-index: 10;
}

#startScreen, #gameOverScreen, #pauseScreen {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 11;
  text-align: center;
}

#startScreen, #gameOverScreen {
  background: rgba(0,0,0,0.95);
  border: 3px solid #0ff;
  padding: 30px;
  border-radius: 10px;
  max-width: 300px;
  box-shadow: 
    0 0 30px rgba(0, 255, 255, 0.5),
    inset 0 0 20px rgba(0, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

#gameOverScreen {
  border-color: #f0f;
  box-shadow: 
    0 0 30px rgba(255, 0, 255, 0.5),
    inset 0 0 20px rgba(255, 0, 255, 0.1);
}

#pauseScreen {
  background: rgba(0,0,0,0.7);
  border: none;
  width: 100%;
  height: 100%;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

#pauseScreen.hidden {
  display: none;
}


.pause-content {
  background: rgba(0,0,0,0.9);
  border: 3px solid #ff0;
  padding: 20px;
  border-radius: 10px;
  max-width: 300px;
}

.pause-content .mobile-controls {
  display: none;
}

.pause-content .desktop-controls {
  display: block;
}

.skull {
  font-size: 3rem;
  margin-bottom: 10px;
  animation: pulse 1.5s infinite;
}

.credits {
  margin-top: 20px;
  font-size: 0.8rem;
  color: #aaa;
}

.credits .desktop-controls {
  display: block;
}

.credits .mobile-controls {
  display: none;
}

.copyright {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid rgba(0, 255, 255, 0.3);
  font-size: 0.75rem;
  color: #0ff;
}

.copyright p {
  margin: 5px 0;
}

.copyright strong {
  color: #ff0;
  text-shadow: 0 0 5px #ff0;
  font-size: 1.1em;
}

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

@keyframes flash {
  0% { opacity: 0.8; }
  100% { opacity: 0; }
}

.flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: white;
  pointer-events: none;
  animation: flash 0.3s ease-out;
}

.hidden {
  display: none;
}


/* Touch Controls for Mobile */
.touch-controls {
  display: none;
  margin: 15px auto 10px;
  max-width: fit-content;
  padding: 15px;
  background: rgba(0, 0, 0, 0.7);
  border: 2px solid #0ff;
  border-radius: 15px;
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.3);
}

.controls-layout {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin: 0 auto;
  padding: 0;
}

.dpad-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dpad-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.dpad-spacer {
  width: 60px;
  height: 60px;
}

.action-section {
  display: flex;
  align-items: center;
}

.control-btn {
  width: 60px;
  height: 60px;
  font-size: 1.4rem;
  background: rgba(0, 255, 255, 0.2);
  border: 2px solid #0ff;
  color: #0ff;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.1s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-btn {
  background: rgba(0, 255, 255, 0.15);
  box-shadow: 0 2px 8px rgba(0, 255, 255, 0.2);
}

.control-btn:active {
  background: rgba(0, 255, 255, 0.6);
  transform: scale(0.92);
  box-shadow: 0 0 20px #0ff;
}

.action-btn {
  width: 80px;
  height: 80px;
  background: rgba(255, 0, 255, 0.2);
  border-color: #f0f;
  color: #f0f;
  font-size: 0.9rem;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(255, 0, 255, 0.3);
  font-weight: bold;
  letter-spacing: 1px;
}

.action-btn:active {
  background: rgba(255, 0, 255, 0.6);
  box-shadow: 0 0 25px #f0f;
}

.control-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.hard-drop-btn {
  background: rgba(255, 0, 255, 0.2);
  border-color: #f0f;
  color: #f0f;
}

.hard-drop-btn:active {
  background: rgba(255, 0, 255, 0.5);
  box-shadow: 0 0 15px #f0f;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
  /* Optimize animations for mobile performance */
  * {
    animation-duration: 1s !important;
  }
  
  h1 {
    animation: glow-pulse-mobile 2s ease-in-out infinite;
  }
  
  @keyframes glow-pulse-mobile {
    0%, 100% { 
      text-shadow: 0 0 5px #0ff, 0 0 10px #0ff, 0 0 20px #0ff;
    }
    50% { 
      text-shadow: 0 0 10px #0ff, 0 0 20px #0ff, 0 0 30px #0ff;
    }
  }
  
  body {
    padding: 5px 10px;
  }

  h1 {
    font-size: 1.5rem;
    margin-bottom: 5px;
  }

  .score {
    font-size: 0.9rem;
    margin-bottom: 8px;
  }

  #gameWrapper {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 100%;
  }

  #highScoreWrapper {
    order: 1;
    width: 100%;
    max-width: 300px;
    margin: 0 auto 5px;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  #highScoreWrapper p {
    font-size: 0.65rem;
    margin-bottom: 3px;
  }

  .high-score-display {
    min-height: 35px;
    padding: 6px;
    font-size: 0.9rem;
  }

  #highScoreWrapper .controls {
    display: flex;
    flex-direction: row;
    gap: 6px;
    margin: 0;
    width: auto;
  }

  #highScoreWrapper .controls button {
    padding: 6px 10px;
    font-size: 0.65rem;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  #tetris {
    order: 2;
    margin: 0 auto;
    /* Simplify shadow for mobile performance */
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.6);
  }

  #gameCanvas {
    width: 100%;
    max-width: 240px;
    height: auto;
    aspect-ratio: 3 / 5;
  }

  #sidePanel {
    order: 3;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
  }

  #nextWrapper {
    width: 100%;
    margin-bottom: 0;
  }

  #nextWrapper p {
    margin-bottom: 5px;
    font-size: 0.85rem;
  }

  #nextCanvas {
    width: 80px;
    height: 80px;
    /* Simplify shadow for mobile performance */
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.4);
  }

  .controls-info {
    display: none;
  }

  .touch-controls {
    display: flex;
    order: 4;
    position: sticky;
    bottom: 0;
    margin: 10px auto 0;
    padding: 12px;
    border-radius: 15px 15px 0 0;
    border-bottom: none;
    background: rgba(0, 0, 0, 0.95);
    z-index: 100;
    max-width: fit-content;
    /* Simplify shadow for mobile */
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
  }

  #startScreen, #gameOverScreen {
    max-width: 90%;
    padding: 20px;
    /* Simplify effects for mobile */
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.4);
    backdrop-filter: blur(5px);
  }
  
  #gameOverScreen {
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.4);
  }

  #startScreen h2, #gameOverScreen h2 {
    font-size: 1.5rem;
  }

  .skull {
    font-size: 2.5rem;
  }

  .credits .desktop-controls {
    display: none;
  }

  .credits .mobile-controls {
    display: block;
  }

  .pause-content .desktop-controls {
    display: none;
  }

  .pause-content .mobile-controls {
    display: block;
    margin-top: 15px;
  }

  button {
    padding: 10px 20px;
    font-size: 0.85rem;
  }
  
  /* Disable hover effects on mobile for better performance */
  button:hover {
    transform: none;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
  }
  
  button:hover::before {
    width: 0;
    height: 0;
  }
}

@media (max-width: 480px) {
  body {
    padding: 3px 8px;
  }

  h1 {
    font-size: 1.3rem;
    margin-bottom: 3px;
  }

  .score {
    font-size: 0.85rem;
    margin-bottom: 5px;
  }

  #gameCanvas {
    max-width: 220px;
  }

  #nextCanvas {
    width: 70px;
    height: 70px;
  }

  .dpad-spacer {
    width: 55px;
    height: 55px;
  }

  .control-btn {
    width: 55px;
    height: 55px;
    font-size: 1.2rem;
  }

  .action-btn {
    width: 70px;
    height: 70px;
    font-size: 0.8rem;
  }

  .controls-layout {
    gap: 15px;
    padding: 0;
  }

  #startScreen, #gameOverScreen {
    padding: 15px;
  }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
  #gameWrapper {
    max-width: 90%;
  }

  #highScoreWrapper {
    width: 140px;
  }

  #sidePanel {
    width: 140px;
  }
}
