/*
 * مركز الألعاب — شريط علوي ثابت لزر «تسجيل / دخول» (و«الأصدقاء» بعد الدخول).
 *
 * Root cause (React bundle, not edited): the hub screen is
 *   div.fixed.inset-0.flex.flex-col.justify-center.overflow-y-auto
 * with the account button as `absolute top-4 right-4` inside it.
 *  1. justify-content:center on a scroll container whose content is taller
 *     than the viewport overflows the content UPWARDS: the «مركز الألعاب»
 *     title ends up above the scroll origin (unreachable) and the cards move
 *     up under the button, which stays at the scroll origin → the button
 *     appears in the middle of the cards (worst on iPhone Safari).
 *  2. position:absolute inside the scroll container makes it scroll away.
 *  3. viewport-fit=cover without safe-area insets puts it under the notch.
 *
 * Scope: only the hub screen (the one containing the games grid
 * .grid.max-w-3xl next to the account button). Other screens are untouched.
 * Without :has() support (iOS < 15.4) the page simply keeps its old layout.
 */
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) {
  --hub-bar: calc(64px + env(safe-area-inset-top, 0px));
  /* Safe centring: top-aligned when the content overflows, centred (auto
     margins below) when it fits. */
  justify-content: flex-start;
  padding-top: calc(var(--hub-bar) + 24px);
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); /* room for the floating 🎧 button */
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
}
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) > div:first-of-type {
  margin-top: auto;
}
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) > :last-child {
  margin-bottom: auto;
}

/* The bar itself (decorative; never intercepts taps). */
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4)::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--hub-bar);
  z-index: 40;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.94), rgba(15, 23, 42, 0.86));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.35);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* Account buttons: fixed in the bar — «تسجيل / دخول» on the right (RTL start),
   «الأصدقاء» (logged in only) on the left. */
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > button.absolute.top-4.right-4,
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) > button.absolute.top-4.left-4 {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  z-index: 50;
  min-height: 44px;
  max-width: calc(50vw - 28px);
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  touch-action: manipulation;
}
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > button.absolute.top-4.right-4 {
  right: max(16px, env(safe-area-inset-right, 0px));
  left: auto;
}
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) > button.absolute.top-4.left-4 {
  left: max(16px, env(safe-area-inset-left, 0px));
  right: auto;
}
/* Long player names are shortened instead of pushing into the other button. */
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > button.absolute.top-4 > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > button.absolute.top-4:focus-visible {
  outline: 3px solid #38bdf8;
  outline-offset: 2px;
}

/* Tablets and larger: a bit more breathing room. */
@media (min-width: 768px) {
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) {
    --hub-bar: calc(72px + env(safe-area-inset-top, 0px));
  }
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > button.absolute.top-4.right-4,
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) > button.absolute.top-4.left-4 {
    top: calc(env(safe-area-inset-top, 0px) + 14px);
    max-width: 320px;
  }
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > button.absolute.top-4.right-4 { right: max(24px, env(safe-area-inset-right, 0px)); }
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4) > button.absolute.top-4.left-4 { left: max(24px, env(safe-area-inset-left, 0px)); }
}

/* ===== v2: «الرئيسية» button (→ https://wahanest.com/) — injected by hub-nav-v2.js =====
   Layout in the bar (RTL): «تسجيل / دخول» on the right; «الرئيسية» on the left;
   «الأصدقاء» (logged in only) next to «الرئيسية». Same stacking context as the
   login button, so the login dialog (body-level overlay, z-20) still covers it. */
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > a.hub-home-btn {
  --home-w: 120px;
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: max(16px, env(safe-area-inset-left, 0px));
  z-index: 50;
  box-sizing: border-box;
  width: var(--home-w);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 9999px;
  border: 1px solid rgba(56, 189, 248, 0.55);
  background-color: rgba(14, 165, 233, 0.18);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > a.hub-home-btn:hover { background-color: rgba(14, 165, 233, 0.3); }
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > a.hub-home-btn:focus-visible { outline: 3px solid #38bdf8; outline-offset: 2px; }
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > a.hub-home-btn svg { flex: none; }

/* «الأصدقاء» moves next to «الرئيسية» (never under it). */
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4):has(> a.hub-home-btn) > button.absolute.top-4.left-4 {
  left: calc(max(16px, env(safe-area-inset-left, 0px)) + 128px);
}
/* Login/name button never reaches the left-hand buttons. */
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> a.hub-home-btn) > button.absolute.top-4.right-4 {
  max-width: calc(100vw - 184px);
}
.fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> a.hub-home-btn):has(> button.absolute.top-4.left-4) > button.absolute.top-4.right-4 {
  max-width: calc(100vw - 320px);
}
/* Phones: «الأصدقاء» becomes an icon button (its label stays as aria-label). */
@media (max-width: 559px) {
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4):has(> a.hub-home-btn) > button.absolute.top-4.left-4 {
    width: 44px;
    padding: 0;
    justify-content: center;
  }
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4):has(> a.hub-home-btn) > button.absolute.top-4.left-4 > span:last-child {
    display: none;
  }
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> a.hub-home-btn):has(> button.absolute.top-4.left-4) > button.absolute.top-4.right-4 {
    max-width: calc(100vw - 232px);
  }
}
@media (min-width: 768px) {
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl) > a.hub-home-btn {
    top: calc(env(safe-area-inset-top, 0px) + 14px);
    left: max(24px, env(safe-area-inset-left, 0px));
  }
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> button.absolute.top-4.right-4):has(> a.hub-home-btn) > button.absolute.top-4.left-4 {
    left: calc(max(24px, env(safe-area-inset-left, 0px)) + 128px);
  }
  .fixed.inset-0.overflow-y-auto:has(> .grid.max-w-3xl):has(> a.hub-home-btn) > button.absolute.top-4.right-4 { max-width: 320px; }
}
