/* =============================================================================
   mobile-nav.css - Arcane Rebirth: Modern Dark-Fantasy Mobile Navigation
   Ergonomic Persistent Bottom Bar & Slide-Up Secondary Drawer
   Strictly Scoped to Mobile (viewport < 768px)
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. Desktop Reset & Responsive Guard (>= 768px)
   ----------------------------------------------------------------------------- */
@media (min-width: 768px) {
  .mobile-bottom-nav,
  .mobile-drawer,
  .mobile-drawer-overlay {
    display: none !important;
  }
}

/* -----------------------------------------------------------------------------
   2. Mobile Scoped Styles (< 768px)
   ----------------------------------------------------------------------------- */
@media (max-width: 767.98px) {

  /* Body safe-area spacing so fixed bottom bar & live chat ticker never overlap content (pb-28 clearance) */
  body {
    padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body.mobile-drawer-open {
    overflow: hidden !important;
    touch-action: none;
  }

  body.mobile-drawer-open .global-chat-ticker,
  body.touch-modal-open .global-chat-ticker,
  body.touch-modal-open .global-chat-ticker-wrap {
    display: none !important;
  }

  body.touch-modal-open .mobile-bottom-nav {
    display: none !important;
  }

  /* Header refactor: Hide old hamburger toggle and raw logout button */
  .nav-mobile-toggle {
    display: none !important;
  }

  .nav-logout-btn {
    display: none !important;
  }

  /* Keep top header dedicated to Brand, Sound widget, and Avatar profile */
  .site-nav {
    position: sticky;
    top: 0;
    z-index: 900;
  }

  .nav-inner {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 0.75rem !important;
    height: 52px;
  }

  .nav-brand-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .nav-brand {
    display: flex !important;
    align-items: center;
    gap: 0.4rem;
    font-size: 1.05rem;
    text-decoration: none;
  }

  .nav-brand__logo {
    height: 30px;
    width: auto;
  }

  .nav-brand-name {
    display: inline-block !important;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
  }

  .nav-user {
    display: flex !important;
    align-items: center;
    gap: 0.6rem;
    margin-left: auto !important;
  }

  .nav-username {
    display: none !important; /* Kept concise for mobile header */
  }

  .nav-staff-tools {
    display: none !important; /* Kept on desktop, accessible via More drawer on mobile */
  }

  .nav-avatar {
    width: 32px;
    height: 32px;
    border: 2px solid var(--c-gold, #e8c96b);
    box-shadow: 0 0 10px rgba(232, 201, 107, 0.25);
  }

  /* Old desktop nav-links list hidden on mobile */
  .nav-links {
    display: none !important;
  }

  /* ---------------------------------------------------------------------------
     2.5 Global Toast / Flash Positioning (Top Heads-Up Notification)
     --------------------------------------------------------------------------- */
  .flash-container,
  .toast-container,
  .global-toast-container {
    position: fixed !important;
    top: calc(56px + env(safe-area-inset-top, 0px) + 8px) !important;
    bottom: auto !important;
    left: 16px !important;
    right: 16px !important;
    width: auto !important;
    max-width: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 8px !important;
    z-index: 1100 !important; /* Above sticky header (900) and page modals */
    pointer-events: none !important; /* Container wrapper never blocks game taps */
  }

  .flash,
  .toast {
    pointer-events: auto !important; /* Dismiss button & toast remain interactive */
    width: 100% !important;
    max-width: 480px !important;
    box-sizing: border-box !important;
    animation: mobileToastSlideDown 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65), 0 0 14px rgba(0, 0, 0, 0.45) !important;
  }

  .flash__close {
    pointer-events: auto !important;
  }

  @keyframes mobileToastSlideDown {
    from {
      opacity: 0;
      transform: translateY(-16px) scale(0.98);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  /* ---------------------------------------------------------------------------
     3. Persistent Mobile Bottom Bar
     --------------------------------------------------------------------------- */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    background: rgba(10, 12, 22, 0.94);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid rgba(232, 201, 107, 0.22);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
    user-select: none;
  }

  .mobile-bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    min-width: 48px;
    padding: 0.35rem 0.2rem;
    color: var(--c-text-muted, #7a729a);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    position: relative;
    transition: color 0.18s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-bottom-nav__item:active {
    transform: scale(0.92);
    color: var(--c-gold, #e8c96b);
  }

  .mobile-bottom-nav__item:hover {
    color: var(--c-text, #ddd8f0);
  }

  .mobile-bottom-nav__item.is-active {
    color: var(--c-gold, #e8c96b);
  }

  /* Glowing active top indicator pip */
  .mobile-bottom-nav__item.is-active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 2.5px;
    background: linear-gradient(90deg, transparent, var(--c-gold, #e8c96b), transparent);
    box-shadow: 0 0 10px rgba(232, 201, 107, 0.7);
    border-radius: 2px;
  }

  .mobile-bottom-nav__icon-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
  }

  .mobile-bottom-nav__icon {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    transition: transform 0.2s ease, filter 0.2s ease;
  }

  .mobile-bottom-nav__item.is-active .mobile-bottom-nav__icon {
    filter: drop-shadow(0 0 6px rgba(232, 201, 107, 0.45));
    transform: translateY(-1px);
  }

  .mobile-bottom-nav__label {
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.03em;
    margin-top: 3px;
    font-family: var(--font-body, 'Inter', sans-serif);
    text-transform: capitalize;
  }

  /* Dynamic notification badges */
  .mobile-nav-badge {
    position: absolute;
    top: -4px;
    right: -7px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 9999px;
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    color: #ffffff;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    border: 1.5px solid #0a0c16;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    animation: badgePulse 2.4s infinite ease-in-out;
  }

  .mobile-nav-badge--dot {
    width: 9px;
    height: 9px;
    min-width: 9px;
    top: -2px;
    right: -3px;
    padding: 0;
  }

  @keyframes badgePulse {
    0%, 100% {
      transform: scale(1);
      box-shadow: 0 0 8px rgba(239, 68, 68, 0.8);
    }
    50% {
      transform: scale(1.12);
      box-shadow: 0 0 14px rgba(239, 68, 68, 1);
    }
  }

  /* ---------------------------------------------------------------------------
     4. Secondary Bottom Sheet / Drawer ("More")
     --------------------------------------------------------------------------- */
  .mobile-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4, 5, 10, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
  }

  .mobile-drawer-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-drawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1045;
    max-height: 84vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #13162b 0%, #0c0e1b 100%);
    border-top: 1px solid rgba(232, 201, 107, 0.35);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transform: translateY(105%);
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-drawer.is-open {
    transform: translateY(0);
  }

  /* Drag handle & header */
  .mobile-drawer__handle-wrap {
    width: 100%;
    padding: 8px 0 4px;
    display: flex;
    justify-content: center;
    cursor: grab;
  }

  .mobile-drawer__handle {
    width: 44px;
    height: 4.5px;
    background: rgba(255, 255, 255, 0.22);
    border-radius: 9999px;
  }

  .mobile-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 1.25rem 0.65rem;
    border-bottom: 1px solid rgba(138, 100, 255, 0.15);
  }

  .mobile-drawer__title {
    font-family: var(--font-display, 'Cinzel', serif);
    font-size: 1rem;
    font-weight: 700;
    color: var(--c-gold, #e8c96b);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: 0.05em;
  }

  .mobile-drawer__title-sigil {
    font-size: 0.85rem;
    color: var(--c-primary, #8a64ff);
    filter: drop-shadow(0 0 6px rgba(138, 100, 255, 0.6));
  }

  .mobile-drawer__close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    color: var(--c-text-muted, #7a729a);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .mobile-drawer__close-btn:active {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
    transform: scale(0.92);
  }

  /* Drawer Scrollable Content */
  .mobile-drawer__content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .mobile-drawer__section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-display, 'Cinzel', serif);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--c-gold, #e8c96b);
    margin-bottom: 0.45rem;
  }

  .mobile-drawer__section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, rgba(232, 201, 107, 0.25), transparent);
  }

  /* 3-Column Touch Grid */
  .mobile-drawer__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
  }

  .mobile-drawer__grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 68px;
    min-width: 48px;
    padding: 0.65rem 0.35rem;
    background: rgba(20, 24, 46, 0.65);
    border: 1px solid rgba(138, 100, 255, 0.18);
    border-radius: 12px;
    text-decoration: none;
    color: var(--c-text, #ddd8f0);
    position: relative;
    transition: all 0.16s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-drawer__grid-item:active {
    background: rgba(138, 100, 255, 0.2);
    border-color: rgba(232, 201, 107, 0.5);
    color: #ffffff;
    transform: scale(0.95);
    box-shadow: 0 0 16px rgba(138, 100, 255, 0.3);
  }

  .mobile-drawer__grid-item.is-active {
    background: rgba(138, 100, 255, 0.18);
    border-color: rgba(232, 201, 107, 0.55);
    color: var(--c-gold, #e8c96b);
    box-shadow: 0 0 14px rgba(232, 201, 107, 0.25);
  }

  .mobile-drawer__grid-icon-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
  }

  .mobile-drawer__grid-icon {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    color: var(--c-gold, #e8c96b);
    transition: transform 0.15s ease;
  }

  .mobile-drawer__grid-item:active .mobile-drawer__grid-icon {
    transform: scale(1.1);
  }

  .mobile-drawer__grid-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.15;
    letter-spacing: 0.02em;
    font-family: var(--font-body, 'Inter', sans-serif);
  }

  /* ---------------------------------------------------------------------------
     5. System Strip (Logout, Settings, Manual)
     --------------------------------------------------------------------------- */
  .mobile-drawer__system-strip {
    margin-top: 0.75rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .mobile-drawer__system-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1;
    min-height: 48px;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    font-size: 0.76rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--c-text-muted, #7a729a);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-drawer__system-link:active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--c-text, #ddd8f0);
    transform: scale(0.96);
  }

  .mobile-drawer__system-link--danger {
    color: var(--c-error, #f87171);
    background: rgba(248, 113, 113, 0.06);
    border-color: rgba(248, 113, 113, 0.22);
  }

  .mobile-drawer__system-link--danger:active {
    background: rgba(248, 113, 113, 0.2);
    border-color: rgba(248, 113, 113, 0.5);
    color: #ffffff;
  }

  .mobile-drawer__system-icon {
    width: 17px;
    height: 17px;
    stroke: currentColor;
    flex-shrink: 0;
  }
}
