/* =========================================================
   UI CLEAN - loads LAST
   - Popups scroll on PC + mobile
   - No em-dash-era layout traps
   - Clean battle pick / selection (no square frames)
   ========================================================= */

/* ---------- ALL body overlays: scrollable on desktop ---------- */
body > .bp-overlay.is-open,
body > .bp-overlay[data-bp]:not([hidden]).is-open,
body > .bp-cardview-overlay.is-open,
body > .bp-overlay[data-bp="collectible-overlay"].is-open,
body > .bp-overlay[data-bp="store-overlay"].is-open,
body > .bp-overlay[data-bp="trade-offer-overlay"].is-open,
body > .bp-overlay[data-bp="claim-reel-overlay"].is-open,
body > .bp-overlay[data-bp="edit-overlay"].is-open,
body > .bp-overlay[data-bp="reward-overlay"].is-open,
body > .bp-overlay[data-bp="star-hub-overlay"].is-open {
  display: flex !important;
  align-items: flex-start !important;
  justify-content: center !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain !important;
  -webkit-overflow-scrolling: touch !important;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom)) !important;
  box-sizing: border-box !important;
  pointer-events: auto !important;
}

/* Modal panels grow naturally and scroll if needed */
body > .bp-overlay.is-open > .bp-modal,
body > .bp-overlay.is-open .bp-store-modal,
body > .bp-overlay.is-open .bp-trade-modal,
body > .bp-overlay.is-open .bp-reward-full-modal,
body > .bp-overlay.is-open .bp-pt-full-modal,
body > .bp-overlay.is-open .bp-claim-reel-modal,
body > .bp-overlay.is-open .bp-cardview,
body > .bp-overlay.is-open .bp-star-hub {
  max-height: none !important;
  margin: 12px auto !important;
  overflow: visible !important;
}

/* Store / trade: allow full content height with page scroll */
body > .bp-overlay.is-open .bp-store-modal,
body > .bp-overlay.is-open .bp-trade-modal {
  width: min(420px, calc(100vw - 24px)) !important;
  max-width: 420px !important;
  max-height: none !important;
  overflow: visible !important;
}
body > .bp-overlay.is-open .bp-store-body,
body > .bp-overlay.is-open .bp-trade-modal-scroll {
  max-height: none !important;
  overflow: visible !important;
}

/* Card inspect: center with scroll room */
body > .bp-overlay[data-bp="collectible-overlay"].is-open .bp-cardview,
body > .bp-cardview-overlay.is-open .bp-cardview {
  max-height: none !important;
  margin: 20px auto !important;
  overflow: visible !important;
}

/* ---------- Battle root: setup scrolls; arena does not need the log ---------- */
body > .cbg-root.is-open,
body > [data-bp="card-battle-root"].is-open {
  overflow: hidden !important; /* full-screen shell */
}
body > .cbg-root.is-open .cbg-shell,
body > [data-bp="card-battle-root"].is-open .cbg-shell {
  height: 100% !important;
  max-height: 100dvh !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  min-height: 0 !important;
}

/* SETUP phase: entire panel scrolls so PC can see whole pick UI */
body > .cbg-root.is-open .cbg-setup:not([hidden]),
body > .cbg-root.is-open .cbg-setup.is-phase-on,
body > [data-bp="card-battle-root"].is-open .cbg-setup:not([hidden]) {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  overscroll-behavior: contain !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 10px !important;
  padding: 0 4px 16px !important;
}

/* Pool area: natural height inside scrollable setup (no trapped inner scroll hell) */
body > .cbg-root.is-open .cbg-setup .cbg-pool-wrap {
  flex: 0 0 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
  border: 0 !important;
  background: transparent !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
body > .cbg-root.is-open .cbg-setup .cbg-pool-head {
  background: transparent !important;
  border: 0 !important;
  border-bottom: 1px solid rgba(255,255,255,0.08) !important;
  padding: 4px 2px 8px !important;
  margin: 0 0 8px !important;
}
body > .cbg-root.is-open .cbg-setup .cbg-pool,
body > .cbg-root.is-open .cbg-setup .cbg-pool-browse {
  flex: 0 0 auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
  padding: 0 !important;
  display: block !important;
}

/* Squad row clean */
body > .cbg-root.is-open .cbg-squad {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  gap: 8px !important;
  padding: 4px 0 8px !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}
body > .cbg-root.is-open .cbg-slot {
  border: 1px dashed rgba(255,255,255,0.14) !important;
  border-radius: 10px !important;
  background: rgba(255,255,255,0.03) !important;
  box-shadow: none !important;
  outline: none !important;
  overflow: hidden !important;
}
body > .cbg-root.is-open .cbg-slot.is-filled {
  border: 0 !important;
  background: transparent !important;
  overflow: visible !important;
  box-shadow: none !important;
}

/* Pool grid: clean faces, no square chrome */
body > .cbg-root.is-open .cbg-pool-grid {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 8px 8px !important;
}
body > .cbg-root.is-open .cbg-pool-card,
body > .cbg-root.is-open .cbg-pool-face {
  border: 0 !important;
  outline: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
  aspect-ratio: 1049 / 1559 !important;
}
body > .cbg-root.is-open .cbg-pool-card > img,
body > .cbg-root.is-open .cbg-pool-face > img,
body > .cbg-root.is-open .cbg-slot.is-filled > img {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  object-position: center !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: 0 8px 18px rgba(0,0,0,0.45) !important;
  display: block !important;
}
body > .cbg-root.is-open .cbg-pool-card:hover > img,
body > .cbg-root.is-open .cbg-pool-card:focus-visible > img {
  filter: brightness(1.06) !important;
  box-shadow: 0 0 0 2px rgba(125,255,192,0.55), 0 10px 22px rgba(0,0,0,0.5) !important;
}
body > .cbg-root.is-open .cbg-pool-card.is-picked > img,
body > .cbg-root.is-open .cbg-pool-card.is-in-squad > img {
  box-shadow: 0 0 0 2px rgba(125,255,192,0.7), 0 10px 22px rgba(0,0,0,0.5) !important;
  filter: brightness(1.05) !important;
}

/* Setup action buttons: cleaner, less "boxed app UI" */
body > .cbg-root.is-open .cbg-setup-actions-top {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 8px !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 5 !important;
  background: linear-gradient(180deg, rgba(6,10,18,0.98), rgba(6,10,18,0.92)) !important;
  padding: 6px 0 8px !important;
  margin: 0 !important;
  border: 0 !important;
  box-shadow: 0 8px 16px rgba(0,0,0,0.35) !important;
}
body > .cbg-root.is-open .cbg-btn-action {
  border-radius: 12px !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  background: rgba(255,255,255,0.04) !important;
  box-shadow: none !important;
  min-height: 48px !important;
}
body > .cbg-root.is-open .cbg-btn-start:not(:disabled) {
  border-color: rgba(125,255,192,0.35) !important;
  background: linear-gradient(180deg, rgba(40,90,70,0.55), rgba(20,50,40,0.65)) !important;
}
body > .cbg-root.is-open .cbg-lead {
  margin: 0 2px !important;
  font-size: 13px !important;
  line-height: 1.35 !important;
  color: rgba(220,228,240,0.78) !important;
}

/* How-to sheet scrolls */
body > .cbg-root.is-open .cbg-howto:not([hidden]) {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
}
body > .cbg-root.is-open .cbg-howto-card {
  max-height: min(86dvh, 720px) !important;
  overflow-y: auto !important;
}

/* Coin flip / result: centered, scroll if needed */
body > .cbg-root.is-open .cbg-coinflip:not([hidden]),
body > .cbg-root.is-open .cbg-result:not([hidden]) {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
}

/* Arena: no outer scroll, field fills */
body > .cbg-root.is-open .cbg-arena:not([hidden]),
body > .cbg-root.is-open .cbg-arena.is-phase-on {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  gap: 6px !important;
}

/* Kill accidental double frames from older CSS */
body > .cbg-root.is-open .cbg-pool-card::before,
body > .cbg-root.is-open .cbg-pool-card::after,
body > .cbg-root.is-open .cbg-slot::before,
body > .cbg-root.is-open .cbg-slot::after {
  display: none !important;
  content: none !important;
}

@media (max-width: 720px) {
  body > .cbg-root.is-open .cbg-setup-actions-top {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }
  body > .cbg-root.is-open .cbg-pool-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }
  body > .bp-overlay.is-open > .bp-modal,
  body > .bp-overlay.is-open .bp-store-modal,
  body > .bp-overlay.is-open .bp-trade-modal {
    width: min(100%, calc(100vw - 20px)) !important;
    max-width: 100% !important;
  }
}

@media (min-width: 900px) {
  body > .cbg-root.is-open .cbg-pool-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
}

/* Claim reel result stats must show (ATK DEF SPD HP under reward name) */
body > .bp-overlay .bp-claim-reel-stats:not([hidden]),
#battlepass-app .bp-claim-reel-stats:not([hidden]),
body .bp-claim-reel-stats:not([hidden]) {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  visibility: visible !important;
  opacity: 1 !important;
}
