* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #8fd0ff; }
body { font-family: 'VT323', monospace; -webkit-user-select: none; user-select: none; touch-action: none; }

#scene-container { position: fixed; inset: 0; }
canvas { display: block; }

/* Crosshair */
#crosshair {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: rgba(255,255,255,0.85); font-size: 24px; font-weight: bold;
  text-shadow: 0 0 3px rgba(0,0,0,0.7); pointer-events: none; z-index: 5;
  font-family: monospace;
}

/* HUD */
#hud {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none; padding-bottom: 14px;
}
#block-name {
  font-size: 26px; color: #fff; text-shadow: 2px 2px 0 #000;
  opacity: 0; transition: opacity 0.3s; margin-bottom: 8px; letter-spacing: 1px;
}
#block-name.show { opacity: 1; }

#hotbar {
  display: flex; gap: 6px; padding: 6px;
  background: rgba(20,20,25,0.55); border: 3px solid rgba(0,0,0,0.5);
  border-radius: 4px; pointer-events: auto;
}
.slot {
  width: 52px; height: 52px; position: relative; cursor: pointer;
  background: rgba(139,139,139,0.4); border: 3px solid #3a3a3a;
  display: flex; align-items: center; justify-content: center;
  image-rendering: pixelated;
}
.slot.selected { border-color: #ff4d94; box-shadow: 0 0 12px #ff4d94; transform: scale(1.08); }
.slot-icon {
  width: 38px; height: 38px; image-rendering: pixelated;
  border-radius: 2px;
}
.slot-num {
  position: absolute; top: -2px; left: 2px; font-size: 16px;
  color: #fff; text-shadow: 1px 1px 0 #000;
}
#block-count {
  margin-top: 8px; font-size: 18px; color: #fff; text-shadow: 1px 1px 0 #000;
}

/* Procedural icon fallbacks (gradients approximating each block) */
.icon-oak    { background: repeating-linear-gradient(0deg,#c49a63,#c49a63 6px,#a67f4d 6px,#a67f4d 8px); }
.icon-cobble { background: radial-gradient(circle at 30% 30%,#9a9a9e,#6f6f74); }
.icon-grass  { background: linear-gradient(#5fa03c 0 40%,#8a5a34 40% 100%); }
.icon-brick  { background: repeating-linear-gradient(0deg,#a53f31,#a53f31 5px,#c9b7a0 5px,#c9b7a0 6px); }

/* Menu */
#menu {
  position: fixed; inset: 0; z-index: 20; display: flex;
  align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(255,255,255,0.15), transparent 60%),
    linear-gradient(160deg, #4a7a2e, #2d5220);
  transition: opacity 0.4s; overflow-y: auto;
}
#menu.hidden { opacity: 0; pointer-events: none; }

.menu-panel {
  text-align: center; padding: 30px 24px; max-width: 480px; width: 90%;
  background: rgba(20,25,20,0.82);
  border: 4px solid #1a1a1a; border-radius: 6px;
  box-shadow: 0 0 0 4px rgba(255,77,148,0.25), 0 20px 40px rgba(0,0,0,0.5);
}
.menu-panel h1 {
  font-family: 'Press Start 2P', monospace; font-size: 24px; line-height: 1.5;
  color: #e8e8e8; text-shadow: 3px 3px 0 #000, 0 0 18px rgba(120,220,80,0.4);
  margin-bottom: 14px;
}
.menu-panel h1 .berrry { color: #ff4d94; text-shadow: 3px 3px 0 #5a0f2e; }
.tagline { font-size: 22px; color: #d8ffb0; margin-bottom: 16px; }

#tex-status { font-size: 18px; color: #ffd27a; margin-bottom: 12px; }

#play-btn {
  font-family: 'Press Start 2P', monospace; font-size: 15px;
  padding: 16px 22px; margin: 6px auto 18px; cursor: pointer;
  background: #6b6b6b; color: #888; border: 3px solid #000;
  border-bottom-width: 6px; transition: all 0.1s; letter-spacing: 1px;
}
#play-btn.ready {
  background: #6cc24a; color: #123; box-shadow: 0 0 20px rgba(108,194,74,0.5);
}
#play-btn.ready:hover { background: #7ed957; transform: translateY(-2px); }
#play-btn.ready:active { transform: translateY(2px); border-bottom-width: 3px; }
#play-btn:disabled { cursor: wait; }

.controls-list {
  display: flex; gap: 20px; justify-content: center; flex-wrap: wrap;
  font-size: 20px; color: #cfe8ff; margin-bottom: 14px;
}
.ctrl-col { text-align: left; line-height: 1.7; }
.k {
  display: inline-block; background: #2a2a2a; border: 2px solid #000;
  color: #ffd27a; padding: 0 6px; margin-right: 4px; border-radius: 3px;
  font-size: 15px; min-width: 30px; text-align: center;
}
/* Saved Worlds panel */
#worlds-section {
  margin: 4px auto 18px; text-align: left;
  background: rgba(0,0,0,0.28); border: 3px solid #1a1a1a;
  border-radius: 5px; padding: 10px 12px;
}
.worlds-header {
  display: flex; align-items: center; justify-content: space-between;
  font-family: 'Press Start 2P', monospace; font-size: 11px;
  color: #ffd27a; margin-bottom: 10px; letter-spacing: 1px;
}
#save-world-btn {
  font-family: 'VT323', monospace; font-size: 17px; cursor: pointer;
  background: #6cc24a; color: #123; border: 2px solid #000;
  border-bottom-width: 4px; padding: 3px 10px; border-radius: 3px;
  letter-spacing: 1px; transition: transform .1s;
}
#save-world-btn:hover { background: #7ed957; }
#save-world-btn:active { transform: translateY(2px); border-bottom-width: 2px; }

#worlds-list { max-height: 180px; overflow-y: auto; }
.worlds-empty { font-size: 17px; color: #9fbf82; padding: 6px 2px; }
.world-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 8px; margin-bottom: 6px;
  background: rgba(255,255,255,0.06); border: 2px solid rgba(0,0,0,0.5);
  border-radius: 4px;
}
.world-info { display: flex; flex-direction: column; min-width: 0; }
.world-name {
  font-size: 20px; color: #fff; text-shadow: 1px 1px 0 #000;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px;
}
.world-meta { font-size: 14px; color: #9fbf82; }
.world-btns { display: flex; gap: 5px; flex-shrink: 0; }
.wbtn {
  font-family: 'VT323', monospace; font-size: 15px; cursor: pointer;
  border: 2px solid #000; border-bottom-width: 3px; border-radius: 3px;
  padding: 3px 7px; color: #fff; letter-spacing: 1px; transition: transform .1s;
}
.wbtn:active { transform: translateY(2px); border-bottom-width: 2px; }
.wbtn.load { background: #4d94ff; }
.wbtn.over { background: #6b6b6b; color: #eee; }
.wbtn.del  { background: #c8503c; padding: 3px 8px; }
#worlds-list::-webkit-scrollbar { width: 8px; }
#worlds-list::-webkit-scrollbar-thumb { background: #ff4d94; border-radius: 4px; }

.footnote { font-size: 17px; color: #9fbf82; margin-bottom: 14px; line-height: 1.4; }
.remix {
  display: inline-block; color: #ff9ac1; font-size: 18px;
  text-decoration: none; border-bottom: 1px dotted #ff9ac1;
}
.remix:hover { color: #ffbdd8; }

/* Fly indicator */
#fly-indicator {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 20px; color: #fff; background: rgba(255,77,148,0.7);
  padding: 4px 14px; border: 2px solid #000; border-radius: 4px;
  z-index: 7; display: none; text-shadow: 1px 1px 0 #000;
}
#fly-indicator.on { display: block; }

/* Mobile controls */
#mobile-controls {
  position: fixed; inset: 0; z-index: 6; display: none;
  pointer-events: none;
}
#joystick {
  position: absolute; bottom: 90px; left: 24px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,0.12); border: 3px solid rgba(0,0,0,0.4);
  pointer-events: auto;
}
#joystick-knob {
  position: absolute; top: 50%; left: 50%; width: 50px; height: 50px;
  margin: -25px 0 0 -25px; border-radius: 50%;
  background: rgba(255,77,148,0.7); border: 3px solid rgba(0,0,0,0.5);
}
#action-buttons {
  position: absolute; bottom: 90px; right: 20px;
  display: grid; grid-template-columns: repeat(2, 76px); gap: 10px;
  pointer-events: auto;
}
.mbtn {
  height: 60px; font-family: 'VT323', monospace; font-size: 18px;
  background: rgba(30,30,35,0.7); color: #fff; border: 3px solid #000;
  border-radius: 6px; letter-spacing: 1px;
}
.mbtn.place { background: rgba(108,194,74,0.75); color:#123; }
.mbtn.break { background: rgba(200,80,60,0.8); }
.mbtn:active { transform: scale(0.94); }

@media (max-width: 520px) {
  .menu-panel h1 { font-size: 18px; }
  #hotbar { transform: scale(0.9); }
}