/* App shell at <=640px: the fixed bottom nav bar and the "More" sheet. */
/* Mobile: sidebar becomes a fixed bottom-nav bar; desktop "collapsed" is ignored. */
@media (max-width: 640px) {
  .app-shell {
    display: block;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .app-main {
    padding-bottom: 64px; /* room for the fixed bottom bar */
    min-height: 100vh;
    min-height: 100dvh;
  }
  .app-sidebar {
    position: fixed;
    /* Reset top:auto — fixed lets top beat bottom, else it renders at viewport top. */
    top: auto;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 64px;
    max-height: 64px;
    border-right: 0;
    border-top: 1px solid var(--border);
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 40%),
      var(--bg-1);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.28);
    z-index: 500;
    transition: height 0.22s ease, max-height 0.22s ease, border-radius 0.22s ease;
  }
  .app-sidebar::before {
    content: '';
    position: absolute;
    top: 0; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent,
      color-mix(in srgb, var(--bronze) 35%, transparent), transparent);
    pointer-events: none;
  }
  .app-shell.is-collapsed .app-sidebar { width: 100%; }
  .app-sidebar-brand { display: none; }
  .app-shell .app-sidebar-nav {
    flex-direction: row;
    padding: 4px 6px;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    align-items: stretch;
  }
  /* display:contents makes .app-nav-item a direct flex child for cross-section `order:`;
     `.app-shell` prefix beats the [data-group="account"] hide (0,2,0). */
  .app-shell .app-nav-section {
    display: contents;
  }
  .app-nav-label { display: none; }
  .app-sidebar-bottom {
    display: contents;
    margin-top: 0;
  }
  .app-nav-divider { display: none; }
  /* Prefix must out-rank the desktop rail's `.is-collapsed .app-nav-item` (0,3,0). */
  .app-shell .app-sidebar-nav .app-nav-item {
    flex: 1 1 0;
    width: auto;
    min-width: 60px;
    margin: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 2px 6px;
    /* Kill desktop borders (1px hairlines on HiDPI). Active indicator moves to ::before. */
    border: 0;
    border-radius: 10px;
    color: var(--ink-2);
    font: 600 11px/1.1 var(--font-display);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    position: relative;
  }
  .app-nav-item::before {
    content: "";
    position: absolute;
    top: -4px; left: 50%;
    transform: translateX(-50%);
    height: 2px; width: 28px;
    background: transparent;
    border-radius: 0 0 2px 2px;
    pointer-events: none;
  }
  .app-nav-item.is-active::before {
    background: var(--bronze);
    box-shadow: 0 0 8px color-mix(in srgb, var(--bronze) 50%, transparent);
  }
  .app-nav-item-icon { width: 22px; height: 22px; }
  /* Labels under icons, beating .is-collapsed's hide; compact variant swaps in to avoid overflow. */
  .app-shell .app-sidebar-nav .app-nav-item-label,
  .app-shell .app-sidebar-nav .app-nav-item-label-s {
    display: block;
    max-width: 100%;
    /* 1.1 gives a 12.1px box that clips the display face's ink under overflow:hidden. */
    line-height: 15px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .app-shell .app-sidebar-nav .app-nav-item.has-short .app-nav-item-label { display: none; }
  .app-shell .app-sidebar-nav .app-nav-item.has-short .app-nav-item-label-s { display: block; }
  .app-shell .app-sidebar-nav .app-nav-item.is-active {
    background: linear-gradient(180deg,
      color-mix(in srgb, var(--bronze) 14%, transparent),
      color-mix(in srgb, var(--bronze) 2%, transparent));
    box-shadow: none;
    color: var(--bronze);
  }
  .app-nav-item-ext { display: none; }

  /* Hide all, re-show the pinned set + More toggle; overflow → sheet. */
  .app-shell .app-nav-item                     { display: none; order: 99; }
  .app-shell .app-nav-item.nav-item-battlefield { display: flex; order: 1; }
  .app-shell .app-nav-item.nav-item-warroom     { display: flex; order: 2; }
  .app-shell .app-nav-item.nav-item-live        { display: flex; order: 3; }
  .app-shell .app-nav-item.nav-item-companions  { display: flex; order: 4; }
  .app-shell .app-nav-item.nav-item-mobile-more { display: flex; order: 5; }

  .app-shell.is-mobile-more-open .app-sidebar {
    height: auto;
    max-height: 84vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 20px 20px 0 0;
    background:
      linear-gradient(180deg, color-mix(in srgb, var(--bronze) 4%, transparent), transparent 18%),
      var(--bg-1);
    box-shadow: 0 -28px 80px rgba(0, 0, 0, 0.55);
    animation: app-sheet-slide 240ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
  }
  .app-shell.is-mobile-more-open .app-sidebar::before {
    left: 0; right: 0;
    background: linear-gradient(90deg, transparent,
      color-mix(in srgb, var(--bronze) 45%, transparent) 40%,
      color-mix(in srgb, var(--bronze) 45%, transparent) 60%, transparent);
  }
  .app-shell.is-mobile-more-open .app-mobile-more-head {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 6px 14px 0;
    background: var(--bg-1);
  }
  .app-mobile-more-handle {
    align-self: center;
    width: 44px; height: 4px;
    border-radius: 2px;
    background: var(--border);
    opacity: 0.7;
    margin: 6px 0 10px;
  }
  .app-mobile-more-headrow {
    display: flex; align-items: center; gap: 10px;
    padding: 0 0 12px;
    border-bottom: 1px solid var(--divider);
  }
  .app-mobile-more-user {
    display: flex; align-items: center; gap: 12px;
    flex: 1 1 auto; min-width: 0;
    background: none; border: 0;
    text-align: left; cursor: pointer;
    color: var(--ink);
    padding: 4px 6px;
    border-radius: 10px;
    transition: background 0.14s ease;
  }
  .app-mobile-more-user:hover { background: var(--bg-2); }
  .app-mobile-more-user .app-user-avatar { width: 40px; height: 40px; font-size: 1.05rem; }
  /* Last row of the Account group, so it matches .app-nav-item's box and type exactly; the left
     padding lands the glyph on the rows' 31px and the text on their 65px. Grey, not brand colour,
     and underlined — it is a link out, not a nav row. */
  .app-shell.is-mobile-more-open .app-mobile-more-discord-link {
    display: flex; align-items: center; justify-content: flex-start; gap: 12px;
    min-height: 36px;
    padding: 6px 12px 6px 15px;
    font-family: var(--font-display); font-size: 0.92rem; font-weight: 500;
    letter-spacing: 0.01em;
    color: var(--ink-3); text-decoration: none;
    border-radius: var(--radius-s);
  }
  .app-mobile-more-discord-ico {
    flex: 0 0 auto; width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    color: inherit;
  }
  .app-mobile-more-discord-ico svg { width: 17px; height: 17px; }
  .app-mobile-more-discord-t { text-decoration: underline; text-underline-offset: 2px; }
  .app-mobile-more-discord-link:hover { background: var(--bg-2); color: var(--ink); }
  .app-mobile-more-user-meta { display: flex; flex-direction: column; min-width: 0; }
  .app-mobile-more-user-name {
    font-family: var(--font-display);
    font-size: 1.02rem;
    letter-spacing: 0.01em;
    color: var(--ink);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .app-mobile-more-user-sub {
    font-size: 0.78rem;
    color: var(--ink-3);
    letter-spacing: 0.02em;
    margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .app-mobile-more-user-elo { font-family: var(--font-mono); font-weight: 600; color: var(--bronze); }
  .app-mobile-more-x {
    flex: 0 0 auto;
    width: 34px; height: 34px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--ink-3);
    font-size: 1.2rem; line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
  }
  .app-mobile-more-x:hover {
    background: var(--bg-2);
    color: var(--ink);
    border-color: var(--divider);
  }
  .app-shell.is-mobile-more-open .app-sidebar-nav {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 16px 18px; /* safe-area handled by the sheet foot below */
    gap: 0;
    overflow: visible;
  }
  /* Groups become real blocks again (bar dissolves them via display:contents). */
  .app-shell.is-mobile-more-open .app-nav-section { display: block; }
  .app-shell.is-mobile-more-open .app-nav-section + .app-nav-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--divider);
  }
  /* Double class beats the icon-rail's `.is-collapsed .app-nav-toggle` hide. */
  .app-shell.is-mobile-more-open .app-nav-label.app-nav-toggle {
    display: flex;
    padding: 0 4px 10px;
    font: 600 10px/1 var(--font-display);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--ink-3);
  }
  /* Extra .app-nav-section out-ranks the icon-rail's `display:flex !important`. */
  /* One column: the sheet is a sidebar, not a tile grid. A tree cannot nest inside grid cells. */
  .app-shell.is-mobile-more-open .app-nav-section .app-nav-items {
    display: flex !important;
    flex-direction: column;
    gap: 2px;
  }
  /* Collapsed section stays collapsed in the sheet: the rule above is !important (it has to beat
     the bar's display:contents), so the hide needs !important too or the header does nothing. */
  .app-shell.is-mobile-more-open .app-nav-section.is-collapsed .app-nav-items { display: none !important; }
  /* Expanded = a real sidebar, not a grid of buttons: full-width rows, icon beside the label,
     so a nested tree reads as a tree instead of tiles with things hanging off them. */
  /* Colours come from the DESKTOP sidebar rules, not a sheet palette: same bg, ink and active
     treatment, so the mobile menu is the same menu. Only geometry is overridden here. */
  .app-shell.is-mobile-more-open .app-nav-item {
    /* --ink, matching desktop: the BAR rule sets --ink-2 for tiles and would otherwise win. */
    color: var(--ink);
    display: flex;
    order: 0; /* reset bar ordering — the sheet follows sidebar DOM order */
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    min-width: 0;
    min-height: 2.75rem;
    padding: 0.625rem 0.75rem;
    letter-spacing: 0;
    text-align: left;
    text-transform: none;
    position: relative;
    overflow: hidden;
    border-left: 3px solid transparent;   /* desktop active spine */
  }
  /* Label was hidden/shrunk for the bar; in the sheet it is the row. */
  /* Left-aligned: the bar centres its labels under the icons, which the sheet must undo. */
  .app-shell.is-mobile-more-open .app-nav-item-label {
    display: block; font-size: 0.92rem;
    flex: 1 1 auto; text-align: left; max-width: none;
  }
  .app-shell.is-mobile-more-open .app-nav-item-label-s { display: none; }
  .app-shell.is-mobile-more-open .app-nav-item-icon { flex: 0 0 auto; width: 1.1rem; height: 1.1rem; }

  /* Compact rows. The bar needs 78px tiles; a sidebar row does not. */
  .app-shell.is-mobile-more-open .app-nav-item { min-height: 2.25rem; padding: 0.375rem 0.75rem; }
  .app-shell.is-mobile-more-open .app-nav-subitem {
    min-height: 2.125rem; padding: 0.3125rem 0.75rem;
    border-bottom: 0;                 /* the per-row rules read as a table */
    font-size: 0.86rem;
  }
  /* Depth by fill, not by rules: each level sits a shade deeper with a bronze spine. */
  /* ONE treatment for every level: indent plus a single spine. No per-depth fills — stacking
     washes made each level a different colour. */
  .app-shell.is-mobile-more-open .app-nav-subgroup {
    background: none;
    border-left: 2px solid var(--divider);
    margin-left: 1.1rem;
  }
  .app-shell.is-mobile-more-open .app-nav-subitem[data-depth="1"],
  .app-shell.is-mobile-more-open .app-nav-subitem[data-depth="2"] { margin-left: 0; }
  /* Same rule as the sidebar: one spine per branch, not one per level. */
  .app-shell.is-mobile-more-open .app-nav-subgroup .app-nav-subgroup { border-left: 0; }
  .app-shell.is-mobile-more-open .app-nav-subitem.is-active {
    background: color-mix(in srgb, var(--accent-gold) 10%, transparent);
    color: var(--accent-gold);
    border-bottom-color: transparent;
  }
  /* Section headers carry the separation instead. */
  .app-shell.is-mobile-more-open .app-nav-section + .app-nav-section {
    margin-top: 0.625rem; padding-top: 0.625rem;
  }
  .app-shell.is-mobile-more-open .app-nav-item::before { display: none; }
  /* Active row: the desktop gold treatment, not a sheet-only gradient. */
  .app-shell.is-mobile-more-open .app-nav-item.is-active {
    background: color-mix(in srgb, var(--accent-gold) 10%, transparent);
    color: var(--accent-gold);
    border-left-color: var(--accent-gold);
  }
  .app-shell.is-mobile-more-open .app-nav-item.nav-item-mobile-more {
    display: none;
  }
  .app-shell.is-mobile-more-open .app-nav-item-icon {
    width: 22px; height: 22px;
    flex: 0 0 auto;
  }
  /* Sheet rows show the FULL label, left-aligned (short stays bar-only). */
  .app-shell.is-mobile-more-open .app-nav-item .app-nav-item-label,
  .app-shell.is-mobile-more-open .app-nav-item.has-short .app-nav-item-label {
    display: block;
    text-align: left;   /* sheet is a sidebar; the bar is what centres labels under icons */
    line-height: 1.15;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .app-shell.is-mobile-more-open .app-nav-item.has-short .app-nav-item-label-s { display: none; }
  .app-shell.is-mobile-more-open .app-nav-item-badge {
    position: absolute;
    top: 7px; right: 7px;
    margin-left: 0;
    font-size: 9px;
    padding: 2px 5px;
  }
  .app-shell.is-mobile-more-open .app-mobile-more-foot {
    display: block;
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--divider);
  }
  .app-mobile-more-signout {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    padding: 11px;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    color: var(--ink);
    font: 600 0.92rem var(--font-sans);
    cursor: pointer;
    transition: background 0.14s ease, border-color 0.14s ease;
  }
  .app-mobile-more-signout:hover { background: var(--bg-2); border-color: var(--bronze); }
  .app-mobile-more-signout svg { width: 16px; height: 16px; display: block; }
  .app-mobile-more-confirm-q {
    text-align: center;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 10px;
  }
  .app-mobile-more-confirm-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .app-mobile-more-confirm-btns .btn { justify-content: center; }
  .app-sidebar-collapse { display: none; }
  .app-topbar { padding: 6px 14px; gap: 8px; min-height: 54px; align-items: center; }
  .app-user-identity { display: none; }
  .app-user-chip { padding: 5px; }
  /* Both states → icon only; the queue pill on the other side of the bar carries the words. */
  .app-topbar-quickmatch { padding: 8px 10px; font-size: 0.82rem; min-width: 0; }
  .app-topbar-quickmatch .app-topbar-quickmatch-label { display: none; }
  .app-topbar-quickmatch .app-topbar-quickmatch-ico { display: inline-flex; }
  .app-topbar-quickmatch-ico { width: 16px; height: 16px; }
}
