* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  overflow: hidden;
  background: #0b0b14;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  -moz-user-drag: none;
  -ms-user-drag: none;
}

#c {
  width: 100vw;
  height: 100dvh;
  display: block;
  outline: none;
}

/* ── LOADING ── */
#loading {
  position: fixed;
  inset: 0;
  background: #080810;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 999;
  transition: opacity .6s;
}

#loading h1 {
  font-size: 28px;
  color: #00ff99;
  letter-spacing: 6px;
  margin-bottom: 8px;
  font-weight: 800;
  text-align: center;
}

#loading p {
  color: #556;
  font-size: 12px;
  margin-bottom: 30px;
  letter-spacing: 2px;
  font-weight: 600;
  text-align: center;
}

.bar-bg {
  width: 280px;
  height: 3px;
  background: #1a1a2a;
  border-radius: 2px;
}

.bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00ff99, #00aaff);
  border-radius: 2px;
  transition: width .3s;
}

.bar-label {
  margin-top: 10px;
  color: #445;
  font-size: 11px;
  text-align: center;
}

/* ── HUD ── */
#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  pointer-events: none;
  user-select: none;
  z-index: 100;
}

.panel {
  background: rgba(8, 8, 16, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 10px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.state-label {
  font-size: 9px;
  color: #6c6c8c;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 600;
}

.state-val {
  font-size: 22px;
  font-weight: 800;
  color: #00ff99;
  letter-spacing: 1px;
  margin: 2px 0;
  text-shadow: 0 0 10px rgba(0, 255, 153, 0.2);
}

.anim-val {
  font-size: 12px;
  color: #aeb4ff;
  font-weight: 500;
}

.weapon-val {
  font-size: 12px;
  color: #ffa500;
  margin-top: 2px;
  font-weight: 600;
}

.speed-val {
  font-size: 11px;
  color: #8c8c9c;
  font-family: monospace;
}

.keys-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  font-size: 11px;
}

.krow {
  color: #8c8c9c;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.krow span {
  display: inline-block;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 4px;
  padding: 2px 6px;
  color: #e0e0e6;
  font-size: 11px;
  margin-right: 8px;
  font-family: monospace;
  font-weight: bold;
}

/* ── CROSSHAIR ── */
#xhair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}

#xhair.on {
  opacity: .8;
}

#xhair::before,
#xhair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, .9);
}

#xhair::before {
  width: 2px;
  height: 100%;
  left: 50%;
  transform: translateX(-50%);
}

#xhair::after {
  height: 2px;
  width: 100%;
  top: 50%;
  transform: translateY(-50%);
}

/* ── COMBO ── */
#combo {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  font-weight: 800;
  color: #ffcc00;
  letter-spacing: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s, transform 0.3s;
  text-shadow: 0 0 15px rgba(255, 204, 0, 0.6);
  text-transform: uppercase;
}

#combo.show {
  opacity: 1;
  transform: translateX(-50%) scale(1.1);
}

/* ── SWIM INDICATOR ── */
#swim-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 60, 120, .7);
  border: 1px solid rgba(0, 200, 255, .4);
  border-radius: 20px;
  padding: 4px 16px;
  color: #0cf;
  font-size: 11px;
  letter-spacing: 2px;
  display: none;
}

#swim-bar.on {
  display: block;
}

/* ── MOBILE CONTROLS (GLASSMORPHISM) ── */
#mobile-ctrls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  display: none;
  /* Show only when touch device detected */
}

body.touch-device #mobile-ctrls {
  display: block;
}

#joystick-zone {
  position: absolute;
  bottom: 15px;
  left: 15px;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
}

#joystick-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid rgba(0, 255, 153, 0.25);
  backdrop-filter: blur(8px);
  box-shadow: 0 0 15px rgba(0, 255, 153, 0.1), inset 0 0 15px rgba(0, 255, 153, 0.05);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#joystick-ring.active {
  border-color: rgba(0, 255, 153, 0.6);
  box-shadow: 0 0 25px rgba(0, 255, 153, 0.3), inset 0 0 20px rgba(0, 255, 153, 0.1);
}

#joystick-knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3), 0 0 10px rgba(0, 255, 153, 0.2);
  backdrop-filter: blur(4px);
  position: absolute;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

#joystick-ring.active #joystick-knob {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(0, 255, 153, 0.8);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), 0 0 15px rgba(0, 255, 153, 0.5);
}

#action-btns {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: grid;
  grid-template-areas:
    "spell act crouch"
    "roll sprint jump";
  gap: 12px;
  pointer-events: auto;
  align-items: center;
  justify-items: center;
}

.touch-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255, 255, 255, 0.85);
  font-family: inherit;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 1.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.touch-btn:active,
.touch-btn.active {
  background: rgba(0, 255, 153, 0.22);
  border-color: rgba(0, 255, 153, 0.7);
  color: #fff;
  box-shadow: 0 0 16px rgba(0, 255, 153, 0.45);
  text-shadow: 0 0 5px rgba(0, 255, 153, 0.5);
}

.touch-btn:active {
  transform: scale(0.9);
}

.touch-btn.active {
  transform: scale(0.94);
}

#btn-sprint {
  grid-area: sprint;
  background: rgba(0, 170, 255, 0.05);
  border-color: rgba(0, 170, 255, 0.2);
}

#btn-sprint:active,
#btn-sprint.active {
  background: rgba(0, 170, 255, 0.22);
  border-color: rgba(0, 170, 255, 0.7);
  box-shadow: 0 0 16px rgba(0, 170, 255, 0.45);
  color: #fff;
  text-shadow: 0 0 5px rgba(0, 170, 255, 0.5);
}

#btn-sprint:active {
  transform: scale(0.9);
}

#btn-sprint.active {
  transform: scale(0.94);
}

#btn-jump {
  grid-area: jump;
  width: 70px;
  height: 70px;
  background: rgba(0, 255, 153, 0.07);
  border-color: rgba(0, 255, 153, 0.25);
  font-size: 9px;
}

#btn-roll {
  grid-area: roll;
}

#btn-crouch {
  grid-area: crouch;
}

#btn-act {
  grid-area: act;
  background: rgba(255, 102, 0, 0.05);
  border-color: rgba(255, 102, 0, 0.2);
}

#btn-act:active {
  background: rgba(255, 102, 0, 0.2);
  border-color: rgba(255, 102, 0, 0.6);
  box-shadow: 0 0 15px rgba(255, 102, 0, 0.4);
}

#btn-spell {
  grid-area: spell;
  background: rgba(168, 85, 247, 0.05);
  border-color: rgba(168, 85, 247, 0.25);
}

#btn-spell:active {
  background: rgba(168, 85, 247, 0.2);
  border-color: rgba(168, 85, 247, 0.6);
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.4);
}

/* Modify existing hud for touch compatibility */
body.touch-device #hud {
  top: 16px;
  bottom: auto;
  left: 16px;
  right: 16px;
  width: auto;
  max-width: none;
}

body.touch-device .keys-grid {
  display: none;
  /* Hide keyboard shortcut help on touch */
}

/* ── WEIGHT SLIDER ── */
.weight-container {
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 10px;
}

.weight-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.weight-label {
  font-size: 10px;
  color: #556;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.weight-val {
  font-size: 11px;
  font-weight: bold;
  color: #00ff99;
}

.slider-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.weight-slider {
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: #1a1a2a;
  outline: none;
  cursor: pointer;
  transition: background 0.3s;
}

.weight-slider::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  border-radius: 2px;
}

.weight-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #00ff99;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 255, 153, 0.6);
  transition: transform 0.1s, background-color 0.1s;
  margin-top: -4px;
}

.weight-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: #00ffcc;
  box-shadow: 0 0 12px rgba(0, 255, 204, 0.9);
}

.weight-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: #00ff99;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 255, 153, 0.6);
  transition: transform 0.1s, background-color 0.1s;
}

.weight-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  background: #00ffcc;
  box-shadow: 0 0 12px rgba(0, 255, 204, 0.9);
}

/* ── RESPONSIVE / MOBILE OPTIMIZATIONS ── */
@media (max-width: 600px) {
  #loading h1 {
    font-size: 20px;
    letter-spacing: 3px;
    line-height: 1.4;
  }

  #loading p {
    font-size: 10px;
    letter-spacing: 1px;
    margin-bottom: 20px;
  }
}

/* ── HUD TOGGLE BUTTON & COLLAPSE SYSTEM (PREMIUM TOP UX/UI) ── */
.main-panel {
  position: relative;
  transition: all 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 180px;
  overflow: hidden;
}

.hud-content {
  max-height: 400px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 0.45s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease, margin-top 0.45s ease;
  margin-top: 0;
}

#hud .panel.keys-grid {
  transition: max-height 0.45s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s ease, margin 0.45s ease, padding 0.45s ease, border-width 0.45s ease;
  max-height: 300px;
  opacity: 1;
  overflow: hidden;
}

#hud-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8c8c9c;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  z-index: 110;
}

#hud-toggle:hover {
  background: rgba(0, 255, 153, 0.15);
  border-color: rgba(0, 255, 153, 0.4);
  color: #00ff99;
  box-shadow: 0 0 8px rgba(0, 255, 153, 0.2);
}

#hud-toggle .toggle-icon {
  width: 14px;
  height: 14px;
  fill: currentColor;
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  transform: rotate(0deg);
}

/* Collapsed States - Morphs HUD into a single sleek glass bead */
#hud.collapsed .main-panel {
  min-width: 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border-color: rgba(0, 255, 153, 0.45);
  box-shadow: 0 0 15px rgba(0, 255, 153, 0.25);
  background: rgba(8, 8, 16, 0.85);
}

#hud.collapsed .hud-content {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

#hud.collapsed .panel.keys-grid {
  max-height: 0;
  opacity: 0;
  margin: 0;
  padding: 0;
  border-width: 0;
  pointer-events: none;
}

#hud.collapsed #hud-toggle {
  top: 50%;
  right: 50%;
  transform: translate(50%, -50%);
  background: transparent;
  border: none;
  color: #00ff99;
  width: 32px;
  height: 32px;
  box-shadow: none;
}

#hud.collapsed #hud-toggle:hover {
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 255, 153, 0.5);
}

#hud.collapsed #hud-toggle .toggle-icon {
  transform: rotate(180deg);
}

/* ── HUD SETTINGS TOGGLES (SWITCHES) ── */
.hud-toggle-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.switch-toggle {
  position: relative;
  display: inline-block;
  width: 28px;
  height: 16px;
  pointer-events: auto;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.slider-toggle:before {
  position: absolute;
  content: "";
  height: 10px;
  width: 10px;
  left: 2px;
  bottom: 2px;
  background-color: #8c8c9c;
  border-radius: 50%;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.switch-toggle input:checked+.slider-toggle {
  background-color: rgba(0, 255, 153, 0.15);
  border-color: rgba(0, 255, 153, 0.4);
  box-shadow: 0 0 10px rgba(0, 255, 153, 0.15);
}

.switch-toggle input:checked+.slider-toggle:before {
  transform: translateX(12px);
  background-color: #00ff99;
  box-shadow: 0 0 6px rgba(0, 255, 153, 0.8);
}

/* ── INDEPENDENT HUD FPS OVERLAY ── */
#hud-fps {
  position: fixed;
  top: 122px;
  /* Perfectly aligned inside the HUD panel vertically below spd: X with balanced spacing */
  left: 32px;
  font-size: 11px;
  color: #00aaff;
  font-family: monospace;
  transition: all 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 120;
  pointer-events: none;
}

/* Slide FPS to the top right corner with a premium glass border when the main HUD collapses */
#hud.collapsed+#hud-fps {
  top: 16px;
  left: auto;
  right: 16px;
  font-size: 13px;
  font-weight: 800;
  color: #00ff99;
  background: rgba(8, 8, 16, 0.65);
  border: 1px solid rgba(0, 255, 153, 0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 6px;
  padding: 4px 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

/* ── BUY ME A COFFEE PANEL ── */
.bmac-panel {
  transition: max-height 0.45s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s ease, margin 0.45s ease, padding 0.45s ease, border-width 0.45s ease;
  max-height: 200px;
  opacity: 1;
  overflow: hidden;
}

.bmac-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.bmac-tag {
  font-size: 9px;
  color: #ffcc00;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 800;
  text-shadow: 0 0 8px rgba(255, 204, 0, 0.3);
}

.bmac-text {
  font-size: 11px;
  color: #8c8c9c;
  line-height: 1.4;
}

.bmac-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
  background: linear-gradient(135deg, #ffdd00, #ffaa00);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  color: #0b0b14;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 4px 15px rgba(255, 170, 0, 0.25);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.bmac-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(255, 170, 0, 0.4);
  background: linear-gradient(135deg, #ffea00, #ffbb00);
}

.bmac-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 10px rgba(255, 170, 0, 0.2);
}

.bmac-icon {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Collapsed state support */
#hud.collapsed .panel.bmac-panel {
  max-height: 0;
  opacity: 0;
  margin: 0;
  padding: 0;
  border-width: 0;
  pointer-events: none;
}