* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #111; color: #eee;
  font-family: 'Courier New', monospace;
  image-rendering: pixelated;
  user-select: none;
}
.hidden { display: none !important; }

/* ---------- Menus ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(#1b2a1b, #0c130c);
  z-index: 50;
}
.menu-panel {
  background: rgba(20, 24, 18, 0.9);
  border: 2px solid #4c4c3a;
  padding: 24px 32px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 0 0 4px #000 inset;
}
.game-title {
  text-align: center; color: #7ee06a; text-shadow: 3px 3px 0 #263b1d;
  letter-spacing: 4px; margin: 0 0 20px 0; font-size: 2em;
}
.death-title { color: #d34848; text-align: center; margin: 0 0 10px 0; }
.menu-btn {
  background: #5a6b4a; border: 2px solid #2e3a24; color: #fff;
  padding: 12px 18px; font-family: inherit; font-size: 15px; cursor: pointer;
  transition: background .1s;
}
.menu-btn:hover { background: #7a8d64; }
.menu-btn.secondary { background: #444; }
.menu-btn.secondary:hover { background: #666; }
.menu-btn.small { padding: 4px 10px; font-size: 13px; }
.menu-panel label { font-size: 13px; margin-top: 6px; color: #ccc; }
.menu-panel input[type="text"], .menu-panel select {
  background: #222; border: 1px solid #555; color: #fff; padding: 8px; font-family: inherit;
}
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.setting-row input[type="range"] { flex: 1; }
.controls-list { display: grid; grid-template-columns: 1fr; gap: 4px; font-size: 13px; }
.keybind-list { display: grid; grid-template-columns: 1fr; gap: 3px; font-size: 13px; max-height: 340px; overflow-y: auto; padding-right: 4px; }
.keybind-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.keybind-row .kb-label { color: #ddd; }
.keybind-row .kb-key-btn {
  min-width: 90px; text-align: center; background: #444; border: 1px solid #222; color: #fff;
  padding: 4px 8px; cursor: pointer; font-size: 12px;
}
.keybind-row .kb-key-btn:hover { background: #5a5a5a; }
.keybind-row .kb-key-btn.capturing { background: #8a6a2a; }
.keybind-row .kb-key-btn.conflict { background: #7a2a2a; }
.world-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.world-entry { display: flex; justify-content: space-between; align-items: center; background: #2a2f22; padding: 8px 10px; cursor: pointer; }
.world-entry:hover { background: #3a412e; }
.world-entry button { background: #7a3a3a; border: none; color: #fff; padding: 4px 8px; cursor: pointer; }

/* ---------- Game container ---------- */
#game-container { position: fixed; inset: 0; }
#game-canvas { display: block; width: 100%; height: 100%; outline: none; }

#crosshair {
  position: fixed; top: 50%; left: 50%; width: 20px; height: 20px;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 20;
}
#crosshair::before, #crosshair::after {
  content: ""; position: absolute; background: #fff; box-shadow: 0 0 2px #000;
}
#crosshair::before { width: 2px; height: 14px; left: 9px; top: 3px; }
#crosshair::after { height: 2px; width: 14px; top: 9px; left: 3px; }

#loading-overlay {
  position: fixed; inset: 0; background: #0c130c; display: flex;
  align-items: center; justify-content: center; z-index: 40; color: #7ee06a;
  font-size: 1.4em;
}
#loading-overlay.hidden { display: none; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 15; }
#bars { position: absolute; bottom: 78px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 2px; }
.bar-row { display: flex; gap: 2px; }
.bar-icon { width: 18px; height: 18px; position: relative; }
.bar-icon svg { width: 100%; height: 100%; }

#hotbar {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 3px; background: rgba(0,0,0,0.35); padding: 4px; border: 2px solid #000;
  pointer-events: auto;
}
.hotbar-slot {
  width: 46px; height: 46px; background: rgba(50,50,50,0.65); border: 2px solid #222;
  position: relative; display: flex; align-items: center; justify-content: center;
}
.hotbar-slot.selected { border-color: #fff; box-shadow: 0 0 4px #fff; }
.hotbar-slot canvas { width: 32px; height: 32px; image-rendering: pixelated; pointer-events: none; }
.slot-count {
  position: absolute; bottom: 1px; right: 3px; font-size: 12px; color: #fff;
  text-shadow: 1px 1px 0 #000; pointer-events: none;
}
.slot-durability { position: absolute; left: 3px; right: 3px; bottom: 3px; height: 3px; background: #333; pointer-events: none; }
.slot-durability-fill { height: 100%; background: #4caf50; }

#debug-overlay {
  position: fixed; top: 6px; left: 6px; background: rgba(0,0,0,0.5); color: #fff;
  padding: 8px 10px; font-size: 12px; line-height: 1.5; z-index: 25; white-space: pre; pointer-events: none;
}

#hurt-flash {
  position: fixed; inset: 0; background: rgba(200,0,0,0.35); opacity: 0; pointer-events: none; z-index: 18;
  transition: opacity 0.35s;
}
#hurt-flash.active { opacity: 1; transition: opacity 0s; }

#blocker-hint {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6); color: #fff; padding: 8px 16px; z-index: 60; font-size: 14px;
}

/* ---------- Inventory ---------- */
#inventory-screen { z-index: 30; background: rgba(0,0,0,0.55); }
.inventory-panel {
  background: #2b2f24; border: 3px solid #12140f; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 10px; pointer-events: auto;
}
.inventory-panel h3 { margin: 0 0 6px 0; color: #ddd; }
#craft-and-book { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 8px; }
#craft-area { display: flex; align-items: center; gap: 10px; }
#craft-grid { display: grid; grid-template-columns: repeat(3, 42px); gap: 3px; }
#craft-grid.grid2x2 { grid-template-columns: repeat(2, 42px); }
.craft-arrow { font-size: 22px; color: #aaa; }
#craft-output { width: 46px; }

/* ---------- Recipe book ---------- */
#recipe-book {
  width: 230px; background: #23261c; border: 2px solid #12140f; padding: 6px;
  display: flex; flex-direction: column; gap: 6px;
}
#recipe-book-tabs { display: flex; flex-wrap: wrap; gap: 3px; }
.recipe-tab {
  background: #3a3f30; border: 1px solid #14160f; color: #cfcfcf; font-size: 10px;
  padding: 3px 6px; cursor: pointer;
}
.recipe-tab:hover { background: #4a4f3c; }
.recipe-tab.active { background: #6a8d4e; color: #fff; }
#recipe-book-list { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; }
.recipe-row {
  display: flex; align-items: center; gap: 6px; padding: 4px 5px; cursor: pointer;
  background: #2f3326; border: 1px solid transparent;
}
.recipe-row:hover { background: #3a3f30; border-color: #555; }
.recipe-row.selected { border-color: #e0a838; background: #3a3f30; }
.recipe-row.uncraftable { opacity: 0.45; }
.recipe-row canvas { width: 22px; height: 22px; image-rendering: pixelated; flex-shrink: 0; }
.recipe-row .recipe-name { font-size: 12px; color: #eee; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-row .recipe-count { font-size: 11px; color: #9c9; margin-left: auto; }
.recipe-row.uncraftable .recipe-count { color: #c77; }
.inv-slot.missing-ingredient { border-color: #b33 !important; box-shadow: inset 0 0 0 1px #b33; }
#inventory-grid { display: grid; grid-template-columns: repeat(9, 42px); gap: 3px; }
#inventory-hotbar-grid { display: grid; grid-template-columns: repeat(9, 42px); gap: 3px; padding-top: 6px; border-top: 2px solid #12140f; }
.inv-slot {
  width: 42px; height: 42px; background: #3a3f30; border: 2px solid #14160f;
  position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.inv-slot:hover { background: #4a4f3c; }
.inv-slot canvas { width: 30px; height: 30px; image-rendering: pixelated; pointer-events: none; }
#drag-ghost {
  position: fixed; width: 30px; height: 30px; pointer-events: none; z-index: 100; display: none;
  image-rendering: pixelated;
}

/* ---------- Item tooltips ---------- */
#item-tooltip {
  position: fixed; z-index: 200; pointer-events: none; display: none;
  background: rgba(10, 10, 14, 0.92); border: 1px solid #000; color: #eee;
  padding: 6px 9px; font-size: 12px; line-height: 1.5; max-width: 220px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
#item-tooltip .tt-name { font-weight: bold; color: #fff; margin-bottom: 2px; }
#item-tooltip .tt-category { color: #a89cd8; font-size: 11px; margin-bottom: 2px; }
#item-tooltip .tt-desc { color: #ccc; }
#item-tooltip .tt-stat { color: #8fbf8f; font-size: 11px; }

/* ---------- Game-mode segmented toggle (create-world screen) ---------- */
.segmented-toggle { display: flex; gap: 0; margin-bottom: 10px; border: 1px solid #555; border-radius: 3px; overflow: hidden; }
.seg-btn {
  flex: 1; padding: 8px 6px; background: #2a2e22; color: #ccc; border: none; cursor: pointer;
  font-size: 13px; border-right: 1px solid #555;
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active { background: #5c7a3a; color: #fff; }
.seg-btn:hover:not(.active) { background: #3a3f2e; }

/* ---------- Creative inventory panel ---------- */
#creative-inventory { display: flex; flex-direction: column; gap: 6px; }
#creative-search { width: 100%; box-sizing: border-box; padding: 5px 7px; margin-bottom: 4px; background: #1c1e16; color: #eee; border: 1px solid #555; }
#creative-tabs { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 4px; }
#creative-tabs .recipe-tab { font-size: 11px; }
#creative-grid {
  display: grid; grid-template-columns: repeat(9, 36px); gap: 2px; max-height: 420px; overflow-y: auto;
  padding: 4px; background: #1c1e16; border: 1px solid #444;
  scrollbar-color: #7a8a5a #1c1e16; scrollbar-width: thin;
}
#creative-grid::-webkit-scrollbar { width: 10px; }
#creative-grid::-webkit-scrollbar-track { background: #1c1e16; }
#creative-grid::-webkit-scrollbar-thumb { background: #7a8a5a; border: 2px solid #1c1e16; border-radius: 5px; }
#creative-grid .inv-slot { width: 36px; height: 36px; }
#creative-grid .inv-slot canvas { width: 28px; height: 28px; }

/* ---------- Chat ---------- */
#chat-container {
  position: absolute; left: 10px; bottom: 60px; width: 480px; max-width: 42vw;
  z-index: 50; display: flex; flex-direction: column; gap: 4px;
  font-size: 13px; pointer-events: none;
}
#chat-log {
  display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow: hidden;
}
.chat-line {
  background: rgba(0,0,0,0.45); color: #fff; padding: 3px 7px; border-radius: 2px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.6); word-break: break-word;
  transition: opacity 1.2s ease;
}
.chat-line.chat-system { color: #ffd23e; }
.chat-line.chat-error { color: #ff6b5e; }
.chat-line .chat-name { color: #7fc8ff; font-weight: bold; }
#chat-input {
  pointer-events: auto; width: 100%; box-sizing: border-box; padding: 5px 8px;
  background: rgba(0,0,0,0.65); color: #fff; border: 1px solid #666; font-size: 13px;
}
#chat-suggestions {
  pointer-events: none; background: rgba(0,0,0,0.55); color: #aaa; padding: 3px 8px;
  border-radius: 2px; font-size: 12px;
}
