/* NRPSL 2K26 — mobile & touch layouts (phase 1) */

@media (max-width: 900px) {
  .playoff-select,
  .playoff-wildcard-intro {
    padding:
      calc(18px + var(--safe-top))
      calc(16px + var(--safe-right))
      calc(18px + var(--safe-bottom))
      calc(16px + var(--safe-left));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .playoff-team-card {
    min-height: 0;
  }
}

@media (max-width: 680px) {
  .broadcast {
    min-height: 100dvh;
  }

  /* —— Main menu —— */
  .main-menu {
    align-content: start;
    gap: 12px;
    padding:
      calc(56px + var(--safe-top))
      calc(16px + var(--safe-right))
      calc(20px + var(--safe-bottom))
      calc(16px + var(--safe-left));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .logo-lockup h1 {
    font-size: clamp(42px, 14vw, 72px);
  }

  .presenter-logo {
    width: min(72vw, 220px);
  }

  .main-menu button.play-now,
  .main-menu button.alt-mode,
  .main-menu .playoffs-mode-button {
    width: min(100%, 320px);
    min-width: 0;
    height: 52px;
  }

  .main-menu .music-toggle,
  .main-menu .credits-toggle {
    top: calc(10px + var(--safe-top));
    right: auto;
    width: auto;
    min-width: 88px;
    min-height: 36px;
    padding: 0 10px;
    transform: none;
  }

  .main-menu .music-toggle {
    left: calc(12px + var(--safe-left));
  }

  .main-menu .credits-toggle {
    left: calc(108px + var(--safe-left));
    top: calc(10px + var(--safe-top));
  }

  .main-menu .music-toggle:hover,
  .main-menu .music-toggle:focus-visible,
  .main-menu .credits-toggle:hover,
  .main-menu .credits-toggle:focus-visible {
    transform: none;
  }

  /* —— Intro —— */
  .intro-continue {
    bottom: calc(20px + var(--safe-bottom));
    width: min(calc(100vw - 40px), 280px);
    min-height: var(--touch-min);
  }

  .intro-court::before,
  .intro-court::after {
    width: 280px;
    height: 280px;
  }

  /* —— In-match HUD —— */
  .scorebug {
    top: calc(10px + var(--safe-top));
    width: calc(100vw - 20px - var(--safe-left) - var(--safe-right));
    min-height: 56px;
    grid-template-columns: minmax(0, 1fr) 92px minmax(0, 1fr);
  }

  body.playoffs-active .scorebug {
    top: calc(8px + var(--safe-top));
    width: calc(100vw - 16px - var(--safe-left) - var(--safe-right));
    grid-template-columns: minmax(0, 1fr) 108px minmax(0, 1fr);
  }

  body.playoffs-active .playoff-series-panel {
    top: calc(62px + var(--safe-top));
  }

  body.playoffs-active.match-mode .match-log {
    top: calc(78px + var(--safe-top));
  }

  .match-meta button {
    min-width: 0;
    min-height: 30px;
    height: auto;
    padding: 4px 6px;
    font-size: 9px;
  }

  .choice-panel {
    left: 50%;
    right: auto;
    width: calc(100vw - 20px - var(--safe-left) - var(--safe-right));
    max-width: 420px;
    justify-content: center;
    gap: 8px;
  }

  /* Match: commentary on the bottom rail; throws sit above it (desktop uses 66px / 16px). */
  body.match-mode .ticker {
    bottom: calc(10px + var(--safe-bottom));
    z-index: 2;
    min-height: 30px;
    padding: 6px 10px;
    font-size: 11px;
    line-height: 1.25;
  }

  body.match-mode .choice-panel {
    bottom: calc(48px + var(--safe-bottom));
    z-index: 3;
  }

  .choice-panel button {
    flex: 1 1 0;
    min-width: 0;
    min-height: var(--touch-min);
    height: auto;
    padding: 10px 6px;
    font-size: 12px;
  }

  .overview-rosters {
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
    bottom: calc(78px + var(--safe-bottom));
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .overview-rosters button {
    width: 100%;
    min-width: 0;
    min-height: var(--touch-min);
    height: auto;
  }

  .match-log {
    top: calc(78px + var(--safe-top));
    right: calc(10px + var(--safe-right));
    width: calc(100vw - 20px - var(--safe-left) - var(--safe-right));
    max-width: none;
    min-width: 0;
    resize: none;
  }

  .ticker {
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
  }

  /* —— Blacktop —— */
  body.blacktop-select-mode {
    overflow: hidden;
  }

  body.blacktop-select-mode .blacktop-select {
    display: flex;
    flex-direction: column;
    inset: 0;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    pointer-events: auto;
  }

  body.blacktop-select-mode .blacktop-side {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    padding:
      calc(12px + var(--safe-top))
      calc(12px + var(--safe-right))
      14px
      calc(12px + var(--safe-left));
    border-right: 0;
    border-bottom: 1px solid rgba(247, 240, 223, 0.12);
    overflow: visible;
  }

  body.blacktop-select-mode .blacktop-side.right {
    border-bottom: 0;
    padding-top: 10px;
  }

  body.blacktop-select-mode .blacktop-side header {
    flex: 0 0 auto;
  }

  body.blacktop-select-mode .blacktop-team-nav {
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
    pointer-events: auto;
  }

  body.blacktop-select-mode .blacktop-cycle {
    min-width: var(--touch-min);
    width: var(--touch-min);
    min-height: var(--touch-min);
    height: var(--touch-min);
    pointer-events: auto;
  }

  body.blacktop-select-mode .blacktop-player-card {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    min-height: 96px;
    margin: 0;
    padding: 12px 14px;
  }

  body.blacktop-select-mode .blacktop-player-card h2 {
    font-size: clamp(28px, 8.5vw, 40px);
  }

  body.blacktop-select-mode .blacktop-player-ovr strong {
    font-size: clamp(24px, 7vw, 34px);
  }

  body.blacktop-select-mode .blacktop-roster {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    max-height: none;
    margin-top: 0;
    overflow: visible;
    pointer-events: auto;
  }

  body.blacktop-select-mode .blacktop-roster button {
    position: relative;
    z-index: 2;
    min-height: var(--touch-min);
    height: auto;
    padding: 10px 12px;
    pointer-events: auto;
  }

  body.blacktop-select-mode .blacktop-actions {
    flex: 0 0 auto;
    position: relative;
    left: auto;
    bottom: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    width: 100%;
    min-height: 108px;
    margin: 0;
    padding:
      8px
      calc(12px + var(--safe-right))
      calc(12px + var(--safe-bottom))
      calc(12px + var(--safe-left));
    transform: none;
    pointer-events: auto;
  }

  body.blacktop-select-mode .blacktop-actions #startBlacktop {
    position: relative;
    flex: 0 0 auto;
    width: min(100%, 360px);
    min-width: 0;
    min-height: 52px;
    background: #f0c45c;
    color: #11131a;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  body.blacktop-select-mode .blacktop-actions #backFromBlacktop {
    position: relative;
    flex: 0 0 auto;
    width: 150px;
    min-width: 0;
    min-height: 38px;
    margin-top: 0;
    font-size: 12px;
  }

  /* —— Player cards —— */
  body.player-cards-mode .player-cards {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    padding:
      calc(10px + var(--safe-top))
      calc(12px + var(--safe-right))
      calc(12px + var(--safe-bottom))
      calc(12px + var(--safe-left));
  }

  body.player-cards-mode .player-cards header {
    flex: 0 0 auto;
  }

  .player-cards header h1 {
    font-size: clamp(26px, 8vw, 40px);
  }

  .player-cards header p {
    font-size: 11px;
    letter-spacing: 0.12em;
  }

  .player-card-grid {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 4px 2px 10px;
    scroll-padding-bottom: 16px;
  }

  .player-team-group {
    overflow: visible;
  }

  .player-team-group.open {
    margin-bottom: 12px;
  }

  .player-team-toggle {
    grid-template-columns: 50px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 6px 12px;
    align-items: start;
    min-height: 72px;
    height: auto;
    padding: 12px 14px;
  }

  .team-toggle-logo {
    grid-row: 1 / span 2;
    align-self: center;
    width: 50px;
    height: 50px;
  }

  .team-toggle-logo img {
    width: 76%;
    height: 76%;
    object-fit: contain;
  }

  .player-team-toggle > span:not(.team-toggle-logo) {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding-right: 4px;
  }

  .player-team-toggle b {
    font-size: clamp(17px, 4.8vw, 22px);
    line-height: 1.06;
    overflow-wrap: anywhere;
  }

  .player-team-toggle small {
    margin-top: 0;
    font-size: 10px;
    line-height: 1.35;
    letter-spacing: 0.08em;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .player-team-toggle strong {
    grid-column: 3;
    grid-row: 1;
    align-self: start;
    font-size: clamp(16px, 4.2vw, 20px);
    line-height: 1;
    padding-top: 2px;
  }

  .player-team-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(172px, auto);
    gap: 10px;
    padding: 4px 10px 14px;
  }

  .league-player-card {
    min-height: 172px;
    height: auto;
    overflow: visible;
    padding: 10px 10px 12px;
  }

  .card-logo {
    width: 52px;
    height: 52px;
    margin: 28px auto 8px;
  }

  .card-name {
    min-height: auto;
    font-size: 16px;
    line-height: 1.08;
    padding: 0 2px;
  }

  .card-team {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    line-height: 1.2;
    min-height: 24px;
  }

  .card-overall strong {
    font-size: 26px;
  }

  .player-cards > button {
    width: min(100%, 320px);
    min-height: var(--touch-min);
    height: auto;
    margin-top: 4px;
  }

  .player-profile-modal {
    padding:
      calc(12px + var(--safe-top))
      calc(10px + var(--safe-right))
      calc(12px + var(--safe-bottom))
      calc(10px + var(--safe-left));
    align-items: center;
  }

  .profile-card {
    width: min(100%, 390px);
    max-height: min(88dvh, 640px);
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .profile-card h2 {
    font-size: clamp(28px, 8vw, 40px);
  }

  /* —— Team select —— */
  .team-select {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: none;
    min-height: 100dvh;
    max-height: 100dvh;
    padding:
      calc(12px + var(--safe-top))
      calc(12px + var(--safe-right))
      calc(12px + var(--safe-bottom))
      calc(12px + var(--safe-left));
    transform: none;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    pointer-events: auto;
  }

  .team-select::after {
    display: none;
  }

  .team-select header {
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
  }

  .team-select h1 {
    font-size: clamp(28px, 8vw, 44px);
  }

  .team-carousel {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    width: 100%;
    min-height: 0;
    margin-bottom: 4px;
  }

  .versus-mark {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    margin: 0 auto;
    font-size: 18px;
  }

  .team-card {
    flex: 0 0 auto;
    min-height: 0;
    max-height: none;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    padding: 14px 12px;
  }

  .team-card h2 {
    font-size: clamp(18px, 5.5vw, 28px);
    margin-top: 10px;
  }

  .team-card > div {
    padding-bottom: 52px;
  }

  .team-logo {
    width: 92px;
    height: 92px;
  }

  .team-card .team-logo {
    margin-top: -8px;
  }

  .team-card small {
    margin-top: 10px;
    font-size: 10px;
  }

  .cycle-team,
  .random-team {
    min-height: var(--touch-min);
  }

  .cycle-team {
    width: 40px;
    min-width: 40px;
    height: 56px;
    font-size: 28px;
  }

  .team-select fieldset {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 10px 12px;
  }

  .team-select fieldset label {
    flex: 1 1 calc(50% - 10px);
    min-width: 0;
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    font-size: 11px;
  }

  .team-select > #confirmTeams,
  .team-select > #backToMenu {
    position: relative !important;
    inset: auto !important;
    flex: 0 0 auto;
    width: 100%;
    max-width: 360px;
    align-self: center;
    margin: 0;
    z-index: 1;
  }

  .team-select > #confirmTeams {
    min-height: var(--touch-min);
    margin-top: 4px;
    order: 1;
  }

  .team-select > #backToMenu {
    order: 2;
    min-height: var(--touch-min);
    margin-top: 4px;
  }

  /* —— Board assignment (same scroll model as team select) —— */
  body.assignment-mode .roster-setup {
    inset: 0;
    display: flex !important;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: none;
    min-height: 100dvh;
    max-height: 100dvh;
    height: 100dvh;
    transform: none !important;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    pointer-events: auto;
    padding:
      calc(10px + var(--safe-top))
      calc(12px + var(--safe-right))
      calc(20px + var(--safe-bottom))
      calc(12px + var(--safe-left));
  }

  body.assignment-mode .roster-setup header,
  body.assignment-mode .assignment-grid,
  body.assignment-mode .assignment-card-tray,
  body.assignment-mode .roster-setup > button {
    flex: 0 0 auto;
  }

  body.assignment-mode .roster-setup header {
    width: 100%;
    grid-template-columns: 72px 1fr;
    column-gap: 12px;
  }

  body.assignment-mode .roster-setup h1 {
    font-size: clamp(22px, 6vw, 32px);
  }

  body.assignment-mode .assignment-grid {
    width: 100%;
    gap: 10px;
  }

  body.assignment-mode .assignment-board-slot {
    padding: 12px;
  }

  body.assignment-mode .assignment-dropzone {
    min-height: 120px;
  }

  body.assignment-mode .assignment-dropzone b {
    font-size: 16px;
  }

  body.assignment-mode .assignment-card-tray {
    width: 100%;
    grid-auto-columns: minmax(124px, 42vw);
    min-height: 186px;
    max-height: none;
    padding: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  body.assignment-mode .assignment-player-card {
    min-height: 168px;
    height: auto;
    padding: 12px 12px 14px;
    overflow: visible;
    touch-action: pan-x pan-y;
  }

  body.assignment-mode .assignment-player-card img {
    margin: 34px auto 8px;
  }

  body.assignment-mode .assignment-player-card b {
    min-height: 0;
    line-height: 1.15;
    padding: 0 4px;
    overflow-wrap: anywhere;
  }

  body.assignment-mode .assignment-player-card small {
    margin-top: 4px;
    line-height: 1.2;
  }

  body.assignment-mode .assignment-player-card.selected {
    outline: 2px solid #f0c45c;
    outline-offset: 2px;
  }

  body.assignment-mode .roster-setup > button {
    width: 100%;
    max-width: none;
    min-height: var(--touch-min);
    margin: 8px 0 0;
  }

  body.assignment-mode .roster-setup > #beginMatchup {
    background: #f0c45c;
    color: #11131a;
  }

  /* —— Board overview (pick a board to play) —— */
  body.overview-mode .scorebug {
    top: calc(8px + var(--safe-top));
  }

  body.overview-mode .overview-rosters {
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
    bottom: calc(12px + var(--safe-bottom));
    z-index: 4;
  }

  body.overview-mode .ticker {
    display: none;
  }

  .board-actions.open {
    position: fixed;
    left: 50%;
    bottom: calc(12px + var(--safe-bottom));
    top: auto;
    width: calc(100vw - 20px - var(--safe-left) - var(--safe-right));
    max-width: 420px;
    transform: translateX(-50%);
    z-index: 5;
  }

  .board-actions div {
    flex-wrap: wrap;
  }

  .board-actions button {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }

  /* —— Modals —— */
  .finish-confirm div,
  .credits-panel div {
    width: min(calc(100vw - 24px), 420px);
    max-height: min(80dvh, 520px);
    overflow-y: auto;
  }

  .board-actions {
    width: calc(100vw - 24px);
    max-width: 420px;
  }

  .board-actions button {
    flex: 1 1 0;
    min-width: 0;
    min-height: var(--touch-min);
  }
}

@media (max-width: 480px) {
  .team-card > div {
    padding-bottom: 50px;
  }

  .assignment-dropzone {
    min-height: 100px;
  }

  body.assignment-mode .assignment-card-tray {
    min-height: 186px;
    max-height: none;
  }

  .versus-mark {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .play-now span {
    font-size: 18px;
  }

  .blacktop-side h1 {
    font-size: clamp(20px, 6vw, 28px);
  }

  .match-log header,
  .match-log li {
    grid-template-columns: 22px 20px 18px 20px 20px 44px;
    font-size: 10px;
  }
}

/* —— Match arena: immersive phone landscape —— */
@media (orientation: landscape) and (hover: none) and (pointer: coarse) {
  body.match-mode {
    min-height: 100dvh;
    min-height: 100svh;
    overflow: hidden;
  }

  body.match-mode .broadcast {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    min-width: 100vw;
    min-height: 100dvh;
    min-height: 100svh;
    overflow: hidden;
  }

  body.match-mode canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  body.match-mode .scorebug {
    top: calc(4px + var(--safe-top));
    width: calc(100vw - 12px - var(--safe-left) - var(--safe-right));
    max-width: none;
    min-height: 40px;
    grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr);
  }

  body.match-mode .team {
    padding: 3px 8px;
    gap: 6px;
  }

  body.match-mode .team strong {
    font-size: 22px;
  }

  body.match-mode .team span,
  body.match-mode .match-meta span,
  body.match-mode .match-meta b {
    font-size: 9px;
  }

  body.match-mode .match-meta button {
    min-height: 22px;
    padding: 2px 5px;
    font-size: 8px;
  }

  body.playoffs-active.match-mode .scorebug {
    top: calc(4px + var(--safe-top));
    width: calc(100vw - 12px - var(--safe-left) - var(--safe-right));
    grid-template-columns: minmax(0, 1fr) 88px minmax(0, 1fr);
  }

  body.playoffs-active .playoff-series-panel {
    top: calc(44px + var(--safe-top));
    font-size: 9px;
    letter-spacing: 0.06em;
  }

  body.playoffs-active.match-mode .match-log {
    top: calc(50px + var(--safe-top));
  }

  body.match-mode .match-log {
    top: calc(46px + var(--safe-top));
    right: calc(6px + var(--safe-right));
    width: min(168px, 32vw);
    max-height: min(34dvh, 120px);
    min-height: 36px;
  }

  body.match-mode .match-log header {
    padding: 6px 8px;
  }

  body.match-mode .match-log header span {
    font-size: 10px;
  }

  body.match-mode .choice-panel {
    left: 50%;
    right: auto;
    bottom: calc(6px + var(--safe-bottom));
    width: min(calc(100vw - 16px - var(--safe-left) - var(--safe-right)), 520px);
    max-width: none;
    transform: translateX(-50%);
    gap: 6px;
  }

  body.match-mode .choice-panel button {
    min-height: 40px;
    padding: 8px 8px;
    font-size: 11px;
  }

  body.match-mode .ticker {
    left: 50%;
    right: auto;
    width: min(calc(100vw - 24px - var(--safe-left) - var(--safe-right)), 640px);
    transform: translateX(-50%);
    bottom: calc(50px + var(--safe-bottom));
    min-height: 24px;
    padding: 4px 10px;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .main-menu {
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: auto;
    align-items: start;
    gap: 8px 12px;
  }

  .main-menu .logo-lockup,
  .main-menu .presenter-logo {
    grid-column: 1 / -1;
  }

  .main-menu button.play-now,
  .main-menu button.alt-mode,
  .main-menu .playoffs-mode-button {
    width: 100%;
    height: 44px;
  }

  body.blacktop-select-mode .blacktop-select {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  body.blacktop-select-mode .blacktop-side {
    min-height: 0;
    overflow: visible;
  }
}

@media (hover: none) and (pointer: coarse) {
  button {
    -webkit-tap-highlight-color: transparent;
  }

  .player-team-toggle,
  .league-player-card,
  .blacktop-roster button {
    min-height: var(--touch-min);
  }

  body.assignment-mode .roster-setup {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  body.assignment-mode .assignment-player-card {
    touch-action: pan-x pan-y;
  }

  body.assignment-mode .assignment-player-card.drag-armed,
  body.assignment-mode .assignment-player-card.dragging {
    touch-action: none;
  }

  body.assignment-mode .assignment-card-tray {
    touch-action: pan-x pan-y;
  }
}
