* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #10201a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #f4f7f2;
  touch-action: none;
}

#gameContainer {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* HUD Atas */
.hud-top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.hud-card {
  background: rgba(16, 28, 23, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 7px 11px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
}

.hud-time-box {
  min-width: 158px;
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-sub {
  margin-top: 4px;
}

.badge-day {
  font-size: 11px;
  font-weight: 700;
  color: #ffe39e;
  letter-spacing: 0.2px;
}

.weather-pill {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 99px;
}

.clock-text {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.coin-text {
  font-size: 13px;
  font-weight: 700;
  color: #ffd54f;
}

.hud-bars-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 122px;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-label {
  font-size: 12px;
  width: 16px;
  text-align: center;
}

.bar-track {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.2s ease;
}

.bar-fill.stamina {
  background: linear-gradient(90deg, #43d17a, #a6f25c);
}

.bar-fill.water {
  background: linear-gradient(90deg, #29b6f6, #80deea);
}

.bar-num {
  font-size: 11px;
  font-weight: 700;
  min-width: 28px;
  text-align: right;
  color: #d9e6df;
}

.hud-actions {
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(16, 28, 23, 0.8);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.icon-btn:active {
  transform: scale(0.92);
}

/* Toast */
.toast {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: rgba(16, 28, 23, 0.92);
  border: 1px solid rgba(255, 227, 158, 0.35);
  color: #fff6dc;
  padding: 8px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 25;
  text-align: center;
  max-width: 86vw;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Kontrol Bawah */
.controls-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  padding: 0 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
  z-index: 15;
}

/* Analog Virtual */
.joystick-zone {
  width: 118px;
  height: 118px;
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: none;
}

.joystick-base {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: rgba(16, 28, 23, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  position: relative;
}

.joystick-knob {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #cbd9cf);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transform: translate(0px, 0px);
  transition: transform 0.05s linear;
}

/* Hotbar */
.hotbar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 28, 23, 0.82);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 6px;
  border-radius: 16px;
  pointer-events: auto;
  max-width: calc(100vw - 245px);
  overflow-x: auto;
  scrollbar-width: none;
}

.hotbar::-webkit-scrollbar {
  display: none;
}

.slot-btn {
  position: relative;
  min-width: 48px;
  height: 50px;
  border-radius: 11px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.slot-btn.active {
  border-color: #ffd54f;
  background: rgba(255, 213, 79, 0.22);
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(255, 213, 79, 0.25);
}

.slot-icon {
  font-size: 20px;
  line-height: 1;
}

.slot-name {
  font-size: 9px;
  color: #d6e4dc;
  margin-top: 3px;
  font-weight: 600;
}

.slot-count {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
  font-weight: 800;
  color: #ffe082;
  text-shadow: 0 1px 2px #000;
}

/* Tombol Aksi Kanan */
.action-zone {
  pointer-events: auto;
}

.action-btn {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 232, 163, 0.75);
  background: radial-gradient(circle at 30% 25%, #379c63, #1d633d);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.42);
  transition: transform 0.08s ease, background 0.15s ease;
}

.action-btn:active {
  transform: scale(0.92);
}

.action-icon {
  font-size: 26px;
  line-height: 1;
}

.action-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

/* Modal */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 16, 13, 0.68);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 82dvh;
  background: #172720;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.2);
}

.modal-header h2 {
  font-size: 16px;
  color: #ffe39e;
}

.close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
  line-height: 1.5;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  padding: 10px 12px;
  border-radius: 13px;
}

.shop-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.shop-emoji {
  font-size: 26px;
}

.shop-title {
  font-weight: 700;
  font-size: 14px;
}

.shop-meta {
  font-size: 11.5px;
  color: #b8ccc0;
}

.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, #38a169, #2f855a);
  color: #fff;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #f4f7f2;
}

.btn-danger {
  background: #c53030;
  color: #fff;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Penyesuaian Layar HP Sempit (Portrait) */
@media (max-width: 600px) {
  .hud-top {
    flex-wrap: wrap;
  }
  .hud-bars-box {
    order: 3;
    width: 100%;
    flex-direction: row;
    gap: 12px;
  }
  .bar-group {
    flex: 1;
  }
  .controls-layer {
    padding: 0 10px;
  }
  .joystick-zone {
    width: 102px;
    height: 102px;
  }
  .joystick-base {
    width: 92px;
    height: 92px;
  }
  .joystick-knob {
    width: 40px;
    height: 40px;
  }
  .action-btn {
    width: 74px;
    height: 74px;
  }
  .hotbar {
    position: absolute;
    left: 50%;
    bottom: 112px;
    transform: translateX(-50%);
    max-width: 94vw;
  }
}