/* ============================================================
 * Mobile + PWA enhancements
 * ============================================================
 * Loaded from every page via includes/components/pwa_head.php.
 *
 * The goal isn't to redo the site's responsive work — each
 * section already has its own breakpoints in home.css and
 * home-index.css — it's to patch the cross-cutting issues
 * that become visible when the site is installed to the
 * home screen and launched as a standalone app:
 *
 *   - iPhone notch / status-bar overlap
 *   - iOS auto-zoom on input focus
 *   - touch targets smaller than Apple's 44px guideline
 *   - horizontal-scroll strips that clip on very narrow
 *     phones (stats-strip, sections-nav, feed-tabs)
 *   - tap-highlight flashing on interactive elements
 * ========================================================== */

:root {
  --nf-safe-top:    env(safe-area-inset-top, 0px);
  --nf-safe-bottom: env(safe-area-inset-bottom, 0px);
  --nf-safe-left:   env(safe-area-inset-left, 0px);
  --nf-safe-right:  env(safe-area-inset-right, 0px);
}

/* iOS Safari inflates text on landscape rotation. Disable that so
   fonts stay the size we designed them at. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Match the themed background so back-navigation never shows a
     white canvas between the cached paint and the style bundle. */
  background-color: var(--bg, #faf6ec);
}
[data-theme="dark"] html,
html[data-theme="dark"] {
  background-color: var(--bg, #0f1220);
}

/* Neutralise the blue tap-flash so interactions feel native. */
* {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

body {
  /* Allow the header's dark gradient to reach the notch, but pad
     any full-bleed bottom bar so it clears the iPhone home line. */
  padding-bottom: var(--nf-safe-bottom);
}

/* ---- iOS input auto-zoom guard --------------------------------
   Safari on iPhone zooms any <input>/<textarea>/<select> with a
   font-size below 16px when the field receives focus. Force 16px
   on small screens to prevent that lurch. */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
  /* Search box in the header is styled through a wrapper, so bump
     the input itself to avoid the zoom while keeping the visual
     size controlled by the wrapper. */
  .site-header .search-box input,
  #nfSearchInput {
    font-size: 16px !important;
  }
}

/* ---- Minimum touch targets ------------------------------------
   Apple HIG: 44×44. Most of our pills/buttons were sized around
   36–40px on mobile. Bump just the hit area with a minimum, not
   the visible padding, so the UI stays compact. */
@media (max-width: 768px) {
  .sec-pill,
  .feed-tab,
  .site-header .icon-btn,
  .site-header .menu-toggle,
  .mobile-nav a,
  .ticker-item,
  .btn-join {
    min-height: 44px;
  }
}

/* ---- Horizontal-scroll strips: never clip ---------------------
   The stats-strip and sections-nav already have overflow-x:auto
   but on very narrow phones they sometimes get compressed flex
   children that wrap. Force no-wrap + padding-right for a bit of
   breathing room past the last chip. */
@media (max-width: 520px) {
  .stats-strip-inner,
  .sections-nav-inner {
    flex-wrap: nowrap;
    scroll-padding-right: 12px;
    padding-right: calc(10px + var(--nf-safe-right));
    padding-left:  calc(10px + var(--nf-safe-left));
  }
  .stats-strip-inner > *,
  .sections-nav-inner > * {
    flex-shrink: 0;
  }
}

/* ---- Feed tabs (Telegram/Twitter/YouTube) -----
   Three tabs with "أخبار <platform>" labels overflow a 360px
   viewport and wrap onto two rows. On mobile we:
     1. Hide the "أخبار " / "منصة " prefixes via .feed-tab-pre,
        so labels collapse to just the platform name.
     2. Shrink the icon, padding, font-size and gap.
     3. Fall back to horizontal scroll below 380px as a safety
        net — useful when Facebook/Instagram tabs land later. */
/* `!important` is deliberate here: this file is included via
   pwa_head.php early in <head>, which means home-index.min.css
   (loaded later) wins the cascade on same-specificity selectors.
   The mobile overrides MUST win, so we force them. */
@media (max-width: 640px) {
  .feed-tab-pre { display: none !important; }
  .feed-tab {
    padding: 9px 12px !important;
    font-size: 13px !important;
    gap: 6px !important;
  }
  .feed-tab-ico {
    width: 16px !important;
    height: 16px !important;
  }
  .feed-tabs {
    gap: 2px !important;
    flex-wrap: nowrap !important;
  }
  .feed-tab-label {
    white-space: nowrap;
  }
}
@media (max-width: 380px) {
  .feed-tabs {
    overflow-x: auto !important;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .feed-tabs::-webkit-scrollbar { display: none; }
  .feed-tab {
    flex: 0 0 auto !important;
    padding: 9px 10px !important;
    font-size: 12.5px !important;
  }
}

/* ---- Social breaking cards on tiny screens --------------------
   tg-card / tw-card / yt-card use `flex:0 0 90px` on their image
   column. On a 320px screen that leaves ~180px for the text and
   padding, which is fine — but the 160px YT thumbnail overflows.
   Let the YT thumb shrink too below 380px. */
@media (max-width: 380px) {
  .tg-card, .tw-card, .yt-card {
    padding: 12px;
    gap: 10px;
  }
  .tg-img, .tw-img {
    flex: 0 0 76px;
    height: 76px;
  }
  .yt-img {
    flex: 0 0 104px;
    height: 60px;
  }
  .tg-text, .tw-text {
    font-size: 12.5px;
    -webkit-line-clamp: 3;
  }
  .yt-title {
    font-size: 13px;
    -webkit-line-clamp: 2;
  }
}

/* ---- Main layout edge padding --------------------------------- */
@media (max-width: 520px) {
  .main-layout,
  .nf-feature-container,
  .container {
    padding-left:  calc(12px + var(--nf-safe-left));
    padding-right: calc(12px + var(--nf-safe-right));
  }
}

/* ==============================================================
 * Standalone (installed PWA) specific tweaks
 * ============================================================ */
@media (display-mode: standalone) {
  /* The OS status bar overlaps the header when launched as a
     standalone app because our <meta status-bar-style> is
     "black-translucent". Pad the header so the logo stays clear
     of the notch. */
  .site-header {
    padding-top: var(--nf-safe-top);
  }
  /* Breaking ticker is full-bleed, nothing special.
     The bottom install banner self-dismisses because we hide
     it via JS when `window.matchMedia('(display-mode: standalone)')`
     matches — see install-prompt.js. */
}

/* iOS Safari "standalone" reports via window.navigator.standalone.
   The install-prompt.js adds `body.nf-standalone` on launch so we
   can target iOS PWA specifically too. */
body.nf-standalone .site-header {
  padding-top: calc(var(--nf-safe-top) + 4px);
}

/* Improve scroll momentum on old iOS WebKit. */
html, body {
  -webkit-overflow-scrolling: touch;
}

/* ---- Prevent scroll-snap "slide" on back navigation ----------
   The reels strip uses `scroll-snap-type:x mandatory`. When the
   browser restores its scroll position on back-nav, mandatory
   snap forces a re-align to the nearest snap point, which the
   user perceives as a horizontal slide animation. Swapping to
   `proximity` keeps the snap feel for forward user gestures but
   lets the exact restored position stick. */
.reels-scroll {
  scroll-snap-type: x proximity !important;
  overscroll-behavior-x: contain;
}

/* ---- Kill transitions during the first paint ------------------
   install-prompt.js adds `.nf-booting` on <html> before any layout
   happens, then clears it two rAFs later. While the class is on,
   no element animates between states — this prevents the visible
   "ghost of the homepage slides off to the right and vanishes"
   glitch when returning from an article via back/BFCache.
   Covers .mobile-nav (right transition), modals, drawers, header
   sticky, and any card hover transforms. */
.nf-booting *,
.nf-booting *::before,
.nf-booting *::after {
  transition: none !important;
  animation-duration: 0s !important;
  animation-delay: 0s !important;
}

/* Hide the header's bulky live-pill below 480px — already hidden by
   site-header.css at 1100px but re-state here in case of cascade
   ordering when this file loads late. */
@media (max-width: 480px) {
  .site-header .live-pill { display: none !important; }
}
