
/* V4.5 — iPhone 16 Pro Max / modern large iPhone optimization
   Target CSS viewport is roughly 440px wide in portrait. Desktop/tablet remain untouched. */

@supports (padding: max(0px)) {
  html, body {
    min-height: 100%;
  }
}

@media (max-width: 480px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: 110px;
  }

  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Header: preserve artwork but give Dynamic Island / status bar breathing room in PWA mode */
  header, .topbar {
    padding-top: max(10px, env(safe-area-inset-top)) !important;
  }

  .losers-badge,
  .home-logo-link {
    width: 58px !important;
    height: 58px !important;
    min-width: 58px !important;
    min-height: 58px !important;
    border-radius: 14px !important;
  }

  .losers-badge img,
  .home-logo-link img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
  }

  .brand-title {
    font-size: clamp(24px, 7vw, 31px) !important;
    line-height: .98 !important;
    letter-spacing: -.035em !important;
    white-space: normal !important;
  }

  /* Main nav: thumb-friendly horizontal rail */
  .competition-nav {
    position: sticky;
    top: 0;
    z-index: 120;
    display: flex !important;
    gap: 7px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 8px 12px !important;
    margin: 0 -12px 10px !important;
    background: rgba(250,249,246,.95);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(0,0,0,.06);
  }
  .competition-nav::-webkit-scrollbar { display:none; }

  .competition-nav button {
    flex: 0 0 auto !important;
    min-height: 44px !important;
    padding: 0 14px !important;
    border-radius: 12px !important;
    font-size: 10px !important;
    touch-action: manipulation;
  }

  /* Global content width */
  main, .page, .content, .shell, .wrap {
    width: 100% !important;
    max-width: 100% !important;
  }

  .competition-panel {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Hero blocks */
  .competition-hero {
    padding: 18px 14px !important;
    border-radius: 17px !important;
  }
  .competition-hero h1 {
    font-size: clamp(31px, 10vw, 42px) !important;
    line-height: .98 !important;
    letter-spacing: -.035em !important;
  }
  .competition-hero p {
    font-size: 13px !important;
    line-height: 1.45 !important;
  }

  /* Home dashboard: one clear column, no crushed cards */

  .comp-card,
  .history-global-card {
    border-radius: 17px !important;
  }

  /* Match rows: readable on 440px without horizontal squeeze */
  .ll-tag {
    min-width: 36px !important;
    font-size: 8px !important;
  }

  /* Rivalry card */
  .ll-duel-score {
    padding: 10px 0 !important;
  }
  .ll-duel-score > div > b {
    font-size: 42px !important;
  }
  .ll-duel-score em {
    width: 54px !important;
    height: 54px !important;
  }

  .ll-rivalry-split-grid {
    grid-template-columns: 1fr !important;
  }

  /* Brackets/tables should scroll rather than implode */
  .bracket, .playoff-grid, .table-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  table {
    font-size: 11px !important;
  }

  /* Inputs/selects: prevent iOS zoom, 44px hit targets */
  input, select, textarea, button {
    font-size: 16px;
  }
  input, select, textarea {
    min-height: 44px !important;
  }
  button, .owner-select, .wc-controller {
    min-height: 44px !important;
    touch-action: manipulation;
  }

  /* Match protocol modal: bottom sheet style is easier on a phone */
  .matchcard-sheet,
  .team-history-sheet {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    transform: none !important;
    width: 100% !important;
    max-width: none !important;
    max-height: calc(92dvh - env(safe-area-inset-top)) !important;
    border-radius: 22px 22px 0 0 !important;
    padding: 20px 14px calc(18px + env(safe-area-inset-bottom)) !important;
  }

  .matchcard-close,
  .team-history-close {
    width: 44px !important;
    height: 44px !important;
    right: 8px !important;
    top: 7px !important;
    display: grid !important;
    place-items: center !important;
    font-size: 30px !important;
  }

  .mc-scoreline {
    grid-template-columns: minmax(0,1fr) 58px minmax(0,1fr) !important;
    gap: 7px !important;
    padding: 12px 8px !important;
  }

  .mc-event-row {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
    padding: 9px 0 !important;
    border-bottom: 1px solid #ece8e1;
  }
  .mc-event-row input,
  .mc-event-row select {
    width: 100% !important;
    font-size: 16px !important;
  }

  /* History is converted to stacked cards */
  .history-global-head {
    padding: 15px !important;
  }
  .history-item {
    grid-template-columns: 1fr auto !important;
    gap: 6px 10px !important;
    padding: 13px 0 !important;
  }
  .history-time,
  .history-editor {
    grid-column: 1;
  }
  .history-main {
    grid-column: 1 / -1;
  }
  .history-index {
    display: block !important;
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: start;
  }

  /* Team profile */
  .th-player-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .th-stat-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Footer safe area */
  .foot, footer {
    padding-bottom: calc(18px + env(safe-area-inset-bottom)) !important;
  }
}

/* Specifically tune portrait width used by iPhone 16 Pro Max */
@media (min-width: 430px) and (max-width: 450px) {
  .competition-panel {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .competition-nav {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .ll-record-row {
    grid-template-columns: 26px minmax(0,1fr) 54px minmax(0,1fr) !important;
  }
}

/* Landscape: use the extra room instead of giant single-column cards */
@media (max-height: 500px) and (orientation: landscape) {
  .matchcard-sheet,
  .team-history-sheet {
    max-height: 100dvh !important;
    border-radius: 0 !important;
  }
}
