:root {
  --color-primary: #10b981;
  --color-gold: #fbbf24;
  --color-gold-dark: #d97706;
  --color-bg-dark: rgba(15, 23, 42, 0.82);
  --color-card-bg: rgba(30, 41, 59, 0.92);
  --color-border: rgba(255, 255, 255, 0.16);
  --font-display: 'Fredoka', 'Outfit', sans-serif;
  --font-sans: 'Outfit', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0f172a;
  font-family: var(--font-sans);
  touch-action: none;
}

#game-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#game-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* HUD Overlay */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 14px) env(safe-area-inset-right, 14px) env(safe-area-inset-bottom, 14px) env(safe-area-inset-left, 14px);
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  z-index: 60;
  pointer-events: auto;
}

/* Stat Pill (Money) */
.stat-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-bg-dark);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  padding: 5px 16px 5px 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.coin-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fef08a, #eab308 60%, #ca8a04 100%);
  border: 2px solid #fef08a;
  box-shadow: 0 4px 10px rgba(234, 179, 8, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
  color: #713f12;
  animation: pulse-coin 2.5s infinite ease-in-out;
}

@keyframes pulse-coin {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); filter: brightness(1.15); }
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 9px;
  letter-spacing: 0.8px;
  font-weight: 800;
  color: #94a3b8;
  line-height: 1;
}

.stat-val {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Quest / Objective Banner */
.quest-banner {
  flex: 1;
  max-width: 340px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.quest-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.quest-text {
  font-size: 13px;
  font-weight: 600;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Top Right Actions */
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 70;
  pointer-events: auto;
  flex-shrink: 0;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-bg-dark);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  padding: 4px 10px 4px 10px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.user-name {
  max-width: 90px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-mini-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.logout-mini-btn:hover {
  opacity: 1;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--color-bg-dark);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--color-border);
  color: white;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease, background-color 0.2s ease, border-color 0.2s ease;
  position: relative;
  z-index: 80;
  pointer-events: auto !important;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.2);
}

.icon-btn:hover {
  transform: scale(1.08);
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(30, 41, 59, 0.95);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn span {
  pointer-events: none;
}

/* Backpack Card */
.backpack-card {
  position: absolute;
  top: 72px;
  left: 14px;
  background: var(--color-bg-dark);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1.5px solid var(--color-border);
  border-radius: 18px;
  padding: 10px 12px;
  min-width: 170px;
  pointer-events: auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.backpack-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.backpack-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #94a3b8;
}

.backpack-count {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: #38bdf8;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  border-radius: 999px;
  transition: width 0.2s ease-out;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  font-size: 11px;
  color: #cbd5e1;
  font-weight: 600;
}

.inv-item {
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 6px;
}

.inv-icon {
  font-size: 12px;
}

.full-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ef4444;
  color: white;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.5);
  animation: bounce-full 0.6s infinite alternate ease-in-out;
}

@keyframes bounce-full {
  from { transform: scale(0.95); }
  to { transform: scale(1.1); }
}

/* Floating Upgrades FAB */
.upgrades-fab {
  position: absolute;
  bottom: 30px;
  right: 20px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border: 2px solid #fef08a;
  border-radius: 999px;
  padding: 10px 20px 10px 14px;
  box-shadow: 0 8px 24px rgba(217, 119, 6, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.4);
  cursor: pointer;
  z-index: 20;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  animation: pulse-fab 2.5s infinite ease-in-out;
}

.upgrades-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 30px rgba(217, 119, 6, 0.7);
}

.upgrades-fab:active {
  transform: scale(0.95);
}

@keyframes pulse-fab {
  0%, 100% { box-shadow: 0 8px 24px rgba(217, 119, 6, 0.5); }
  50% { box-shadow: 0 12px 32px rgba(245, 158, 11, 0.85); }
}

.fab-icon {
  font-size: 22px;
}

.fab-text {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.fab-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ef4444;
  color: white;
  border: 2px solid #ffffff;
  border-radius: 999px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#settings-modal {
  z-index: 250;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  background: var(--color-card-bg);
  border: 1.5px solid var(--color-border);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-enter 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.92) translateY(15px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--color-border);
}

.modal-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-icon {
  font-size: 24px;
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 20px;
  color: #ffffff;
  letter-spacing: 0.5px;
}

.modal-close-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #cbd5e1;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

/* Category Tabs */
.upgrade-tabs, .auth-tabs {
  display: flex;
  padding: 10px 18px;
  gap: 8px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  scrollbar-width: none;
}

.upgrade-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  color: #94a3b8;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.5);
  color: #38bdf8;
}

/* Upgrade Item Rows */
.upgrades-list-container {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upgrade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 12px 14px;
  gap: 12px;
}

.upgrade-row-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.up-icon-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.up-details {
  display: flex;
  flex-direction: column;
}

.up-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.up-desc {
  font-size: 11px;
  color: #94a3b8;
}

.up-lvl {
  font-size: 11px;
  color: #38bdf8;
  font-weight: 700;
}

.btn-buy-upgrade {
  background: linear-gradient(135deg, #10b981, #059669);
  border: 1.5px solid #6ee7b7;
  color: white;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
  transition: transform 0.1s, opacity 0.2s;
  min-width: 90px;
  text-align: center;
}

.btn-buy-upgrade:disabled {
  background: #334155;
  border-color: #475569;
  color: #64748b;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-buy-upgrade.maxed {
  background: rgba(255, 255, 255, 0.08);
  border-color: transparent;
  color: #10b981;
  cursor: default;
}

/* Auth Modal Card */
.auth-card {
  max-width: 400px;
  padding: 24px;
}

.auth-subtext {
  font-size: 13px;
  color: #94a3b8;
  margin-top: 6px;
  line-height: 1.4;
}

.auth-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
}

.form-group input {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 10px 14px;
  color: #ffffff;
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: #38bdf8;
}

.auth-error-msg {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 8px;
}

.primary-action-btn {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: 1.5px solid #60a5fa;
  color: white;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
  transition: transform 0.1s;
}

.primary-action-btn:active {
  transform: scale(0.98);
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  color: #64748b;
  font-size: 12px;
}

.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.auth-divider span {
  padding: 0 10px;
}

.secondary-action-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.secondary-action-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Toast Messages */
#toast-container {
  position: absolute;
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 50;
}

.toast {
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border: 1.5px solid rgba(245, 158, 11, 0.6);
  border-radius: 999px;
  padding: 8px 18px;
  color: #fef08a;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toast-pop 2.2s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes toast-pop {
  0% { opacity: 0; transform: translateY(15px) scale(0.8); }
  15% { opacity: 1; transform: translateY(0) scale(1.05); }
  25% { transform: translateY(0) scale(1); }
  80% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-20px) scale(0.9); }
}

/* Virtual Joystick */
#joystick-zone {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
  z-index: 5;
}

#joystick-base {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.03) 70%, rgba(255, 255, 255, 0.25) 100%);
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), inset 0 2px 10px rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#joystick-thumb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #60a5fa, #2563eb 70%, #1d4ed8 100%);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.6);
  transform: translate(-50%, -50%);
}

.desktop-hint {
  align-self: center;
  margin-bottom: 8px;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 14px;
  border-radius: 999px;
  color: #94a3b8;
  font-size: 11px;
  pointer-events: none;
}

.desktop-hint b {
  color: #e2e8f0;
}

.hidden {
  display: none !important;
}

.floating-coin-num {
  position: absolute;
  color: #fbbf24;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: float-up-fade 1s forwards ease-out;
  z-index: 60;
}

@keyframes float-up-fade {
  0% { opacity: 1; transform: translateY(0) scale(0.8); }
  40% { transform: translateY(-25px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-55px) scale(1); }
}

@media (hover: none) and (pointer: coarse) {
  .desktop-hint {
    display: none;
  }
}

/* Quest Tracker Card */
.quest-tracker-card {
  position: absolute;
  top: 72px;
  right: 14px;
  background: var(--color-bg-dark);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1.5px solid rgba(251, 191, 36, 0.4);
  border-radius: 18px;
  padding: 10px 14px;
  min-width: 190px;
  max-width: 260px;
  pointer-events: auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4), 0 0 15px rgba(245, 158, 11, 0.15);
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: float-banner 3s ease-in-out infinite;
}

.quest-tracker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.quest-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #fbbf24;
}

.quest-reward-pill {
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.5);
  border-radius: 999px;
  padding: 2px 8px;
  color: #fef08a;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
}

.quest-title-text {
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.3;
}

.quest-tracker-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  margin-top: 2px;
}

.quest-progress-num {
  font-family: var(--font-display);
  font-size: 13px;
  color: #38bdf8;
  font-weight: 700;
}

/* Raid Warning Banner */
.raid-banner {
  position: absolute;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  border: 2px solid #fecaca;
  border-radius: 999px;
  padding: 10px 22px;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 30px rgba(220, 38, 38, 0.7), 0 0 20px rgba(239, 68, 68, 0.6);
  z-index: 45;
  pointer-events: none;
  animation: pulse-raid 1s infinite alternate ease-in-out;
}

@keyframes pulse-raid {
  from { transform: translateX(-50%) scale(0.96); filter: brightness(1); }
  to { transform: translateX(-50%) scale(1.04); filter: brightness(1.2); }
}

.raid-icon {
  font-size: 20px;
}

.raid-text {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

/* Floating Coin Number on Sales */
.floating-coin-num {
  position: fixed;
  pointer-events: none;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 900;
  color: #fbbf24;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8), 0 0 14px rgba(251, 191, 36, 0.7);
  z-index: 120;
  transform: translate(-50%, -50%);
  animation: float-up-fade 1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes float-up-fade {
  0% {
    opacity: 1;
    transform: translate(-50%, 0) scale(0.85);
  }
  40% {
    opacity: 1;
    transform: translate(-50%, -26px) scale(1.25);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -55px) scale(1.0);
  }
}

/* ==========================================================================
   SETTINGS MODAL & CONTROLS
   ========================================================================== */
.settings-gear-icon {
  display: inline-block;
  transition: transform 0.3s ease;
}

#btn-settings:hover .settings-gear-icon {
  transform: rotate(45deg);
}

.settings-card {
  max-width: 530px;
  max-height: 92vh;
}

.settings-content {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: 78vh;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.settings-section {
  background: rgba(15, 23, 42, 0.6);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.8px;
}

.settings-section-title .sec-icon {
  font-size: 16px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.setting-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.setting-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.setting-desc {
  font-size: 12px;
  color: #94a3b8;
}

/* Modern iOS-Style Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #334155;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 34px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 2.5px;
  background-color: #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-switch input:checked + .toggle-slider {
  background: linear-gradient(135deg, #10b981, #059669);
  border-color: #6ee7b7;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(21px);
}

/* Custom Range Slider */
.slider-container {
  width: 140px;
  display: flex;
  align-items: center;
}

.custom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #334155;
  outline: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
}

.custom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #67e8f9, #0284c7);
  border: 2px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4), 0 0 10px rgba(56, 189, 248, 0.6);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.custom-slider::-webkit-slider-thumb:active {
  transform: scale(1.18);
}

.custom-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #67e8f9, #0284c7);
  border: 2px solid #ffffff;
  cursor: pointer;
}

/* Graphics Presets 3-Column Grid */
.graphics-presets-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.preset-card {
  background: rgba(15, 23, 42, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  outline: none;
}

.preset-card:hover {
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

.preset-top {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preset-tag {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  display: inline-block;
  width: fit-content;
}

.tag-low {
  background: rgba(100, 116, 139, 0.25);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.tag-med {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.tag-high {
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.3), rgba(168, 85, 247, 0.3));
  color: #f472b6;
  border: 1px solid rgba(244, 114, 182, 0.5);
  text-shadow: 0 0 8px rgba(244, 114, 182, 0.5);
}

.preset-fps-badge {
  font-size: 10px;
  font-weight: 700;
  color: #cbd5e1;
  opacity: 0.85;
}

.preset-summary {
  font-size: 10px;
  line-height: 1.35;
  color: #94a3b8;
}

/* Active Preset Card States */
.preset-card.active {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.15);
  box-shadow: 0 4px 18px rgba(56, 189, 248, 0.25);
}

.preset-card.active#preset-btn-low {
  border-color: #94a3b8;
  background: rgba(148, 163, 184, 0.15);
  box-shadow: 0 4px 14px rgba(148, 163, 184, 0.2);
}

.preset-card.active#preset-btn-high {
  border-color: #ec4899;
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.2), rgba(168, 85, 247, 0.22));
  box-shadow: 0 6px 24px rgba(236, 72, 153, 0.35), 0 0 12px rgba(168, 85, 247, 0.3);
}

/* Preset Specifications Box */
.preset-specs-panel {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px 12px;
}

.spec-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #cbd5e1;
}

.spec-bullet {
  color: #10b981;
  font-weight: 800;
  font-size: 12px;
}

.spec-item.disabled {
  color: #64748b;
  text-decoration: line-through;
}

.spec-item.disabled .spec-bullet {
  color: #64748b;
}

/* FPS Presets Grid */
.fps-presets-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.sec-title-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fps-live-badge {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.4);
  letter-spacing: 0.5px;
}

.tag-fps-30 {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.4);
}

.tag-fps-60 {
  background: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.tag-fps-max {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(234, 88, 12, 0.3));
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.5);
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

.fps-preset-card.active#fps-btn-30 {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.15);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.25);
}

.fps-preset-card.active#fps-btn-60 {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.15);
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.25);
}

.fps-preset-card.active#fps-btn-max {
  border-color: #f59e0b;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(234, 88, 12, 0.22));
  box-shadow: 0 6px 22px rgba(245, 158, 11, 0.35), 0 0 12px rgba(234, 88, 12, 0.3);
}

.settings-footer {
  padding: 14px 20px;
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--color-border);
}

/* ==========================================================================
   MOBILE RESPONSIVENESS & SMARTPHONE OPTIMIZATION
   Guaranteed 100% untouched and intact on desktop / PC (width >= 900px)
   ========================================================================== */
@media (max-width: 820px) {
  #hud {
    padding: env(safe-area-inset-top, 6px) env(safe-area-inset-right, 6px) env(safe-area-inset-bottom, 6px) env(safe-area-inset-left, 6px);
  }

  /* 1. Header & Top Bar */
  .top-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 8px;
    width: 100%;
    padding: 0 2px;
  }

  /* Money Pill (Left) */
  .stat-pill.money-pill {
    order: 1;
    padding: 2px 10px 2px 5px;
    gap: 6px;
    height: 36px;
    border-width: 1.5px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  }

  .coin-icon {
    width: 28px;
    height: 28px;
    font-size: 15px;
  }

  .stat-label {
    font-size: 7.5px;
    letter-spacing: 0.5px;
  }

  .stat-val {
    font-size: 16px;
    line-height: 1;
  }

  /* Top Right Actions (Sound, Settings, Profile) */
  .top-actions {
    order: 2;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
  }

  .user-pill {
    padding: 3px 6px;
    gap: 3px;
    height: 36px;
    font-size: 11px;
    border-width: 1.5px;
  }

  /* Compact avatar pill on small screens: icon + mini logout, hide long text */
  .user-pill .user-name {
    display: none;
  }

  .user-icon {
    font-size: 14px;
  }

  .logout-mini-btn {
    font-size: 12px;
    padding: 0;
  }

  /* Sound & Settings buttons ALWAYS fully visible */
  .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 15px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  }

  /* Quest Banner: Wraps neatly into line 2 below header */
  .quest-banner {
    order: 3;
    width: 100%;
    max-width: 100%;
    flex: unset;
    margin: 2px 0 0 0;
    padding: 4px 10px;
    height: 26px;
    justify-content: center;
    gap: 6px;
    border-radius: 999px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  }

  .quest-icon {
    font-size: 13px;
  }

  .quest-text {
    font-size: 11px;
    max-width: 86%;
  }

  /* 2. Backpack Card (Compact, Left) */
  .backpack-card {
    top: 78px;
    left: 6px;
    min-width: unset;
    width: 122px;
    padding: 5px 7px;
    border-radius: 12px;
    gap: 3px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    background: rgba(15, 23, 42, 0.88);
  }

  .backpack-title {
    font-size: 9px;
    letter-spacing: 0.5px;
    gap: 3px;
  }

  .backpack-icon {
    font-size: 11px;
  }

  .backpack-count {
    font-size: 12px;
  }

  .progress-track {
    height: 4px;
  }

  .inventory-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 2px;
    font-size: 9px;
  }

  .inv-item {
    padding: 1px 3px;
    border-radius: 4px;
    gap: 2px;
  }

  .inv-icon {
    font-size: 10px;
  }

  .full-badge {
    font-size: 8px;
    padding: 2px 5px;
    top: -6px;
    right: -6px;
  }

  /* 3. Quest Contract Card (Compact, Right) */
  .quest-tracker-card {
    top: 78px;
    right: 6px;
    min-width: unset;
    width: 134px;
    max-width: 140px;
    padding: 5px 7px;
    border-radius: 12px;
    gap: 3px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    background: rgba(15, 23, 42, 0.88);
  }

  .quest-badge {
    font-size: 8px;
    letter-spacing: 0.4px;
  }

  .quest-reward-pill {
    font-size: 8.5px;
    padding: 1px 5px;
  }

  .quest-title-text {
    font-size: 9.5px;
    line-height: 1.2;
    max-height: 2.4em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .quest-tracker-footer {
    font-size: 8.5px;
    margin-top: 1px;
  }

  .quest-progress-num {
    font-size: 10.5px;
  }

  /* Raid Warning Banner (Non-colliding position) */
  .raid-banner {
    top: 136px;
    padding: 6px 14px;
    font-size: 11px;
    max-width: 90%;
    gap: 6px;
  }

  .raid-icon {
    font-size: 16px;
  }

  .raid-text {
    font-size: 11px;
  }

  /* 4. Bottom Upgrades FAB */
  .upgrades-fab {
    bottom: 12px;
    right: 8px;
    padding: 6px 12px 6px 10px;
    gap: 5px;
    border-width: 1.5px;
    box-shadow: 0 6px 18px rgba(217, 119, 6, 0.5);
  }

  .fab-icon {
    font-size: 16px;
  }

  .fab-text {
    font-size: 11px;
  }

  .fab-badge {
    width: 18px;
    height: 18px;
    font-size: 9px;
    top: -5px;
    right: -5px;
    border-width: 1.5px;
  }

  /* Hide Desktop Keyboard Controls Text on Mobile */
  .desktop-hint {
    display: none !important;
  }

  /* 5. Touch Virtual Joystick Dimensions */
  #joystick-base {
    width: 104px;
    height: 104px;
  }

  #joystick-thumb {
    width: 44px;
    height: 44px;
  }

  /* 6. Settings & General Modals Mobile Adaptation */
  .modal-card {
    width: 95vw;
    max-width: 430px;
    max-height: 88vh;
    border-radius: 18px;
  }

  .modal-header {
    padding: 10px 14px 8px;
  }

  .modal-header h2 {
    font-size: 16px;
  }

  .modal-close-btn {
    width: 32px;
    height: 32px;
    font-size: 20px;
  }

  .upgrades-list-container {
    padding: 10px 12px;
    gap: 8px;
  }

  .upgrade-row {
    padding: 8px 10px;
    gap: 8px;
    border-radius: 12px;
  }

  .up-icon-badge {
    width: 36px;
    height: 36px;
    font-size: 18px;
    border-radius: 10px;
  }

  .up-title {
    font-size: 13px;
  }

  .up-desc {
    font-size: 10px;
  }

  .btn-buy-upgrade {
    padding: 6px 12px;
    font-size: 12px;
    min-width: 76px;
  }

  /* Settings Modal on Smartphones */
  .settings-card {
    width: 95vw;
    max-width: 430px;
    max-height: 90vh;
  }

  .settings-content {
    padding: 8px 10px;
    gap: 8px;
    max-height: 74vh;
  }

  .settings-section {
    padding: 8px 10px;
    border-radius: 14px;
    gap: 6px;
  }

  .settings-section-title {
    font-size: 11px;
    gap: 6px;
  }

  .setting-name {
    font-size: 13px;
  }

  .setting-desc {
    font-size: 10px;
  }

  .toggle-switch {
    width: 46px;
    height: 26px;
  }

  .toggle-slider:before {
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 2.5px;
  }

  .toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(18px);
  }

  .slider-container {
    width: 110px;
  }

  .graphics-presets-row,
  .fps-presets-row {
    gap: 6px;
  }

  .preset-card,
  .fps-preset-card {
    padding: 7px 5px;
    border-radius: 10px;
    gap: 3px;
  }

  .preset-tag {
    font-size: 11px;
    padding: 2px 5px;
  }

  .preset-fps-badge {
    font-size: 9px;
  }

  .preset-summary {
    display: none;
  }

  .preset-specs-panel {
    padding: 6px 8px;
    gap: 4px 8px;
    grid-template-columns: 1fr;
  }

  .spec-item {
    font-size: 9.5px;
  }

  .settings-footer {
    padding: 8px 14px;
  }

  .primary-action-btn {
    padding: 8px 16px;
    font-size: 13px;
  }
}

/* Extra small mobile screens (e.g. 320px - 360px) */
@media (max-width: 360px) {
  .backpack-card {
    width: 112px;
    left: 4px;
    padding: 4px 5px;
  }

  .quest-tracker-card {
    width: 122px;
    right: 4px;
    padding: 4px 5px;
  }

  .stat-pill.money-pill {
    padding: 2px 6px 2px 4px;
    gap: 4px;
  }

  .stat-val {
    font-size: 14px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }
}

/* Mobile Landscape orientation optimization */
@media (max-height: 500px) and (orientation: landscape) {
  .backpack-card {
    top: 52px;
    width: 120px;
    padding: 4px 6px;
  }

  .quest-tracker-card {
    top: 52px;
    width: 130px;
    padding: 4px 6px;
  }

  .quest-banner {
    display: none; /* Hide top banner in landscape to conserve vertical height */
  }

  .upgrades-fab {
    bottom: 8px;
    right: 8px;
    padding: 5px 10px;
  }

  .modal-card {
    max-height: 94vh;
  }

  .settings-content {
    max-height: 68vh;
  }
}

