/* =================================================================
   WMMC — Mobile Experience (rebuilt)
   Activates at ≤ 768 px. This round focuses on the Scoreboard (home)
   landing: a balanced header, a centered readable banner, the Pool
   Play Overall card, and stacked, tap-to-expand Pool Play 1 / Pool
   Play 2 sections. Other tabs fall back to the desktop layout.

   Colors come from the global CSS custom properties in styles.css, so
   both Light and Dark themes (html.theme-dark) work automatically —
   never hardcode theme colors here.
   ================================================================= */

/* Header short title hidden on desktop; shown on mobile by media query */
.header-title-short {
  display: none;
}

/* ── Bottom nav (always in DOM, hidden on desktop) ───────────────── */
.mobile-bottom-nav {
  display: none;
  /* Plain fixed bottom bar — always visible, locked to the viewport bottom,
     above page content. (We deliberately do NOT JS-transform this on
     pinch-zoom; that hack left the bar floating on scroll and vanishing on
     tab switches.) */
  position: fixed;
  top: auto; /* override nav { top: 0 } from styles.css */
  bottom: 0;
  left: 0;
  right: 0;
  height: 72px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  border-bottom: none;
  overflow: hidden;
  z-index: 1000;
  padding: 0 0.25rem;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.18);
}

.mobile-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.4rem 0.25rem;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.mobile-nav-btn .mnb-icon {
  font-size: 1.6rem;
  line-height: 1;
  transition: transform 0.15s;
}

.mobile-nav-btn.active {
  color: var(--primary);
}

.mobile-nav-btn.active .mnb-icon {
  transform: scale(1.1);
}

/* ── More overlay + bottom sheet ──────────────────────────────────── */
.mobile-more-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 998;
}

.mobile-more-overlay.open {
  display: block;
}

.mobile-more-sheet {
  display: none;
  position: fixed;
  bottom: 72px;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  z-index: 999;
  padding: 0.625rem 0 0.5rem;
  transform: translateY(110%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
}

.mobile-more-sheet.open {
  transform: translateY(0);
}

.mobile-more-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 0.875rem;
}

.mobile-more-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.875rem 1.5rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
  text-align: left;
}

.mobile-more-item:active {
  background: rgba(127, 127, 127, 0.12);
}

.mobile-more-item.active {
  color: var(--primary);
}

.mmi-icon {
  font-size: 1.3rem;
  width: 2rem;
  text-align: center;
  flex-shrink: 0;
}

/* =================================================================
   MOBILE MEDIA QUERY — activates ≤ 768 px
   ================================================================= */
@media (max-width: 768px) {
  /* ── Body / chrome ─────────────────────────────────────────────── */
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  /* Hide the desktop nav; show the bottom nav + sheet */
  #main-nav {
    display: none !important;
  }
  .mobile-bottom-nav {
    display: flex;
  }
  .mobile-more-sheet {
    display: block;
  }

  main {
    max-width: 100%;
    padding: 0.6rem 0.5rem;
  }

  /* ── Header: one balanced row — title | season | user ──────────── */
  header {
    padding: 0.5rem 0.75rem;
  }

  header::after {
    height: 3px;
  }

  .header-top {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  /* Three equal-width cells so nothing dominates and font sizes match */
  .header-top > h1,
  .header-top > .season-selector,
  .header-top > .user-bar {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
  }

  header h1 {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    justify-content: flex-start;
    font-size: clamp(0.95rem, 4vw, 1.2rem);
    font-weight: 800;
    white-space: nowrap;
  }

  .header-ball {
    font-size: 1em;
  }

  .header-title-long {
    display: none !important;
  }

  .header-title-short {
    display: inline !important;
  }

  .season-selector {
    text-align: center;
    overflow: hidden;
  }

  .season-selector select {
    width: 100%;
    max-width: 100%;
    -webkit-appearance: none;
    appearance: none;
    background-color: rgba(255, 255, 255, 0.14);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23ffffff'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.4rem center;
    background-size: 8px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 6px;
    color: #fff;
    -webkit-text-fill-color: #fff;
    font-size: clamp(0.85rem, 3.6vw, 1.05rem);
    font-weight: 600;
    text-align: center;
    text-align-last: center;
    padding: 0.3rem 1.1rem 0.3rem 0.5rem;
    cursor: pointer;
  }

  /* No display override here — app.js flips this from none → flex on login. */
  .user-bar {
    justify-content: flex-end;
    margin-left: 0;
  }

  .user-dropdown,
  .user-dropdown-trigger {
    max-width: 100%;
    min-width: 0;
  }

  .user-dropdown-trigger {
    font-size: clamp(0.85rem, 3.6vw, 1.05rem) !important;
    padding: 0.3rem 0.5rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .user-dropdown-trigger #user-display-name {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #online-users-bar {
    display: none !important;
  }

  /* ── Champion banner: centered + readable (no separate mini banner) ── */
  #champion-banner {
    display: block !important;
  }

  .champion-banner {
    padding: 1rem 1rem 0.85rem;
    border-radius: 12px;
    margin-bottom: 0.75rem;
  }

  /* Top row: "WMMC (year)" left, reigning champion right — both kept on a
     single row (no wrap), vertically centered against each other. Fonts are
     viewport-sized (clamp + vw) so they shrink to fit narrow screens instead
     of wrapping. The season info line sits below (separate .banner-footer). */
  .banner-main {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  /* Title (+ status line below it) is fixed-width — never resized by a long
     champion name. Stacked vertically so the short status sits under the title. */
  .banner-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    flex: 0 0 auto;
    min-width: 0;
  }

  .banner-title {
    font-size: clamp(1.2rem, 6.2vw, 2.2rem);
    letter-spacing: 1px;
    white-space: nowrap;
  }

  /* Short season status ("In Progress" / "Preseason") moved under the title
     by arrangeMobileBannerStatus() in js/mobile.js. */
  .banner-status-mobile {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.8;
    margin-top: 0.15rem;
    white-space: nowrap;
  }

  /* Champion block takes the leftover space (a fixed amount, since the title
     is fixed). The name auto-fits into it via fitBannerChampName() in
     js/mobile.js, so a long name shrinks instead of resizing anything else. */
  .banner-right {
    text-align: right;
    justify-content: flex-end;
    align-items: center;
    gap: 0.4rem !important; /* tighten trophy ↔ text (overrides inline gap) */
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  /* Trophy: shrink the glyph (overrides inline 2.5rem) and never let it shrink */
  .banner-right > div:first-child {
    font-size: 1.4rem !important;
    flex-shrink: 0;
  }

  /* label / name / year text block — bounded so the name can be measured + fit */
  .banner-right > div:last-child {
    min-width: 0;
    overflow: hidden;
  }

  .banner-champ-label {
    font-size: 0.62rem;
    letter-spacing: 1px;
    white-space: nowrap;
  }

  .banner-champ-name {
    font-size: clamp(1rem, 4.6vw, 1.5rem);
    white-space: nowrap;
    display: block;
    overflow: hidden;
  }

  .banner-champ-year {
    font-size: 0.72rem;
    opacity: 0.85;
    white-space: nowrap;
  }

  .banner-footer {
    text-align: center;
    font-size: clamp(0.74rem, 3.2vw, 0.92rem);
    letter-spacing: 0.8px;
    opacity: 0.9;
    margin-top: 0.75rem;
  }

  /* Footer keeps only the period status (e.g. "Pool Play 2 — Week 5 of 5") on a
     single row; the season status moved under the title (.banner-status-mobile). */
  .banner-footer .banner-status,
  .banner-footer .banner-sep {
    display: none;
  }

  .banner-footer .banner-period {
    white-space: nowrap;
  }

  /* ── Cards ─────────────────────────────────────────────────────── */
  .card {
    border-radius: 10px;
    padding: 0.75rem;
    margin-bottom: 0.625rem;
  }

  .scoreboard-card {
    padding: 0.5rem 0.4rem;
  }

  /* =============================================================
     POOL PLAY — landing scoreboard
     ============================================================= */

  /* Drop the period tab bar + secondary legends/info — we stack the
     periods and surface only what matters on the landing. */
  #scoreboard-content .scoreboard-tabs,
  #scoreboard-content .sb-tab,
  .highlight-legend,
  .sb-color-legend,
  .advancement-info,
  .pp-leader-cards {
    display: none !important;
  }

  /* Period accordion section headers */
  .sb-section-header {
    padding: 0.6rem 0.3rem;
    border-top: 2px solid var(--border);
  }

  .sb-section:first-child .sb-section-header {
    border-top: none;
  }

  .sb-section-title {
    font-size: 1.05rem !important;
    font-weight: 800;
    color: var(--primary) !important;
  }

  /* Accordion section headers: "Pool Play", "Quarterfinals", … */
  .mob-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    padding: 0.55rem 0.5rem;
    border-top: 2px solid var(--border);
    margin-top: 0.3rem;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-group-header::after {
    content: '▾';
    color: var(--text-muted);
    font-size: 0.8rem;
    transition: transform 0.2s;
  }

  .mob-group-header.collapsed::after {
    transform: rotate(-90deg);
  }

  /* Outer "Pool Play Scoreboard" header: the name itself is the toggle
     (onclick lives on the header) — hide the old Show/Hide button. */
  .sb-poolplay-header {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 0.5rem 0.25rem;
  }

  .sb-poolplay-header h2 {
    font-size: 1.15rem !important;
    color: var(--primary) !important;
    margin: 0 !important;
  }

  .sb-poolplay-toggle {
    display: none !important;
  }

  /* Section heading inside Overall period ("Overall Pool Play Standings") */
  #scoreboard-content .sb-period > h3 {
    font-size: clamp(0.9rem, 3.8vw, 1.1rem);
    color: var(--text-light);
    padding: 0.4rem 0.25rem 0.3rem;
    margin: 0;
    border: none;
  }

  /* Period header (Pool Play 1 / 2): inner title (not a toggle — section
     header handles collapse). */
  .pool-period-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0.4rem 0.5rem;
    border-top: 1px solid var(--border);
    margin-top: 0.4rem;
  }

  .pool-period-header h3 {
    font-size: clamp(0.9rem, 3.8vw, 1.1rem) !important;
    font-weight: 700;
    text-align: center;
    color: var(--text-light) !important;
    margin: 0;
    padding: 0;
    border: none;
  }

  .pool-expand-all-btn {
    display: none !important;
  }

  /* Single-column pools */
  .pool-play-grid {
    grid-template-columns: 1fr !important;
    gap: 0.5rem;
  }

  .pool-card {
    margin-bottom: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--card-bg);
  }

  /* Pool / matchup name: larger, left-aligned, tap to collapse */
  .pool-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    cursor: pointer;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 0.75rem;
  }

  .pool-card-header h3,
  .pool-card-header h4 {
    font-size: clamp(1rem, 4.5vw, 1.25rem);
    font-weight: 700;
    text-align: left;
    color: var(--text);
    margin: 0;
    padding: 0;
    background: none;
  }

  .pool-toggle-btn {
    display: none !important;
  }

  .pool-card-header::after {
    content: '▾';
    color: var(--text-muted);
    font-size: 0.85rem;
    transition: transform 0.2s;
  }

  .pool-card.mob-pool-collapsed .pool-card-header::after {
    transform: rotate(-90deg);
  }

  .pool-card.mob-pool-collapsed .pool-card-body {
    display: none !important;
  }

  /* ── Scoreboard tables → block + card rows ─────────────────────── */
  #scoreboard-content .data-table,
  #scoreboard-content .data-table tbody {
    display: block !important;
    width: 100%;
    border: none;
  }

  #scoreboard-content .data-table thead {
    display: none !important;
  }

  #scoreboard-content .table-wrapper,
  #scoreboard-content .pool-card-body .table-wrapper {
    overflow: visible;
    border: none;
    border-radius: 0;
  }

  /* Manager summary row → flex card: [rank] [name ……] [score]
     Name flexes + truncates; score never shrinks, so they can't collide. */
  #scoreboard-content .mob-sbrow {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem !important;
    border-bottom: 1px solid var(--border) !important;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(127, 127, 127, 0.08);
  }

  #scoreboard-content .mob-sbrow td {
    display: none !important;
    padding: 0 !important;
    border: none !important;
  }

  /* Rank */
  #scoreboard-content .mob-sbrow td:first-child {
    display: flex !important;
    flex: 0 0 auto;
    width: 1.75rem;
    justify-content: center;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-muted);
  }

  #scoreboard-content .mob-sbrow td:first-child.rank-1 {
    color: var(--rank1);
  }
  #scoreboard-content .mob-sbrow td:first-child.rank-2 {
    color: var(--rank2);
  }
  #scoreboard-content .mob-sbrow td:first-child.rank-3 {
    color: var(--rank3);
  }

  /* Name */
  #scoreboard-content .mob-sbrow td:nth-child(2) {
    display: flex !important;
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    gap: 0.25rem;
    font-size: clamp(1.05rem, 4.5vw, 1.4rem);
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
  }

  #scoreboard-content .mob-sbrow td:nth-child(2) strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  #scoreboard-content .mob-sbrow .sb-expand-arrow {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.7rem;
  }

  /* Score — last cell for 5-col pool tables (Rank|Name|Bat|Pit|Total) */
  #scoreboard-content .mob-sbrow td:last-child {
    display: flex !important;
    flex: 0 0 auto;
    justify-content: flex-end;
    align-items: center;
    font-size: clamp(1.05rem, 4.8vw, 1.5rem);
    font-weight: 800;
    color: var(--text);
    white-space: nowrap;
    letter-spacing: -0.5px;
    padding-left: 0.5rem !important;
  }

  #scoreboard-content .mob-sbrow td:last-child strong {
    font-size: inherit;
    font-weight: inherit;
  }

  /* Overall standings table has 9 cols; the last is a Status badge.
     Hide it and promote col 8 (PP Total) to the score slot. */
  #scoreboard-content #sb-pp-overall .mob-sbrow td:last-child {
    display: none !important;
  }

  #scoreboard-content #sb-pp-overall .mob-sbrow td:nth-child(8) {
    display: flex !important;
    flex: 0 0 auto;
    justify-content: flex-end;
    align-items: center;
    font-size: clamp(1.05rem, 4.8vw, 1.5rem);
    font-weight: 800;
    color: var(--text);
    white-space: nowrap;
    letter-spacing: -0.5px;
    padding-left: 0.5rem !important;
  }

  /* ── Manager detail (player list) pop-down — full width, readable ── */
  /* Leave the <tr> display to JS — it toggles inline display:none to collapse
     the panel. Forcing display here would pin every panel open (stuck on its
     "Loading…" placeholder). Only the <td> becomes a full-width block. */
  #scoreboard-content .sb-manager-detail-row {
    width: 100% !important;
  }

  #scoreboard-content .sb-manager-detail-row td {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box;
    padding: 0 !important;
    border: none !important;
  }

  #scoreboard-content .mgr-detail-panel {
    width: 100% !important;
    box-sizing: border-box;
    margin: 0 !important;
    padding: 0.4rem 0.4rem 0.5rem !important;
    background: var(--bg);
  }

  #scoreboard-content .mgr-detail-cols {
    display: block !important;
    width: 100% !important;
    gap: 0 !important;
  }

  #scoreboard-content .mgr-detail-section {
    width: 100%;
    margin-bottom: 0.5rem;
  }

  #scoreboard-content .mgr-detail-header {
    font-size: 0.95rem !important;
    font-weight: 700;
    color: var(--text-light) !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.5rem 0.25rem 0.4rem !important;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
  }

  /* Player tables inside the detail panel keep a real table layout.
     The #scoreboard-content .data-table prefix (specificity beats the
     outer display:block!important on .data-table). */
  #scoreboard-content .data-table .mgr-detail-section table {
    display: table !important;
    width: 100% !important;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.95rem;
  }

  #scoreboard-content .data-table .mgr-detail-section table thead {
    display: table-header-group !important;
  }

  #scoreboard-content .data-table .mgr-detail-section table thead th {
    display: table-cell !important;
    font-size: 0.72rem !important;
    font-weight: 700;
    color: var(--text-muted) !important;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 0.35rem !important;
    border-bottom: 1px solid var(--border) !important;
    text-align: left;
    background: none !important;
  }

  #scoreboard-content .data-table .mgr-detail-section table tbody {
    display: table-row-group !important;
  }

  #scoreboard-content .data-table .mgr-detail-section table tbody tr {
    display: table-row !important;
  }

  #scoreboard-content .data-table .mgr-detail-section table tbody td {
    display: table-cell !important;
    padding: 0.4rem 0.35rem !important;
    color: var(--text);
    border-bottom: 1px solid var(--border) !important;
    vertical-align: middle;
  }

  #scoreboard-content .data-table .mgr-detail-section table tbody td:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ── Seeding list (below Overall) ──────────────────────────────── */
  .seed-item {
    font-size: 0.9rem;
    gap: 0.5rem;
    padding: 0.375rem 0;
  }

  .seed-number {
    font-size: 1.1rem;
    font-weight: 900;
    min-width: 1.75rem;
  }

  /* =============================================================
     OTHER TABS — desktop fallback (this round). Keep wide tables
     horizontally scrollable so they don't break the page width.
     ============================================================= */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  canvas {
    max-height: 240px;
  }
}

/* ── Very small phones (≤ 380 px) ─────────────────────────────────── */
@media (max-width: 380px) {
  .mobile-nav-btn {
    font-size: 0.55rem;
  }

  .mobile-nav-btn .mnb-icon {
    font-size: 1.4rem;
  }

  main {
    padding: 0.5rem 0.4rem;
  }
}
