* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

body {
  background-color: #121113;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#game-container {
  width: 100%;
  max-width: 600px;
  padding: 0 16px;
  display: flex;
  justify-content: center;
  position: relative;
}

#game-container canvas {
  width: 100%;
  aspect-ratio: 4 / 1;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#score-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 17, 19, 0.88);
  z-index: 10;
}

#score-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: #1a1a1b;
  border: 2px solid #3a3a3b;
  border-radius: 4px;
  padding: 32px;
  font-family: 'PressStart2P', monospace;
  color: #e8e8e8;
  text-align: center;
  min-width: 400px;
  max-width: 90vw;
}

@media (max-width: 500px) {
  #score-modal {
    min-width: auto;
    width: 90vw;
  }
}

/* Ensure modal is visible above mobile keyboard */
@media (max-height: 600px) {
  #score-modal {
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    gap: 12px;
  }
}

#score-modal h2 {
  font-size: 14px;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

#final-score-display {
  font-size: 12px;
  color: #a8a8a8;
}

#submit-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#player-initials {
  width: 100px;
  padding: 12px 8px;
  font-family: 'PressStart2P', monospace;
  font-size: 16px;
  background: #121113;
  border: 2px solid #3a3a3b;
  border-radius: 2px;
  color: #e8e8e8;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 4px;
  outline: none;
}

#player-initials:focus {
  border-color: #5a5a5b;
}

#player-initials::placeholder {
  color: #5a5a5b;
  letter-spacing: 4px;
}

#submit-btn,
#action-btn {
  width: 100%;
  max-width: 200px;
  padding: 12px 16px;
  font-family: 'PressStart2P', monospace;
  font-size: 10px;
  background: #2a2a2b;
  border: 2px solid #4a4a4b;
  border-radius: 2px;
  color: #e8e8e8;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#submit-btn:hover:not(:disabled),
#action-btn:hover {
  background: #3a3a3b;
  border-color: #5a5a5b;
}

#submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}

.leaderboard-table th {
  padding: 8px 4px;
  border-bottom: 1px solid #3a3a3b;
  color: #a8a8a8;
}

.leaderboard-table td {
  padding: 8px 4px;
}

.leaderboard-table tbody tr:hover {
  background: #252526;
}

.leaderboard-table tbody tr.highlight {
  background: #2a3a2a;
  color: #7fc97f;
}

.loading,
.empty,
.error {
  font-size: 10px;
  color: #a8a8a8;
  padding: 20px;
}

.error {
  color: #e85a5a;
}

#cheatsheet {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  padding: 12px 16px;
  font-family: 'PressStart2P', monospace;
  font-size: 8px;
  color: #4a4a4b;
  letter-spacing: 0.5px;
  padding-top: 24px;
  opacity: 1;
  transition: opacity 0.6s ease;
}

#cheatsheet.hidden {
  opacity: 0;
}

#touch-zones {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  top: 60%;
  gap: 1px;
  opacity: 1;
  transition: opacity 0.6s ease;
}

#touch-zones.hidden {
  opacity: 0;
}

#touch-zones > div {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #3a3a3b;
  border-radius: 4px;
  font-family: 'PressStart2P', monospace;
  font-size: 10px;
  color: #4a4a4b;
  user-select: none;
  -webkit-user-select: none;
}

@media (pointer: coarse) {
  #cheatsheet {
    display: none;
  }

  #touch-zones {
    display: flex;
  }
}
