/* ==========================================================================
   topbar.css: header com navegação, menus suspensos, busca, Discord e conta.
   Deve ser o ÚLTIMO css carregado.
   Os seletores começam com "#topbar.tb" de propósito: o layout.css estiliza
   o header por ID, e seletores só de classe perderiam a disputa.
   ========================================================================== */

/* ---------- Base (todas as larguras) ---------- */
#topbar.tb {
  --tb-accent: var(--gold, #e6c35c);
  --tb-ease: .15s ease;
}

/* Menu superior e sino amarelo desativados — a navegação fica só na sidebar,
   e a central de notificações usa apenas o botão com contador. */
#topbar.tb #topbarNav,
#topbar.tb #topbarDiscord,
#topbar.tb .tb-kbd,
#topbar.tb .bell { display: none; }

#topbar.tb .tb-wordmark,
#topbar.tb #topbarBrand .tb-wordmark b {
  font-family: Rajdhani, Outfit, ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
}
#topbar.tb .tb-wordmark { font-size: .95rem; color: var(--text); }
#topbar.tb #topbarBrand .tb-wordmark b {
  display: inline;
  font-size: inherit;
  color: var(--tb-accent);
}

@media (max-width: 520px) {
  #topbar.tb .tb-wordmark { display: none; }
}

/* ---------- Desktop (900px ou mais) ---------- */
@media (min-width: 900px) {
  #topbar.tb { gap: 10px; }

  /* Menu superior continua oculto (navegação fica só na sidebar). */
  #topbar.tb #topbarNav {
    display: none;
    align-items: center;
    gap: 2px;
    min-width: 0;
    margin-left: 6px;
  }

  #topbar.tb .tb-item { position: relative; }

  #topbar.tb .tb-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 0;
    margin: 0;
    padding: 8px 11px;
    border: 0;
    border-radius: var(--radius-sm, 8px);
    background: transparent;
    box-shadow: none;
    transform: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: .82rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--tb-ease), color var(--tb-ease);
  }
  #topbar.tb .tb-link[aria-expanded="true"] {
    background: var(--surface-2);
    color: var(--text);
  }
  #topbar.tb .tb-link.is-active { color: var(--text); }
  #topbar.tb .tb-link.is-active::after {
    content: "";
    position: absolute;
    left: 11px;
    right: 11px;
    bottom: 2px;
    height: 2px;
    border-radius: 2px;
    background: var(--tb-accent);
  }
  #topbar.tb .tb-link:focus-visible,
  #topbar.tb .tb-menu button:focus-visible,
  #topbar.tb .tb-icon-link:focus-visible,
  #topbar.tb #topbarDiscord:focus-visible {
    outline: 2px solid var(--tb-accent);
    outline-offset: 2px;
  }

  #topbar.tb .tb-caret {
    width: 10px;
    height: 10px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform var(--tb-ease);
  }
  #topbar.tb .tb-trigger[aria-expanded="true"] .tb-caret { transform: rotate(180deg); }

  /* ---- Menu suspenso ---- */
  #topbar.tb .tb-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 40;
    display: grid;
    gap: 2px;
    min-width: 290px;
    max-width: min(360px, calc(100vw - 24px));
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: 0 16px 40px rgba(0, 0, 0, .55);
    transform-origin: top left;
    animation: tb-menu-in .14s ease-out;
  }
  /* o JS adiciona esta classe quando o menu estouraria a borda direita da janela */
  #topbar.tb .tb-menu.tb-menu--end {
    left: auto;
    right: 0;
    transform-origin: top right;
  }
  #topbar.tb .tb-menu[hidden] { display: none; }
  /* ponte invisível: o mouse não "cai no vazio" entre o botão e o menu */
  #topbar.tb .tb-menu::before {
    content: "";
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
  }
  #topbar.tb .tb-menu button {
    display: grid;
    gap: 2px;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 9px 12px;
    border: 0;
    border-left: 2px solid transparent;
    border-radius: var(--radius-sm, 8px);
    background: transparent;
    box-shadow: none;
    transform: none;
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background var(--tb-ease), border-color var(--tb-ease);
  }
  #topbar.tb .tb-menu button:focus-visible {
    background: var(--surface-2);
    border-left-color: var(--tb-accent);
  }
  #topbar.tb .tb-menu button.is-active {
    border-left-color: var(--tb-accent);
    background: rgba(230, 195, 92, .08); /* fallback */
    background: color-mix(in srgb, var(--tb-accent) 9%, transparent);
  }
  @media (hover: hover) {
    #topbar.tb .tb-link:hover:not(:disabled) {
      background: var(--surface-2);
      color: var(--text);
    }
    #topbar.tb .tb-menu button:hover:not(:disabled) {
      background: var(--surface-2);
      border-left-color: var(--tb-accent);
    }
    #topbar.tb #topbarDiscord:hover { color: var(--tb-accent); background: var(--surface-2); }
  }
  #topbar.tb .tb-menu button b {
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  #topbar.tb .tb-menu button small {
    color: var(--text-muted);
    font-size: .7rem;
    font-weight: 500;
    line-height: 1.3;
  }

  /* ---- Busca ---- */
  #topbar.tb #topbarSearch {
    flex: 1 1 170px;
    width: auto;
    max-width: 340px;
    margin: 0 0 0 auto;
  }
  #topbar.tb .tb-kbd {
    display: inline-block;
    flex: 0 0 auto;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: .64rem;
    font-weight: 600;
    letter-spacing: .03em;
    white-space: nowrap;
  }

  /* ---- Discord ---- */
  #topbar.tb #topbarDiscord {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-muted);
    text-decoration: none;
    transition: background var(--tb-ease), color var(--tb-ease);
  }
  #topbar.tb #topbarDiscord svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }

  #topbar.tb #topbarAccount { gap: 10px; }
}

/* ---------- Telas médias: libera espaço ---------- */
@media (min-width: 900px) and (max-width: 1239px) {
  #topbar.tb .tb-wordmark,
  #topbar.tb .tb-kbd,
  #topbar.tb .sidebar-user-copy,
  #topbar.tb #sideCoins small { display: none; }
  #topbar.tb .tb-link { padding-inline: 9px; }
  #topbar.tb .tb-link.is-active::after { left: 9px; right: 9px; }
}
@media (min-width: 900px) and (max-width: 1060px) {
  #topbar.tb #topbarDiscord { display: none; }
  #topbar.tb #topbarSearch { flex-basis: 130px; }
}

@keyframes tb-menu-in {
  from { opacity: 0; transform: translateY(-4px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  #topbar.tb .tb-caret,
  #topbar.tb .tb-link,
  #topbar.tb .tb-menu button,
  #topbar.tb #topbarDiscord { transition: none; }
  #topbar.tb .tb-menu { animation: none; }
}

/* Modo de alto contraste */
@media (forced-colors: active) {
  #topbar.tb .tb-link.is-active::after { background: Highlight; }
  #topbar.tb .tb-menu button.is-active { border-left-color: Highlight; }
  #topbar.tb .tb-menu { border-color: CanvasText; }
}