@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600&display=swap');

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #222;
  font-family: 'Fredoka', sans-serif;
  color: white;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
}

canvas {
  display: block;
}

#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Let clicks pass through to canvas if not on UI */
}

/* Allow pointer events on specific UI elements */
.overlay-screen, #hud, #dialogue-box, #mobile-controls, button {
  pointer-events: auto;
}

/* HUD */
#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-container {
  position: relative;
  width: 200px;
  height: 24px;
  background: rgba(0,0,0,0.5);
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #fff;
}

#hp-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff4d4d, #ff9999);
  transition: width 0.2s;
}

#hp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #000;
}

.currency-display {
  font-size: 20px;
  background: rgba(0,0,0,0.4);
  padding: 5px 10px;
  border-radius: 20px;
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
}

.inventory-preview {
  display: flex;
  gap: 5px;
}

.inv-item {
  background: rgba(0,0,0,0.4);
  padding: 5px;
  border-radius: 5px;
  font-size: 14px;
}

#quest-tracker {
  background: rgba(255, 255, 255, 0.2);
  padding: 8px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 300px;
  text-shadow: 1px 1px 2px black;
}

/* Character Creator & Screens */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.hidden {
  display: none !important;
}

h1, h2 {
  color: #ff99aa;
  text-shadow: 2px 2px 0 #a33;
  margin-bottom: 20px;
  text-align: center;
}

.preview-box {
  background: #aaddaa;
  border-radius: 50%;
  padding: 20px;
  margin-bottom: 20px;
  border: 5px solid #fff;
}

.controls-scroll {
  background: rgba(255,255,255,0.1);
  padding: 20px;
  border-radius: 10px;
  max-height: 40vh;
  overflow-y: auto;
  width: 90%;
  max-width: 400px;
}

.control-group {
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
}

label {
  margin-bottom: 5px;
}

button {
  background: #ff4d6d;
  border: none;
  padding: 12px 24px;
  color: white;
  font-family: 'Fredoka', sans-serif;
  font-size: 18px;
  border-radius: 25px;
  cursor: pointer;
  box-shadow: 0 4px #a33;
  margin-top: 20px;
  transition: transform 0.1s;
}

button:active {
  transform: translateY(4px);
  box-shadow: 0 0 #a33;
}

/* Dialogue */
#dialogue-box {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 600px;
  background: rgba(255, 240, 245, 0.95);
  color: #333;
  border: 4px solid #ff99aa;
  border-radius: 15px;
  padding: 20px;
  text-align: center;
}

#npc-name {
  color: #d6336c;
  margin: 0 0 10px 0;
}

/* Shop */
#shop-screen {
  background: rgba(40, 30, 30, 0.95);
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 15px;
  width: 90%;
  max-width: 800px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 10px;
}

.shop-item {
  background: rgba(255,255,255,0.1);
  padding: 10px;
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s;
}

.shop-item:hover {
  background: rgba(255,255,255,0.2);
}

.shop-item h4 {
  margin: 5px 0;
  font-size: 14px;
}

.cost {
  color: #88ff88;
  font-weight: bold;
}

/* Mobile Controls */
#mobile-controls {
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
  height: 150px;
  pointer-events: none; /* Container passes through */
}

#joystick-zone {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
  pointer-events: auto;
  border: 2px solid rgba(255,255,255,0.2);
}

#joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  background: rgba(255,255,255,0.5);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

#action-buttons {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 15px;
  pointer-events: auto;
}

.action-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  font-size: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.2);
  box-shadow: 0 0 10px rgba(0,0,0,0.3);
  margin: 0; /* Override generic button margin */
}

#btn-attack { background: rgba(255, 80, 80, 0.6); }
#btn-interact { background: rgba(80, 180, 255, 0.6); }
#btn-heal { background: rgba(100, 255, 100, 0.6); }

.action-btn:active {
  transform: scale(0.95);
}

@media (min-width: 1024px) {
  /* Hide mobile controls on desktop initially, though logic enables them if touch detected or strictly for mobile view */
  #mobile-controls {
    /* Keep visible for this demo as requested "Controls for mobile devices" implies prioritizing this interface */
  }
}
