/* Global Reset & Typography */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
}

body {
  background-color: #030510;
  color: #e2e8f0;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Starry Parallax Background */
#space-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  overflow: hidden;
}

.stars1, .stars2 {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 200%;
  background-repeat: repeat;
  opacity: 0.8;
}

.stars1 {
  background-image: radial-gradient(1.5px 1.5px at 20px 30px, #fff, rgba(0,0,0,0)),
                    radial-gradient(2px 2px at 40px 70px, #fff, rgba(0,0,0,0)),
                    radial-gradient(1px 1px at 90px 10px, #fff, rgba(0,0,0,0)),
                    radial-gradient(1.5px 1.5px at 150px 120px, #e2e8f0, rgba(0,0,0,0));
  background-size: 200px 200px;
  animation: moveStars 60s linear infinite;
}

.stars2 {
  background-image: radial-gradient(2px 2px at 15px 40px, #00ffff, rgba(0,0,0,0)),
                    radial-gradient(3px 3px at 75px 150px, #ff00ff, rgba(0,0,0,0)),
                    radial-gradient(1px 1px at 120px 90px, #fff, rgba(0,0,0,0));
  background-size: 300px 300px;
  animation: moveStars 120s linear infinite;
  opacity: 0.5;
}

@keyframes moveStars {
  from { transform: translate(0, 0); }
  to { transform: translate(-50%, -50%); }
}

/* Game Wrapper Container */
#game-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: 1000px;
  height: 600px;
  background-color: rgba(5, 7, 20, 0.9);
  border: 2px solid rgba(0, 255, 255, 0.15);
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(0, 255, 255, 0.05), inset 0 0 20px rgba(0, 255, 255, 0.05);
  overflow: hidden;
  z-index: 10;
  transform-origin: center center;
  flex-shrink: 0;
}

/* Canvas styling */
#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Heads Up Display (HUD) */
#hud {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  height: 50px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
  pointer-events: none;
  font-family: 'Share Tech Mono', monospace;
}

.hud-item {
  background: rgba(10, 15, 30, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 255, 255, 0.2);
  border-radius: 6px;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hud-label {
  font-size: 9px;
  color: #00ffff;
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.hud-value {
  font-size: 18px;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

/* HUD Timer Special Styles */
.timer-item {
  width: 250px;
}

.progress-bar-container {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin: 4px 0 2px 0;
  overflow: hidden;
}

.progress-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #39ff14, #00ffff);
  box-shadow: 0 0 8px #00ffff;
  transition: width 0.1s linear, background 0.5s ease;
}

.progress-bar.warning {
  background: linear-gradient(90deg, #ff9900, #ff0055);
  box-shadow: 0 0 8px #ff0055;
}

/* Screen Overlay Layouts */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
  background: rgba(3, 5, 15, 0.6);
  backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity 0.3s ease;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  display: none !important;
}

/* Glassmorphic Panels */
.glass-panel {
  width: 90%;
  max-width: 650px;
  max-height: 90%;
  padding: 40px;
  background: rgba(10, 15, 30, 0.75);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 255, 255, 0.25);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 
              0 0 30px rgba(0, 255, 255, 0.1),
              inset 0 0 15px rgba(255, 255, 255, 0.05);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  animation: zoomIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes zoomIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Typography & Glows */
h1 {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 4px;
  margin-bottom: 20px;
  text-transform: uppercase;
}

.glow-text {
  color: #ffffff;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.6), 
               0 0 20px rgba(0, 255, 255, 0.4), 
               0 0 45px rgba(0, 255, 255, 0.2);
}

.error-glow {
  color: #ff0055;
  text-shadow: 0 0 10px rgba(255, 0, 85, 0.6), 
               0 0 20px rgba(255, 0, 85, 0.4), 
               0 0 45px rgba(255, 0, 85, 0.2);
}

.success-glow {
  color: #39ff14;
  text-shadow: 0 0 10px rgba(57, 255, 20, 0.6), 
               0 0 20px rgba(57, 255, 20, 0.4), 
               0 0 45px rgba(57, 255, 20, 0.2);
}

/* Narrative text boxes */
.narrative-text {
  font-size: 14px;
  line-height: 1.6;
  color: #cbd5e1;
  text-align: left;
  margin-bottom: 30px;
  overflow-y: auto;
  padding-right: 8px;
  flex-grow: 1;
}

.narrative-text p {
  margin-bottom: 16px;
}

.narrative-text p:last-child {
  margin-bottom: 0;
}

/* Custom Scrollbar for narratives */
.narrative-text::-webkit-scrollbar {
  width: 4px;
}
.narrative-text::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}
.narrative-text::-webkit-scrollbar-thumb {
  background: rgba(0, 255, 255, 0.3);
  border-radius: 2px;
}

/* SVG Container */
.alien-svg-container {
  display: flex;
  justify-content: center;
  margin: 15px 0;
}

#alien-svg {
  filter: drop-shadow(0 0 10px rgba(0, 255, 255, 0.3));
  animation: floatAlien 4s ease-in-out infinite;
}

@keyframes floatAlien {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
  100% { transform: translateY(0px); }
}

/* Buttons styling */
.glow-btn {
  display: inline-block;
  padding: 14px 40px;
  background: transparent;
  color: #00ffff;
  border: 1px solid #00ffff;
  border-radius: 6px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  cursor: pointer;
  outline: none;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.1), inset 0 0 5px rgba(0, 255, 255, 0.1);
  transition: all 0.25s ease;
}

.glow-btn:hover {
  background: #00ffff;
  color: #030510;
  box-shadow: 0 0 20px #00ffff;
  transform: translateY(-2px);
}

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

.error-btn {
  color: #ff0055;
  border-color: #ff0055;
  box-shadow: 0 0 10px rgba(255, 0, 85, 0.1);
}
.error-btn:hover {
  background: #ff0055;
  color: #030510;
  box-shadow: 0 0 20px #ff0055;
}

.success-btn {
  color: #39ff14;
  border-color: #39ff14;
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.1);
}
.success-btn:hover {
  background: #39ff14;
  color: #030510;
  box-shadow: 0 0 20px #39ff14;
}

/* Leaderboard Screen Panels */
.leaderboard-panel {
  width: 720px;
  max-height: 550px;
  padding: 30px;
}

/* Score display inside leaderboard */
.submission-box {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(0, 255, 255, 0.2);
  border-radius: 8px;
  padding: 15px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.score-display {
  font-family: 'Share Tech Mono', monospace;
  font-size: 20px;
  color: #cbd5e1;
  letter-spacing: 1px;
}

.neon-number {
  color: #00ffff;
  font-size: 28px;
  font-weight: 800;
  margin-left: 10px;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.6);
}

/* Inputs & Form layout */
.input-group {
  display: flex;
  gap: 10px;
  margin-top: 5px;
}

#initials-input {
  background: rgba(5, 7, 20, 0.8);
  border: 1px solid rgba(0, 255, 255, 0.4);
  border-radius: 4px;
  color: #ffffff;
  padding: 10px 15px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 16px;
  width: 120px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 2px;
  outline: none;
  transition: all 0.3s ease;
}

#initials-input:focus {
  border-color: #00ffff;
  box-shadow: 0 0 12px rgba(0, 255, 255, 0.4);
}

.neon-submit-btn {
  background: rgba(0, 255, 255, 0.1);
  color: #00ffff;
  border: 1px solid #00ffff;
  border-radius: 4px;
  padding: 10px 20px;
  font-family: 'Share Tech Mono', monospace;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}

.neon-submit-btn:hover {
  background: #00ffff;
  color: #030510;
  box-shadow: 0 0 15px #00ffff;
}

.error-msg {
  color: #ff3366;
  font-size: 12px;
  margin-top: 6px;
  text-align: left;
  font-family: 'Share Tech Mono', monospace;
}

.success-msg {
  color: #39ff14;
  font-size: 16px;
  font-weight: 600;
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.4);
}

/* High score Table styling */
.table-container {
  width: 100%;
  flex-grow: 1;
  overflow-y: auto;
  max-height: 230px;
  margin-bottom: 15px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 6px;
}

/* Custom scrollbar for table container */
.table-container::-webkit-scrollbar {
  width: 4px;
}
.table-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}
.table-container::-webkit-scrollbar-thumb {
  background: rgba(0, 255, 255, 0.2);
  border-radius: 2px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Share Tech Mono', monospace;
  font-size: 15px;
}

.leaderboard-table th {
  background-color: rgba(5, 7, 20, 0.9);
  color: #00ffff;
  font-weight: bold;
  letter-spacing: 1px;
  padding: 10px 15px;
  position: sticky;
  top: 0;
  text-align: left;
  border-bottom: 1px solid rgba(0, 255, 255, 0.2);
  font-size: 12px;
}

.leaderboard-table td {
  padding: 8px 15px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.leaderboard-table tr:hover {
  background: rgba(0, 255, 255, 0.03);
}

.leaderboard-table tr.highlighted {
  background: rgba(0, 255, 255, 0.08) !important;
  font-weight: bold;
}

.leaderboard-table tr.highlighted td {
  color: #00ffff;
  border-bottom: 1px solid rgba(0, 255, 255, 0.3);
}

.leaderboard-table tr.highlighted td:nth-child(2) {
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
}

/* Rank special badges */
.rank-badge {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  font-weight: bold;
  font-size: 12px;
}

.rank-1 {
  background: radial-gradient(circle, #ffd700, #b8860b);
  color: #000;
  box-shadow: 0 0 8px #ffd700;
}
.rank-2 {
  background: radial-gradient(circle, #c0c0c0, #708090);
  color: #000;
  box-shadow: 0 0 8px #c0c0c0;
}
.rank-3 {
  background: radial-gradient(circle, #cd7f32, #8b4513);
  color: #000;
  box-shadow: 0 0 8px #cd7f32;
}

.loading-text {
  text-align: center !important;
  color: #64748b;
  padding: 40px 0 !important;
  letter-spacing: 1px;
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 0.8; }
  100% { opacity: 0.4; }
}

/* Restart hint styling */
.restart-hint {
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  color: #64748b;
  letter-spacing: 1px;
  margin-top: 5px;
}

#leaderboard-restart-btn {
  display: none;
}

.key-badge {
  background: #1f2937;
  color: #ffffff;
  border: 1px solid #4b5563;
  border-radius: 4px;
  padding: 2px 6px;
  box-shadow: 0 2px 0 #000;
  font-size: 11px;
  font-weight: bold;
  animation: blinkKey 2s infinite steps(1);
}

@keyframes blinkKey {
  0%, 100% { border-color: #4b5563; box-shadow: 0 2px 0 #000; color: #fff; }
  50% { border-color: #00ffff; box-shadow: 0 2px 0 rgba(0, 255, 255, 0.4); color: #00ffff; }
}

/* Touch and mobile support */
#game-canvas {
  touch-action: none;
}

#mobile-controls {
  position: fixed;
  bottom: 25px;
  right: 25px;
  display: none; /* hidden on non-touch devices by default */
  flex-direction: row;
  gap: 15px;
  z-index: 90;
  pointer-events: auto;
}

.mobile-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(10, 15, 30, 0.65);
  border: 1.5px solid rgba(0, 255, 255, 0.35);
  color: #00ffff;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 15px rgba(0, 255, 255, 0.15), inset 0 0 8px rgba(0, 255, 255, 0.05);
  cursor: pointer;
  touch-action: none;
  transition: all 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
}

.mobile-btn:active, .mobile-btn.active {
  transform: scale(0.92);
  background: rgba(0, 255, 255, 0.2);
  border-color: #00ffff;
  box-shadow: 0 0 25px rgba(0, 255, 255, 0.4), inset 0 0 10px rgba(0, 255, 255, 0.1);
  text-shadow: 0 0 8px #00ffff;
}

#mobile-btn-brake {
  color: #ff9900;
  border-color: rgba(255, 153, 0, 0.35);
  box-shadow: 0 0 15px rgba(255, 153, 0, 0.15), inset 0 0 8px rgba(255, 153, 0, 0.05);
}

#mobile-btn-brake:active, #mobile-btn-brake.active {
  background: rgba(255, 153, 0, 0.2);
  border-color: #ff9900;
  box-shadow: 0 0 25px rgba(255, 153, 0, 0.4), inset 0 0 10px rgba(255, 153, 0, 0.1);
  text-shadow: 0 0 8px #ff9900;
}

/* Show mobile controls on touch devices */
@media (pointer: coarse) {
  #mobile-controls {
    display: flex;
  }
}

/* Orientation Warning styles */
#orientation-warning {
  display: none;
  z-index: 100;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(3, 5, 15, 0.95);
  backdrop-filter: blur(8px);
}

.warning-panel {
  border-color: rgba(255, 0, 85, 0.4) !important;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 
              0 0 30px rgba(255, 0, 85, 0.15) !important;
  max-width: 450px !important;
}

.rotate-icon-container {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#rotate-svg {
  filter: drop-shadow(0 0 10px rgba(255, 0, 85, 0.5));
  animation: rotateDevice 2.5s ease-in-out infinite;
}

@keyframes rotateDevice {
  0% { transform: rotate(0deg); }
  45%, 55% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

/* Portrait Block Query */
body.portrait-mode #orientation-warning {
  display: flex !important;
}
body.portrait-mode #game-container {
  display: none !important;
}
body.portrait-mode #mobile-controls {
  display: none !important;
}

/* Mobile and touch screen layout refinements */
@media (pointer: coarse) or (max-width: 1024px) or (max-height: 1024px) {
  #game-container {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  .glass-panel {
    padding: 24px !important;
    width: 95% !important;
    max-height: 95% !important;
  }

  h1 {
    font-size: 26px !important;
    margin-bottom: 12px !important;
    letter-spacing: 2px !important;
  }

  .narrative-text {
    font-size: 13px !important;
    margin-bottom: 20px !important;
    line-height: 1.5 !important;
  }

  .narrative-text p {
    margin-bottom: 10px !important;
  }

  .glow-btn {
    padding: 10px 30px !important;
    font-size: 14px !important;
    letter-spacing: 1px !important;
  }

  /* Shrink alien SVG slightly for mobile screens */
  .alien-svg-container svg {
    width: 110px !important;
    height: 110px !important;
  }

  /* HUD layout adjustments for touch screens */
  .hud-item {
    min-width: 120px !important;
    padding: 6px 12px !important;
  }

  .hud-label {
    font-size: 8px !important;
  }

  .hud-value {
    font-size: 14px !important;
  }

  .timer-item {
    width: 180px !important;
  }

  #leaderboard-restart-hint {
    display: none !important;
  }

  #leaderboard-restart-btn {
    display: inline-block !important;
    margin-top: 15px !important;
  }
}
