/* ============ Block Kingdoms styles ============ */
html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: #1c3d5c;
  font-family: -apple-system, "SF Pro Rounded", "Trebuchet MS", "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; -webkit-user-select: none; user-select: none; touch-action: none; border: none; cursor: pointer; }
#app { position: fixed; inset: 0; }
#world-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

.crosshair {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  color: #fff; font-size: 26px; font-weight: 900; text-shadow: 0 0 4px rgba(0,0,0,0.6);
  pointer-events: none !important; z-index: 400;
}

/* ---------- top bar ---------- */
#topbar {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 0; right: 0;
  display: flex; justify-content: center; align-items: center; gap: 10px;
  padding: 0 10px; z-index: 900; pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.tb-btn {
  width: 62px; height: 62px; border-radius: 18px;
  background: rgba(255,255,255,0.92); font-size: 28px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
}
.tb-btn:active { transform: scale(0.93); }
.tb-chip {
  min-width: 96px; height: 62px; border-radius: 18px; padding: 0 14px;
  background: rgba(255,255,255,0.92);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.tb-chip:active { transform: scale(0.95); }
.qc-icon { font-size: 26px; }
.qc-text { font-size: 18px; font-weight: 900; color: #333; }
.tb-mode {
  height: 62px; padding: 0 16px; border-radius: 18px; border: 4px solid #fff;
  background: #2f9e44; color: #fff; font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: background 0.2s ease;
}
.tb-mode.mode-break { background: #e63946; }
.tb-mode:active { transform: scale(0.95); }

/* ---------- movement controls ---------- */
.joystick {
  position: absolute; left: 18px; bottom: max(110px, calc(env(safe-area-inset-bottom) + 104px));
  width: 150px; height: 150px; border-radius: 50%;
  background: rgba(255,255,255,0.28); border: 4px solid rgba(255,255,255,0.55);
  z-index: 500; touch-action: none;
}
.joystick-knob {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 70px; height: 70px; border-radius: 50%;
  background: rgba(255,255,255,0.9); box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  pointer-events: none;
}
.jump-btn {
  position: absolute; right: 18px; bottom: max(110px, calc(env(safe-area-inset-bottom) + 104px));
  width: 100px; height: 100px; border-radius: 50%;
  background: #ffb703; border: 4px solid #fff; color: #fff;
  font-size: 15px; font-weight: 900; z-index: 500;
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}
.jump-btn:active { transform: scale(0.92); }

/* ---------- hotbar ---------- */
#hotbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; gap: 8px; padding: 8px;
  background: rgba(0,0,0,0.28); border-radius: 20px;
  max-width: 92vw; overflow-x: auto; z-index: 600;
  -webkit-overflow-scrolling: touch;
}
.hotbar-slot {
  position: relative; width: 62px; height: 62px; border-radius: 14px; flex: 0 0 auto;
  background: rgba(255,255,255,0.85); border: 3px solid rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
}
.hotbar-slot.selected { border-color: #ffd166; box-shadow: 0 0 0 3px #ffd166; }
.slot-icon { font-size: 30px; }
.slot-count {
  position: absolute; right: 2px; bottom: 1px;
  font-size: 13px; font-weight: 900; color: #333;
  background: rgba(255,255,255,0.9); border-radius: 8px; padding: 0 4px;
}

/* ---------- popups & toast ---------- */
#popups {
  position: absolute; top: 42%; left: 50%; transform: translateX(-50%);
  pointer-events: none !important; z-index: 950;
  display: flex; flex-direction: column; align-items: center;
}
.popup {
  font-size: 26px; font-weight: 900; color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  animation: popup-rise 0.9s ease-out forwards;
}
@keyframes popup-rise {
  0% { opacity: 0; transform: translateY(10px) scale(0.7); }
  20% { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 0; transform: translateY(-44px) scale(1); }
}
#toast {
  position: absolute; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 90px));
  background: rgba(20,20,30,0.85); color: #fff;
  padding: 12px 22px; border-radius: 18px;
  font-size: 17px; font-weight: 800; text-align: center;
  opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none !important; z-index: 960; max-width: 86vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- panels ---------- */
.panel-backdrop {
  position: absolute; inset: 0; z-index: 2000;
  background: rgba(15,25,45,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.panel {
  background: linear-gradient(160deg, #fdfbff, #eef3ff);
  border-radius: 26px; padding: 18px;
  width: min(640px, 94vw); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0,0,0,0.4);
  -webkit-overflow-scrolling: touch;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2, .tutorial-panel h2 { margin: 0; font-size: 24px; color: #333; }
.panel-close {
  width: 60px; height: 60px; border-radius: 16px; font-size: 22px;
  background: #f1f3f5; box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.panel-close:active { transform: scale(0.93); }

/* map */
.map-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.map-card {
  min-height: 130px; border-radius: 20px; padding: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(160deg, #74c0ff, #4d96ff); color: #fff;
  box-shadow: 0 6px 0 rgba(0,0,0,0.15), 0 8px 16px rgba(0,0,0,0.2);
}
.map-card:active { transform: translateY(3px); }
.map-card.current { outline: 4px solid #ffd166; }
.map-card.locked {
  background: linear-gradient(160deg, #b9c2cc, #8d99a6);
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  opacity: 0.85;
}
.mc-icon { font-size: 40px; }
.mc-label { font-size: 15px; font-weight: 800; text-align: center; }
.mc-req {
  font-size: 14px; font-weight: 800; background: rgba(255,255,255,0.25);
  border-radius: 12px; padding: 2px 10px;
}

/* backpack */
.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.pack-cell {
  position: relative; min-height: 86px; border-radius: 16px; padding: 8px;
  background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,0.12);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.pack-cell.selected { outline: 4px solid #ffd166; }
.pack-label { font-size: 12px; font-weight: 800; color: #555; }
.craft-title { margin: 16px 0 8px; font-size: 20px; color: #333; }
.craft-list { display: flex; flex-direction: column; gap: 10px; }
.craft-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #fff; border-radius: 16px; padding: 10px 12px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}
.craft-io { font-size: 18px; font-weight: 800; color: #444; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.craft-need { opacity: 0.45; }
.craft-need.have { opacity: 1; }
.craft-out { background: #e7f7ec; border-radius: 10px; padding: 2px 8px; }
.craft-btn {
  min-width: 96px; min-height: 60px; border-radius: 16px;
  background: #2f9e44; color: #fff; font-size: 17px; font-weight: 800;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}
.craft-btn:disabled { background: #ced4da; box-shadow: none; }
.craft-btn:active:not(:disabled) { transform: translateY(2px); }

/* gallery */
.gallery-hint { margin: 4px 0 10px; font-size: 16px; font-weight: 700; color: #555; }
.gallery-picker { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.gallery-pick {
  width: 62px; height: 62px; border-radius: 16px; font-size: 30px;
  background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}
.gallery-pick:active { transform: scale(0.92); }
.gallery-list { display: flex; flex-direction: column; gap: 8px; }
.gallery-entry {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border-radius: 14px; padding: 10px 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  font-size: 18px; font-weight: 800; color: #444;
}
.ge-icon { font-size: 28px; }
.gallery-empty { font-size: 16px; font-weight: 700; color: #777; padding: 8px; }

/* tutorial */
.tutorial-panel { text-align: center; }
.tut-row {
  display: flex; align-items: center; gap: 14px;
  background: #fff; border-radius: 16px; padding: 12px 16px; margin: 10px 0;
  box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}
.tut-icon { font-size: 34px; }
.tut-text { font-size: 17px; font-weight: 800; color: #444; text-align: left; }
.big-btn {
  min-width: 220px; min-height: 70px; border-radius: 20px; margin-top: 8px;
  font-size: 21px; font-weight: 800; color: #fff; background: #2f9e44;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2), 0 10px 18px rgba(0,0,0,0.25);
}
.big-btn:active { transform: translateY(4px); }

/* error */
.friendly-error-inner {
  background: #fff; border-radius: 24px; padding: 30px 24px; text-align: center;
  max-width: 80vw; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  font-size: 20px; font-weight: 700; color: #333;
}
.fe-emoji { font-size: 64px; }

#confetti-canvas {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 5000; display: none;
}
