:root {
  --bg-color: #050510;
  --text-color: #dcdcdc;
  --accent-color: #c0392b;
  --hud-bg: rgba(0, 0, 0, 0.8);
  --border-color: #4a4a5a;
  --log-color: #a0a0b0;
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: 'Press Start 2P', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

#game-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
}

#hud-top {
  display: flex;
  justify-content: space-between;
  background-color: var(--hud-bg);
  padding: 10px 15px;
  border: 2px solid var(--border-color);
  border-radius: 4px;
  gap: 15px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat .label {
  color: #888;
  font-size: 10px;
}

#val-hp { color: #e74c3c; }
#val-lvl { color: #3498db; }
#val-floor { color: #f1c40f; }
#val-score { color: #2ecc71; }
#val-keys { color: #9b59b6; }
#val-xp, #val-xp-next { font-size: 10px; color: #888; }

#canvas-container {
  position: relative;
  border: 4px solid var(--border-color);
  border-radius: 4px;
  background-color: #000;
  overflow: hidden;
}

canvas {
  display: block;
  image-rendering: pixelated; /* Essential for crisp pixel art */
  width: 640px;
  height: 480px;
  max-width: 100vw;
  /* aspect-ratio scaling handled implicitly by rigid bounds or JS */
}

/* Message Log Overlay */
#message-log {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
  padding: 10px 15px;
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
  pointer-events: none;
}

#log-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-msg {
  font-size: 10px;
  color: var(--log-color);
  text-shadow: 1px 1px 0 #000;
  animation: fadeOut 5s forwards;
  opacity: 1;
}
.log-msg.combat { color: #e74c3c; }
.log-msg.item { color: #2ecc71; }
.log-msg.level { color: #f1c40f; }
.log-msg.descend { color: #9b59b6; }

@keyframes fadeOut {
  0% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* Game Over Overlay */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
  backdrop-filter: blur(2px);
  gap: 15px;
}

.overlay.hidden {
  display: none !important;
}

.overlay h1 {
  color: var(--accent-color);
  font-size: 32px;
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 20px;
}

/* High Score System */
#high-score-form-container {
  margin: 15px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#high-score-form-container input {
  font-family: 'Press Start 2P', monospace;
  padding: 10px;
  background: #111;
  border: 2px solid var(--border-color);
  color: #fff;
  text-align: center;
  font-size: 12px;
  outline: none;
}

#high-score-form-container input:focus {
  border-color: #f1c40f;
}

.leaderboard-container {
  background: rgba(20, 20, 30, 0.9);
  border: 2px solid var(--border-color);
  padding: 15px;
  border-radius: 4px;
  width: 80%;
  max-width: 400px;
}

.leaderboard-container h3 {
  text-align: center;
  font-size: 14px;
  color: #f1c40f;
  margin-bottom: 15px;
}

#leaderboard-list {
  list-style: none;
  font-size: 10px;
  max-height: 120px;
  overflow-y: auto;
}

.lb-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px dashed #333;
}
.lb-item.is-me {
  color: #2ecc71;
}
.lb-item .lb-rank { color: #888; width: 30px; }
.lb-item .lb-name { flex: 1; text-align: left; }
.lb-item .lb-score { color: #e74c3c; }

.action-btn {
  font-family: 'Press Start 2P', monospace;
  background: #222;
  color: #fff;
  border: 2px solid var(--border-color);
  padding: 12px 20px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.1s;
}

.action-btn:hover, #btn-submit-score:hover {
  background: var(--border-color);
  color: #f1c40f;
}
.action-btn:active, #btn-submit-score:active {
  transform: scale(0.95);
}

#btn-submit-score {
  font-family: 'Press Start 2P', monospace;
  background: #2ecc71;
  color: #000;
  border: 2px solid #27ae60;
  padding: 8px 15px;
  cursor: pointer;
  font-size: 10px;
}
#btn-submit-score:disabled {
  background: #555;
  color: #888;
  border-color: #444;
  cursor: not-allowed;
}

#controls-hint {
  text-align: center;
  font-size: 10px;
  color: #666;
  margin-top: 5px;
}

/* Make it somewhat responsive */
@media (max-width: 680px) {
  canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 4/3;
  }
  #hud-top {
    font-size: 10px;
    padding: 8px;
    gap: 10px;
  }
}
