/* Qubris - 3D Tetris Game Styles */

/* General Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent; /* Disable tap highlight on mobile */
}

body {
  font-family: 'Orbitron', 'Rajdhani', sans-serif;
  margin: 0;
  overflow: hidden;
  background-color: #000;
  color: #fff;
  /* Prevent native mobile behaviors */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  /* Prevent double-tap zoom */
  -ms-touch-action: manipulation;
  -ms-user-select: none;
}

canvas {
  display: block;
  /* Prevent native touch behaviors on canvas */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Game UI Container */
.game-ui {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Allow clicking through to the game */
  z-index: 10;
}

/* Info Panel (Controls) */
.info-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  background-color: rgba(0, 0, 0, 0.75);
  border: 2px solid #3fe0ff;
  border-radius: 10px;
  padding: 15px;
  box-shadow: 0 0 20px rgba(63, 224, 255, 0.3);
  max-width: 280px;
  pointer-events: auto; /* Make this clickable */
  transition: opacity 0.3s ease;
}

.info-panel h2 {
  color: #3fe0ff;
  font-size: 24px;
  margin-bottom: 10px;
  letter-spacing: 3px;
  text-shadow: 0 0 8px rgba(63, 224, 255, 0.7);
}

.info-panel p {
  margin: 8px 0;
  font-size: 14px;
  color: #ffffff;
}

.info-panel kbd {
  background-color: #333;
  border-radius: 4px;
  color: #fff;
  padding: 2px 5px;
  font-family: monospace;
  margin: 0 2px;
}

.info-panel .controls-toggle {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  color: #3fe0ff;
  cursor: pointer;
  font-size: 16px;
}

/* Score Display */
.score-display {
  position: absolute;
  top: 20px;
  right: 20px;
  background-color: rgba(0, 0, 0, 0.75);
  border: 2px solid #ff3f3f; /* Red border for score */
  border-radius: 10px;
  padding: 15px 25px;
  text-align: center;
  box-shadow: 0 0 20px rgba(255, 63, 63, 0.3);
  pointer-events: auto;
  width: 120px;
}

.score-display h3 {
  color: #ff3f3f;
  font-size: 16px;
  margin-bottom: 5px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.score-display .score-value {
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 63, 63, 0.7);
}

/* Game Over Screen */
.game-over {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.game-over.active {
  opacity: 1;
  pointer-events: auto;
}

.game-over-content {
  background-color: rgba(20, 20, 30, 0.9);
  border: 3px solid #ff3f8f;
  border-radius: 15px;
  padding: 30px 50px;
  text-align: center;
  max-width: 500px;
  box-shadow: 0 0 30px rgba(255, 63, 143, 0.4);
  transform: translateY(20px);
  animation: float 3s ease-in-out infinite;
}

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

.game-over h2 {
  font-size: 42px;
  color: #ff3f8f;
  margin-bottom: 20px;
  letter-spacing: 4px;
  text-shadow: 0 0 15px rgba(255, 63, 143, 0.7);
  text-transform: uppercase;
}

.game-over p {
  margin: 15px 0;
  font-size: 20px;
  color: #ffffff;
}

.game-over .final-score {
  font-size: 48px;
  color: #ffffff;
  margin: 10px 0 25px;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}

/* Buttons */
.btn {
  background-color: rgba(63, 224, 255, 0.1);
  color: #3fe0ff;
  border: 2px solid #3fe0ff;
  padding: 12px 24px;
  margin: 10px;
  font-size: 16px;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 2px;
  text-transform: uppercase;
  transition: all 0.3s ease;
  outline: none;
  box-shadow: 0 0 10px rgba(63, 224, 255, 0.2);
}

.btn:hover {
  background-color: rgba(63, 224, 255, 0.3);
  box-shadow: 0 0 15px rgba(63, 224, 255, 0.5);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(1px);
}

.btn-restart {
  background-color: rgba(255, 63, 143, 0.1);
  color: #ff3f8f;
  border: 2px solid #ff3f8f;
  box-shadow: 0 0 10px rgba(255, 63, 143, 0.2);
}

.btn-restart:hover {
  background-color: rgba(255, 63, 143, 0.3);
  box-shadow: 0 0 15px rgba(255, 63, 143, 0.5);
}

/* New Mobile UI Styles */
.mobile-ui-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none; /* Pass clicks through */
    display: none; /* Hide by default, shown on mobile */
}

.game-top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 8px 15px;
    box-sizing: border-box;
    pointer-events: auto;
}

/* Removed - no longer needed for mobile layout */

.mobile-pause-btn {
    background: none;
    border: 2px solid #fff;
    color: #fff;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    /* Prevent native touch behaviors */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    /* Improve touch responsiveness */
    transition: background-color 0.1s ease;
}

.mobile-pause-btn:active {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Removed - no longer needed for mobile layout */

/* Swipe area for camera controls */
#swipe-area {
    position: absolute;
    top: 65px; /* Below the top bar */
    left: 0;
    width: 100%;
    height: calc(100% - 65px - 200px); /* Leave space for controls at bottom */
    pointer-events: auto;
    /* Essential for proper touch handling */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile Controls Container */
.mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1001;
    display: none; /* Hidden by default */
    pointer-events: none; /* Allow events to pass through to canvas */
    padding: 15px;
    box-sizing: border-box;
    /* Prevent native touch behaviors */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

/* Style for the D-pad and action buttons container */
.mobile-controls-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    pointer-events: none; /* Allow events to pass through to canvas */
}

/* D-pad container */
#d-pad-container {
    width: 150px;
    height: 150px;
    position: relative;
    display: grid;
    grid-template-areas:
        ". up ."
        "left . right"
        ". down .";
    gap: 5px;
    pointer-events: auto; /* Allow D-pad to receive events */
}

.d-pad-btn {
    background-color: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    font-size: 28px;
    cursor: pointer;
    border-radius: 10px;
    /* Prevent native touch behaviors */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    /* Improve touch responsiveness */
    transition: background-color 0.1s ease;
    pointer-events: auto; /* Allow buttons to receive events */
}
.d-pad-btn:active {
    background-color: rgba(255, 255, 255, 0.4);
}
#d-pad-up { grid-area: up; }
#d-pad-down { grid-area: down; }
#d-pad-left { grid-area: left; }
#d-pad-right { grid-area: right; }

/* Action buttons container */
#action-buttons-container {
    display: grid;
    grid-template-areas:
        "rotate-y"
        "rotate-x"
        "rotate-z"
        "hard-drop";
    gap: 15px;
    pointer-events: auto; /* Allow action buttons to receive events */
}

/* Base style for mobile buttons */
.mobile-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    font-size: 24px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transition: background-color 0.2s, transform 0.1s;
    /* Prevent native touch behaviors */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto; /* Allow buttons to receive events */
}

.mobile-btn:active {
    background-color: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* Individual button styles */
#mobile-rotate-y { grid-area: rotate-y; }
#mobile-rotate-x { grid-area: rotate-x; }
#mobile-rotate-z { grid-area: rotate-z; }
#mobile-hard-drop {
    grid-area: hard-drop;
    font-size: 20px;
    background-color: rgba(255, 50, 50, 0.2);
    border-color: rgba(255, 80, 80, 1);
}

/* Duplicate swipe area definition removed */


/* Animation for score increase */
@keyframes scoreIncrease {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.score-flash {
  animation: scoreIncrease 0.3s ease;
}

/* Combo message styles */
.combo-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  background-color: rgba(20, 20, 30, 0.8);
  border: 3px solid #ff3fff;
  border-radius: 15px;
  padding: 20px 40px;
  text-align: center;
  z-index: 50;
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
  box-shadow: 0 0 30px rgba(255, 63, 255, 0.5);
}

.combo-message.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.combo-text {
  font-size: 32px;
  font-weight: 700;
  color: #ff3fff;
  margin-bottom: 10px;
  letter-spacing: 2px;
  text-shadow: 0 0 15px rgba(255, 63, 255, 0.7);
  text-transform: uppercase;
}

.combo-points {
  font-size: 24px;
  color: #ff3fff;
}

@media (max-width: 768px) {
  .combo-message {
    padding: 15px 30px;
    border-width: 2px;
  }
  .combo-text {
    font-size: 24px;
  }
  .combo-points {
    font-size: 18px;
  }
}

/* Retro grid overlay effect */
.retro-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(circle, rgba(63, 224, 255, 0.1) 1px, transparent 1px);
  background-size: 30px 30px;
  pointer-events: none;
  z-index: 5;
  opacity: 0.3;
}

/* Level indicator */
.level-indicator {
  position: absolute;
  top: 120px;
  right: 20px;
  background-color: rgba(0, 0, 0, 0.75);
  border: 2px solid #3fff3f; /* Green border for level */
  border-radius: 10px;
  padding: 15px 25px;
  text-align: center;
  box-shadow: 0 0 20px rgba(63, 255, 63, 0.3);
  pointer-events: auto;
  width: 120px;
}

.level-indicator h3 {
  color: #3fff3f;
  font-size: 16px;
  margin-bottom: 5px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.level-indicator .level-value {
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(63, 255, 63, 0.7);
}

/* Next Block Preview */
.next-block-container {
  position: absolute;
  top: 220px;
  right: 20px;
  background-color: rgba(0, 0, 0, 0.75);
  border: 2px solid #3f3fff; /* Blue border for next block */
  border-radius: 10px;
  padding: 15px;
  text-align: center;
  box-shadow: 0 0 20px rgba(63, 63, 255, 0.3);
  pointer-events: auto;
  width: 120px;
}

.next-block-container h3 {
  color: #3f3fff;
  font-size: 16px;
  margin-bottom: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.next-block-display {
  background-color: rgba(20, 20, 40, 0.5);
  border-radius: 5px;
  width: 90px;
  height: 90px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
}

.next-block-placeholder {
  color: rgba(255, 255, 255, 0.3);
  font-size: 24px;
}

.next-block-3d-effect {
  filter: drop-shadow(0 0 5px rgba(63, 63, 255, 0.7));
  animation: blockRotate 0.3s ease-in-out;
  transform-origin: center;
}

@keyframes blockRotate {
  0% { transform: perspective(200px) rotateY(0deg); }
  50% { transform: perspective(200px) rotateY(10deg); }
  100% { transform: perspective(200px) rotateY(0deg); }
}

@media (max-width: 768px), (orientation: portrait) {
  .info-panel {
    display: none; /* Hide desktop controls on mobile */
  }

  .score-display, .level-indicator {
    position: static;
    width: auto;
    margin: 0;
    border: none;
    background: none;
    box-shadow: none;
    padding: 0;
    text-align: center;
    min-width: 60px;
  }
  
  .score-display h3, .level-indicator h3 {
    font-size: 12px;
    margin-bottom: 2px;
  }
  
  .score-display .score-value, .level-indicator .level-value {
    font-size: 18px;
  }
  
  .next-block-container {
    position: static;
    width: 60px;
    min-width: 60px;
    padding: 0;
    margin: 0;
    border: none;
    background: none;
    box-shadow: none;
    text-align: center;
  }
  
  .next-block-container h3 {
    font-size: 12px;
    margin-bottom: 2px;
    color: #3f3fff;
  }
  
  .next-block-display {
    width: 50px;
    height: 50px;
    margin: 0 auto;
    background-color: rgba(63, 63, 255, 0.1);
    border: 1px solid rgba(63, 63, 255, 0.3);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
  }
  
  .game-top-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 8px 12px;
    z-index: 1000;
    pointer-events: auto;
    gap: 8px;
    height: 65px;
    box-sizing: border-box;
  }

  .game-over-content {
    padding: 20px;
    width: 90%;
  }
  .game-over h2 {
    font-size: 32px;
  }
  .game-over .final-score {
    font-size: 38px;
  }
}

/* Start Screen Styles */
.start-screen {
  position: fixed; /* Use fixed positioning */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  pointer-events: auto;
  transition: opacity 0.5s ease;
}

.start-screen.fade-out {
  opacity: 0;
}

.start-screen-content {
  text-align: center;
  padding: 40px;
  border: 2px solid #3fe0ff;
  border-radius: 15px;
  background-color: rgba(0, 0, 0, 0.8);
  box-shadow: 0 0 30px rgba(63, 224, 255, 0.5);
  animation: float 3s ease-in-out infinite;
  max-width: 600px;
  width: 80%;
}

.game-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 72px;
  font-weight: 900;
  color: #3fe0ff;
  text-shadow: 0 0 20px rgba(63, 224, 255, 0.7);
  margin-bottom: 10px;
  letter-spacing: 8px;
}

.game-subtitle {
  font-family: 'Rajdhani', sans-serif;
  font-size: 24px;
  color: #fff;
  margin-bottom: 40px;
  letter-spacing: 4px;
}

.button-container {
  margin-top: 30px;
}

.btn-play {
  background: linear-gradient(45deg, #1a6680, #3fe0ff);
  border: 2px solid #3fe0ff;
  color: #fff;
  font-family: 'Orbitron', sans-serif;
  font-size: 28px;
  padding: 15px 50px;
  letter-spacing: 4px;
  box-shadow: 0 0 20px rgba(63, 224, 255, 0.5);
  transition: all 0.3s ease;
}

.btn-play:hover {
  background: linear-gradient(45deg, #3fe0ff, #1a6680);
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(63, 224, 255, 0.8);
}

.btn-play:active {
  transform: scale(0.98);
}

/* Player Name Input on Start Screen */
.player-name-container {
  margin-bottom: 25px;
}

.player-name-container label {
  color: #fff;
  margin-right: 10px;
  font-size: 16px;
}

.player-name-input {
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid #3fe0ff;
  border-radius: 5px;
  color: #fff;
  padding: 8px 12px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 16px;
  width: 200px;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.player-name-input:focus {
  border-color: #fff;
  box-shadow: 0 0 10px rgba(63, 224, 255, 0.5);
}

/* Leaderboard Styles */
.leaderboard-overlay {
  /* Uses .game-over styles for base */
  z-index: 110; /* Ensure it's above the game over screen (z-index: 100) */
  /* Specific overrides if needed */
}

.leaderboard-content {
  /* Uses .game-over-content styles for base */
  border-color: #3fff3f; /* Green border for leaderboard */
  box-shadow: 0 0 30px rgba(63, 255, 63, 0.4);
  max-height: 80vh; /* Limit height */
  display: flex;
  flex-direction: column;
}

.leaderboard-content h2 {
  color: #3fff3f; /* Green title */
  text-shadow: 0 0 15px rgba(63, 255, 63, 0.7);
}

.leaderboard-list-container {
  flex-grow: 1; /* Allow list to take available space */
  overflow-y: auto; /* Enable scrolling for long lists */
  margin: 20px 0;
  padding-right: 10px; /* Space for scrollbar */
  /* Custom scrollbar styling (optional) */
  scrollbar-width: thin;
  scrollbar-color: #3fff3f rgba(0, 0, 0, 0.5);
}

/* Webkit scrollbar styling */
.leaderboard-list-container::-webkit-scrollbar {
  width: 8px;
}
.leaderboard-list-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}
.leaderboard-list-container::-webkit-scrollbar-thumb {
  background-color: #3fff3f;
  border-radius: 4px;
  border: 2px solid rgba(0, 0, 0, 0.5);
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 5px;
  border-bottom: 1px solid rgba(63, 255, 63, 0.2);
  font-size: 16px;
}

.leaderboard-list li:last-child {
  border-bottom: none;
}

.leaderboard-list .rank {
  color: #3fff3f;
  font-weight: bold;
  min-width: 30px;
  text-align: right;
  margin-right: 15px;
}

.leaderboard-list .name {
  flex-grow: 1;
  text-align: left;
  margin-right: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list .score {
  font-weight: 700;
  color: #ffcc00;
}


/* Media query for smaller screens */
@media (max-width: 768px) {
  .game-title {
    font-size: 48px;
    letter-spacing: 4px;
  }
  
  .game-subtitle {
    font-size: 18px;
  }
  
  .btn-play {
    font-size: 22px;
    padding: 12px 40px;
  }
  
  .start-screen-content {
    padding: 20px;
    width: 90%;
  }
}