/* Modern MMORPG UI - Inspired by Lost Ark, Albion Online, Genshin Impact */

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

:root {
  --primary-gold: #FFD700;
  --primary-silver: #C0C0C0;
  --primary-bronze: #CD7F32;
  --dark-bg: rgba(10, 10, 20, 0.85);
  --panel-bg: rgba(20, 20, 35, 0.9);
  --hp-green: #00ff88;
  --hp-yellow: #ffaa00;
  --hp-red: #ff3333;
  --mana-blue: #3399ff;
  --shadow-glow: 0 0 20px rgba(0, 0, 0, 0.8);
  --embed-bg: #3d6b2e;
}

/* Kill white letterboxing when embedded in an iframe */
html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--embed-bg);
  background-color: var(--embed-bg);
  color-scheme: dark;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  font-family: 'Rajdhani', 'Segoe UI', sans-serif;
  background-color: var(--embed-bg);
  background-image: url('../assets/epic-back.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  overflow: hidden;
  position: relative;
}

canvas {
  display: block;
  margin: 0;
  background: #3d6b2e;
  overflow: hidden;
  cursor: crosshair;
}

/* Main game canvas — sized via JS bitmap attrs (avoid CSS stretch mismatch) */
#game {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  display: block;
}

/* Fog of War — sized via JS; never leave default 300×150 cut */
#fog-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
  pointer-events: none;
  display: block;
}

/* =========================
   HUD - Modern Top Bar (Desktop: 20% | 40% | 20%)
   ========================= */

#game-hud {
  position: fixed;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 1400px;
  background: transparent;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  gap: 15px;
  justify-content: space-between;
}

.hud-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stat-bar-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-icon {
  font-size: 20px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}

.stat-bar {
  position: relative;
  width: 100%;
  max-width: 450px;
  min-width: 250px;
  height: 38px;
  background: rgba(0, 0, 0, 0.7);
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 
    inset 0 2px 8px rgba(0,0,0,0.8),
    0 4px 12px rgba(0,0,0,0.4);
}

.stat-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  transition: width 0.3s ease;
  border-radius: 10px;
}

.hp-bar-fill {
  background: linear-gradient(90deg, #ff3333 0%, #ff6666 50%, #ff3333 100%);
  box-shadow: 0 0 15px rgba(255, 51, 51, 0.8);
}

.hp-bar-fill.high {
  background: linear-gradient(90deg, #00ff88 0%, #00ffaa 50%, #00ff88 100%);
  box-shadow: 0 0 15px rgba(0, 255, 136, 0.6);
}

.hp-bar-fill.medium {
  background: linear-gradient(90deg, #ffaa00 0%, #ffcc00 50%, #ffaa00 100%);
  box-shadow: 0 0 15px rgba(255, 170, 0, 0.6);
}

.stat-text {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 50%;
  transform: translateY(-50%);
  color: white;
  font-weight: 900;
  font-size: 18px;
  text-shadow: 
    0 2px 4px rgba(0,0,0,1),
    0 0 15px rgba(0,0,0,0.9),
    2px 2px 0 rgba(0,0,0,0.8),
    -1px -1px 0 rgba(0,0,0,0.8);
  letter-spacing: 1px;
  z-index: 10;
}

/* =========================
   Player Stats Panel (Desktop: 25% of HUD width)
   ========================= */

#player-stats {
  position: relative;
  flex: 0 0 25%;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 12px;
  padding: 15px 20px;
  box-shadow: var(--shadow-glow);
}

#player-stats h3,
#player-stats .panel-header {
  color: var(--primary-gold);
  font-size: 16px;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  border-bottom: 2px solid rgba(255, 215, 0, 0.3);
  padding: 8px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#player-stats .panel-header:hover {
  background: rgba(0, 0, 0, 0.4);
  border-bottom-color: var(--primary-gold);
}

/* Hide mobile title on desktop, show toggle icon */
.mobile-title {
  display: none;
}

/* Show desktop title and toggle icon */
.desktop-title {
  display: inline;
}

#player-stats .toggle-icon,
#leaderboard .toggle-icon {
  display: inline;
  margin-left: 8px;
  font-size: 14px;
  transition: transform 0.3s ease;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-value {
  color: white;
  font-weight: 700;
  font-size: 16px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.stat-value.special {
  color: var(--primary-gold);
  font-size: 18px;
}

/* =========================
   HUD Center - HP Bar (Desktop: 50% of HUD width)
   ========================= */

.hud-center {
  flex: 0 0 50%;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 12px;
  padding: 12px 25px;
  box-shadow: var(--shadow-glow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud-center-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  align-items: center;
}

/* Zoom Control */
.zoom-control {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 350px;
}

.zoom-label {
  font-size: 18px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}

.zoom-slider {
  flex: 1;
  height: 6px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 5px;
  outline: none;
  opacity: 0.9;
  transition: opacity 0.2s;
  cursor: pointer;
}

.zoom-slider:hover {
  opacity: 1;
}

.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--primary-gold);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
  transition: all 0.2s;
}

.zoom-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.9);
}

.zoom-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--primary-gold);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
  transition: all 0.2s;
}

.zoom-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.9);
}

.zoom-value {
  color: white;
  font-weight: 700;
  font-size: 14px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  min-width: 45px;
  text-align: right;
}

/* =========================
   Leaderboard - Modern Right Panel (Desktop: 25% of HUD width)
   ========================= */

#leaderboard {
  position: relative;
  flex: 0 0 25%;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 12px;
  padding: 15px 20px;
  box-shadow: var(--shadow-glow);
}

#leaderboard h3,
#leaderboard .panel-header {
  color: var(--primary-gold);
  font-size: 16px;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid rgba(255, 215, 0, 0.3);
  padding: 8px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
}

#leaderboard .panel-header:hover {
  background: rgba(0, 0, 0, 0.4);
  border-bottom-color: var(--primary-gold);
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  margin: 6px 0;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  border-left: 4px solid transparent;
  transition: all 0.2s ease;
}

.leaderboard-entry:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(3px);
}

.leaderboard-entry.rank-1 {
  border-left-color: var(--primary-gold);
  background: rgba(255, 215, 0, 0.1);
}

.leaderboard-entry.rank-2 {
  border-left-color: var(--primary-silver);
}

.leaderboard-entry.rank-3 {
  border-left-color: var(--primary-bronze);
}

.rank-icon {
  font-size: 24px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
}

.player-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-name {
  color: white;
  font-weight: 600;
  font-size: 15px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.player-stats-line {
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  display: flex;
  gap: 12px;
}

/* =========================
   Floating Text - Enhanced
   ========================= */

.damage-text, .bonus-text {
  position: absolute;
  font-size: 24px;
  font-weight: 900;
  animation: floatUp 1.2s ease-out forwards;
  pointer-events: none;
  z-index: 2000;
  font-family: 'Impact', 'Arial Black', sans-serif;
  letter-spacing: 1px;
}

.damage-text {
  color: #ff3333;
  text-shadow: 
    0 0 10px rgba(255, 51, 51, 0.8),
    2px 2px 4px rgba(0, 0, 0, 0.9),
    -1px -1px 2px rgba(255, 100, 100, 0.5);
}

.bonus-text {
  color: #33ff33;
  text-shadow: 
    0 0 10px rgba(51, 255, 51, 0.8),
    2px 2px 4px rgba(0, 0, 0, 0.9),
    -1px -1px 2px rgba(100, 255, 100, 0.5);
}

@keyframes floatUp {
  0% {
    transform: translateY(0) scale(0.5);
    opacity: 0;
  }
  20% {
    opacity: 1;
    transform: translateY(-10px) scale(1.3);
  }
  80% {
    opacity: 1;
    transform: translateY(-40px) scale(1.1);
  }
  100% {
    transform: translateY(-60px) scale(0.8);
    opacity: 0;
  }
}

/* =========================
   Death Screen - Dramatic
   ========================= */

#death-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(139, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.95) 100%);
  display: none;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 9999;
  animation: fadeIn 0.5s ease-in;
}

#death-screen.visible {
  display: flex;
}

#death-screen h1 {
  color: #ff3333;
  font-size: 96px;
  text-shadow: 
    0 0 30px rgba(255, 0, 0, 0.8),
    4px 4px 12px rgba(0, 0, 0, 0.9);
  margin-bottom: 30px;
  animation: deathPulse 1.5s ease-in-out infinite;
  font-weight: 900;
  letter-spacing: 8px;
}

#death-screen p {
  color: white;
  font-size: 28px;
  text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.9);
  animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes deathPulse {
  0%, 100% { 
    transform: scale(1) rotate(0deg); 
    filter: drop-shadow(0 0 30px rgba(255, 0, 0, 0.8));
  }
  50% { 
    transform: scale(1.08) rotate(-2deg); 
    filter: drop-shadow(0 0 50px rgba(255, 0, 0, 1));
  }
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* =========================
   Loading Screen - Elegant
   ========================= */

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e 0%, #0f0f1e 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 10000;
}

#loading-screen.hidden {
  display: none;
}

#loading-screen h2 {
  color: var(--primary-gold);
  font-size: 42px;
  margin-bottom: 30px;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
  letter-spacing: 3px;
  animation: loadingPulse 2s ease-in-out infinite;
}

@keyframes loadingPulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

.spinner {
  border: 6px solid rgba(255, 215, 0, 0.2);
  border-top: 6px solid var(--primary-gold);
  border-radius: 50%;
  width: 70px;
  height: 70px;
  animation: spin 1s linear infinite;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.4);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* =========================
   Mobile Controls — 360° virtual stick + ATK
   ========================= */

#mobile-controls {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1250;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#mobile-controls .joystick-zone,
#mobile-controls .joystick-base,
#mobile-controls .atk-pad,
#mobile-controls .mobile-attack-btn {
  pointer-events: auto;
}

.joystick-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 48%;
  max-width: 220px;
  height: 44%;
  max-height: 300px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.joystick-base {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(110px, calc(96px + env(safe-area-inset-bottom)));
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(20, 28, 18, 0.45);
  border: 2px solid rgba(220, 230, 200, 0.4);
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.3);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.88;
}

.joystick-base.active {
  opacity: 1;
  border-color: rgba(200, 240, 140, 0.7);
  background: rgba(30, 42, 24, 0.55);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 28%, #b8d88a, #4a6b32 72%);
  border: 2px solid rgba(255, 255, 230, 0.55);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* Large exclusive thumb pad — blocks map under/near ATK */
.atk-pad {
  position: absolute;
  right: 0;
  bottom: max(72px, calc(60px + env(safe-area-inset-bottom)));
  width: 140px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}

.mobile-attack-btn {
  position: relative;
  right: auto;
  bottom: auto;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 3px solid rgba(255, 210, 120, 0.7);
  background: radial-gradient(circle at 35% 28%, rgba(120, 180, 70, 0.95), rgba(40, 70, 30, 0.9) 72%);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.06em;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.08s linear, transform 0.08s ease, filter 0.08s ease;
}

.mobile-attack-btn .atk-label {
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
}

.mobile-attack-btn:active,
.mobile-attack-btn.pressed {
  transform: scale(0.92);
  filter: brightness(1.12);
}

.mobile-attack-btn.on-cooldown {
  opacity: 0.28;
  border-color: rgba(180, 180, 160, 0.35);
  filter: grayscale(0.35);
}

.mobile-attack-btn.ready {
  opacity: 1;
}

body.is-mobile-ui {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body.is-mobile-ui input,
body.is-mobile-ui textarea {
  -webkit-user-select: text;
  user-select: text;
}

body.is-mobile-ui #game {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1250;
  pointer-events: auto;
}
#panel-backdrop.hidden { display: none; }

.mobile-only-block { display: none; }

@media (max-width: 1024px), (pointer: coarse) {
  #mobile-controls {
    display: block;
  }
  body.is-mobile-ui #mobile-controls {
    display: block;
  }
}

/* =========================
   Desktop - Panels are collapsible
   ========================= */

@media (min-width: 901px) {
  .collapsible-panel .panel-content {
    max-height: 400px;
    overflow-y: auto;
    transition: max-height 0.3s ease, opacity 0.3s ease;
  }

  .collapsible-panel.collapsed .panel-content {
    max-height: 0 !important;
    opacity: 0 !important;
    overflow: hidden;
  }

  .collapsible-panel.collapsed .toggle-icon {
    transform: rotate(-90deg);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.collapsible-panel {
  transition: all 0.3s ease;
}

.collapsible-panel .panel-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0;
  padding: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}

.collapsible-panel .toggle-icon {
  transition: transform 0.3s ease;
  font-size: 0.8em;
}

.collapsible-panel.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.collapsible-panel .panel-content {
  max-height: 500px;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}

.collapsible-panel.collapsed .panel-content {
  max-height: 0;
  opacity: 0;
}

/* =========================
   Mobile / tablet game UI
   ========================= */

@media (max-width: 900px) {
  .desktop-title { display: none !important; }
  .mobile-title { display: inline !important; }
  .mobile-only-block { display: block; }

  /* Slim top status strip — keep playfield clear */
  #game-hud {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    transform: none !important;
    max-width: none !important;
    display: grid !important;
    grid-template-columns: 48px 1fr 48px;
    align-items: center !important;
    gap: 6px !important;
    padding: max(8px, env(safe-area-inset-top)) 8px 8px !important;
    background: linear-gradient(180deg, rgba(8, 14, 8, 0.78), rgba(8, 14, 8, 0.15)) !important;
    z-index: 1200 !important;
    pointer-events: none;
  }

  #game-hud .collapsible-panel,
  #game-hud .hud-center,
  #game-hud .panel-header {
    pointer-events: auto;
  }

  .world-label { display: none !important; }
  .zoom-control { display: none !important; }

  .mobile-left-panel,
  .mobile-right-panel {
    width: 48px !important;
    min-width: 48px !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    position: relative !important;
  }

  .mobile-left-panel .panel-header,
  .mobile-right-panel .panel-header {
    width: 44px;
    height: 44px;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 12px !important;
    background: rgba(20, 30, 18, 0.85) !important;
    border: 1px solid rgba(180, 210, 140, 0.4) !important;
    font-size: 18px !important;
  }

  .mobile-left-panel .toggle-icon,
  .mobile-right-panel .toggle-icon {
    display: none;
  }

  .mobile-left-panel .panel-content,
  .mobile-right-panel .panel-content {
    position: absolute !important;
    top: calc(100% + 6px) !important;
    background: rgba(12, 18, 12, 0.97) !important;
    border: 1px solid rgba(180, 210, 140, 0.5) !important;
    border-radius: 12px !important;
    padding: 10px !important;
    min-width: 160px !important;
    max-height: 55vh !important;
    overflow-y: auto !important;
    z-index: 1300 !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  }

  .mobile-left-panel .panel-content { left: 0 !important; }
  .mobile-right-panel .panel-content { right: 0 !important; left: auto !important; }

  .mobile-left-panel.collapsed .panel-content,
  .mobile-right-panel.collapsed .panel-content {
    display: none !important;
  }

  .hud-center {
    width: auto !important;
    min-width: 0 !important;
  }

  .hud-center-content {
    width: 100%;
    gap: 4px;
  }

  .hud-center .stat-bar-container {
    width: 100% !important;
    margin: 0 !important;
  }

  .hud-center .stat-icon {
    font-size: 10px;
    min-width: 22px;
  }

  .hud-center .stat-bar {
    height: 16px !important;
    border-radius: 999px;
  }

  .hud-center .stat-text {
    font-size: 13px !important;
    text-shadow: 0 1px 3px #000, 0 0 6px #000;
    color: #ffffff !important;
  }

  .xp-bar-container .stat-bar {
    height: 16px !important;
    background: rgba(0, 0, 0, 0.85) !important;
    border-color: rgba(200, 230, 150, 0.45) !important;
  }

  .xp-bar-container .stat-text {
    font-size: 12px !important;
    letter-spacing: 0.5px;
  }

  /* Bottom menu dock — thumb zone center */
  #panel-dock {
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: min(320px, calc(100vw - 24px));
    justify-content: space-between;
    gap: 6px;
    padding: 6px;
    background: rgba(12, 18, 12, 0.88);
    border: 1px solid rgba(170, 200, 130, 0.35);
    border-radius: 18px;
    backdrop-filter: blur(10px);
    z-index: 1200 !important;
  }

  .dock-btn {
    flex: 1;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    border-radius: 14px;
    font-size: 10px;
    border: none;
    background: transparent;
    color: #e8f5d8;
    -webkit-tap-highlight-color: transparent;
  }

  .dock-btn.active,
  .dock-btn:active {
    background: rgba(120, 170, 70, 0.35);
  }

  .dock-icon { font-size: 18px; line-height: 1; }
  .dock-label { font-size: 10px; opacity: 0.9; }

  /* Bottom sheets for game panels */
  #game-panels {
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    transform: none !important;
    width: 100% !important;
    max-width: none !important;
    z-index: 1300 !important;
    pointer-events: none;
  }

  #game-panels .game-panel {
    pointer-events: auto;
    position: relative;
    margin: 0;
    width: 100%;
    max-height: min(72vh, 620px);
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 14px 14px max(18px, env(safe-area-inset-bottom));
    animation: sheetUp 0.22s ease-out;
  }

  #game-panels .game-panel.hidden {
    display: none;
  }

  @keyframes sheetUp {
    from { transform: translateY(24px); opacity: 0.6; }
    to { transform: translateY(0); opacity: 1; }
  }

  .panel-title-bar h3 {
    font-size: 18px;
  }

  .panel-close {
    width: 44px;
    height: 44px;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .item-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .item-cell {
    min-height: 72px;
    padding: 10px 6px;
    font-size: 12px;
    border-radius: 12px;
  }

  .equip-slot {
    min-height: 72px;
    border-radius: 12px;
  }

  .spend-btn,
  .settings-btn,
  .signup-soon-btn {
    min-height: 48px;
    border-radius: 12px;
    font-size: 15px;
    width: 100%;
  }

  .spend-row {
    flex-direction: column;
  }

  /* Consumables — compact, above dock, clear of mid-screen controls */
  #consumables-bar {
    bottom: max(66px, calc(58px + env(safe-area-inset-bottom))) !important;
    z-index: 1210 !important;
    gap: 4px !important;
    padding: 2px 4px;
  }

  .consumable-slot {
    width: 32px !important;
    height: 32px !important;
    border-radius: 8px !important;
    padding: 0 !important;
  }

  .consumable-slot .c-icon { font-size: 13px !important; }
  .consumable-slot .c-qty { font-size: 9px !important; right: 2px; bottom: 1px; }
  .consumable-slot .c-key { display: none !important; }

  #toast-host {
    top: auto;
    bottom: max(160px, calc(150px + env(safe-area-inset-bottom)));
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(90vw, 320px);
    align-items: center;
  }

  #death-screen h1 {
    font-size: 40px;
  }

  #death-screen p {
    font-size: 14px;
    padding: 0 16px;
  }

  /* Keep canvas free of accidental text selection */
  canvas {
    touch-action: none;
  }
}

@media (max-width: 420px) {
  .joystick-base {
    width: 112px;
    height: 112px;
  }
  .joystick-knob {
    width: 48px;
    height: 48px;
  }
  .atk-pad {
    width: 128px;
    height: 148px;
  }
  .mobile-attack-btn {
    width: 80px;
    height: 80px;
    font-size: 13px;
  }
}


/* === Mine to Legend beta panels === */
.world-label {
  text-align: center;
  color: #eef8d8;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
  text-shadow: 0 1px 3px #000;
}

.xp-bar-fill {
  background: linear-gradient(90deg, #3d6b2e, #8fd46a) !important;
}

.xp-bar-container .stat-bar {
  background: rgba(8, 12, 8, 0.92);
  border-color: rgba(180, 210, 140, 0.4);
}

#xp-text {
  color: #f5ffe8 !important;
  font-weight: 800;
}

#panel-dock {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 1200;
  pointer-events: auto;
}

.dock-btn {
  background: rgba(20, 28, 18, 0.85);
  border: 1px solid rgba(180, 200, 140, 0.45);
  color: #e8f0d8;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
}

.dock-btn:hover { background: rgba(40, 55, 35, 0.95); }

#game-panels {
  position: fixed;
  top: 110px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1300;
  width: min(440px, 92vw);
}

.game-panel {
  background: rgba(22, 32, 20, 0.97);
  border: 1px solid rgba(180, 210, 140, 0.55);
  border-radius: 8px;
  padding: 12px;
  color: #f2ffe8;
  max-height: 60vh;
  overflow: auto;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

.game-panel.hidden { display: none; }

.panel-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.panel-close {
  background: transparent;
  border: none;
  color: #ccc;
  font-size: 22px;
  cursor: pointer;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.item-cell {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
  min-height: 88px;
  user-select: none;
  -webkit-user-select: none;
}
.item-cell.selected { outline: 2px solid #c9a227; }
.item-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  width: 100%;
  justify-content: center;
}
.item-act {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 4px;
  min-height: 34px;
  border-radius: 6px;
  border: 1px solid #6a8f55;
  background: #2f4a28;
  color: #eef5e4;
  cursor: pointer;
}
.item-act.drop {
  border-color: #b06060;
  background: #5a2828;
}
#inv-count { font-weight: 500; opacity: 0.95; font-size: 13px; color: #c9e0a8; }

.item-icon { display: block; font-size: 22px; }
.item-name { font-size: 13px; font-weight: 600; color: #f5ffe8; }
.item-lvl { opacity: 0.95; font-size: 12px; color: #d5e8c0; }

.equip-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.equip-slot {
  min-height: 64px;
  border: 1px dashed rgba(200,200,160,0.35);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
}

.equip-slot.filled {
  border-style: solid;
  background: rgba(100, 120, 70, 0.2);
}

.slot-label { font-size: 11px; opacity: 0.85; display: block; color: #d8ecc0; }
.panel-hint, .empty-hint, .guest-banner {
  font-size: 13px;
  opacity: 1;
  color: #e8f5d8;
  line-height: 1.4;
}
.guest-banner {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 10px;
  border-radius: 6px;
  border-left: 3px solid #8fd46a;
}

.element-picker {
  margin: 10px 0 14px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
}
.element-picker h4 {
  margin: 0 0 6px;
  font-size: 14px;
}
.element-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.element-btn {
  background: rgba(20, 28, 18, 0.9);
  border: 2px solid #6a8f55;
  color: #eef5e4;
  padding: 10px 8px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  min-height: 44px;
}
.element-btn:hover, .element-btn:focus {
  filter: brightness(1.15);
}

.spend-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.spend-btn, .settings-btn, .signup-soon-btn {
  background: #2f4a28;
  border: 1px solid #6a8f55;
  color: #eef5e4;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 4px;
}
.signup-soon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.derived-stats { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.derived-stats li {
  background: rgba(255,255,255,0.08);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: #f2ffe8;
}

.element-chosen {
  margin: 8px 0 0;
  font-weight: 700;
  font-size: 15px;
  color: #ffe8a0 !important;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

#consumables-bar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 1200;
}

.consumable-slot {
  width: 52px;
  height: 52px;
  background: rgba(18, 24, 16, 0.92);
  border: 1px solid rgba(170, 190, 130, 0.55);
  border-radius: 6px;
  color: #fff;
  position: relative;
  cursor: pointer;
}
.consumable-slot:disabled { opacity: 0.55; cursor: default; }
.c-icon { font-size: 18px; }
.c-qty { position: absolute; right: 4px; bottom: 2px; font-size: 11px; font-weight: 700; }
.c-key {
  position: absolute;
  left: 4px;
  top: 2px;
  font-size: 11px;
  font-weight: 700;
  opacity: 1;
  color: #e8f5d8;
  text-shadow: 0 1px 2px #000;
}

/* Mobile override must follow base consumable rules (cascade) */
@media (max-width: 900px), (pointer: coarse) {
  #consumables-bar {
    bottom: max(66px, calc(58px + env(safe-area-inset-bottom)));
    gap: 4px;
  }
  .consumable-slot {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }
  .consumable-slot .c-icon { font-size: 13px; }
  .consumable-slot .c-key { display: none; }
}

#toast-host {
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 1400;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.toast {
  background: rgba(20, 30, 18, 0.95);
  color: #f2ffe8;
  padding: 10px 14px;
  border-radius: 6px;
  border-left: 3px solid #8fd46a;
  font-size: 14px;
  font-weight: 600;
  text-shadow: 0 1px 2px #000;
  max-width: 280px;
}

.beta-cap-row .stat-value { color: #f0c040; }

.settings-zoom {
  margin-top: 12px;
}
.settings-zoom label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}
.settings-zoom input[type="range"] {
  width: 100%;
}

