/* ============================================================
   mobile.css — mobile-first polish + native app surface
   Loaded after site.css.

   Layers
     1. Global niceties            (every viewport, harmless on desktop)
     2. Native app surface         (phones + small tablets, ≤991.98px)
     3. Phones only                (≤767.98px / ≤575.98px refinements)
     4. Touch input                (hover:none / pointer:coarse)
     5. App webview extras         (body.s24-webview — the Android shell)
     6. PWA standalone + a11y motion
   ============================================================ */

/* ─── 1. Global niceties ───────────────────────────────────── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background-color: var(--bg-page, #f7f9f8);
  /* Sticky header is 4rem tall: anchor jumps must clear it */
  scroll-padding-top: 4.5rem;
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-x: none;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Keep the sticky header clear of the notch/status bar */
.menu-section {
  padding-top: env(safe-area-inset-top, 0px);
}

/* iOS momentum scrolling for horizontal rails and tables */
.table-responsive,
.s24-scroll-x,
.nav-scroller,
.dropdown-menu {
  -webkit-overflow-scrolling: touch;
}

/* Comfortable, visible focus for keyboard users on every surface */
a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.datetab:focus-visible {
  outline: 2px solid var(--primary-color, #260051);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ─── 2. Native app surface — all mobiles ──────────────────── *
   Everything here is scoped to small viewports, so the desktop
   layout is untouched. The goal is the feel of a native sports
   app: one sticky app bar, segmented controls, elevated cards,
   list rhythm, safe-area aware floating controls.                */
@media (max-width: 991.98px) {
  body {
    overflow-x: clip;
    touch-action: manipulation;
    /* style.css sets a 2rem line-height; mobile body text breathes
       better slightly tighter and keeps Arabic readable */
    line-height: 1.75;
    min-height: 100vh;
    background-color: var(--bg-page, #f7f9f8);
  }

  @supports (min-height: 100dvh) {
    body {
      min-height: 100dvh;
    }
  }

  img,
  video,
  iframe {
    max-width: 100%;
  }

  /* ── App bar: opaque, edge-to-edge elevation under the sticky bar ── */
  .menu-section {
    border-bottom: 1px solid var(--border-subtle, #e1e0e7);
    box-shadow: 0 1px 0 rgba(16, 18, 24, 0.04), 0 10px 24px -20px rgba(16, 18, 24, 0.65);
    background-color: var(--bg-surface, #fff);
  }

  .menu-section .nav-container {
    height: 3.5rem !important; /* compact bar; inline style is 4rem */
  }

  .navbar-brand img {
    height: 30px !important;
  }

  .container-lg {
    padding-left: 14px;
    padding-right: 14px;
  }

  /* ── Comfortable tap targets ── */
  .navbar-toggler,
  .menu-section button,
  .favorite-btn,
  .star-btn,
  .theme-toggle {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .datetab {
    min-height: 40px;
  }

  /* 16px stops iOS Safari from zooming on focus */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  h1 {
    font-size: clamp(1.35rem, 5vw, 1.75rem);
    line-height: 1.5;
  }
  h2 {
    font-size: clamp(1.15rem, 4.4vw, 1.5rem);
    line-height: 1.55;
  }

  /* ── Segmented control: the live/refresh/فرقي row ── */
  .live-only.rounded {
    background-color: var(--bg-surface-2, #f0f2f5);
    border: 1px solid var(--border-subtle, #e1e0e7);
    border-radius: 999px !important;
    padding: 8px 12px !important;
    gap: 4px;
  }

  .live-only__text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-body, #222226);
  }

  /* ── Date strip: pill tabs, no hard borders ── */
  .datetab {
    border-radius: 999px;
    border-color: transparent;
    background-color: var(--bg-surface, #fff);
    box-shadow: 0 1px 2px rgba(16, 18, 24, 0.06);
  }

  .datetab.active {
    box-shadow: 0 8px 18px -10px rgba(38, 0, 81, 0.7);
  }

  .datePickerMatches .form-control {
    font-weight: 600;
    background-color: transparent;
  }

  /* ── Cards: elevated native list rows ── */
  .single-match.card-outer {
    border-radius: 16px;
    border: 1px solid var(--border-subtle, #e1e0e7);
    background-color: var(--bg-surface, #fff);
    box-shadow: 0 1px 2px rgba(16, 18, 24, 0.05), 0 12px 24px -20px rgba(16, 18, 24, 0.55);
    transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
  }

  .single-match.card-outer:active {
    transform: scale(0.985);
  }

  .leagues-title {
    margin-top: 4px;
  }

  .singlecomp {
    margin-bottom: 8px;
  }

  /* Team names must truncate, never push the score out of the card */
  .cardtitle,
  .teamName {
    min-width: 0;
  }

  /* ── Horizontal rails + tables scroll like native carousels ── */
  .table-responsive {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .table-responsive::-webkit-scrollbar {
    display: none;
  }

  /* ── Floating controls respect the gesture bar ── */
  #back-to-top-btn {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: calc(16px + env(safe-area-inset-right, 0px));
  }

  .snackbar {
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  /* The bell panel is fixed at top:60px — the sticky bar is taller than
     that on mobile, so it used to slide underneath the header */
  .notification-dropdown {
    top: calc(3.5rem + env(safe-area-inset-top, 0px) + 8px);
    width: min(320px, calc(100vw - 24px));
    max-height: calc(100dvh - 8rem);
    overflow-y: auto;
  }

  /* Offcanvas menu: safe areas + native list spacing */
  .offcanvas {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-top: env(safe-area-inset-top, 0px);
  }

  .offcanvas .nav-link {
    padding: 12px 8px;
    border-radius: 10px;
  }

  /* Ads must never cause horizontal scroll on a phone */
  .adsense,
  .adspos,
  .adsbyvli {
    max-width: 100%;
    overflow-x: auto;
  }
}

/* ─── 3. Phones only ───────────────────────────────────────── */
@media (max-width: 767.98px) {
  /* Cards are emitted with style="min-width:342px" — wider than the content
     area of a 360px phone (container padding + gutters), which clipped the
     right edge. On phones a card is simply full width. */
  article.match.col,
  .skeleton-card.match.col {
    min-width: 0 !important;
    max-width: 100%;
    /* one card per row: .col is flex:1 0 0, so a bare width would let two
       cards share a 360px screen */
    flex: 1 0 100%;
  }

  .matches-container.row {
    --bs-gutter-x: 0.75rem;
    margin-inline: 0;
  }

  .matches-container > .match.col {
    padding-inline: calc(var(--bs-gutter-x) * 0.5);
  }

  /* Section header rows sit tight against their cards */
  .leagues-title {
    padding-top: 6px !important;
    padding-bottom: 2px !important;
  }

  .leagues-title h3 {
    font-size: 1rem;
    font-weight: 600;
  }

  /* Native apps use a slightly larger body size and tighter measure */
  .text-small {
    font-size: 0.8rem;
  }
}

@media (max-width: 575.98px) {
  /* The header holds logo + 3 icons + search + brand icon; keep it to one
     row by trimming the search field and dropping the decorative icon */
  #search input[type="search"] {
    width: 92px;
    padding-inline: 10px;
  }

  .facebook-icon.icon {
    display: none;
  }

  .navbar-brand {
    padding: 3px 5px !important;
  }
}

/* ─── 4. Touch input ──────────────────────────────────────── */
/* Touch devices keep :hover styles forever after a tap — neutralise them */
@media (hover: none) {
  a:hover,
  button:hover,
  .btn:hover,
  .nav-link:hover,
  .list-group-item-action:hover,
  .topplayers__item:hover,
  .card-hover:hover {
    color: inherit;
    background-color: inherit;
  }

  .card:hover,
  .match-card:hover,
  .video-card:hover {
    transform: none;
    box-shadow: none;
  }
}

/* In-app press feedback for every touch device, not just the shell */
@media (hover: none), (pointer: coarse) {
  a,
  button,
  [role="button"],
  .nav-link,
  .list-group-item-action {
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.12s ease, transform 0.12s ease;
  }

  a:active,
  button:active,
  [role="button"]:active,
  .nav-link:active,
  .list-group-item-action:active {
    opacity: 0.72;
  }

  .single-match.card-outer:active {
    opacity: 1;
    transform: scale(0.985);
  }

  .datetab:active,
  .live-only.rounded label:active {
    opacity: 0.8;
  }
}

/* ─── 5. App webview extras (Android shell only) ──────────── */
body.s24-webview {
  /* No rubber-band pull-to-refresh; the native app owns refresh */
  overscroll-behavior-y: none;
  background-color: var(--bg-page, #f7f9f8);
  min-height: 100vh;
}

@supports (height: 100dvh) {
  body.s24-webview {
    min-height: 100dvh;
  }
}

/* No long-press context menus on app chrome… */
body.s24-webview,
body.s24-webview a,
body.s24-webview button,
body.s24-webview img {
  -webkit-touch-callout: none;
}

/* …but keep article/comment text selectable and copyable */
body.s24-webview p,
body.s24-webview article,
body.s24-webview .match-page,
body.s24-webview .comment-text,
body.s24-webview .player-bio {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

/* Chrome-like app controls: no text/drag selection on interactive chrome */
body.s24-webview button,
body.s24-webview .btn,
body.s24-webview .menu-section {
  -webkit-user-select: none;
  user-select: none;
}

body.s24-webview img,
body.s24-webview svg {
  -webkit-user-drag: none;
}

/* Hide scrollbars so the webview looks like a native scroll surface */
body.s24-webview ::-webkit-scrollbar {
  width: 0;
  height: 0;
}
body.s24-webview {
  scrollbar-width: none;
}

/* ─── 6. PWA standalone + motion ──────────────────────────── */
/* Reduced motion users get an instant, calm interface */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Installed PWA / standalone mode */
@media (display-mode: standalone) {
  .menu-section {
    padding-top: env(safe-area-inset-top, 0px);
  }
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}
