:root {
  --dirt: #8b6b45;
  --dirt-dark: #5a4228;
  --slot: #8b8b8b;
  --slot-dark: #373737;
  --panel: rgba(22, 16, 10, 0.86);
  --text: #f4f1e8;
  --accent: #3d9c3d;
  --accent-hover: #4cbe4c;
  --danger: #b33a3a;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  user-select: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
}

.panel {
  width: min(520px, 92vw);
  background: var(--panel);
  border: 4px solid #2b2116;
  box-shadow: 0 0 0 2px #c4a574 inset;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-panel {
  width: min(640px, 94vw);
  max-height: 92vh;
  overflow: auto;
}

h1,
h2,
h3 {
  margin: 0 0 6px;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 #000;
}

h1 {
  font-size: 42px;
  text-align: center;
}

.subtitle,
.hint {
  text-align: center;
  color: #d7c7a5;
  font-size: 13px;
}

label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0;
}

input[type="text"],
select {
  flex: 1;
  background: #1b140d;
  color: var(--text);
  border: 2px solid #3d2d1c;
  padding: 6px 8px;
}

input[type="range"] {
  flex: 1;
}

button {
  background: #7a7a7a;
  color: #fff;
  border: 3px solid #000;
  box-shadow: inset 0 3px 0 #a8a8a8, inset 0 -3px 0 #4a4a4a;
  padding: 10px 14px;
  font-size: 16px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:focus-visible {
  outline: 2px solid #ffe08a;
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

button.primary {
  background: var(--accent);
  box-shadow: inset 0 3px 0 #73d073, inset 0 -3px 0 #246624;
}

button.danger {
  background: var(--danger);
}

.row {
  display: flex;
  gap: 10px;
}

.row button {
  flex: 1;
}

#world-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.world-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: #1d1610;
  border: 2px solid #3b2c1c;
  padding: 8px 10px;
}

.world-row span {
  display: block;
  color: #c8b89a;
  font-size: 12px;
}

.world-row button {
  padding: 6px 10px;
  font-size: 13px;
}

.empty {
  color: #c8b89a;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#attack-cd {
  position: absolute;
  left: 50%;
  top: calc(50% + 14px);
  width: 28px;
  height: 3px;
  background: #fff;
  transform-origin: center;
  transform: translateX(-50%);
  opacity: 0.7;
  pointer-events: none;
}

label.check {
  justify-content: flex-start;
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  background:
    linear-gradient(#fff, #fff) center/2px 12px no-repeat,
    linear-gradient(#fff, #fff) center/12px 2px no-repeat;
  filter: drop-shadow(0 0 1px #000);
}

#status {
  position: absolute;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  display: flex;
  justify-content: space-between;
  width: 364px;
}

#air {
  position: absolute;
  left: 50%;
  bottom: 112px;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
}

#hearts,
#hunger {
  display: flex;
  gap: 1px;
}

#hearts.hurt {
  animation: shake 0.25s linear;
}

.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  image-rendering: pixelated;
}

.heart {
  background: radial-gradient(circle at 30% 30%, #ff6b6b 0 40%, #d42222 41% 100%);
  clip-path: polygon(50% 88%, 8% 48%, 18% 18%, 50% 30%, 82% 18%, 92% 48%);
}

.heart.half {
  background: linear-gradient(90deg, #d42222 50%, #3a3a3a 50%);
  clip-path: polygon(50% 88%, 8% 48%, 18% 18%, 50% 30%, 82% 18%, 92% 48%);
}

.heart.empty {
  background: #3a3a3a;
  clip-path: polygon(50% 88%, 8% 48%, 18% 18%, 50% 30%, 82% 18%, 92% 48%);
}

.food {
  background: #c45a2a;
  border-radius: 50% 50% 40% 40%;
  box-shadow: inset -3px -3px 0 #8a3a16;
}

.food.half {
  background: linear-gradient(90deg, #c45a2a 50%, #3a3a3a 50%);
}

.food.empty {
  background: #3a3a3a;
}

.bubble {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d8f4ff 0 35%, #4aa7d4 36% 100%);
  box-shadow: inset -2px -2px 0 #2a6f90;
}

.bubble.empty {
  background: #3a3a3a;
  box-shadow: none;
}

#hotbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid #111;
}

.slot {
  width: 40px;
  height: 40px;
  background: #8b8b8b;
  border: 2px solid #373737;
  box-shadow: inset 2px 2px 0 #bdbdbd, inset -2px -2px 0 #555;
  position: relative;
  image-rendering: pixelated;
}

.slot.selected,
.slot.result {
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.slot img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

.slot .count {
  position: absolute;
  right: 2px;
  bottom: 0;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}

#debug {
  position: absolute;
  left: 10px;
  top: 10px;
  margin: 0;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.45);
  font: 12px/1.45 ui-monospace, Consolas, monospace;
  white-space: pre;
}

.inv-panel {
  background: #c6c6c6;
  color: #202020;
  border: 4px solid #2b2b2b;
  padding: 16px 18px 20px;
  min-width: min(560px, 94vw);
  max-width: 96vw;
  max-height: 92vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.inv-panel h2,
.inv-panel h3 {
  color: #303030;
  text-shadow: none;
}

.inv-layout {
  display: flex;
  gap: 18px;
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(9, 40px);
  gap: 2px;
  margin-top: 14px;
}

.slot-row {
  display: grid;
  grid-template-columns: repeat(9, 40px);
  gap: 2px;
  margin-top: 10px;
}

.craft-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.craft-grid {
  display: grid;
  gap: 2px;
}

.craft-grid.size-2 {
  grid-template-columns: repeat(2, 40px);
}

.craft-grid.size-3 {
  grid-template-columns: repeat(3, 40px);
}

#container-area {
  margin-bottom: 12px;
}

.chest-grid {
  display: grid;
  grid-template-columns: repeat(9, 40px);
  gap: 2px;
}

.furnace-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.furnace-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.furnace-bar {
  width: 56px;
  height: 10px;
  background: #4a4a4a;
  border: 2px solid #222;
}

.furnace-bar > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #e07020, #ffd060);
}

.furnace-bar.cook > div {
  background: linear-gradient(90deg, #d8d070, #fff4a8);
}

.arrow {
  font-size: 28px;
  color: #444;
}

.recipe-book {
  width: 168px;
}

#recipe-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.recipe {
  width: 36px;
  height: 36px;
}

.floating {
  position: fixed;
  pointer-events: none;
  z-index: 40;
}

.bar {
  width: 100%;
  height: 14px;
  background: #1b140d;
  border: 2px solid #000;
}

#loading-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
}

#toast {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  padding: 8px 16px;
  z-index: 50;
  border: 2px solid #000;
}

#save-indicator {
  position: absolute;
  right: 16px;
  top: 14px;
  z-index: 45;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid #000;
  pointer-events: none;
}

.death h2 {
  color: #ff6b6b;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

#fps-meter {
  position: absolute;
  left: 12px;
  top: 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: #b7f7b0;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
  letter-spacing: 0.5px;
}

#fps-meter.low {
  color: #ffb4a2;
}

#compass {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  font-size: 14px;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}

#minimap {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 128px;
  height: 128px;
  border: 3px solid #1a140c;
  box-shadow: 0 0 0 1px #c4a574;
  image-rendering: pixelated;
  background: #0b0d12;
  opacity: 0.92;
  pointer-events: none;
}

.slot.pulse {
  outline: 2px solid #ffe08a;
}

#look-name {
  position: absolute;
  left: 50%;
  top: calc(50% + 22px);
  transform: translateX(-50%);
  font-size: 13px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}

#held-name {
  position: absolute;
  left: 50%;
  bottom: 66px;
  transform: translateX(-50%);
  font-size: 13px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}

#water-overlay,
#lava-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#water-overlay {
  background: rgba(20, 70, 150, 0.32);
  box-shadow: inset 0 0 80px rgba(10, 30, 80, 0.45);
}

#lava-overlay {
  background: rgba(180, 40, 0, 0.38);
  box-shadow: inset 0 0 90px rgba(80, 10, 0, 0.5);
}

#boot-error {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 80;
  max-width: 640px;
  background: rgba(40, 0, 0, 0.88);
  color: #ffd0d0;
  padding: 16px 18px;
  border: 2px solid #800;
  white-space: pre-wrap;
  font: 14px/1.45 ui-monospace, Consolas, monospace;
}

.recipe.slot {
  cursor: pointer;
}

.dur-bar {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 2px;
  height: 3px;
  background: #222;
  pointer-events: none;
}

.dur-bar > span {
  display: block;
  height: 100%;
  background: #5dcc4a;
}

.dur-bar > span.low {
  background: #d44;
}

#rain-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(80, 90, 100, 0.12), rgba(40, 50, 60, 0.08));
}

#creative-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-height: 220px;
  overflow: auto;
  margin-top: 6px;
}

#creative-grid .slot {
  width: 32px;
  height: 32px;
}
