:root{ 
  --nav-h:64px; 
  --nav-gap:8px;
  --blue:#1E40AF; 
  --red:#DC143C;
  --purple:#a855f7;
  --glow-blue: 0 0 20px rgba(30, 64, 175, 0.5);
  --glow-red: 0 0 20px rgba(220, 20, 60, 0.5);
  --glow-purple: 0 0 20px rgba(168, 85, 247, 0.5);
}
html { scroll-padding-top: calc(var(--nav-h) + var(--nav-gap)); }
html, body { margin:0; }
body.has-fixed-nav { padding-top: calc(var(--nav-h) + var(--nav-gap)); }
.dfb-navbar{ 
  position:fixed; 
  top:0; 
  left:0; 
  right:0; 
  height:var(--nav-h); 
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-bottom: 1px solid rgba(30, 64, 175, 0.4);
  z-index:9999; 
  display:flex; 
  align-items:center; 
  box-shadow: 0 4px 20px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.05);
}
.dfb-nav-inner{ 
  max-width:1100px; 
  margin:0 auto; 
  display:flex; 
  align-items:center; 
  gap:20px; 
  width:100%; 
  padding:0 16px; 
}
.dfb-nav-inner a{ 
  color:#e2e8f0; 
  text-decoration:none; 
  font-weight:600; 
  padding:8px 12px;
  border-radius:8px;
  transition: all 0.3s ease;
  position:relative;
}
.dfb-nav-inner a:hover{
  color: var(--blue);
  background: rgba(30, 64, 175, 0.1);
  box-shadow: var(--glow-blue);
}

.dfb-nav-inner a:active{
  background: rgba(30, 64, 175, 0.2);
  box-shadow: var(--glow-blue), inset 0 2px 4px rgba(0,0,0,0.2);
  transform: translateY(0); /* Prevent any movement on click */
}
/* Removed :first-child selector to avoid conflicts - using .brand class instead */

/* Right side group: Language selector + Connect button (fixed position) */
.nav-right-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto; /* Push to the right side */
}

/* Wallet button */
.nav-wallet{
  height: 44px;
  padding: 0 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(30, 35, 48, 0.8), rgba(42, 47, 58, 0.8));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #e2e8f0;
  border: 2px solid rgba(30, 64, 175, 0.4);
  cursor: pointer;
  font-weight: 700;
  line-height: 40px;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
}
.nav-wallet:hover{
  background: linear-gradient(135deg, rgba(36, 42, 58, 0.9), rgba(47, 52, 68, 0.9));
  border-color: rgba(30, 64, 175, 0.8);
  box-shadow: var(--glow-blue), 0 4px 12px rgba(0,0,0,0.3);
  transform: translateY(-1px);
}
.nav-wallet:active{
  background: linear-gradient(135deg, #1a2e3a, #2a3f4a);
  box-shadow: var(--glow-blue), inset 0 2px 4px rgba(0,0,0,0.2);
}
.nav-wallet.connected{
  background: linear-gradient(135deg, #1a2e3a, #2a3f4a);
  border-color: rgba(30, 64, 175, 0.8);
  box-shadow: 0 0 15px rgba(30, 64, 175, 0.6);
  animation: neonPulse 2s ease-in-out infinite;
}


/* Brand link (DeFiBall) inline with others but bolder */
.dfb-nav-inner a.brand{
  font-weight:800;
  margin-right:16px;
  font-size: 1.1rem;
}

/* Keyframe Animations */
@keyframes neonPulse {
  0%, 100% { 
    box-shadow: 0 0 5px var(--glow-blue), 0 0 10px var(--glow-blue); 
  }
  50% { 
    box-shadow: 0 0 10px var(--glow-blue), 0 0 20px var(--glow-blue); 
  }
}

/* Hamburger Menu for Mobile */
.nav-toggle {
  display: none;
}

.nav-toggle-label {
  display: none;
  cursor: pointer;
  padding: 10px;
  margin-right: 0;
  margin-left: 0;
  order: 999; /* Last item - far right */
  z-index: 10001;
}

.nav-toggle-label span,
.nav-toggle-label span::before,
.nav-toggle-label span::after {
  display: block;
  background: var(--blue);
  height: 3px;
  width: 28px;
  border-radius: 3px;
  position: relative;
  transition: all 0.3s ease;
  box-shadow: 0 0 8px var(--blue);
}

.nav-toggle-label span::before,
.nav-toggle-label span::after {
  content: '';
  position: absolute;
}

.nav-toggle-label span::before {
  top: -8px;
}

.nav-toggle-label span::after {
  top: 8px;
}

/* Animated hamburger to X */
.nav-toggle:checked ~ .nav-toggle-label span {
  background: transparent;
  box-shadow: none;
}

.nav-toggle:checked ~ .nav-toggle-label span::before {
  transform: rotate(45deg);
  top: 0;
}

.nav-toggle:checked ~ .nav-toggle-label span::after {
  transform: rotate(-45deg);
  top: 0;
}

/* Mobile Navigation Overlay */
.nav-menu-mobile {
  position: fixed;
  top: var(--nav-h);
  left: -100%;
  width: 280px;
  height: calc(100vh - var(--nav-h));
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-right: 2px solid rgba(30, 64, 175, 0.6);
  box-shadow: 4px 0 20px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
  transition: left 0.3s ease;
  z-index: 10000;
  overflow-y: auto;
}

.nav-toggle:checked ~ .dfb-nav-inner .nav-menu-mobile {
  left: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .nav-toggle-label {
    display: block;
  }

  .dfb-nav-inner {
    position: relative;
    justify-content: space-between;
  }
  
  .dfb-nav-inner a.brand {
    order: -1; /* First item - far left */
    margin-left: 0;
    margin-right: auto;
  }

  .dfb-nav-inner a:not(.brand) {
    display: none;
  }

  .dfb-nav-inner .nav-wallet {
    display: none;
  }

  .dfb-nav-inner .nav-right-group {
    display: none;
  }
  
  .dfb-nav-inner .lang-selector {
    display: none;
  }

  /* Show mobile menu */
  .nav-menu-mobile {
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 0;
  }

  .nav-menu-mobile a {
    display: block !important;
    padding: 16px 20px;
    color: var(--fg);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    transition: all 0.3s ease;
    border-radius: 8px;
    margin-bottom: 8px;
  }

  .nav-menu-mobile a:hover {
    background: rgba(30, 64, 175, 0.1);
    border-right: 4px solid var(--blue);
    padding-right: 24px;
    box-shadow: var(--glow-blue);
  }

  /* NO wallet button in mobile menu */
  .nav-menu-mobile .nav-wallet {
    display: none !important;
  }

  .dfb-nav-inner a.brand {
    font-size: 1rem;
  }

  .dfb-nav-inner a.brand img {
    height: 28px;
  }
}

/* Language Selector */
.lang-selector {
  position: relative;
  /* Remove margins - spacing handled by nav-right-group */
}

/* Hide language selector in MetaMask in-app browser (same logic as Connect button) */
html.metamask-inapp .dfb-nav-inner .nav-right-group,
html.metamask-inapp .dfb-nav-inner .lang-selector,
html.metamask-inapp .lang-selector {
  display: none !important;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(30, 35, 48, 0.8), rgba(42, 47, 58, 0.8));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #e2e8f0;
  border: 2px solid rgba(30, 64, 175, 0.4);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
  white-space: nowrap; /* Prevent text wrapping */
}

.lang-btn:hover {
  background: linear-gradient(135deg, rgba(36, 42, 58, 0.9), rgba(47, 52, 68, 0.9));
  border-color: rgba(30, 64, 175, 0.8);
  box-shadow: var(--glow-blue), 0 4px 12px rgba(0,0,0,0.3);
  transform: translateY(-1px);
}

.lang-btn:active {
  transform: translateY(0);
}

.lang-flag {
  width: 24px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0; /* Prevent flag from shrinking */
  display: inline-block; /* Ensure proper rendering */
}

.lang-name {
  font-weight: 600;
  white-space: nowrap; /* Prevent text wrapping */
  display: inline-block; /* Ensure proper rendering */
  /* Ensure no pseudo-elements add content */
}

/* Ensure no ::before or ::after add content to language elements */
.lang-btn .lang-flag::before,
.lang-btn .lang-flag::after,
.lang-btn .lang-name::before,
.lang-btn .lang-name::after {
  content: none !important;
  display: none !important;
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 2px solid rgba(30, 64, 175, 0.6);
  border-radius: 12px;
  box-shadow: var(--glow-blue), 0 8px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 10001;
  overflow: hidden;
}

.lang-selector.active .lang-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: #e2e8f0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: left;
  transition: all 0.2s ease;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.lang-option:last-child {
  border-bottom: none;
}

.lang-option:hover {
  background: rgba(30, 64, 175, 0.2);
  color: var(--blue);
}

.lang-option:active {
  background: rgba(30, 64, 175, 0.3);
}

.lang-option .lang-flag {
  width: 26px;
  height: 20px;
  object-fit: contain;
  flex-shrink: 0;
}

.lang-option .lang-name {
  flex: 1;
}

/* Mobile Language Selector */
.lang-selector-mobile {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Mobile Language Toggle Button */
.lang-mobile-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px 20px;
  background: rgba(30, 64, 175, 0.1);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #e2e8f0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: left;
  transition: all 0.2s ease;
}

.lang-mobile-toggle:hover {
  background: rgba(30, 64, 175, 0.2);
  border-color: rgba(30, 64, 175, 0.4);
  box-shadow: var(--glow-blue);
}

.lang-mobile-toggle:active {
  background: rgba(30, 64, 175, 0.3);
}

.lang-toggle-text {
  flex: 1;
}

.lang-toggle-arrow {
  font-size: 0.75rem;
  transition: transform 0.3s ease;
  color: rgba(255, 255, 255, 0.7);
}

/* Rotate arrow when submenu is expanded */
.lang-selector-mobile.expanded .lang-toggle-arrow {
  transform: rotate(180deg);
}

/* Mobile Language Submenu (scrollable, shows ~3 languages at a time) */
.lang-mobile-submenu {
  max-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 0;
  transition: max-height 0.3s ease, margin-top 0.3s ease;
  border-radius: 0 0 8px 8px;
}

/* Expanded state */
.lang-selector-mobile.expanded .lang-mobile-submenu {
  max-height: 200px; /* Approximately 3 languages visible (each ~60-65px) */
  margin-top: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  /* Custom scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: rgba(30, 64, 175, 0.5) rgba(255, 255, 255, 0.1);
}

.lang-selector-mobile.expanded .lang-mobile-submenu::-webkit-scrollbar {
  width: 6px;
}

.lang-selector-mobile.expanded .lang-mobile-submenu::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
}

.lang-selector-mobile.expanded .lang-mobile-submenu::-webkit-scrollbar-thumb {
  background: rgba(30, 64, 175, 0.5);
  border-radius: 3px;
}

.lang-selector-mobile.expanded .lang-mobile-submenu::-webkit-scrollbar-thumb:hover {
  background: rgba(30, 64, 175, 0.7);
}

/* Language options inside submenu */
.lang-selector-mobile .lang-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  background: rgba(30, 64, 175, 0.05);
  color: #e2e8f0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: left;
  transition: all 0.2s ease;
  width: 100%;
}

.lang-selector-mobile .lang-option:first-child {
  border-top: 1px solid rgba(255,255,255,0.05);
}

.lang-selector-mobile .lang-option:last-child {
  border-bottom: none;
}

.lang-selector-mobile .lang-option:hover {
  background: rgba(30, 64, 175, 0.2);
  border-color: rgba(30, 64, 175, 0.3);
  box-shadow: inset 0 0 10px rgba(30, 64, 175, 0.1);
}

.lang-selector-mobile .lang-option:active {
  background: rgba(30, 64, 175, 0.3);
}

.lang-selector-mobile .lang-option .lang-flag {
  width: 28px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
}

.lang-selector-mobile .lang-option .lang-name {
  flex: 1;
  font-weight: 600;
}

/* Mobile menu: Language names only (no codes) */
/* Removed ::after pseudo-elements that displayed EN/ZH codes */

/* Desktop: Ensure right group stays fixed */
@media (min-width: 769px) {
  .nav-right-group {
    flex-shrink: 0; /* Prevent shrinking */
  }
  
  .lang-selector {
    flex-shrink: 0; /* Prevent shrinking */
  }
}

/* Accessibility - Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
