* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #000; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", monospace, sans-serif;
  color: #fff;
  user-select: none;
}
#game { position: fixed; inset: 0; }
#game canvas { display: block; }

/* crosshair */
#crosshair {
  position: fixed; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px; line-height: 1;
  color: #fff; opacity: 0.85;
  text-shadow: 0 0 2px #000;
  pointer-events: none; z-index: 20;
}

/* block-breaking progress bar, just below the crosshair */
#mine-progress {
  position: fixed; left: 50%; top: 50%;
  transform: translate(-50%, 22px);
  width: 60px; height: 7px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(0,0,0,0.7);
  border-radius: 2px;
  opacity: 0; transition: opacity 0.1s linear;
  pointer-events: none; z-index: 20;
  overflow: hidden;
}
#mine-progress.visible { opacity: 1; }
#mine-progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(to bottom, #f4f4f4, #c8c8c8);
  transition: width 0.05s linear;
}

/* coordinate readout */
#coords {
  position: fixed; left: 8px; top: 8px;
  font-size: 13px; font-family: monospace;
  color: #fff; text-shadow: 1px 1px 0 #000;
  background: rgba(0,0,0,0.25);
  padding: 4px 8px; border-radius: 4px;
  z-index: 20; pointer-events: none;
}

/* ---- hotbar ---- */
#hotbar {
  position: fixed; left: 50%; bottom: 14px;
  transform: translateX(-50%);
  display: flex; gap: 4px;
  padding: 4px; background: rgba(0,0,0,0.35);
  border: 2px solid rgba(0,0,0,0.5); border-radius: 6px;
  z-index: 20;
}
.slot {
  position: relative;
  width: 52px; height: 52px;
  background: rgba(139,139,139,0.35);
  border: 2px solid #373737;
  border-top-color: #8b8b8b; border-left-color: #8b8b8b;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.slot.sel { border-color: #fff; box-shadow: 0 0 0 2px #fff inset; }
.slot canvas { image-rendering: pixelated; }
.slot .num {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 11px; font-family: monospace;
  text-shadow: 1px 1px 0 #000; opacity: 0.7;
}
.slot .count {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 14px; font-weight: bold; font-family: monospace;
  text-shadow: 1.5px 1.5px 0 #000;
}

/* ---- survival stat bars (hearts / hunger / air) ---- */
.statbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  display: none; gap: 1px; z-index: 21;
  font-size: 16px; line-height: 1;
  text-shadow: 1px 1px 0 #000, -1px 0 0 #000;
  pointer-events: none;
}
#hpbar     { bottom: 74px; margin-left: -160px; }
#hungerbar { bottom: 74px; margin-left: 160px; flex-direction: row-reverse; }
#airbar    { bottom: 96px; margin-left: 160px; flex-direction: row-reverse; }
.statbar .heart { color: #ff2b2b; }
.statbar .food  { color: #d79b52; }
.statbar .air   { color: #bfe6ff; font-size: 12px; }

/* red damage flash + underwater tint overlays */
#hurt, #water-overlay {
  position: fixed; inset: 0; z-index: 30;
  pointer-events: none; opacity: 0;
  transition: opacity 0.12s linear;
}
#hurt { background: radial-gradient(circle at 50% 50%, transparent 30%, rgba(160,0,0,0.55) 100%); }
#water-overlay { background: rgba(30,80,170,0.5); transition: opacity 0.25s linear; }

/* death screen */
#death {
  position: fixed; inset: 0; z-index: 55;
  display: none; align-items: center; justify-content: center;
  background: rgba(80,0,0,0.5);
}
#death .panel { text-align: center; }
#death h1 { font-size: 42px; color: #ff5a5a; text-shadow: 2px 2px 0 #000; }
#death p { margin-top: 8px; color: #eee; font-size: 15px; }
#respawnBtn {
  margin-top: 22px; padding: 12px 30px; font-size: 18px; font-family: inherit;
  color: #fff; background: #4a7a34; border: 3px solid #2c4a1f; border-radius: 6px; cursor: pointer;
}
#respawnBtn:hover { background: #5a913f; }

/* in survival mode, hide search box */
#inventory.survival #search { display: none; }

/* ---- start overlay ---- */
#start {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #3a5a8c, #10131f);
}
#start .panel {
  background: rgba(0,0,0,0.55);
  border: 3px solid #222; border-radius: 10px;
  padding: 32px 40px; text-align: center;
  max-width: 520px;
}
#start h1 { font-size: 30px; letter-spacing: 1px; text-shadow: 2px 2px 0 #000; }
#start .sub { margin-top: 6px; color: #b7d0ff; font-size: 15px; }
#start .controls {
  list-style: none; text-align: left;
  margin: 22px auto; max-width: 400px;
  font-size: 14px; line-height: 2;
}
#start .controls b { color: #ffe36b; }
#startBtn {
  margin-top: 8px; padding: 12px 30px;
  font-size: 18px; font-family: inherit;
  color: #fff; background: #4a7a34;
  border: 3px solid #2c4a1f; border-radius: 6px;
  cursor: pointer;
}
#startBtn:hover:not(:disabled) { background: #5a913f; }
#startBtn:disabled { opacity: 0.5; cursor: default; }
#start .hint { margin-top: 14px; font-size: 12px; color: #9fb3d0; }

/* ---- inventory overlay ---- */
#inventory {
  position: fixed; inset: 0; z-index: 40;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55);
}
/* hide floating hotbar when inventory is open */
#inventory:not([style*="display: none"]) ~ #hotbar { display: none !important; }

.inv-wrap {
  display: flex; flex-direction: column; gap: 10px;
  background: #c6c6c6;
  border: 4px solid #555;
  border-top-color: #fff; border-left-color: #fff;
  border-radius: 4px; padding: 16px;
  max-width: 920px; max-height: 85vh;
  overflow-y: auto;
}

/* ---- top section: creative palette OR crafting grid ---- */
#inv-top {
  display: flex; flex-direction: column;
  background: #8b8b8b; padding: 12px; border: 2px solid #373737;
  min-height: 280px; max-height: 45vh;
  overflow: hidden;
}
/* creative view: show palette, hide craft */
#inventory.view-creative #creative-top { display: flex; flex-direction: column; }
#inventory.view-creative #craft-top { display: none; }
/* craft view (survival-E or table): hide palette, show craft */
#inventory.view-craft #creative-top { display: none; }
#inventory.view-craft #craft-top { display: flex; flex-direction: column; align-items: center; }

.inv-title {
  color: #3a3a3a; font-size: 16px; font-weight: bold;
  margin-bottom: 10px; text-shadow: 1px 1px 0 rgba(255,255,255,0.4);
}
#search {
  width: 100%; padding: 8px 10px; margin-bottom: 10px;
  font-size: 14px; font-family: inherit;
  border: 2px solid #555; border-radius: 3px;
  background: #f4f4f4; color: #222;
}
#palette {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, 48px);
  gap: 4px; align-content: start;
  padding: 6px; min-height: 280px;
}
.pcell {
  width: 46px; height: 46px;
  background: rgba(139,139,139,0.5);
  border: 2px solid #373737;
  border-top-color: #b0b0b0; border-left-color: #b0b0b0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.pcell:hover { border-color: #fff; }
.pcell canvas { image-rendering: pixelated; }

.craft-area {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
}
#craftgrid {
  display: grid; gap: 3px;
}
/* 2x2 grid for survival inventory crafting */
#inventory.craft-2x2 #craftgrid {
  grid-template-columns: repeat(2, 52px);
  grid-template-rows: repeat(2, 52px);
}
/* 3x3 grid for crafting table */
#inventory.craft-3x3 #craftgrid {
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
}
.craft-arrow { font-size: 28px; color: #3a3a3a; }
.slot.big { width: 60px; height: 60px; background: rgba(139,139,139,0.5); }
#craftout { position: relative; }
.slot.big canvas { image-rendering: pixelated; }

/* ---- bottom section: 27-slot + hotbar row (all views) ---- */
#inv-bottom {
  display: flex; flex-direction: column; gap: 8px;
  background: #8b8b8b; padding: 12px; border: 2px solid #373737;
}
.inv-bottom-head {
  display: flex; justify-content: space-between; align-items: center;
}
#destroy-wrap {
  display: flex; align-items: center; gap: 6px;
}
.destroy-label {
  font-size: 12px; color: #3a3a3a; font-weight: bold;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.3);
}
#destroy {
  background: rgba(200,80,80,0.3);
  border-color: #8b4a4a;
  font-size: 24px; line-height: 1;
  user-select: none;
}
#destroy.drag-over {
  background: rgba(255,100,100,0.5);
  border-color: #ff6060;
}

#invgrid {
  display: grid; grid-template-columns: repeat(9, 52px);
  grid-template-rows: repeat(3, 52px); gap: 3px;
}
#inv-hotbar {
  display: grid; grid-template-columns: repeat(9, 52px);
  gap: 3px; padding-top: 6px;
  border-top: 2px solid #373737;
}

.inv-hint { color: #4a4a4a; font-size: 11px; margin-top: 6px; line-height: 1.4; }
.inv-close { margin-top: 8px; font-size: 13px; color: #ddd; text-align: center; text-shadow: 1px 1px 0 #000; }

/* floating cursor stack */
#cursor {
  position: fixed; z-index: 60; pointer-events: none;
  display: none; transform: translate(-50%, -50%);
}
#cursor canvas { image-rendering: pixelated; }

/* scrollbars */
#palette::-webkit-scrollbar { width: 10px; }
#palette::-webkit-scrollbar-thumb { background: #555; border: 2px solid #8b8b8b; }
