* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #1a2a1a; font-family: 'Segoe UI', system-ui, sans-serif; color: #e8ecdd; }
canvas { position: fixed; inset: 0; display: block; }

/* HUD */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 18px;
  padding: 8px 16px;
  background: rgba(20, 30, 20, 0.85);
  border-bottom: 1px solid rgba(100, 140, 80, 0.3);
  backdrop-filter: blur(6px);
  font-size: 13px;
  z-index: 10;
  pointer-events: none;
  display: none;
}
#hud.show { display: flex; }
#hud .res { display: flex; align-items: center; gap: 4px; }
#hud .res span { color: #b8d4a0; font-weight: 600; }
#hud .region-name { margin-left: auto; color: #a0c090; font-style: italic; }

/* Minecraft-style Inventory */
#inventory {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.95);
  width: 420px;
  background: #8b8b8b;
  border: 4px solid #1a1a1a;
  border-top-color: #c6c6c6; border-left-color: #c6c6c6;
  border-radius: 4px;
  z-index: 30;
  padding: 8px;
  font-size: 12px;
  display: none;
  image-rendering: pixelated;
  box-shadow: 0 8px 30px rgba(0,0,0,0.7);
}
#inventory.open { display: block; }
#inventory h3 { color: #3f3f3f; margin: 0 0 6px; font-size: 13px; font-weight: normal; }
.inv-section { margin-bottom: 6px; }
.inv-grid {
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px;
}
.inv-slot {
  width: 40px; height: 40px;
  background: #555;
  border: 2px solid #1a1a1a;
  border-top-color: #373737; border-left-color: #373737;
  border-bottom-color: #8b8b8b; border-right-color: #8b8b8b;
  position: relative; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
}
.inv-slot:hover { background: #777; }
.inv-slot.hotbar-slot { background: #4a5a3a; }
.inv-slot.active-hb { background: #5a7a3a; border-color: #a0e060; }
.inv-slot .slot-count {
  position: absolute; bottom: 1px; right: 3px;
  font-size: 10px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px 1px 0 #000;
  pointer-events: none;
}
.inv-slot .slot-dur {
  position: absolute; bottom: 1px; left: 2px; right: 2px; height: 2px;
  background: #333; border-radius: 1px; pointer-events: none;
}
.inv-slot .slot-dur-fill { height: 100%; border-radius: 1px; }
.inv-slot .slot-label {
  position: absolute; top: 1px; left: 2px;
  font-size: 7px; color: #ccc; text-shadow: 1px 1px 0 #000;
  pointer-events: none; white-space: nowrap;
}
.inv-separator {
  height: 2px; background: linear-gradient(to right, #6a6a6a, #aaa, #6a6a6a);
  margin: 6px 0;
}
#inv-cursor {
  position: fixed; pointer-events: none; z-index: 35;
  font-size: 22px; transform: translate(-50%, -50%);
  text-shadow: 1px 2px 2px rgba(0,0,0,0.6);
  display: none;
}

/* Slot hover tooltip */
#slot-tip {
  position: fixed; pointer-events: none; z-index: 40;
  background: rgba(10, 15, 10, 0.96);
  border: 1px solid rgba(120, 160, 100, 0.55);
  color: #e8f0d0;
  font-size: 12px; line-height: 1.4;
  padding: 6px 10px;
  border-radius: 4px;
  white-space: pre;
  max-width: 220px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  display: none;
}
#slot-tip.show { display: block; }
#inv-cursor.show { display: block; }
#inv-cursor .cur-count {
  position: absolute; bottom: -4px; right: -4px;
  font-size: 10px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000;
}

/* Quest Panel */
#quest-panel {
  position: fixed; left: 0; top: 44px; bottom: 0; width: 320px;
  background: rgba(20, 30, 20, 0.92);
  border-right: 1px solid rgba(100, 140, 80, 0.3);
  backdrop-filter: blur(8px);
  z-index: 10;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  padding: 12px;
  font-size: 13px;
}
#quest-panel.open { transform: translateX(0); }
#quest-panel h3 { color: #b8d4a0; margin-bottom: 8px; font-size: 14px; border-bottom: 1px solid rgba(100,140,80,0.3); padding-bottom: 6px; }
.quest-entry { padding: 8px; margin-bottom: 6px; background: rgba(40,60,40,0.5); border-radius: 4px; border-left: 3px solid #608040; }
.quest-entry.completed { border-left-color: #40a040; opacity: 0.6; }
.quest-entry.locked { border-left-color: #604040; opacity: 0.4; }
.quest-entry .qt { font-weight: 600; color: #c8e0b0; margin-bottom: 4px; }
.quest-entry .qd { color: #a0b890; font-size: 12px; }
.quest-entry .qp { color: #80a060; font-size: 11px; margin-top: 4px; }

/* Dialog */
#dialog {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  width: 500px; max-width: 90vw;
  background: rgba(20, 30, 20, 0.95);
  border: 1px solid rgba(100, 140, 80, 0.4);
  border-radius: 8px;
  padding: 16px;
  z-index: 20;
  display: none;
  backdrop-filter: blur(8px);
}
#dialog.show { display: block; }
#dialog .speaker { color: #b8d4a0; font-weight: 700; margin-bottom: 6px; font-size: 14px; }
#dialog .text { color: #d0e8c0; font-size: 13px; line-height: 1.5; }
#dialog .hint { color: #708060; font-size: 11px; margin-top: 8px; }
#dialog .choices { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
#dialog .choices button {
  background: rgba(60, 90, 50, 0.6); border: 1px solid rgba(100,140,80,0.4);
  color: #c8e0b0; padding: 6px 14px; border-radius: 4px; cursor: pointer; font-size: 12px;
}
#dialog .choices button:hover { background: rgba(80, 120, 60, 0.7); }

/* Crafting Panel */
#crafting {
  position: fixed; inset: 10vh 10vw;
  background: rgba(20, 30, 20, 0.96);
  border: 1px solid rgba(100, 140, 80, 0.4);
  border-radius: 8px;
  z-index: 25;
  display: none;
  backdrop-filter: blur(10px);
  padding: 20px;
  overflow-y: auto;
}
#crafting.show { display: block; }
#crafting h2 { color: #b8d4a0; margin-bottom: 16px; }
.craft-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px; margin-bottom: 6px;
  background: rgba(40, 60, 40, 0.5); border-radius: 4px;
}
.craft-item .ci-name { color: #c8e0b0; font-weight: 600; }
.craft-item .ci-cost { color: #90b070; font-size: 12px; }
.craft-item button {
  background: rgba(60, 100, 50, 0.7); border: 1px solid rgba(100,160,80,0.5);
  color: #d0f0c0; padding: 5px 12px; border-radius: 4px; cursor: pointer; font-size: 12px;
}
.craft-item button:hover { background: rgba(80, 130, 60, 0.8); }
.craft-item button:disabled { opacity: 0.4; cursor: default; }

/* Enchant Panel — same chrome as crafting */
#enchant-panel {
  position: fixed; inset: 10vh 10vw;
  background: rgba(20, 25, 40, 0.96);
  border: 1px solid rgba(140, 120, 200, 0.5);
  border-radius: 8px;
  z-index: 25;
  display: none;
  backdrop-filter: blur(10px);
  padding: 20px;
  overflow-y: auto;
}
#enchant-panel.show { display: block; }
#enchant-panel h2 { color: #c8b0ff; margin-bottom: 12px; }
#enchant-panel h3 { color: #aa99dd; font-size: 13px; margin: 12px 0 6px; border-bottom: 1px solid rgba(140,120,200,0.2); padding-bottom: 4px; }
.ench-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; margin-bottom: 4px;
  background: rgba(40, 35, 60, 0.55);
  border-left: 3px solid rgba(180, 150, 255, 0.4);
  border-radius: 4px;
}
.ench-item .ei-name { color: #d8c8ff; font-weight: 600; font-size: 13px; }
.ench-item .ei-meta { color: #9080b0; font-size: 11px; margin-top: 2px; }
.ench-item .ei-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.ench-item button {
  background: rgba(80, 60, 130, 0.7); border: 1px solid rgba(160, 120, 220, 0.5);
  color: #e0d0ff; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 11px;
}
.ench-item button:hover { background: rgba(110, 80, 170, 0.85); }
.ench-item button:disabled { opacity: 0.35; cursor: default; }

/* Shop Panel */
#shop-panel {
  position: fixed; inset: 10vh 10vw;
  background: rgba(20, 30, 20, 0.96);
  border: 1px solid rgba(100, 140, 80, 0.4);
  border-radius: 8px;
  z-index: 25;
  display: none;
  backdrop-filter: blur(10px);
  padding: 20px;
  overflow-y: auto;
}
#shop-panel.show { display: block; }
#shop-panel h2 { color: #b8d4a0; margin-bottom: 12px; }
#shop-panel h3 { color: #a0c090; font-size: 13px; margin: 10px 0 6px; border-bottom: 1px solid rgba(100,140,80,0.2); padding-bottom: 4px; }
.shop-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px; margin-bottom: 4px;
  background: rgba(40, 60, 40, 0.5); border-radius: 4px;
}
.shop-row .sr-name { color: #c8e0b0; font-weight: 600; font-size: 13px; }
.shop-row .sr-cost { color: #90b070; font-size: 12px; }
.shop-row button {
  background: rgba(60, 100, 50, 0.7); border: 1px solid rgba(100,160,80,0.5);
  color: #d0f0c0; padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 11px;
}
.shop-row button:hover { background: rgba(80, 130, 60, 0.8); }
.shop-row button:disabled { opacity: 0.4; cursor: default; }

/* Notification */
#notif {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: rgba(40, 70, 40, 0.95);
  border: 1px solid rgba(100, 180, 80, 0.5);
  border-radius: 6px;
  padding: 10px 20px;
  color: #c8f0b0;
  font-size: 13px;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
#notif.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Build Mode */
#build-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(20, 30, 20, 0.92);
  border-top: 1px solid rgba(100,140,80,0.3);
  backdrop-filter: blur(8px);
  z-index: 15;
  display: none;
  padding: 12px 16px;
}
#build-panel.show { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
#build-panel h4 { color: #b8d4a0; width: 100%; margin-bottom: 4px; font-size: 13px; }
.build-btn {
  background: rgba(50, 80, 40, 0.7); border: 1px solid rgba(100,140,80,0.4);
  color: #c8e0b0; padding: 8px 14px; border-radius: 4px; cursor: pointer; font-size: 12px;
}
.build-btn:hover { background: rgba(70, 110, 50, 0.8); }
.build-btn:disabled { opacity: 0.4; cursor: default; }

/* Controls hint */
#controls-hint {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  color: rgba(160,200,140,0.5); font-size: 11px; z-index: 5; pointer-events: none;
}

/* Menu overlay */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: radial-gradient(ellipse at center, rgba(20,40,20,0.92), rgba(10,20,10,0.98));
  z-index: 50;
  transition: opacity 0.4s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay h1 { font-size: 48px; color: #90c870; margin-bottom: 8px; text-shadow: 0 2px 20px rgba(100,180,60,0.3); }
.overlay .sub { color: #80a068; font-size: 16px; margin-bottom: 32px; }
.overlay button {
  background: rgba(60, 100, 50, 0.6); border: 1px solid rgba(100,160,80,0.5);
  color: #c8f0b0; padding: 12px 36px; border-radius: 6px; cursor: pointer;
  font-size: 16px; letter-spacing: 1px; margin: 6px;
  transition: background 0.2s;
}
.overlay button:hover { background: rgba(80, 130, 60, 0.8); }

/* Village status */
#village-status {
  position: fixed; top: 44px; right: 12px;
  background: rgba(20, 30, 20, 0.85);
  border: 1px solid rgba(100,140,80,0.25);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 11px;
  z-index: 8;
  display: none;
  color: #90b070;
}
#village-status.show { display: block; }

/* Map overlay */
#map-overlay {
  position: fixed; inset: 5vh 5vw;
  background: rgba(20, 30, 20, 0.96);
  border: 1px solid rgba(100,140,80,0.4);
  border-radius: 8px;
  z-index: 25;
  display: none;
  backdrop-filter: blur(10px);
}
#map-overlay.show { display: flex; align-items: center; justify-content: center; }
#map-canvas { border-radius: 6px; }

/* Event banner */
#event-banner {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%);
  padding: 7px 20px;
  background: rgba(50, 30, 80, 0.85);
  border: 1px solid rgba(200, 160, 255, 0.5);
  border-radius: 18px;
  color: #e8d8ff; font-size: 13px; letter-spacing: 0.3px;
  z-index: 9; display: none;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#event-banner.show { display: block; }

/* Hotbar */
#hotbar {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: none; gap: 4px; align-items: end;
  z-index: 9;
}
#hotbar.show { display: flex; }

/* Offhand — single slot to the left of the main hotbar */
#offhand {
  position: fixed; bottom: 12px; left: 50%;
  /* 9 main slots at 44px + 4px gap = 48*9 - 4 = 428 total, so shift left by half + extra gap */
  transform: translateX(calc(-50% - 270px));
  display: none; gap: 4px; align-items: end;
  z-index: 9;
  padding-right: 12px;
  border-right: 1px dashed rgba(140, 180, 120, 0.3);
}
#offhand.show { display: flex; }

/* Offhand grid in the inventory panel — single slot */
.inv-grid.inv-grid-offhand {
  grid-template-columns: repeat(1, 1fr);
}
.hb-slot {
  width: 44px; height: 50px;
  background: rgba(20, 25, 20, 0.85);
  border: 2px solid rgba(100, 140, 80, 0.35);
  border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 10px; color: #a0c080;
  position: relative;
  cursor: pointer; user-select: none;
  backdrop-filter: blur(4px);
}
.hb-slot.active { border-color: #a0e070; background: rgba(40, 60, 30, 0.9); }
.hb-slot .hb-icon { font-size: 16px; line-height: 1; }
.hb-slot .hb-label { font-size: 8px; color: #80a060; white-space: nowrap; overflow: hidden; max-width: 40px; }
.hb-slot .hb-dur { position: absolute; bottom: 2px; left: 3px; right: 3px; height: 3px; background: rgba(0,0,0,0.5); border-radius: 1px; }
.hb-slot .hb-dur-fill { height: 100%; border-radius: 1px; }
.hb-slot .hb-key { position: absolute; top: 2px; right: 3px; font-size: 8px; color: rgba(200,230,160,0.6); }

/* Shield HUD — bottom left */
#shield-hud {
  position: fixed; bottom: 12px; left: 12px;
  padding: 6px 12px;
  background: rgba(20, 30, 50, 0.85);
  border: 1px solid rgba(140, 180, 220, 0.5);
  border-radius: 8px;
  color: #c0ddf0; font-size: 12px; letter-spacing: 0.3px;
  z-index: 8; display: none;
  backdrop-filter: blur(4px);
}
#shield-hud.show { display: block; }
#shield-hud b { color: #aaddff; }

/* Minimap */
#minimap {
  position: fixed; right: 12px; bottom: 12px;
  width: 180px; height: 180px;
  background: rgba(10, 18, 10, 0.88);
  border: 2px solid rgba(120, 160, 100, 0.55);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  z-index: 8;
  display: none;
  box-shadow: 0 4px 18px rgba(0,0,0,0.5);
  overflow: hidden;
}
#minimap.show { display: block; }
#minimap canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
#minimap-label {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  color: rgba(200,230,180,0.85); font-size: 10px; letter-spacing: 1px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
  pointer-events: none;
}

/* Test panel */
#test-panel {
  position: fixed; inset: 5vh 5vw;
  background: rgba(15, 20, 15, 0.97);
  border: 2px solid rgba(200, 160, 60, 0.6);
  border-radius: 10px;
  z-index: 40;
  display: none;
  backdrop-filter: blur(10px);
  padding: 20px;
  overflow-y: auto;
  color: #d8e0c8;
  font-size: 13px;
}
#test-panel.show { display: block; }
#test-panel h2 { color: #e0c060; margin-bottom: 12px; }
#test-panel h3 { color: #b8d090; margin: 12px 0 6px; font-size: 13px; border-bottom: 1px solid rgba(200,160,60,0.2); padding-bottom: 4px; }
.test-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.test-btn {
  background: rgba(60, 80, 40, 0.7); border: 1px solid rgba(140, 180, 80, 0.4);
  color: #c8e0b0; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 11px;
}
.test-btn:hover { background: rgba(80, 110, 50, 0.8); }
.test-btn.gold { border-color: rgba(220, 180, 60, 0.6); color: #f0d870; }

/* Tutorial banner */
#tutorial-banner {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 40, 20, 0.95);
  border: 2px solid rgba(160, 200, 100, 0.6);
  border-radius: 8px;
  padding: 14px 24px;
  color: #e8f0d0;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  max-width: 640px;
  min-width: 360px;
  z-index: 15;
  display: none;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
#tutorial-banner.show { display: block; }
#tutorial-banner .tut-progress {
  font-size: 11px;
  color: #a0c080;
  letter-spacing: 1.5px;
  margin-bottom: 6px;
}
#tutorial-banner .tut-msg {
  line-height: 1.45;
  margin-bottom: 10px;
}
#tutorial-banner .tut-skip {
  background: rgba(80, 50, 40, 0.6);
  border: 1px solid rgba(160, 100, 80, 0.45);
  color: #f0c8b0;
  padding: 5px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.5px;
}
#tutorial-banner .tut-skip:hover {
  background: rgba(100, 60, 50, 0.8);
}

/* Fade overlay */
#fade-overlay {
  position: fixed; inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 55;
  transition: opacity 0.6s ease;
  display: flex; align-items: center; justify-content: center;
  color: #c8e0b0; font-size: 14px; letter-spacing: 1px;
}
#fade-overlay.show { opacity: 1; pointer-events: auto; }

/* Ending */
#ending {
  position: fixed; inset: 0;
  display: none; align-items: center; justify-content: center; flex-direction: column;
  background: radial-gradient(ellipse at center, rgba(30,50,20,0.95), rgba(10,20,10,0.99));
  z-index: 60;
}
#ending.show { display: flex; }
#ending h1 { font-size: 42px; color: #90c870; margin-bottom: 12px; }
#ending p { color: #80a068; font-size: 16px; max-width: 500px; text-align: center; line-height: 1.6; margin-bottom: 24px; }
