:root {
  --panel: rgba(20, 28, 44, 0.85);
  --accent: #5bd35b;
  --gold: #ffd54a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #87ceeb;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* Full-screen menus */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 40, 0.35);
  z-index: 30;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

.panel {
  background: var(--panel);
  border: 4px solid #000;
  border-radius: 18px;
  padding: 22px;
  max-width: 560px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  text-align: center;
  box-shadow: 0 8px 0 #000;
}

h1 { font-size: clamp(40px, 9vw, 74px); margin: 4px 0; color: var(--gold); letter-spacing: 2px; }
h2 { font-size: clamp(24px, 5vw, 30px); margin: 8px 0 14px; }
.sub { font-size: 20px; margin: 0 0 16px; color: #cfe8ff; }
.hint { font-size: 16px; opacity: 0.9; margin: 14px 0; line-height: 1.4; }

button {
  font-family: inherit;
  font-size: 22px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  cursor: pointer;
  border: 4px solid #000;
  border-radius: 14px;
  background: #4f8f3a;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.35), 0 4px 0 #000;
  padding: 12px 18px;
  margin: 8px 4px;
  min-height: 60px;
  min-width: 120px;
  touch-action: manipulation;
}
button:active { transform: translateY(3px); }
button:disabled { background: #666; color: #aaa; cursor: not-allowed; }
button.big { display: block; width: 100%; font-size: 28px; min-height: 72px; }
button.pill { background: #3a4d6b; min-width: 150px; opacity: 0.7; }
button.pill.active { opacity: 1; background: #4f8f3a; outline: 4px solid var(--gold); }
button.danger { background: #b5443a; }

.mode-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }

.bar { height: 26px; background: #222; border: 3px solid #000; border-radius: 10px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.scroll { -webkit-overflow-scrolling: touch; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  max-height: 55vh;
  overflow: auto;
  margin-bottom: 8px;
}
.pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  min-width: 0;
  font-size: 15px;
  padding: 8px;
  margin: 0;
  box-shadow: none;
  background: #34495e;
}
.pick img { width: 48px; height: 48px; image-rendering: pixelated; }

.craft {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 18px;
  background: #6b4f2a;
  margin: 6px 0;
  min-height: 0;
  line-height: 1.4;
}
.craft small { font-size: 15px; opacity: 0.9; }

.panel.wide { max-width: 940px; }

.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin: 6px 0 12px;
  max-height: 46vh;
  overflow: auto;
}
.world-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  min-width: 0;
  margin: 0;
  padding: 10px 8px;
  background: #34495e;
  box-shadow: 0 4px 0 #000;
  text-shadow: 1px 1px 0 #000;
  line-height: 1.25;
}
.world-card .we { font-size: 34px; }
.world-card strong { font-size: 18px; margin-top: 4px; }
.world-card small { font-size: 13px; opacity: 0.9; margin-top: 4px; text-shadow: none; }
.world-card em { font-style: normal; font-size: 13px; color: #ffe27a; margin-top: 4px; }
.world-card.active { background: #4f8f3a; outline: 4px solid var(--gold); }

.attrib { font-size: 12px; opacity: 0.8; margin-top: 12px; text-shadow: none; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#crosshair {
  position: absolute; left: 50%; top: 50%;
  width: 6px; height: 6px; margin: -3px;
  background: #fff; box-shadow: 0 0 0 2px #000;
}

#break-ring {
  position: absolute; left: 50%; top: 50%;
  width: 64px; height: 64px; margin: -32px;
  border-radius: 50%;
  background: conic-gradient(#fff calc(var(--p, 0) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 24px, #000 25px);
          mask: radial-gradient(circle, transparent 24px, #000 25px);
  opacity: 0;
}
#break-ring.on { opacity: 1; }

#mode-badge {
  position: absolute; top: 12px; left: 12px;
  background: rgba(0, 0, 0, 0.45); padding: 6px 12px;
  border-radius: 12px; border: 3px solid #000; font-size: 18px;
}

#hearts {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px;
}
body.mode-creative #hearts { display: none; }
.heart {
  width: 24px; height: 24px; background: #555;
  border: 3px solid #000; border-radius: 6px 6px 10px 10px;
}
.heart.full { background: #e53935; }
.heart.half { background: linear-gradient(90deg, #e53935 50%, #555 50%); }

#message {
  position: absolute; top: 64px; left: 50%;
  transform: translate(-50%, -10px);
  background: rgba(0, 0, 0, 0.6); padding: 10px 18px; border-radius: 14px;
  font-size: 19px; opacity: 0; transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
#message.show { opacity: 1; transform: translate(-50%, 0); }

#hurt {
  position: absolute; inset: 0;
  background: radial-gradient(transparent 55%, rgba(255, 0, 0, 0.55));
  opacity: 0; transition: opacity 0.3s;
}
#hurt.on { opacity: 1; transition: none; }

#hotbar {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px;
  background: rgba(0, 0, 0, 0.5); border: 4px solid #000; border-radius: 14px;
  pointer-events: auto;
}
.slot {
  width: 56px; height: 56px;
  border: 3px solid #222; border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.slot.sel { border-color: #fff; background: rgba(255, 255, 255, 0.35); transform: translateY(-4px); }
.slot img { width: 40px; height: 40px; image-rendering: pixelated; pointer-events: none; }
.slot .count {
  position: absolute; right: 3px; bottom: 0;
  font-size: 14px; text-shadow: 1px 1px 0 #000;
}

/* Touch controls */
#touch-ui { display: none; position: fixed; inset: 0; pointer-events: none; z-index: 15; }
body.touch-mode #touch-ui { display: block; }
body.touch-mode #hotbar .slot { width: 62px; height: 62px; }
body.touch-mode #hotbar .slot img { width: 46px; height: 46px; }
body.touch-mode #hotbar { bottom: 10px; }

#joystick {
  position: absolute; left: 24px; bottom: 110px;
  width: 150px; height: 150px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 4px solid rgba(255, 255, 255, 0.5);
}
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 64px; height: 64px; margin: -32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid #000;
}

.touch-btn {
  position: absolute;
  pointer-events: auto;
  width: 84px; height: 84px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  border: 4px solid rgba(255, 255, 255, 0.7);
  font-size: 15px;
  line-height: 1.1;
  padding: 0; margin: 0;
  min-width: 0; min-height: 0;
  box-shadow: none;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
}
.touch-btn:active { transform: none; background: rgba(255, 255, 255, 0.3); }
#btn-down { display: none; }
body.flying #btn-down { display: flex; }
body.mode-survival [data-action="fly"] { display: none; }
body:not(.mode-survival) [data-action="fly"] { display: flex; }

/* Help text: show the right set of controls */
body.touch-mode #help .kb { display: none; }
body:not(.touch-mode) #help .tc { display: none; }

@media (max-width: 600px) {
  .slot { width: 46px; height: 46px; }
  .slot img { width: 34px; height: 34px; }
}
