* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
  font-family: 'Press Start 2P', cursive;
  color: #e8e8e8;
  overflow: hidden;
  position: relative;
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
}

.game-header h1 {
  font-size: 2rem;
  color: #00d9ff;
  text-shadow: 0 0 20px rgba(0, 217, 255, 0.5);
  margin-bottom: 1rem;
  letter-spacing: 0.3em;
}

.stats {
  display: flex;
  gap: 2rem;
  justify-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.5rem;
  color: #6b7280;
}

.stat span:last-child {
  font-size: 0.75rem;
  color: #00d9ff;
}

.game-main {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.next-piece,
.controls {
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid #00d9ff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 0 15px rgba(0, 217, 255, 0.2);
}

.panel-label {
  font-size: 0.5rem;
  color: #6b7280;
  display: block;
  margin-bottom: 0.5rem;
}

#nextCanvas {
  display: block;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}

.controls ul {
  list-style: none;
  font-size: 0.5rem;
  line-height: 1.8;
  color: #9ca3af;
}

.board-wrapper {
  position: relative;
  border: 4px solid #00d9ff;
  border-radius: 8px;
  box-shadow: 
    0 0 30px rgba(0, 217, 255, 0.3),
    inset 0 0 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  background: #0a0a12;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
}

.overlay-content p {
  font-size: 1rem;
  color: #00d9ff;
  margin-bottom: 1.5rem;
  text-shadow: 0 0 10px rgba(0, 217, 255, 0.5);
}

#start-overlay .overlay-content p {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#restart-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.6rem;
  padding: 1rem 1.5rem;
  background: #00d9ff;
  color: #0f0f1a;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

#restart-btn:hover {
  background: #00a8cc;
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(0, 217, 255, 0.6);
}

#restart-btn:active {
  transform: scale(0.98);
}

/* Leaderboard buttons */
#btn-leaderboard,
#btn-back-leaderboard,
#btn-submit-name {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.6rem;
  padding: 0.8rem 1.2rem;
  background: #00d9ff;
  color: #0f0f1a;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 120px;
  min-height: 44px;
}

#btn-leaderboard:hover,
#btn-back-leaderboard:hover,
#btn-submit-name:hover {
  background: #00a8cc;
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(0, 217, 255, 0.6);
}

#btn-leaderboard:active,
#btn-back-leaderboard:active,
#btn-submit-name:active {
  transform: scale(0.98);
}

/* Mobile pause button */
.game-header {
  position: relative;
}

.pause-mobile-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-family: Arial, sans-serif;
  font-size: 1.2rem;
  padding: 0.4rem 0.6rem;
  background: rgba(0, 0, 0, 0.6);
  color: #00d9ff;
  border: 2px solid rgba(0, 217, 255, 0.5);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  z-index: 1000;
  display: none;
  min-width: 44px;
  min-height: 44px;
}

.pause-mobile-btn:active {
  background: rgba(0, 217, 255, 0.3);
  transform: translateY(-50%) scale(0.95);
}

/* Mobile controls */
.mobile-controls {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  padding: 10px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

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

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

.control-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.7rem;
  padding: 0.6rem 0.8rem;
  background: rgba(0, 217, 255, 0.2);
  color: #00d9ff;
  border: 2px solid #00d9ff;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.1s;
  min-width: 50px;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
  background: rgba(0, 217, 255, 0.5);
  transform: scale(0.95);
  box-shadow: 0 0 10px rgba(0, 217, 255, 0.4);
}

#btn-drop {
  font-size: 0.5rem;
  padding: 0.6rem 1.2rem;
}

/* Responsive design */
@media (max-width: 768px), (max-height: 768px) {
  .pause-mobile-btn {
    display: block;
  }
  
  .mobile-controls {
    display: flex;
  }
  
  .game-container {
    padding: 1rem 0.5rem;
    gap: 1rem;
    width: 100%;
  }
  
  .game-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
  }
  
  .stats {
    gap: 1rem;
  }
  
  .stat-label {
    font-size: 0.4rem;
  }
  
  .stat span:last-child {
    font-size: 0.6rem;
  }
  
  .game-main {
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 400px;
  }
  
  .side-panel {
    flex-direction: row;
    gap: 1rem;
    width: 100%;
    justify-content: space-between;
  }
  
  .next-piece,
  .controls {
    flex: 1;
    padding: 0.75rem;
  }
  
  .panel-label {
    font-size: 0.4rem;
  }
  
  .controls ul {
    font-size: 0.4rem;
  }
  
  .board-wrapper {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
  }
  
  #gameCanvas {
    width: 100%;
    height: auto;
  }
  
  .overlay-content p {
    font-size: 0.8rem;
  }
  
  #restart-btn {
    font-size: 0.5rem;
    padding: 0.8rem 1.2rem;
    min-width: 120px;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .game-header h1 {
    font-size: 1.2rem;
  }
  
  .stats {
    gap: 0.5rem;
  }
  
  .stat-label {
    font-size: 0.35rem;
  }
  
  .stat span:last-child {
    font-size: 0.5rem;
  }
  
  .side-panel {
    flex-direction: column;
  }
  
  .control-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 0.6rem;
  }
}

/* Landscape mobile */
@media (max-height: 600px) and (orientation: landscape) {
  .game-container {
    padding: 0.5rem;
    gap: 0.5rem;
  }
  
  .game-header h1 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
  }
  
  .stats {
    gap: 0.75rem;
  }
  
  .game-main {
    flex-direction: row;
    gap: 0.75rem;
  }
  
  .side-panel {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  #gameCanvas {
    max-height: 400px;
    width: auto;
  }
  
  .mobile-controls {
    bottom: 5px;
    gap: 5px;
    padding: 5px;
  }
  
  .control-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0.4rem 0.6rem;
    font-size: 0.5rem;
  }
}
