/* Mobile responsive */

@media (max-width: 1100px) {
  :root { --content-max: 100%; }

  .dash-grid { grid-template-columns: 1fr; }
  .section-grid-2 { grid-template-columns: 1fr; }
  .edu-grid { grid-template-columns: 1fr; }
  .game-panel { grid-template-columns: 1fr; }
  .skill-tree { grid-template-columns: repeat(2, 1fr); }
  .job-grid { grid-template-columns: repeat(2, 1fr); }
  .prop-grid { grid-template-columns: repeat(2, 1fr); }
  .store-grid { grid-template-columns: repeat(2, 1fr); }
  .bank-grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .chat-layout { grid-template-columns: 240px 1fr; }
  .chat-layout > .card { display: none; }
  .inventory-grid { grid-template-columns: repeat(4, 1fr); }
  .search { width: 200px; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; --topbar-h: 64px; }

  /* Drop .app's stacking context on mobile so the sidebar (z-index 1000)
     can render above .sidebar-backdrop (z-index 999), which lives outside
     .app at the body level. Otherwise the backdrop stacks on top of the
     sidebar and visually covers it. */
  .app {
    grid-template-columns: 1fr;
    position: static;
    z-index: auto;
  }

  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    z-index: 1000;
    border-right: 2px solid rgba(167, 139, 250, 0.7);
    box-shadow:
      32px 0 90px rgba(0, 0, 0, 0.9),
      6px 0 32px rgba(167, 139, 250, 0.35);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Solid, clearly-lifted background so the sidebar reads as a distinct
       surface above the dimmed backdrop on mobile. */
    background: linear-gradient(180deg, #2d2452 0%, #1d1638 100%);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding-bottom: 32px;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    /* Fully opaque so no main content bleeds through next to the sidebar. */
    background: #06050d;
    z-index: 999;
    display: none;
  }
  .sidebar-backdrop.active { display: block; }

  .sidebar .nav-item {
    color: #ffffff;
    font-weight: 700;
    font-size: 15px;
  }
  .sidebar .nav-item svg { opacity: 1; }
  .sidebar .nav-label {
    color: #c5c0e8;
    font-size: 11px;
    font-weight: 800;
  }
  .sidebar .nav-item.active {
    background: linear-gradient(90deg, rgba(167, 139, 250, 0.32), rgba(167, 139, 250, 0.12));
    border-color: rgba(167, 139, 250, 0.6);
    box-shadow: inset 0 0 18px rgba(167, 139, 250, 0.22);
  }

  .mobile-menu-btn { display: flex; }

  .topbar {
    /* env() is 0 on devices without a notch, so this is a no-op there and
       only kicks in on cutout/home-indicator hardware (viewport-fit=cover). */
    padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    height: calc(64px + env(safe-area-inset-top));
  }
  .topbar-left h1 { font-size: 18px; }
  .topbar-left .crumb { display: none; }

  /* Larger touch targets on phones (was 32px — below comfortable tap size). */
  .icon-btn { width: 40px; height: 40px; }
  .sfx-toggle { width: 40px; height: 40px; }
  .mobile-menu-btn { min-width: 40px; min-height: 40px; }
  .prestige-pill { display: none; }

  .content {
    padding: 16px max(16px, env(safe-area-inset-right)) calc(64px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .tagline { font-size: 12px; margin-bottom: 16px; }

  .balance-amount { font-size: 44px; }
  .balance-amount .ccy { font-size: 26px; }
  .balance-tiles { grid-template-columns: 1fr; gap: 10px; }
  .balance-card { padding: 20px; }

  .skill-tree { grid-template-columns: 1fr; }
  .job-grid { grid-template-columns: 1fr; }
  .prop-grid { grid-template-columns: 1fr; }
  .store-grid { grid-template-columns: 1fr; }
  .risk-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .inventory-grid { grid-template-columns: repeat(3, 1fr); }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 22px; }

  .chat-layout {
    grid-template-columns: 1fr;
    height: calc(100dvh - var(--topbar-h) - 60px);
  }
  .chat-list { display: none; }
  .chat-layout.show-list .chat-list { display: block; }
  .chat-layout.show-list .chat-main { display: none; }
  /* Show the "conversations" toggle so DMs are reachable on phones. */
  .chat-list-toggle { display: inline-flex; }
  /* When the list is showing, the toggle (which lives in chat-main) is hidden with it. */
  .chat-header { padding: 12px 14px; gap: 8px; }
  /* Collapse the verbose action-button labels to icons to fit the narrow header.
     font-size:0 drops the text node; the SVG keeps its fixed 13px box. */
  .chat-header .btn-sm {
    font-size: 0;
    padding: 0;
    width: 38px;
    min-width: 38px;
    height: 38px;
    justify-content: center;
  }
  .chat-header .btn-sm svg { width: 17px; height: 17px; }
  .chat-header .flex-1 { min-width: 0; }
  #chat-name, #chat-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .card { padding: 18px; }
  .section-title { font-size: 18px; }
  .section-head { flex-direction: column; align-items: flex-start; }

  .casino-tabs, .store-tabs { gap: 4px; padding: 4px; }
  .cas-tab { padding: 10px 12px; font-size: 11.5px; min-width: 80px; min-height: 44px; }
  .cas-tab svg { display: none; }

  .crash-mult { font-size: 64px; }
  .dice-result { font-size: 64px; }
  .wheel-svg { width: 240px; height: 240px; }
  .coin { width: 120px; height: 120px; }
  .coin-side { font-size: 60px; }

  .table { font-size: 11.5px; }
  .table thead th { padding: 10px 8px; font-size: 9.5px; }
  .table tbody td { padding: 10px 8px; }
  /* Tables can't reflow without misaligning columns — let the card scroll
     horizontally on narrow phones instead of clipping content. */
  .card:has(.table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: max-content; }

  /* Filter pill bars: scroll horizontally rather than overflow the viewport. */
  .txn-filters {
    width: auto;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .txn-filters::-webkit-scrollbar { display: none; }
  .txn-filter { flex: 0 0 auto; white-space: nowrap; }

  /* Leaderboard rows: let the name column shrink + ellipsize so long handles
     and big mono net-worth values don't push the row past a narrow screen. */
  .lb-row > :nth-child(3) { min-width: 0; }
  .lb-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lb-row { gap: 10px; padding: 10px 8px; }

  .bank-grid { grid-template-columns: 1fr; }
  .credit-card-vis { padding: 18px; height: 180px; }

  .toast-stack { right: 12px; top: 76px; }
  .toast { min-width: 240px; max-width: 280px; }

  .onb-card { padding: 28px; }
  .onb-title { font-size: 28px; }
  .onb-bonus .amount { font-size: 44px; }
  .onb-bonus .amount .ccy { font-size: 24px; }
  .onb-perks { grid-template-columns: 1fr; }
  .onb-avatar-grid { grid-template-columns: repeat(4, 1fr); }

  .balance-amount { flex-wrap: wrap; }

  .game-stage { min-height: 380px; padding: 16px; }
  .plinko-board { aspect-ratio: 1; }

  .loan-row {
    grid-template-columns: 40px 1fr;
    gap: 10px;
  }
  .loan-row > div:nth-child(n+3):nth-child(-n+5) { display: none; }
}

@media (max-width: 768px) {
  /* New components — mobile polish */
  .announce-banner { padding: 12px 14px; gap: 10px; }
  .announce-icon { width: 32px; height: 32px; }
  .announce-text { font-size: 13.5px; }
  .announce-title { font-size: 9.5px; }

  .stock-grid { grid-template-columns: 1fr; gap: 12px; }
  .stock-card { padding: 14px; }
  .stock-actions { grid-template-columns: 1fr auto auto; gap: 6px; }
  .stock-qty { width: 100%; }

  .roulette-options { grid-template-columns: 1fr; }
  .slots-reels { grid-template-columns: repeat(3, 70px); padding: 12px; gap: 6px; }
  .slots-reel { width: 70px; height: 70px; font-size: 36px; }
  .roul-wheel { width: 160px; height: 160px; }
  .roul-num { width: 60px; height: 60px; font-size: 26px; }
  .bj-card { width: 50px; height: 70px; font-size: 18px; }
  .bj-card .rank { font-size: 18px; }

  .profile-financial { grid-template-columns: 1fr 1fr; }
  .profile-financial .profile-money-tile.primary { grid-column: 1 / -1; }
  .profile-money-tile { padding: 12px 14px; }
  .profile-money-tile .val { font-size: 17px; }
  .profile-hero { padding: 18px; gap: 16px; grid-template-columns: 100px 1fr; }
  .profile-hero-name { font-size: 24px; }

  .admin-row input,
  .admin-row select { width: 100%; flex: 1 1 100%; }
  .admin-row { gap: 8px; }

  .tier-grid { grid-template-columns: 1fr 1fr; }

  /* Casino tabs — let them scroll horizontally instead of cramping */
  .casino-tabs, .store-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .casino-tabs::-webkit-scrollbar,
  .store-tabs::-webkit-scrollbar { display: none; }
  .cas-tab { flex: 0 0 auto; }
}

@media (max-width: 420px) {
  .quick-actions { grid-template-columns: repeat(2, 1fr); }
  .balance-amount { font-size: 36px; }
  .tier-grid { grid-template-columns: 1fr; }
  .slots-reels { grid-template-columns: repeat(3, 64px); }
  .slots-reel { width: 64px; height: 64px; font-size: 32px; }
}
