/* HRK PWA app-shell — global rules that make the standalone-installed
 * site feel like a native iOS app. Loaded on every page via the head
 * block managed by scripts/inject_pwa_head.py.
 *
 * Only the rules that ALWAYS apply (regardless of standalone) live in
 * the :root block. Rules that activate only when running as installed
 * PWA are scoped inside @media (display-mode: standalone) and the
 * supports-based standalone selector for older iOS Safari (which
 * never updated to support display-mode: standalone in the matcher
 * sense — uses navigator.standalone via JS to add .pwa-standalone).
 */

:root {
  /* iPhone X+ safe-area insets. Pages opt in by padding with these. */
  --hrk-safe-top:    env(safe-area-inset-top, 0px);
  --hrk-safe-right:  env(safe-area-inset-right, 0px);
  --hrk-safe-bottom: env(safe-area-inset-bottom, 0px);
  --hrk-safe-left:   env(safe-area-inset-left, 0px);

  /* Bottom tab bar height — used by pages to reserve scroll room. */
  --hrk-tabbar-h: 50px;
}

html, body {
  /* Block iOS's pull-to-refresh + overscroll bounce on the document.
     Inner scrollable elements (tables, dialogs) keep their own scroll. */
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;

  /* ─── iOS SCROLL FREEZE FIX — DO NOT REMOVE ───────────────────────
     `background-attachment: fixed` on <body> HARD-FREEZES scrolling on
     iOS WebKit (Safari AND iOS Chrome — both are WebKit). The page
     becomes completely unscrollable on iPhone. Several HRK pages set it
     on html,body for a subtle fixed top glow; this global !important
     override neutralizes it everywhere app-shell.css is loaded (all 45
     /app/*.html pages) without having to touch each page's <style>.
     The glow simply scroll-attaches instead — visually near-identical.
     The research grid (/app/ index) and HR Central don't load this file,
     so they're fixed at their generator source instead. If scrolling on
     iPhone ever breaks again, grep the codebase for
     `background-attachment` first. */
  background-attachment: scroll !important;
}

/* Tap highlight is the grey rectangle that flashes when you tap a link
   on iOS Safari. Pure giveaway that you're in a browser. Kill it. */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Prevent iOS from auto-zooming when you focus an <input> with
   font-size < 16px. Apply to text inputs only (other elements may
   legitimately want smaller text). */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="tel"],
input[type="url"],
textarea,
select {
  font-size: 16px;
}

/* Hide caret in non-input UI text (e.g., tappable cards): prevents the
   blinking text cursor showing if someone double-taps. */
:root { caret-color: transparent; }
input, textarea, [contenteditable] { caret-color: auto; }

/* Disable text selection on UI chrome — the topbar shouldn't be
   selectable. Pages override on prose content (article, etc.). */
header, nav, footer, .hrk-install-prompt {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ─── Bottom tab bar — installed / standalone PWA only ───
 * 5 quick-access tabs that make the installed app feel native. Renders
 * only in standalone (pwa.js gates it). It COEXISTS with the hamburger
 * top nav — we deliberately do NOT hide the nav (the earlier version did,
 * which lost access to ~13 pages). The tab bar is purely additive.
 * Visible only in browser tabs: never (display:none default below). */

.hrk-tabbar { display: none; }

/* Standalone (installed): show the bar + reserve scroll room so page
   content (e.g. the leaderboard's bottom rows) clears it. Two selectors:
   the @media for modern standalone, and html.pwa-standalone (pwa.js adds
   it) for older iOS Safari that sets navigator.standalone but doesn't
   match the media query. */
@media all and (display-mode: standalone) {
  body { padding-bottom: calc(var(--hrk-tabbar-h) + var(--hrk-safe-bottom)); }
  .hrk-tabbar { display: flex; }
}
html.pwa-standalone body {
  padding-bottom: calc(var(--hrk-tabbar-h) + var(--hrk-safe-bottom));
}
html.pwa-standalone .hrk-tabbar { display: flex; }

.hrk-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--hrk-tabbar-h) + var(--hrk-safe-bottom));
  padding-bottom: var(--hrk-safe-bottom);
  background: rgba(10, 8, 8, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  align-items: stretch;
  justify-content: space-around;
  z-index: 1000;
  font-family: 'Inter', system-ui, sans-serif;
}
.hrk-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-decoration: none;
  color: #8a8a98;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.hrk-tab.active { color: #F5C542; }
.hrk-tab .hrk-tab-icon {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
}
.hrk-tab .hrk-tab-label {
  font-size: 10px; line-height: 1; text-transform: uppercase;
}

/* In standalone, lift the chat bubble clear of the tab bar (it used to
   sit on top of the Account tab) and stop the hamburger drawer at the top
   of the tab bar so the bar doesn't cover the bottom menu items. */
html.pwa-standalone .hrk-chat-btn {
  bottom: calc(var(--hrk-tabbar-h) + var(--hrk-safe-bottom) + 16px) !important;
}
@media all and (display-mode: standalone) {
  .hrk-chat-btn {
    bottom: calc(var(--hrk-tabbar-h) + var(--hrk-safe-bottom) + 16px) !important;
  }
}
html.pwa-standalone #hrk-mobile-drawer {
  bottom: calc(var(--hrk-tabbar-h) + var(--hrk-safe-bottom)) !important;
}
@media all and (display-mode: standalone) {
  #hrk-mobile-drawer {
    bottom: calc(var(--hrk-tabbar-h) + var(--hrk-safe-bottom)) !important;
  }
}

/* ─── "Add to Home Screen" prompt ─── */

.hrk-install-prompt {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--hrk-safe-bottom));
  z-index: 2000;
  background: linear-gradient(135deg, rgba(20, 20, 26, 0.98), rgba(14, 14, 18, 0.98));
  border: 1px solid rgba(245, 197, 66, 0.4);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  font-family: 'Inter', system-ui, sans-serif;
  color: #f1e7dd;
  font-size: 13px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  animation: hrk-install-slide-in 0.35s ease-out;
}
@keyframes hrk-install-slide-in {
  from { opacity: 0; transform: translateY(80px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hrk-install-prompt .hrk-install-title {
  font-weight: 800;
  font-size: 14px;
  color: #F5C542;
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}
.hrk-install-prompt .hrk-install-steps {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12.5px;
  color: #d4cabb;
}
.hrk-install-prompt .hrk-install-steps li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.hrk-install-prompt .hrk-install-steps .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(245, 197, 66, 0.15);
  color: #F5C542;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.hrk-install-prompt .hrk-install-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: 0;
  color: #8a8a98;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}
.hrk-install-prompt .hrk-install-close:active {
  color: #f1e7dd;
}

/* ─── Bottom fixed-element stacking (mobile) ───
 * Several elements anchor to the bottom of the viewport: the iOS install
 * banner (#hrk-pwa-prompt, body.hrk-install-open), the "keep across
 * devices" sync CTA (#hrk-sync-cta, body.hrk-cta-open), and the chat
 * bubble (.hrk-chat-btn). Left uncoordinated they pile up at the same
 * spot — the install banner hid the leaderboard's bottom rows, and the
 * chat bubble covered the CTA's dismiss button. These rules reserve
 * scroll room and lift each element clear of whatever is below it. */
@media (max-width: 900px) {
  /* Reserve scroll room so page content (e.g. the leaderboard table +
     footer) can scroll clear of the fixed install banner. */
  body.hrk-install-open {
    padding-bottom: calc(150px + var(--hrk-safe-bottom)) !important;
  }

  /* Sync CTA sits above the install banner when both are present. */
  body.hrk-install-open #hrk-sync-cta {
    bottom: calc(150px + var(--hrk-safe-bottom)) !important;
  }

  /* Chat bubble lifts clear of whatever bottom banner is showing so it
     never covers a banner's dismiss / action buttons. */
  body.hrk-cta-open .hrk-chat-btn {
    bottom: calc(96px + var(--hrk-safe-bottom)) !important;
  }
  body.hrk-install-open .hrk-chat-btn {
    bottom: calc(150px + var(--hrk-safe-bottom)) !important;
  }
  body.hrk-install-open.hrk-cta-open .hrk-chat-btn {
    bottom: calc(236px + var(--hrk-safe-bottom)) !important;
  }
}

/* Reduce motion respects user preference globally. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Mobile legibility: dense data-cell text ─────────────────────────────
   Network mobile-QA fix (2026-06-20): on phones, raise the smallest
   data-bearing text in stat tables / scanners to a comfortably legible
   minimum (>=12px). Scoped to small viewports only so desktop is unchanged.
   Dense tables already live in overflow:auto/overflow-x:auto wrappers, so
   enlarging cell text widens the scrollable table — it never adds
   page-level horizontal overflow. Decorative chrome (sort arrows, nav
   eyebrows, switcher labels) is intentionally left alone. */
@media (max-width: 600px) {
  /* secondary line inside a table cell (matchup under a player/market) */
  .matchup,
  table.tbl tbody td .matchup { font-size: 12px !important; }
  /* sportsbook / source tags rendered inside data cells */
  .book-tag,
  table.tbl tbody td .book-tag { font-size: 11px !important; }
  /* ensure the primary data cell text itself is never below 12px */
  table.tbl tbody td,
  table.alt-table tbody td { font-size: 12px !important; }
  /* clickable player/team links inherit cell size; pin to >=12 as a floor */
  td a.hrk-tlink, .matchup a.hrk-tlink { font-size: inherit !important; }
  /* dense PrizePicks demon/goblin + info pill tags (all-props scanner) */
  .otag, .infotag { font-size: 11px !important; }
}


/* ── Mobile: stat strips pack instead of stacking ─────────────────────────────
   Compact stat strips size themselves with `repeat(auto-fit, minmax(150..180px,
   1fr))`. A 390px phone has ~340px of usable row, so ONE column fits and a strip
   that reads as a row on desktop becomes N full-width blocks — 324px of screen
   for the three numbers on /app/today.

   Lowering the floor lets them sit side by side. This shows MORE per screen,
   never less: nothing is hidden, dropped, collapsed behind a tap, or shrunk.

   THE FLOORS BELOW ARE MEASURED, NOT CHOSEN. A floor that is too low is worse
   than none: the tile gets narrower than its own label, the label wraps to more
   lines, and the strip ends up TALLER. Heights at 390px, per floor:

                     current   102px   120px
     .slate-hero        324     135     216     today
     .overall           222     134     222     results
     .stat-grid         321     140     210     status
     .statgrid          798     608     798     accuracy   <- 102 helps
     .statgrid          220     235     220     asg        <- 102 HURTS
     .statgrid          439     549     439     hr-derby   <- 102 HURTS
     .summary           202     230     202     tracker    <- 102 HURTS

   So `.slate-hero` and `.overall` (single-page selectors, both clearly better at
   102) get 102. `.stat-grid` gets 120, which helps status and leaves team alone.
   `.statgrid` and `.summary` are NOT touched at all: they are shared by pages
   that move in opposite directions, and there is no floor that helps one without
   hurting another. A partial win with no regressions beats a bigger win that
   makes three pages worse.

   `grid-template-columns` is inert on anything that is not display:grid, so a
   selector meaning something else elsewhere is unaffected. `.hero` is
   deliberately excluded — it doubles as the page-title wrapper network-wide.
   Card grids with a 220px+ floor (.picks-grid, .sport-grid, .live-grid, .cards …)
   are left alone: they hold real content and one-per-row IS right on a phone. */
@media (max-width: 600px) {
  .slate-hero,
  .overall {
    grid-template-columns: repeat(auto-fit, minmax(102px, 1fr)) !important;
  }
  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
  }
  /* Tiles padded for a full-width block are mostly padding at a third of the
     width; trim the horizontal side only so the number keeps its breathing room. */
  .slate-hero > .stat,
  .overall > * {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
}
