/**
 * NCBBX iOS/iPhone CSS Fixes
 * Uses body.ncbbx-ios-device (added via PHP User-Agent detection)
 * Loads on all pages - only applies when body has the class
 */

body.ncbbx-ios-device #bbx-champion-box,
body.ncbbx-ios-device #ncbbx-champion-box,
body.ncbbx-ios-device #ncbbx-seasonal-box,
body.ncbbx-ios-device #seasonalPlayers {
  min-width: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

/* Force seasonal heading block to stay responsive on iPhone */
body.ncbbx-ios-device #ncbbx-seasonal-box {
  width: min(100%, 22rem) !important;
  max-width: 100% !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding: 1rem !important;
  overflow: hidden !important;
}

body.ncbbx-ios-device #ncbbx-seasonal-box h3 {
  width: 100% !important;
  margin: 0 0 0.75rem 0 !important;
  text-align: center !important;
  font-size: clamp(1rem, 4.8vw, 1.25rem) !important;
  line-height: 1.3 !important;
  overflow-wrap: break-word !important;
  word-break: break-word !important;
}

body.ncbbx-ios-device .bbx-card,
body.ncbbx-ios-device .bbx-soft {
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

body.ncbbx-ios-device .champion-gold-ring {
  width: 7rem !important;
  height: 7rem !important;
  max-width: 90% !important;
  -webkit-backface-visibility: hidden !important;
  transform: translateZ(0) !important;
  box-sizing: border-box !important;
}

body.ncbbx-ios-device .grid > *,
body.ncbbx-ios-device .space-y-4 > *,
body.ncbbx-ios-device .space-y-5 > * {
  min-width: 0 !important;
  max-width: 100% !important;
}

body.ncbbx-ios-device .seasonal-box-row {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 0.5rem !important;
  min-width: 0 !important;
  width: 100% !important;
}

body.ncbbx-ios-device .seasonal-box-row-main,
body.ncbbx-ios-device .seasonal-row-main {
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
  flex: 1 1 auto !important;
  min-width: 0 !important;
}

body.ncbbx-ios-device .seasonal-box-row a,
body.ncbbx-ios-device .seasonal-row a {
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
  min-width: 0 !important;
}

body.ncbbx-ios-device .seasonal-box-stats-cell,
body.ncbbx-ios-device .seasonal-stats-cell {
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
  flex: 0 0 auto !important;
  white-space: nowrap !important;
  min-width: 0 !important;
}

body.ncbbx-ios-device .seasonal-box-stats-cell > *,
body.ncbbx-ios-device .seasonal-stats-cell > * {
  display: inline-flex !important;
  align-items: center !important;
}

body.ncbbx-ios-device .champion-medals-row {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 1rem !important;
  flex-wrap: wrap !important;
  min-width: 0 !important;
}

body.ncbbx-ios-device .seasonal-box-row img,
body.ncbbx-ios-device .seasonal-row img {
  width: 24px !important;
  height: 24px !important;
  min-width: 24px !important;
  min-height: 24px !important;
  max-width: 24px !important;
  max-height: 24px !important;
  object-fit: cover !important;
  flex-shrink: 0 !important;
  display: block !important;
}

body.ncbbx-ios-device .responsive-table {
  -webkit-overflow-scrolling: touch !important;
}

/* iPhone fix: contender table row/cell layout stability */
body.ncbbx-ios-device #contenders {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
}

body.ncbbx-ios-device #contenders table {
  width: 100% !important;
  min-width: 100% !important;
  table-layout: fixed !important;
  border-collapse: collapse !important;
}

body.ncbbx-ios-device #contenders thead th:nth-child(1),
body.ncbbx-ios-device #contenders tbody td:nth-child(1) {
  width: 3rem !important;
}

body.ncbbx-ios-device #contenders thead th:nth-child(3),
body.ncbbx-ios-device #contenders tbody td:nth-child(3) {
  width: 7.25rem !important;
}

body.ncbbx-ios-device #contenders .contender-row,
body.ncbbx-ios-device #contenders .contender-row td {
  min-width: 0 !important;
  max-width: 100% !important;
  vertical-align: middle !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

body.ncbbx-ios-device #contenders .contender-row td {
  padding: 0.5rem 0.375rem !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
}

body.ncbbx-ios-device #contenders .contender-row td:nth-child(2) a {
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
  min-width: 0 !important;
  width: 100% !important;
}

body.ncbbx-ios-device #contenders .contender-row td:nth-child(2) a span {
  display: block !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

body.ncbbx-ios-device #contenders .contender-row td:nth-child(2) img {
  width: 24px !important;
  height: 24px !important;
  min-width: 24px !important;
  min-height: 24px !important;
  max-width: 24px !important;
  max-height: 24px !important;
  border-radius: 9999px !important;
  object-fit: cover !important;
  flex-shrink: 0 !important;
  display: block !important;
}

body.ncbbx-ios-device #contenders .contender-row td:nth-child(3) {
  white-space: nowrap !important;
  text-align: left !important;
}

body.ncbbx-ios-device #tabContent,
body.ncbbx-ios-device .tab-content {
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}

body.ncbbx-ios-device .champion-gold-ring,
body.ncbbx-ios-device .champion-gold-ring > div {
  border-radius: 9999px !important;
  overflow: hidden !important;
}

body.ncbbx-ios-device #bbx-champion-box .champion-crown,
body.ncbbx-ios-device #ncbbx-champion-box .champion-crown {
  top: -8px !important;
  right: -8px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 28px !important;
  height: 28px !important;
  line-height: 1 !important;
  font-size: 22px !important;
  z-index: 10 !important;
  transform: translateZ(0) !important;
  -webkit-font-smoothing: antialiased !important;
}

body.ncbbx-ios-device #bbx-champion-box img.emoji,
body.ncbbx-ios-device #ncbbx-champion-box img.emoji,
body.ncbbx-ios-device #bbx-champion-box .text-lg.font-bold.mt-4.text-center.text-white img.emoji,
body.ncbbx-ios-device #ncbbx-champion-box .text-lg.font-bold.mt-4.text-center.text-white img.emoji {
  display: inline-block !important;
  width: 1em !important;
  height: 1em !important;
  min-width: 1em !important;
  min-height: 1em !important;
  max-width: 1em !important;
  max-height: 1em !important;
  margin-left: 0.2em !important;
  vertical-align: -0.12em !important;
}

body.ncbbx-ios-device #bbx-champion-box .text-yellow-400 svg,
body.ncbbx-ios-device #ncbbx-champion-box .text-yellow-400 svg,
body.ncbbx-ios-device #bbx-champion-box .bg-blue-600 svg,
body.ncbbx-ios-device #ncbbx-champion-box .bg-blue-600 svg {
  display: inline-block !important;
  flex: 0 0 16px !important;
  width: 16px !important;
  height: 16px !important;
  min-width: 16px !important;
  min-height: 16px !important;
  max-width: 16px !important;
  max-height: 16px !important;
  vertical-align: middle !important;
  transform: translateY(-0.5px) !important;
}

body.ncbbx-ios-device #bbx-champion-box .text-yellow-400,
body.ncbbx-ios-device #ncbbx-champion-box .text-yellow-400,
body.ncbbx-ios-device #bbx-champion-box .bg-blue-600,
body.ncbbx-ios-device #ncbbx-champion-box .bg-blue-600 {
  align-items: center !important;
}

body.ncbbx-ios-device .champion-gold-ring img,
body.ncbbx-ios-device #bbx-champion-box .w-28.h-28.rounded-full.overflow-hidden img,
body.ncbbx-ios-device #ncbbx-champion-box .w-28.h-28.rounded-full.overflow-hidden img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
  border-radius: 9999px !important;
  -webkit-clip-path: circle(50% at 50% 50%) !important;
  clip-path: circle(50% at 50% 50%) !important;
}

body.ncbbx-ios-device #bbx-champion-box .champion-profile-btn,
body.ncbbx-ios-device #ncbbx-champion-box .champion-profile-btn {
  display: block !important;
  width: 100% !important;
  box-sizing: border-box !important;
  line-height: 1.25 !important;
  text-align: center !important;
  text-decoration: none !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}

body.ncbbx-ios-device #bbx-champion-box a.inline-block.mt-4.px-6.py-2.bg-blue-600.hover\:bg-blue-700.text-white.rounded-lg.font-semibold.w-full.text-center,
body.ncbbx-ios-device #ncbbx-champion-box a.inline-block.mt-4.px-6.py-2.bg-blue-600.hover\:bg-blue-700.text-white.rounded-lg.font-semibold.w-full.text-center,
body.ncbbx-ios-device #bbx-champion-box a.champion-profile-btn,
body.ncbbx-ios-device #ncbbx-champion-box a.champion-profile-btn {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  min-height: 44px !important;
  padding: 0.75rem 1rem !important;
  margin-top: 1rem !important;
  background: #2563eb !important;
  color: #ffffff !important;
  border: 0 !important;
  opacity: 1 !important;
  border-radius: 0.75rem !important;
  box-sizing: border-box !important;
  text-align: center !important;
  text-decoration: none !important;
  line-height: 1.25 !important;
  white-space: normal !important;
  overflow-wrap: break-word !important;
  word-break: break-word !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}

@media screen and (max-width: 430px) {
  body.ncbbx-ios-device #contenders .contender-row td {
    font-size: 0.75rem !important;
    padding: 0.45rem 0.25rem !important;
  }

  body.ncbbx-ios-device #contenders thead th:nth-child(3),
  body.ncbbx-ios-device #contenders tbody td:nth-child(3) {
    width: 6.75rem !important;
  }

  body.ncbbx-ios-device #ncbbx-seasonal-box {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0.875rem !important;
    border-radius: 1rem !important;
  }

  body.ncbbx-ios-device #ncbbx-seasonal-box h3 {
    font-size: 1.125rem !important;
    line-height: 1.3 !important;
    margin-bottom: 0.625rem !important;
  }

  /* Keep seasonal rows on one line on iPhone (Android-like layout) */
  body.ncbbx-ios-device .seasonal-box-row,
  body.ncbbx-ios-device .seasonal-row {
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.5rem !important;
  }

  body.ncbbx-ios-device .seasonal-box-row-main,
  body.ncbbx-ios-device .seasonal-row-main {
    width: auto !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }

  body.ncbbx-ios-device .seasonal-box-stats-cell,
  body.ncbbx-ios-device .seasonal-stats-cell {
    width: auto !important;
    flex: 0 0 auto !important;
    margin-left: 0 !important;
    justify-content: flex-end !important;
    gap: 0.45rem !important;
    white-space: nowrap !important;
  }
}

/* ===========================
   Global iPhone parity layer
   Keeps iOS layout consistent with Android across plugin sections
   =========================== */
body.ncbbx-ios-device {
  -webkit-text-size-adjust: 100% !important;
  text-size-adjust: 100% !important;
}

body.ncbbx-ios-device :where(
  #tabContent,
  .tab-content,
  .pp-tab-content,
  .tournament-sub-tab-content,
  .responsive-table,
  .bbx-card,
  .bbx-soft,
  #bbx-champion-box,
  #ncbbx-champion-box,
  #ncbbx-seasonal-box,
  #seasonalPlayers,
  .events-wrapper,
  .events-grid,
  .event-card,
  .event-content,
  .event-single-wrapper,
  .event-single-grid,
  .event-single-details,
  .community-container,
  .community-filters,
  .community-posts-grid,
  .community-card,
  .community-content
) {
  min-width: 0 !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

body.ncbbx-ios-device :where(
  .events-wrapper img,
  .event-single-wrapper img,
  .community-container img,
  .bbx-card img,
  .bbx-soft img
) {
  max-width: 100% !important;
  height: auto !important;
  display: block !important;
}

body.ncbbx-ios-device :where(
  .tab-btn,
  .pp-tab-btn,
  .tournament-sub-tab-btn,
  .ncbbx-btn,
  .btn,
  .discord-btn,
  .challonge-btn,
  .champion-profile-btn,
  .event-content button,
  .community-filters button
) {
  -webkit-appearance: none !important;
  appearance: none !important;
  line-height: 1.25 !important;
  min-height: 42px !important;
  touch-action: manipulation !important;
}

body.ncbbx-ios-device :where(
  .community-filters input,
  .community-filters select,
  .events-search input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="url"],
  select,
  textarea
) {
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

body.ncbbx-ios-device .responsive-table table {
  width: 100% !important;
  border-collapse: collapse !important;
}

body.ncbbx-ios-device .responsive-table th,
body.ncbbx-ios-device .responsive-table td {
  min-width: 0 !important;
  box-sizing: border-box !important;
}

@media screen and (max-width: 768px) {
  body.ncbbx-ios-device .events-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  body.ncbbx-ios-device .community-posts-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  body.ncbbx-ios-device .community-filters form {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
  }

  body.ncbbx-ios-device .community-filters :where(input, select, button) {
    width: 100% !important;
  }

  body.ncbbx-ios-device .event-single-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
}
