/* app/topbar.css — shared header / nav / topbar styling.
 *
 * Loaded by every page that uses the canonical sticky topbar. Used to
 * be duplicated inline in 15+ pages (~25 lines × 15 = ~375 lines of
 * pure repetition). Single source of truth so brand tweaks land in
 * one place.
 *
 * Notes on CSS-var dependencies: this file expects --bg, --text,
 * --muted, --panel-2, --border, --brand-gold, --brand-crimson to be
 * defined in each page's :root block. All current pages already
 * declare those — no change needed.
 */

header.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  background: rgba(10,10,14,0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 70;
  backdrop-filter: blur(14px);
}

.hrk-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
}

.hrk-mark {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(217,52,43,0.25);
}

.hrk-name {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 16px;
  letter-spacing: 0.09em;
  white-space: nowrap;   /* keep the wordmark on one line on narrow desktop widths */
}
.hrk-name .feat { color: #ee6a62; }
.hrk-name .gold { color: var(--brand-gold); }

.topbar nav {
  display: flex;
  gap: 1px;
  margin-left: auto;
  flex-wrap: wrap;
  align-items: center;
}
.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 7px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.15s;
}
.topbar nav a:hover,
.topbar nav a:focus-visible {
  background: var(--panel-2);
  color: var(--text);
}
/* P3-M5 audit fix (2026-05-28): keyboard focus needs a visible
 * indicator distinct from hover so Tab navigation is discoverable. */
.topbar nav a:focus-visible {
  outline: 2px solid var(--brand-gold);
  outline-offset: 2px;
}
.topbar nav a.active {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--brand-gold);
  border-radius: 6px 6px 0 0;
}
.topbar nav a#watchlist-nav {
  color: var(--brand-gold);
}
.topbar nav a .badge {
  background: var(--brand-crimson);
  color: white;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 4px;
  font-weight: 800;
}

/* ─── Dropdown groups ──────────────────────────────────────────────
 * Hover-open on desktop (≥ 901px); click-toggle on touch via JS that
 * sets .open on the wrapper. Group-level button styled identically to
 * a regular nav link so hover/focus states stay consistent.
 * Active state when the current page lives inside a group: .dropdown.active
 * gives the trigger the same gold inset shadow as a direct active link.
 */
nav[data-nav-version="2"] .dropdown {
  position: relative;
}
nav[data-nav-version="2"] .dropdown-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  white-space: nowrap;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}
nav[data-nav-version="2"] .dropdown-btn:hover,
nav[data-nav-version="2"] .dropdown-btn:focus-visible,
nav[data-nav-version="2"] .dropdown:focus-within .dropdown-btn,
nav[data-nav-version="2"] .dropdown:hover .dropdown-btn {
  background: var(--panel-2);
  color: var(--text);
}
nav[data-nav-version="2"] .dropdown-btn:focus-visible {
  outline: 2px solid var(--brand-gold);
  outline-offset: 2px;
}
nav[data-nav-version="2"] .dropdown-btn .caret {
  font-size: 9px;
  opacity: 0.7;
  margin-top: 1px;
}
nav[data-nav-version="2"] .dropdown.active .dropdown-btn {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--brand-gold);
  border-radius: 6px 6px 0 0;
}
nav[data-nav-version="2"] .dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45), 0 0 0 1px rgba(245,197,66,0.06);
  display: none;
  flex-direction: column;
  gap: 1px;
}
nav[data-nav-version="2"] .dropdown:hover > .dropdown-menu,
nav[data-nav-version="2"] .dropdown:focus-within > .dropdown-menu,
nav[data-nav-version="2"] .dropdown.open > .dropdown-menu {
  display: flex;
}
nav[data-nav-version="2"] .dropdown-menu a {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 5px;
  white-space: nowrap;
}
nav[data-nav-version="2"] .dropdown-menu a:hover,
nav[data-nav-version="2"] .dropdown-menu a:focus-visible {
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}
nav[data-nav-version="2"] .dropdown-menu a.active {
  background: rgba(245,197,66,0.10);
  color: var(--brand-gold);
  box-shadow: none;
  border-radius: 5px;
}
nav[data-nav-version="2"] .dropdown-menu a .badge {
  background: var(--brand-crimson);
  color: white;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 800;
}
nav[data-nav-version="2"] .dropdown-menu .menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}
/* Section labels inside dropdowns (optional grouping aid) */
nav[data-nav-version="2"] .dropdown-menu .menu-label {
  padding: 6px 12px 2px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.discord-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 7px;
  padding: 6px 13px !important;
  background: #5865F2 !important;
  color: #ffffff !important;
  border-radius: 6px !important;
  font-weight: 700 !important;
  font-size: 12px !important;
  text-decoration: none;
  transition: background 0.15s;
  margin-left: 4px;
}
.discord-btn:hover {
  background: #4752c4 !important;
}
.discord-btn svg {
  vertical-align: middle;
  flex-shrink: 0;
}

/* ─── Mobile (≤900px) — collapse v2 nav to hamburger ──────────────
 * Without this, the v2 dropdown nav's flex-wrap layout stacks each
 * item vertically down the right edge of the screen, pushing the
 * logo / search out of place. At phone widths we hide the whole nav
 * and surface a hamburger button (#hrk-mobile-burger) that opens a
 * full-page drawer (#hrk-mobile-drawer). The bottom tab bar still
 * covers the 5 primary destinations; the drawer is the escape hatch
 * for everything else. Markup is injected at runtime by
 * /app/topbar-mobile.js so we don't have to edit 41 HTML pages. */
#hrk-mobile-burger,
#hrk-mobile-drawer { display: none; }

@media (max-width: 900px) {
  /* Date picker: hide the inline header copy (it crowds the hamburger);
     topbar-mobile.js relocates the same #hrk-datepicker into the drawer. */
  header.topbar > #hrk-datepicker,
  header.hrk-header > #hrk-datepicker { display: none !important; }
  #hrk-mobile-drawer .hrk-drawer-dp { padding: 8px 18px 12px; }
  #hrk-mobile-drawer #hrk-datepicker { display: block; }
  #hrk-mobile-drawer #dp-btn { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }
  #hrk-mobile-drawer #dp-pop { position: static; width: auto; margin-top: 8px; box-shadow: none; }

  /* Relocated header search (moved into the drawer by topbar-mobile.js on
     open). The header rule below hides #hrk-search-wrap at <=900px, scoped to
     header.topbar / header.hrk-header — once the node is a drawer child that
     selector no longer matches, so this re-shows it full-width at the top of
     the drawer. search.js sets the wrap/input/dropdown via inline styles, so
     these need !important to win. */
  #hrk-mobile-drawer #hrk-search-wrap {
    display: flex !important;
    position: relative !important;
    width: 100% !important;
    box-sizing: border-box;
    flex: 0 0 auto;
    margin: 4px 18px 12px !important;
  }
  #hrk-mobile-drawer #hrk-search-wrap #hrk-search-input {
    width: 100% !important;
    box-sizing: border-box;
    padding: 11px 14px 11px 32px !important;
    border-radius: 10px !important;
    font-size: 15px !important;
  }
  #hrk-mobile-drawer #hrk-search-wrap #hrk-search-sug {
    position: absolute !important;
    top: calc(100% + 4px) !important;
    left: 0 !important;
    right: 18px !important;
    width: auto !important;
    min-width: 0 !important;
    max-height: 320px !important;
    overflow-y: auto !important;
    z-index: 9100 !important;
  }

  /* Prevent wide data tables (e.g. cheatsheet pages' 37-col tables) from
   * expanding the layout viewport / initial containing block beyond the
   * device width. When a page overflows horizontally, the ICB widens and
   * `position:fixed; right:0` elements — notably #hrk-mobile-drawer — anchor
   * to the off-screen right edge of the widened ICB and paint nothing visible.
   * Clamping overflow-x on BOTH the root and body keeps the ICB at the visual
   * viewport width so the drawer (and any fixed UI) stays on-screen. Tables
   * stay scrollable inside their own overflow-x:auto wrappers. 2026-06-03. */
  html, body { overflow-x: clip !important; }
  /* 2026-08-08: was `overflow-x: hidden !important`. On Samsung Galaxy
   * browsers `overflow-x:hidden` on <body> coerces overflow-y and HARD-FREEZES
   * vertical scroll — a member on an S23 Ultra could only scroll by switching
   * Chrome to Desktop Site, which escapes this mobile media query. theme.css:240
   * had already moved to `clip` for exactly this reason, but the `!important`
   * here overrode it. `clip` still prevents the ICB from widening (the reason
   * this rule exists) without coercing the vertical axis. */

  /* Hide the inline desktop nav (v2 dropdowns AND plain v1 link rows) on
     mobile — both collapse into the injected #hrk-mobile-burger drawer.
     Scoped to direct header children so #hrk-mobile-drawer (in <body>) is
     never matched. */
  nav[data-nav-version="2"],
  header.topbar > nav,
  header.hrk-header > nav { display: none !important; }
  /* Hide secondary header items that don't fit on a phone. */
  header.topbar #hrk-search-wrap,
  header.hrk-header #hrk-search-wrap { display: none !important; }
  .hrk-fresh { display: none !important; }

  /* Tighter padding so the logo + burger sit close to the edges. */
  header.topbar,
  header.hrk-header { padding: 9px 12px; gap: 8px; }

  /* Hamburger — gold-tinted round button, top right. */
  #hrk-mobile-burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 9px;
    background: transparent;
    border: 1px solid rgba(245, 197, 66, 0.22);
    color: #F5C542;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
  }
  #hrk-mobile-burger:active {
    background: rgba(245, 197, 66, 0.12);
    border-color: rgba(245, 197, 66, 0.45);
  }

  /* Drawer — slides in from the right, full height, scrollable. */
  #hrk-mobile-drawer {
    display: block;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(82vw, 320px);
    background: #0a0808;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 9000;
    transform: translateX(100%);
    /* visibility:hidden is what actually pulls the ~50 links inside the
       CLOSED drawer out of the tab order and off the hit-test surface.
       translateX alone leaves them painted and focusable off-screen, so
       tabbing walked into an aria-hidden subtree and focus vanished
       (axe-core aria-hidden-focus). Delayed to the end of the slide-out so
       the close animation still plays; instant on open. Paired with the
       `inert` property set by topbar-mobile.js for the a11y tree. */
    visibility: hidden;
    transition: transform 0.22s ease-out, visibility 0s linear 0.22s;
    padding: calc(env(safe-area-inset-top, 0px) + 14px) 0 calc(env(safe-area-inset-bottom, 0px) + 14px);
    overflow-y: auto;
    box-shadow: -16px 0 40px rgba(0, 0, 0, 0.55);
  }
  #hrk-mobile-drawer.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.22s ease-out, visibility 0s linear 0s;
  }

  #hrk-mobile-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 8999;
    opacity: 0;
    transition: opacity 0.22s ease-out;
  }
  #hrk-mobile-drawer-backdrop.open {
    display: block;
    opacity: 1;
  }

  #hrk-mobile-drawer .hrk-drawer-section {
    padding: 6px 0;
  }
  #hrk-mobile-drawer .hrk-drawer-label {
    padding: 10px 18px 4px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #8a8a98;
  }
  #hrk-mobile-drawer a {
    display: block;
    padding: 11px 18px;
    color: #d4cabb;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    -webkit-tap-highlight-color: rgba(245, 197, 66, 0.1);
  }
  #hrk-mobile-drawer a:active {
    background: rgba(245, 197, 66, 0.08);
    color: #F5C542;
  }
  #hrk-mobile-drawer a.active {
    color: #F5C542;
    background: rgba(245, 197, 66, 0.06);
  }
  #hrk-mobile-drawer .hrk-drawer-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 8px 18px;
  }
}

/* ─── Simple ⇄ Pro view toggle (managed pair w/ scripts/inject_nav.py) ──────
 * Segmented control surfacing the casual "Simple" view next to the dense
 * "Pro" research grid. Lives in the header so it's visible on every page,
 * desktop AND mobile (it is NOT inside <nav>, so the mobile nav-hide rule
 * doesn't touch it). margin-left:auto right-aligns it with the nav. */
.hrk-view-toggle {
  display: inline-flex;
  align-items: stretch;
  margin-left: auto;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  padding: 2px;
  gap: 2px;
}
.hrk-view-toggle .hrk-vt-opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 13px;
  border-radius: 999px;
  font: 800 11px/1 'Inter', system-ui, sans-serif;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.hrk-view-toggle .hrk-vt-opt:hover,
.hrk-view-toggle .hrk-vt-opt:focus-visible {
  color: var(--text);
}
.hrk-view-toggle .hrk-vt-opt:focus-visible {
  outline: 2px solid var(--brand-gold);
  outline-offset: 2px;
}
.hrk-view-toggle .hrk-vt-opt.active {
  background: var(--brand-gold);
  color: #0a0a0e;
  box-shadow: 0 1px 4px rgba(245, 197, 66, 0.35);
}
/* When the toggle is present, the nav shouldn't also grab the auto margin
 * (it would split them to opposite ends). Keep them grouped on the right. */
.hrk-view-toggle + nav { margin-left: 10px; }

@media (max-width: 900px) {
  /* Stay visible on mobile, sitting just left of the hamburger. Slightly
   * more compact so the logo + toggle + burger all fit on a phone row. */
  .hrk-view-toggle { margin-left: auto; }
  .hrk-view-toggle .hrk-vt-opt { padding: 11px 14px; font-size: 11px; min-height: 22px; }
  /* On mobile the inline nav is hidden, so reset the grouping margin. */
  .hrk-view-toggle + nav { margin-left: 0; }
}

/* ─── Mobile menu visibility fix (2026-06-14) ──────────────────────────────
 * On phones the logo wordmark + sport switcher + Simple/Pro toggle crowded the
 * hamburger (#hrk-mobile-burger) off the right edge (it rendered at x>viewport,
 * so the menu looked missing / "hard to see"). Drop the wordmark TEXT on narrow
 * phones — the crown logo mark still carries the brand — so the menu button has
 * room and stays on-screen. Also strengthen the burger so it reads clearly as a
 * tappable control. */
@media (max-width: 560px) {
  header.topbar .hrk-logo .hrk-name,
  header.hrk-header .hrk-logo .hrk-name { display: none !important; }
}
@media (max-width: 900px) {
  #hrk-mobile-burger {
    border-color: rgba(245, 197, 66, 0.55) !important;
    background: rgba(245, 197, 66, 0.10) !important;
    margin-left: auto;
    flex: 0 0 auto;
  }
}

/* ─── Desktop single-row decongestion (2026-06-23) ─────────────────────────
 * At ~1366px the left cluster (logo wordmark + sport switcher + date picker +
 * Simple/Pro toggle + search + freshness pill) is wide enough that the right
 * nav (Top Plays + 5 dropdown groups + Sign-in chip + Join Discord ≈ 790px)
 * can't fit on the same line and wraps to a 2nd row (header → 120-150px).
 * Below 1500px we tighten the left cluster so the whole header stays one row:
 *   - compact the brand wordmark (the crown mark + smaller type still brand it)
 *   - trim Simple/Pro toggle + freshness pill + nav item padding
 * Nothing is hidden or removed — every control stays usable. Above 1500px the
 * full-size layout is untouched. */
@media (min-width: 901px) and (max-width: 1500px) {
  .hrk-name { font-size: 14px; letter-spacing: 0.05em; }
  header.topbar { gap: 8px; }
  .hrk-view-toggle .hrk-vt-opt { padding: 5px 9px; }
  .topbar nav { gap: 0; }
  .topbar nav a { padding: 7px 6px; }
  nav[data-nav-version="2"] .dropdown-btn { padding: 7px 5px; }
  nav[data-nav-version="2"] .dropdown-btn .caret { margin-left: -2px; }
  .hrk-fresh { font-size: 9px; padding: 3px 6px; margin-right: 4px; }
  .discord-btn { padding: 6px 9px !important; margin-left: 2px; }
  #hrk-search-wrap { margin-right: 4px !important; }
  #hrk-search-input { width: 132px !important; }
}
@media (min-width: 901px) and (max-width: 1500px) {
  /* Desktop band where the full wordmark + 6-group nav can't co-exist on one
   * row: drop the wordmark TEXT (the crown mark still links home and carries
   * the brand, exactly as the ≤560px mobile rule already does) so the nav is
   * guaranteed a single row. */
  header.topbar .hrk-logo .hrk-name { display: none; }
}


/* --- Week-0 readiness fix: mobile topbar overflow -------------------------
   header.topbar is a flex row whose children never shrank, so at 390px the row
   (logo + switcher + view-toggle + chat + burger, plus gaps) exceeded the
   padded content box and the burger spilled past the viewport edge -- 5px on
   most pages, 13-14px on a few, measured with overflow-x forced to visible.
   Tighten the gutter and let the two middle items shrink; the burger keeps its
   44x44 tap target and stays the last item in the row. */
@media (max-width: 900px) {
  header.topbar,
  header.hrk-header { padding-left: 8px; padding-right: 8px; gap: 6px; }

  header.topbar > *,
  header.hrk-header > * { min-width: 0; }

  header.topbar > #hrk-view-toggle,
  header.hrk-header > #hrk-view-toggle,
  header.topbar > .ca-sw,
  header.hrk-header > .ca-sw { flex: 0 1 auto; overflow: hidden; }

  header.topbar > #hrk-mobile-burger,
  header.hrk-header > #hrk-mobile-burger { flex: 0 0 auto; margin-right: 0; }
}


/* --- Week-0 readiness fix: last three mobile overflows --------------------- */
@media (max-width: 900px) {
  nav#hrk-bottom-nav {
    max-width: 100vw !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  nav#hrk-bottom-nav > * { min-width: 0 !important; }

  .lc-feed { max-width: 100% !important; box-sizing: border-box; }
}


/* --- Week-0 readiness fix: live-tracker rows overflow -----------------------
   .lc-score/.lc-wp/.lc-mo/.lc-feed compute to 399.375px inside a <=390 parent,
   putting 23px of real (static, not fixed) content past the right edge. */
@media (max-width: 900px) {
  #live-root .lc-score,
  #live-root .lc-wp,
  #live-root .lc-mo,
  #live-root .lc-feed { max-width: 100% !important; box-sizing: border-box !important; }
}


/* --- Week-0 readiness fix: live-tracker row width --------------------------
   .lc-score/.lc-wp/.lc-mo/.lc-feed compute to 399.375px inside a <=390 parent,
   putting 23px of real (static, not fixed) content past the right edge. This is
   the only remaining page with genuine content overflow; the other two flagged
   pages overflow only in position:fixed chrome, which production clips. */
@media (max-width: 900px) {
  #live-root .lc-score,
  #live-root .lc-wp,
  #live-root .lc-mo,
  #live-root .lc-feed { max-width: 100% !important; box-sizing: border-box !important; }
}
