/* ===== RESET & BASE ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #1a1a2e;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport on mobile */
  font-family: 'Courier New', monospace;
  overflow: hidden;
  touch-action: none; /* prevent scroll/zoom interfering with game */
}

#game-container {
  position: relative;
  width: 800px;
  height: 500px;
  overflow: hidden;
  border: 3px solid #c8a000;
  border-radius: 4px;
  box-shadow: 0 0 40px #c8a00066;
  /* Scale to fit any screen while keeping 800x500 aspect ratio */
  transform-origin: center center;
}

#bg-canvas, #game-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 800px;
  height: 500px;
}

#bg-canvas { z-index: 1; }
#game-canvas { z-index: 2; }

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 10;
  display: flex;
  gap: 16px;
  align-items: center;
}

#score-box {
  background: rgba(0,0,0,0.7);
  color: #ffd700;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 14px;
  border: 1px solid #c8a000;
}

#hunger-box {
  background: rgba(0,0,0,0.7);
  color: #ffd700;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 14px;
  border: 1px solid #c8a000;
  display: flex;
  align-items: center;
  gap: 8px;
}

#hunger-bar {
  width: 100px;
  height: 12px;
  background: #333;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #666;
}

#hunger-fill {
  height: 100%;
  width: 60%;
  background: linear-gradient(90deg, #ff6b00, #ff0000);
  border-radius: 6px;
  transition: width 0.5s ease;
}

/* ===== SCENE LABEL ===== */
#scene-label {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #aaa;
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 10px;
  z-index: 10;
  pointer-events: none;
  letter-spacing: 1px;
}

/* ===== INVENTORY ===== */
#inventory {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50px;
  background: rgba(0,0,0,0.85);
  border-top: 2px solid #c8a000;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  color: #ffd700;
  font-size: 13px;
}

#inv-items {
  display: flex;
  gap: 8px;
}

.inv-item {
  background: rgba(200,160,0,0.2);
  border: 1px solid #c8a000;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  color: #ffd700;
  cursor: default;
  user-select: none;
}



/* ===== DIALOGUE ===== */
#dialogue {
  position: absolute;
  bottom: 55px;
  left: 20px;
  right: 20px;
  background: rgba(10,10,30,0.95);
  border: 2px solid #c8a000;
  border-radius: 6px;
  z-index: 20;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-height: 80px;
}

#dialogue.hidden { display: none; }

#dialogue-portrait {
  font-size: 36px;
  flex-shrink: 0;
  line-height: 1;
}

#dialogue-text {
  color: #f0e0a0;
  font-size: 14px;
  line-height: 1.6;
  flex: 1;
}

#dialogue-next {
  align-self: flex-end;
  background: #c8a000;
  color: #000;
  border: none;
  padding: 5px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 13px;
  flex-shrink: 0;
}

#dialogue-next:hover { background: #ffd700; }

/* ===== CURSOR LABEL ===== */
#cursor-label {
  position: absolute;
  pointer-events: none;
  z-index: 30;
  background: rgba(0,0,0,0.75);
  color: #ffd700;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 3px;
  white-space: nowrap;
  display: none;
}

/* ===== TITLE SCREEN ===== */
#title-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: linear-gradient(180deg, #0d0d1a 0%, #1a1000 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
}

#title-canvas {
  border-radius: 4px;
  width: 500px;
  height: 120px;
  display: block;
  flex-shrink: 0;
}

#title-screen h1 {
  font-size: 40px;
  color: #ffd700;
  text-shadow: 0 0 20px #c8a000, 0 0 40px #c8a00066;
  letter-spacing: 4px;
  margin: 0;
}

#title-screen h2 {
  font-size: 15px;
  color: #c8a000;
  letter-spacing: 2px;
  margin: 0;
}

.subtitle {
  color: #888;
  font-size: 12px;
  letter-spacing: 1px;
}

.lore-blurb {
  color: #aaa;
  font-size: 12px;
  text-align: center;
  line-height: 1.7;
  max-width: 500px;
}

#start-btn {
  margin-top: 4px;
  background: #c8a000;
  color: #000;
  border: none;
  padding: 10px 32px;
  font-size: 16px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: background 0.2s, transform 0.1s;
  z-index: 60;
  position: relative;
}

#start-btn:hover { background: #ffd700; transform: scale(1.05); }

/* ===== WIN SCREEN ===== */
#win-screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #ffd700;
  text-align: center;
}

#win-screen h1 { font-size: 40px; text-shadow: 0 0 20px #ffd700; }
#win-screen p { color: #ccc; font-size: 15px; max-width: 500px; line-height: 1.7; }

#restart-btn {
  background: #c8a000;
  color: #000;
  border: none;
  padding: 10px 30px;
  font-size: 16px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
}

#restart-btn:hover { background: #ffd700; }

/* ===== SHOP BUTTON ===== */
#shop-btn {
  background: #c8a000;
  color: #000;
  border: none;
  padding: 4px 14px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.2s, transform 0.1s;
}
#shop-btn:hover { background: #ffd700; transform: scale(1.05); }
#shop-btn.hidden { display: none; }

/* ===== AUDIO TOGGLE BUTTONS ===== */
.audio-btn {
  background: rgba(0,0,0,0.6);
  color: #ffd700;
  border: 1px solid #c8a000;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, opacity 0.15s;
}
.audio-btn:hover { background: rgba(200,160,0,0.25); }
.audio-btn.muted { opacity: 0.35; text-decoration: line-through; }

/* ===== SHOP OVERLAY ===== */
#shop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 40;
}
#shop-overlay.hidden { display: none; }

/* ===== SHOP PANEL ===== */
#shop-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
  background: rgba(10,10,25,0.97);
  border: 2px solid #c8a000;
  border-radius: 8px;
  z-index: 45;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#shop-panel.hidden { display: none; }

#shop-title {
  color: #ffd700;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  letter-spacing: 2px;
  margin-bottom: 4px;
  border-bottom: 1px solid #c8a00066;
  padding-bottom: 8px;
}

/* ===== SHOP ITEMS ===== */
.shop-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 8px;
  background: rgba(200,160,0,0.08);
  border: 1px solid #c8a00044;
  border-radius: 5px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  opacity: 0.55;
}
.shop-item.affordable {
  opacity: 1;
  border-color: #c8a000;
}
.shop-item.affordable:hover {
  background: rgba(200,160,0,0.22);
}
.shop-item.bought {
  opacity: 0.35;
  cursor: default;
  border-color: #444;
}
.shop-emoji {
  font-size: 20px;
  grid-row: 1 / 3;
  text-align: center;
}
.shop-name {
  color: #ffd700;
  font-size: 13px;
  font-weight: bold;
}
.shop-desc {
  color: #aaa;
  font-size: 10px;
  grid-column: 2;
}
.shop-cost {
  color: #ffd700;
  font-size: 12px;
  font-weight: bold;
  grid-row: 1 / 3;
  white-space: nowrap;
}
.shop-item.bought .shop-name::after {
  content: ' ✓';
  color: #44cc44;
}

/* ===== TOAST ===== */
#toast {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #ffd700;
  font: bold 13px 'Courier New', monospace;
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid #c8a000;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 50;
}
#toast.toast-show { opacity: 1; }
#toast.toast-hide { opacity: 0; }

/* ===== MOBILE / SMALL SCREEN ===== */
@media (max-width: 820px) {
  /* On small screens the container is scaled down via JS transform,
     so UI elements inside need to stay readable — bump touch targets */
  #dialogue-next, #start-btn, #restart-btn, #shop-btn, .audio-btn {
    min-height: 36px;
    min-width: 36px;
  }
  #shop-panel {
    width: 90%;
    max-width: 340px;
  }
}
