/* Phone and tablet menu (burger, up to 1024 px): rebuilt in one place, loaded last so it wins over the older rules
   of styles.css, arene.css and light.css. From top to bottom:
     1. the pages, as a grid of tiles (Tools' Versus and Timeline are tiles too, no sub-menu)
     2. search
     3. the account (avatar and name, its links in two columns) or the Discord login
     4. language (its list opens in place) and theme (three icons) on one row
     5. invite the bot
   Everything fits on one phone screen; the menu scrolls inside itself, never the page behind. */
@media (max-width: 1024px) {
  html body #appNavMenu {
    position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 1001;
    display: none; box-sizing: border-box; width: auto; max-width: none; margin: 0; padding: 10px;
    max-height: calc(100dvh - 90px); overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
    background: var(--ar-panel); border: 1px solid var(--ar-line); border-radius: 0; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  }
  html body #appNavMenu.open { display: flex; flex-direction: column; gap: 8px; }
  html body #appNavMenu * { box-sizing: border-box; min-width: 0; }
  html body #appNavMenu .app-nav-actions { display: contents; }

  /* ---- 1. pages: tiles, three per row */
  html body #appNavMenu .app-nav-list {
    order: 1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; width: 100%; margin: 0; padding: 0;
  }
  html body #appNavMenu .app-nav-item { display: block; width: auto; margin: 0; padding: 0; background: none; border: 0; clip-path: none; }
  html body #appNavMenu .app-nav-item.nav-tools,
  html body #appNavMenu .nav-tools > .nav-dropdown-menu { display: contents; }
  html body #appNavMenu .nav-tools > .nav-dropdown-toggle.app-nav-link { display: none; }
  html body #appNavMenu :is(.app-nav-link, .nav-tools .nav-dropdown-item) {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    width: 100%; min-height: 64px; margin: 0; padding: 10px 4px; border: 0; border-radius: 0; clip-path: none; box-shadow: none;
    background: rgba(var(--hgl-ink, 255, 255, 255), 0.035); color: var(--ar-muted);
    font: 600 0.78rem/1.1 var(--ar-body, sans-serif); letter-spacing: 0; text-align: center; text-transform: none;
  }
  html body #appNavMenu :is(.app-nav-link, .nav-tools .nav-dropdown-item):hover { background: rgba(var(--hgl-ink, 255, 255, 255), 0.07); color: var(--ar-fg); }
  html body #appNavMenu :is(.app-nav-link, .nav-tools .nav-dropdown-item).active {
    background: var(--ar-accent-soft); color: var(--ar-fg); box-shadow: inset 0 -2px 0 var(--ar-accent);
  }
  html body #appNavMenu .app-nav-link.active::after { display: none; }
  html body #appNavMenu :is(.nav-icon, .nav-tools .dropdown-item-icon) { display: block; width: 18px; height: 18px; margin: 0; color: inherit; }
  html body #appNavMenu .nav-tools .nav-dropdown-text { display: block; }
  html body #appNavMenu .nav-tools .nav-dropdown-title { font: inherit; color: inherit; }

  /* ---- 2. search */
  html body #appNavMenu .btn-quick-search {
    order: 2; display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; min-height: 42px; height: auto;
    margin: 0; padding: 0 14px; border-radius: 0; font-size: 0.9rem;
  }
  html body #appNavMenu .btn-quick-search .search-btn-text { display: inline; }
  html body #appNavMenu .btn-quick-search .search-btn-kbd { display: none; }

  /* ---- 3. account: name, then its links in two columns (always shown) */
  html body #appNavMenu .app-nav-actions > .nav-dropdown:not(.lang-menu) {
    order: 3; width: 100%; margin: 0; padding: 4px; border: 0; border-radius: 0; clip-path: none;
    background: rgba(var(--hgl-ink, 255, 255, 255), 0.035);
  }
  html body #appNavMenu .auth-user-btn {
    display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; min-height: 0; height: auto;
    padding: 6px 8px; border: 0; background: none; clip-path: none; pointer-events: none;
  }
  html body #appNavMenu .auth-user-avatar { width: 28px; height: 28px; }
  html body #appNavMenu .auth-user-name { display: inline; max-width: none; overflow: hidden; color: var(--ar-fg); font-size: 0.92rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
  html body #appNavMenu .auth-user-btn .chevron-icon { display: none; }
  html body #appNavMenu .app-nav-actions > .nav-dropdown:not(.lang-menu) > .nav-dropdown-menu {
    position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 100%; min-width: 0 !important; margin: 4px 0 0; padding: 0;
    opacity: 1; visibility: visible; transform: none; pointer-events: auto; background: none; border: 0; border-radius: 0; box-shadow: none;
  }
  html body #appNavMenu .nav-logout-form { display: contents; }
  html body #appNavMenu .app-nav-actions > .nav-dropdown:not(.lang-menu) .nav-dropdown-item {
    display: flex; align-items: center; gap: 8px; width: 100%; min-height: 38px; margin: 0; padding: 8px 10px; border: 0; border-radius: 0;
    background: rgba(var(--hgl-ink, 255, 255, 255), 0.03); font: inherit; font-size: 0.84rem; text-align: left; cursor: pointer;
  }
  html body #appNavMenu .app-nav-actions > .nav-dropdown:not(.lang-menu) .nav-dropdown-item .dropdown-item-icon { width: 14px; height: 14px; flex: none; }
  html body #appNavMenu .app-nav-actions > .nav-dropdown:not(.lang-menu) .nav-dropdown-title { overflow: hidden; font-size: 0.84rem; text-overflow: ellipsis; white-space: nowrap; }
  html body #appNavMenu .btn-discord-login {
    order: 3; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 44px; margin: 0; border-radius: 0;
  }

  /* ---- 4. language and theme on one row; the languages open in place, under the row */
  html body #appNavMenu .hdr-prefs { order: 4; display: flex; flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: 4px; width: 100%; }
  html body #appNavMenu .hdr-prefs .hdr-news-btn { display: none; }
  html body #appNavMenu .lang-menu { position: static; flex: 1 1 0; width: auto; margin: 0; padding: 0; background: none; border: 0; clip-path: none; }
  html body #appNavMenu .lang-menu-btn {
    display: flex; align-items: center; gap: 10px; width: 100%; height: 40px; min-height: 0; padding: 0 12px; border-radius: 0;
    font: 600 0.88rem/1 var(--ar-body, sans-serif); letter-spacing: 0;
  }
  html body #appNavMenu .lang-menu-btn .lang-code { display: none; }
  html body #appNavMenu .lang-menu-name { display: inline; flex: 1; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
  html body #appNavMenu .lang-menu-btn .chevron-icon { display: inline-block; flex: none; transition: transform 0.15s ease; }
  html body #appNavMenu .lang-menu.open .lang-menu-btn .chevron-icon { transform: rotate(180deg); }
  html body #appNavMenu .lang-menu .lang-menu-list,
  html body #appNavMenu .lang-menu:hover .lang-menu-list,
  html body #appNavMenu .lang-menu.is-hovered .lang-menu-list { display: none; }
  html body #appNavMenu .lang-menu.open .lang-menu-list {
    position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 100%; min-width: 0; margin: 4px 0 0; padding: 0;
    opacity: 1; visibility: visible; transform: none; pointer-events: auto; background: none; border: 0; box-shadow: none;
  }
  /* the open list takes the whole row: the theme icons go under it */
  html body #appNavMenu .lang-menu.open { flex-basis: 100%; }
  html body #appNavMenu .lang-menu-item { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 6px 10px; overflow: hidden; font-size: 0.84rem; white-space: nowrap; text-overflow: ellipsis; }
  html body #appNavMenu .theme-menu { flex: none; width: auto; margin: 0; }
  html body #appNavMenu .theme-menu-btn { display: none; }
  html body #appNavMenu .theme-menu .theme-menu-list {
    position: static; display: flex; flex-direction: row; gap: 2px; width: auto; min-width: 0; height: 40px; margin: 0; padding: 0;
    opacity: 1; visibility: visible; transform: none; background: none; border: 0; box-shadow: none;
  }
  html body #appNavMenu .theme-menu .theme-menu-item {
    flex: none; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; gap: 0;
    background: rgba(var(--hgl-ink, 255, 255, 255), 0.035); color: var(--ar-muted);
  }
  html body #appNavMenu .theme-menu .theme-menu-item:hover { color: var(--ar-fg); }
  html body #appNavMenu .theme-menu .theme-menu-item.active { background: var(--ar-accent-soft); color: var(--ar-fg); }
  html body #appNavMenu .theme-menu .theme-menu-item span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }

  /* ---- 5. invite the bot */
  html body #appNavMenu .btn-discord-nav {
    order: 5; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 42px; min-height: 0; margin: 0;
    border-radius: 0; font-size: 0.9rem;
  }
  html body #appNavMenu .btn-discord-nav .discord-btn-text { display: inline; }
}
