/* ==========================================================
   v179.9.72 — VIEWPORT STABILIZATION / PRIVATE BETA CLEANUP
   Narrow corrections built from the approved v179.9.70 baseline.
   - Respect iPhone safe areas / Dynamic Island in live scorecard and sheets.
   - Use stable small-viewport heights for mobile sheets; never lock Home.
   - Give MLB browsing its own scroll region with a compact selected-game preview.
   - Remove remaining Wrigley Assist blue accents.
   - Preserve a clean but intentional first-launch Home.
   ========================================================== */

/* Safari's old global smooth document scrolling turns programmatic restore
   calls into a visible top-to-bottom animation. Score-grid horizontal scrolling
   remains separately controlled by the scorebook scrollers. */
@media (max-width:900px){
  html{scroll-behavior:auto!important}
}

/* ---------- iPhone safe-area contract for the live scorecard ---------- */
@media (max-width:900px){
  body:not(.home-page) #main .live-game-bar.v115-live-sticky{
    top:env(safe-area-inset-top)!important;
  }
  body:not(.home-page) #main .mode-workspace-tabs.v115-tabs-sticky{
    top:calc(env(safe-area-inset-top) + var(--v115-livebar-h,76px))!important;
  }
  body:not(.home-page) #app #main .team-scorebook{
    scroll-margin-top:calc(env(safe-area-inset-top) + var(--v179930-team-head-top,130px) + var(--v179930-team-head-h,52px) + 8px)!important;
  }
  body:not(.home-page) #app #main .team-scorebook .team-scorebook-head{
    top:calc(env(safe-area-inset-top) + var(--v179930-team-head-top,130px))!important;
    inset-block-start:calc(env(safe-area-inset-top) + var(--v179930-team-head-top,130px))!important;
  }
  body:not(.home-page) #app #main .unified-score-table .batter-row{
    scroll-margin-top:calc(env(safe-area-inset-top) + var(--v179930-team-head-top,130px) + var(--v179930-team-head-h,52px) + 8px)!important;
  }
}

/* ---------- Stable mobile sheet geometry ----------
   Use the small viewport rather than dvh so browser chrome / live activities
   cannot resize an open sheet while the user is interacting with it. */
@media (max-width:700px){
  body:not(.home-page){
    --v179972-safe-top:max(8px,env(safe-area-inset-top));
    --v179972-safe-bottom:max(8px,env(safe-area-inset-bottom));
  }

  #playModal:not(.hidden){
    padding:var(--v179972-safe-top) 0 0!important;
    box-sizing:border-box!important;
    place-items:end stretch!important;
  }
  #playModal:not(.hidden)>.play-card{
    width:100%!important;
    max-width:none!important;
    max-height:calc(100svh - var(--v179972-safe-top))!important;
    margin:0!important;
    border-radius:22px 22px 0 0!important;
    box-sizing:border-box!important;
  }
  #playModal .modal-head{
    top:0!important;
    flex:0 0 auto!important;
  }

  body:not(.home-page) .modal:not(.hidden):not(#playModal):not(#pitchHistoryModal):not(#lineupManagerModal):not(#v176PersonalTeamModal){
    padding:var(--v179972-safe-top) 0 calc(86px + env(safe-area-inset-bottom))!important;
    box-sizing:border-box!important;
  }
  body:not(.home-page) .modal:not(.hidden):not(#playModal):not(#pitchHistoryModal):not(#lineupManagerModal):not(#v176PersonalTeamModal)>.modal-card{
    max-height:calc(100svh - var(--v179972-safe-top) - 86px - env(safe-area-inset-bottom))!important;
  }
}

/* ---------- MLB game browser: list owns the scrolling ---------- */
@media (max-width:700px){
  #mlbModal:not(.hidden)>.mlb-finder-card{
    display:flex!important;
    flex-direction:column!important;
    overflow:hidden!important;
  }
  #mlbModal .modal-head,
  #mlbModal .mlb-finder-top,
  #mlbModal .mlb-finder-status,
  #mlbModal .mlb-game-preview,
  #mlbModal .mlb-modal-actions{
    flex:0 0 auto!important;
  }
  #mlbModal .mlb-finder-top{gap:8px!important}
  #mlbModal .mlb-finder-status{
    margin:8px 0 6px!important;
    padding:5px 2px!important;
    gap:4px!important;
  }
  #mlbModal .mlb-games-list{
    flex:1 1 240px!important;
    min-height:190px!important;
    max-height:none!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    -webkit-overflow-scrolling:touch!important;
    overscroll-behavior:contain!important;
    padding:2px!important;
  }
  #mlbModal .mlb-game-row{
    min-height:62px!important;
    padding:7px!important;
  }
  #mlbModal .mlb-game-preview{
    margin-top:8px!important;
    padding:9px 10px!important;
    border-radius:13px!important;
  }
  #mlbModal .mlb-preview-head span{font-size:15px!important}
  #mlbModal .mlb-preview-grid{
    grid-template-columns:1fr 1fr!important;
    gap:5px!important;
    margin-top:7px!important;
  }
  #mlbModal .mlb-preview-grid>span{
    gap:2px!important;
    padding:6px 7px!important;
  }
  #mlbModal .mlb-preview-grid small{font-size:8px!important}
  #mlbModal .mlb-preview-grid b{font-size:9.5px!important;line-height:1.15!important}
  #mlbModal .mlb-preview-note{
    margin-top:6px!important;
    padding:6px 8px!important;
    font-size:9px!important;
    line-height:1.25!important;
  }
  #mlbModal .mlb-modal-actions{
    position:static!important;
    bottom:auto!important;
    margin-top:8px!important;
    padding:0!important;
  }
  #mlbModal .mlb-modal-actions button{min-height:48px!important}
}

/* Contrast carry-forward from the rejected beta build, without viewport rules. */
#mlbModal #mlbImportBtn,
#mlbModal #mlbUnlinkBtn{font-weight:900!important}
body.theme-default:not(.theme-generic):not(.dark-mode) #mlbModal #mlbImportBtn:not(:disabled){
  background:#171717!important;
  border-color:#171717!important;
  color:#fff!important;
}
body.theme-default:not(.theme-generic):not(.dark-mode) #mlbModal #mlbImportBtn:not(:disabled) *{color:#fff!important}
body[data-theme-family="generic"].dark-mode #mlbModal #mlbUnlinkBtn:not(.hidden){
  color:#ff8b84!important;
  border-color:color-mix(in srgb,#ff8b84 68%,var(--line))!important;
  background:color-mix(in srgb,#ff8b84 8%,var(--panel2))!important;
  font-weight:950!important;
}

/* ---------- Wrigley: Assist is yellow/cream, never legacy blue ---------- */
body[data-theme-family="wrigley"] #playModal .v171-runner-assist{
  background:var(--wr-green-800)!important;
  border-color:var(--wr-line-soft)!important;
  box-shadow:none!important;
}
body[data-theme-family="wrigley"] #playModal .v171-runner-assist>span{
  color:var(--wr-yellow)!important;
}
body[data-theme-family="wrigley"] #playModal .v171-runner-assist>small{
  color:var(--wr-cream-muted)!important;
}
body[data-theme-family="wrigley"] #playModal .v171-runner-assist button{
  background:var(--wr-green-900)!important;
  color:var(--wr-cream)!important;
  border:1px solid var(--wr-yellow)!important;
}
body[data-theme-family="wrigley"] #playModal .v149-runner-card.v171-assist-prefilled{
  box-shadow:inset 3px 0 0 var(--wr-yellow)!important;
}

/* ---------- Clean first launch: intentional, not empty ---------- */
body.v179972-fresh-home .v179972-empty-hero{
  display:grid;
  grid-template-columns:58px minmax(0,1fr);
  gap:14px;
  align-items:center;
  padding:20px 18px;
  min-height:134px;
  border:1px solid var(--line,#dfe4ea);
  border-radius:22px;
  background:var(--panel,#fff);
  color:var(--text,#172132);
  box-shadow:0 8px 24px rgba(15,23,42,.045);
}
body.v179972-fresh-home .v179972-empty-icon{
  width:54px;height:54px;display:grid;place-items:center;
  border:1px solid color-mix(in srgb,var(--accent) 35%,var(--line));
  border-radius:17px;background:color-mix(in srgb,var(--accent) 7%,var(--panel));
  color:var(--accent);font-size:27px;font-weight:850;
}
body.v179972-fresh-home .v179972-empty-copy{display:grid;gap:4px;min-width:0}
body.v179972-fresh-home .v179972-empty-copy small{font-size:8px;font-weight:950;letter-spacing:.16em;color:var(--accent)}
body.v179972-fresh-home .v179972-empty-copy strong{font-size:18px;line-height:1.15}
body.v179972-fresh-home .v179972-empty-copy p{margin:0;color:var(--muted,#687386);font-size:10px;line-height:1.4}
body.v179972-fresh-home .v179972-first-run-tip{
  display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:7px;
  padding:10px;border:1px solid var(--line,#dfe4ea);border-radius:18px;
  background:color-mix(in srgb,var(--panel,#fff) 92%,var(--accent) 8%);
}
body.v179972-fresh-home .v179972-first-run-tip>span{
  display:grid;grid-template-columns:22px minmax(0,1fr);align-items:center;gap:6px;
  min-width:0;padding:7px 6px;border-radius:11px;
}
body.v179972-fresh-home .v179972-first-run-tip b{
  width:22px;height:22px;display:grid;place-items:center;border-radius:50%;
  background:color-mix(in srgb,var(--accent) 12%,transparent);color:var(--accent);
  font-size:9px;
}
body.v179972-fresh-home .v179972-first-run-tip small{font-size:8.5px;line-height:1.2;color:var(--text,#172132);font-weight:750}
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-empty-hero,
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-first-run-tip{
  background:var(--wr-green-850,#0d4937)!important;
  border-color:var(--wr-line-soft,rgba(243,234,216,.28))!important;
  color:var(--wr-cream,#f3ead8)!important;
  box-shadow:none!important;
}
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-empty-icon{
  background:var(--wr-green-900,#093d2e)!important;
  border-color:var(--wr-line-soft,rgba(243,234,216,.28))!important;
  color:var(--wr-yellow,#efc94b)!important;
}
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-empty-copy small,
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-first-run-tip b{color:var(--wr-yellow,#efc94b)!important}
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-empty-copy p{color:var(--wr-cream-muted,#cfc6b5)!important}
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-first-run-tip small{color:var(--wr-cream,#f3ead8)!important}
body.v179972-fresh-home[data-theme-family="wrigley"] .v179972-first-run-tip b{background:var(--wr-green-900,#093d2e)!important}

@media(max-width:390px){
  body.v179972-fresh-home .v179972-empty-hero{grid-template-columns:48px minmax(0,1fr);padding:16px 14px;gap:11px}
  body.v179972-fresh-home .v179972-empty-icon{width:46px;height:46px}
  body.v179972-fresh-home .v179972-first-run-tip{gap:3px;padding:7px}
  body.v179972-fresh-home .v179972-first-run-tip>span{grid-template-columns:18px minmax(0,1fr);gap:4px;padding:5px 3px}
  body.v179972-fresh-home .v179972-first-run-tip b{width:18px;height:18px;font-size:8px}
  body.v179972-fresh-home .v179972-first-run-tip small{font-size:7.5px}
}

/* Existing game Home: compact only the card stack, never the viewport itself. */
@media(max-width:760px) and (max-height:930px){
  body.home-page:not(.v179972-fresh-home) .v97-home-inner{gap:8px!important;padding-bottom:calc(10px + env(safe-area-inset-bottom))!important}
  body.home-page:not(.v179972-fresh-home) .v97-current-game.is-final .v97-current-matchup{min-height:112px!important;padding-bottom:14px!important}
  body.home-page:not(.v179972-fresh-home) .v97-current-team img{width:46px!important;height:46px!important;margin-bottom:5px!important}
  body.home-page:not(.v179972-fresh-home) .v97-home-tabs{height:46px!important}
  body.home-page:not(.v179972-fresh-home) .v97-continue{min-height:52px!important}
  body.home-page:not(.v179972-fresh-home) .v97-home-actions{gap:8px!important}
  body.home-page:not(.v179972-fresh-home) .v97-home-actions button{min-height:62px!important;padding:7px 9px!important}
  body.home-page:not(.v179972-fresh-home) .launch-postgame.v97-postgame{min-height:50px!important}
}
