/* ====================================================================
   MAGIC SPIN - ULTRA-FLUID RESPONSIVE ENGINE (320px - 1440px+)
   ==================================================================== */

/* Grid Column Spans */
.col-span-1 { grid-column: span 1 / span 1; }
.col-span-2 { grid-column: span 2 / span 2; }
.col-span-3 { grid-column: span 3 / span 3; }
.col-span-4 { grid-column: span 4 / span 4; }

/* Global Viewport Overflow Guard & Mobile Button Desktop Hide */
html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden !important;
  position: relative;
}

.sidebar-close-btn,
.mobile-menu-btn {
  display: none;
}

/* ====================================================================
   TABLET BREAKPOINT (<= 1024px)
   ==================================================================== */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 260px;
    --topbar-height: 60px;
  }

  .app-sidebar {
    transform: translateX(-100%) !important;
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    z-index: 300 !important;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.8) !important;
    visibility: hidden;
    pointer-events: none;
  }

  .app-sidebar.open {
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .sidebar-close-btn {
    display: inline-flex !important;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
  }

  .app-main {
    margin-left: 0 !important;
    max-width: 100vw !important;
    width: 100% !important;
  }

  .app-topbar {
    padding: 0 1.25rem;
  }

  .app-content {
    padding: 1.5rem 1.25rem 5.5rem;
    max-width: 100vw;
  }

  .grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .col-span-3, .col-span-2 {
    grid-column: span 2 / span 2;
  }
}

/* ====================================================================
   MOBILE PHONES BREAKPOINT (<= 768px)
   ==================================================================== */
@media (max-width: 768px) {
  .mobile-nav {
    display: flex !important;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
  }

  .logout-icon-mobile {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  .topbar-logout-btn {
    width: 28px !important;
    height: 28px !important;
    padding: 0 !important;
    border-radius: 6px !important;
    flex-shrink: 0 !important;
  }

  .nav-links {
    display: none !important;
  }

  .hide-on-mobile {
    display: none !important;
  }

  .app-content {
    padding: 1.25rem 0.85rem 6rem !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }

  .grid-cols-1,
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .metrics-strip {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }

  .col-span-1,
  .col-span-2,
  .col-span-3,
  .col-span-4 {
    grid-column: span 1 / span 1 !important;
  }

  .card {
    padding: 1.25rem 1rem !important;
    border-radius: 14px !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .hero-welcome-card {
    padding: 1.25rem 1rem !important;
    border-radius: 14px !important;
  }

  /* Referral Share Bar Mobile Alignment */
  .referral-share-bar {
    padding: 0.85rem 0.85rem !important;
    border-radius: 14px !important;
  }
  .referral-bar-inner {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.65rem !important;
  }
  .referral-bar-title {
    width: 100% !important;
  }
  .referral-title-text {
    font-size: 0.85rem !important;
  }
  .referral-bar-action {
    width: 100% !important;
    max-width: 100% !important;
    flex-direction: row !important;
    gap: 0.4rem !important;
  }
  .referral-bar-action input {
    min-width: 0 !important;
    flex: 1 1 auto !important;
    font-size: 0.75rem !important;
    padding: 0.4rem 0.6rem !important;
    height: 36px !important;
  }
  .referral-copy-btn {
    padding: 0 0.85rem !important;
    font-size: 0.8rem !important;
    height: 36px !important;
  }

  .hero-title {
    font-size: 1.85rem !important;
    line-height: 1.2 !important;
  }

  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.35rem !important; }
  h3 { font-size: 1.2rem !important; }
  h4 { font-size: 1.05rem !important; }

  /* Table Horizontal Scrolling within Cards */
  .table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    display: block !important;
  }

  .table th, .table td {
    padding: 0.75rem 0.65rem !important;
    font-size: 0.8rem !important;
  }

  /* Spin Roulette Container on Mobile */
  .spin-container {
    padding: 0.5rem 0 !important;
  }

  .casino-roulette-stage {
    padding: 0.5rem 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .roulette-housing {
    width: min(330px, 86vw) !important;
    height: min(330px, 86vw) !important;
    max-width: min(330px, 86vw) !important;
    max-height: min(330px, 86vw) !important;
    aspect-ratio: 1 / 1 !important;
    padding: 8px !important;
    margin: 0 auto !important;
  }

  .roulette-wheel-turntable {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 1 / 1 !important;
  }

  .roulette-wheel-canvas {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 1 / 1 !important;
  }

  .spin-wheel-outer {
    width: min(300px, 82vw) !important;
    height: min(300px, 82vw) !important;
    aspect-ratio: 1 / 1 !important;
  }

  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
  }

  /* Mining Accruals Mobile Snug Card Rules (Removes excessive vertical spacing) */
  .mining-hero-card {
    padding: 1rem 0.85rem !important;
    height: auto !important;
    min-height: 0 !important;
  }
  .mining-hero-flex {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
    align-items: stretch !important;
    gap: 0.85rem !important;
    height: auto !important;
    min-height: 0 !important;
  }
  .mining-info-panel {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
  }
  .mining-countdown-card {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 0.85rem !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
}

/* ====================================================================
   EXTRA SMALL SCREENS (<= 480px)
   ==================================================================== */
@media (max-width: 480px) {
  .hide-on-xs {
    display: none !important;
  }

  .app-topbar {
    padding: 0 0.65rem !important;
    height: 52px !important;
  }

  .topbar-left {
    gap: 0.45rem !important;
  }

  .topbar-right {
    gap: 0.38rem !important;
  }

  .topbar-status-chip {
    padding: 0.18rem 0.45rem !important;
    font-size: 0.65rem !important;
  }

  .topbar-ref-pill {
    padding: 0.2rem 0.45rem !important;
    font-size: 0.72rem !important;
    gap: 0.25rem !important;
  }

  .topbar-ref-pill .ref-label {
    font-size: 0.65rem !important;
  }

  .user-avatar-mini {
    width: 26px !important;
    height: 26px !important;
    font-size: 0.72rem !important;
  }

  .topbar-logout-btn {
    width: 26px !important;
    height: 26px !important;
  }

  .topbar-wallet-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    padding: 4px 8px !important;
    font-size: 0.72rem !important;
    font-weight: 700;
    max-width: 105px;
    overflow: hidden;
    white-space: nowrap;
    border-radius: 8px !important;
  }
  .topbar-wallet-btn .wallet-btn-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stat-card-luxury {
    padding: 1.15rem 0.85rem !important;
  }

  .stat-card-luxury .stat-value,
  .stat-card .stat-value {
    font-size: 1.4rem !important;
  }

  .user-avatar-badge {
    width: 44px !important;
    height: 44px !important;
    font-size: 1.2rem !important;
  }

  .btn-lg {
    padding: 0.75rem 1.25rem !important;
    font-size: 0.95rem !important;
  }

  .roulette-housing {
    width: min(285px, 84vw) !important;
    height: min(285px, 84vw) !important;
    max-width: min(285px, 84vw) !important;
    max-height: min(285px, 84vw) !important;
    aspect-ratio: 1 / 1 !important;
    padding: 6px !important;
  }

  /* Mining Countdown Stage Mobile Adjustments */
  #countdown-hours, #countdown-minutes, #countdown-seconds {
    width: 52px !important;
    height: 48px !important;
    font-size: 1.45rem !important;
  }
}
