/* Responsive layer for phones, tablets, and desktops. Loaded last; each block notes the breakpoint
   and the problem it solves (found by the responsive audit in STATUS.md, 2026-10-01).
   Breakpoints: ≤600 phones · ≤1024 tablets (off-canvas nav) · ≤1280 small laptops/landscape tablets. */

/* ---------- Navigation: off-canvas up to tablet width ---------- */
.sidebar-close { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1024px) {
  /* The 208px sidebar left tablets with cramped two-column cards; it slides in like on phones. */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(300px, 86vw);
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: none;
  }
  .sidebar.is-open { transform: none; box-shadow: 12px 0 40px rgba(8, 14, 20, .5); }
  .menu-button { display: grid; width: 44px; height: 44px; margin-left: -8px; place-items: center; border-radius: 8px; }
  .menu-button:focus-visible { outline: 2px solid #b7dcff; }
  .sidebar-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1;
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid #72808b;
    border-radius: 8px;
    background: #26313899;
    color: #e3ebf1;
    font-size: 16px;
  }
  .sidebar-close:hover, .sidebar-close:focus-visible { border-color: #b7dcff; color: #fff; }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    display: block;
    background: rgba(10, 16, 22, .55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.sidebar-open { overflow: hidden; }
  .brand { padding-top: 56px; }
}

@media (prefers-reduced-motion: reduce) { .sidebar, .sidebar-backdrop { transition: none; } }

/* ---------- Tab bar: scrolls inside itself instead of widening the page ---------- */
.main-shell { min-width: 0; }
@media (max-width: 1100px) {
  .tabbar { padding-right: 0; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  .tabbar::-webkit-scrollbar { display: none; }
  .tabs { flex: 0 0 auto; white-space: nowrap; }
  .tab { flex: 0 0 auto; }
  .tagline { display: none; }
}

/* ---------- Card grid ---------- */
@media (min-width: 601px) and (max-width: 1280px) {
  /* Four metric cards per row don't fit next to the sidebar (numbers spilled at 1180px). Phones keep one column. */
  .cards-grid.overview .card[data-size="quarter"] { grid-column: span 6; }
}
@media (min-width: 601px) and (max-width: 1024px) {
  /* Tablets: two columns everywhere, now with the full width. */
  .cards-grid.overview .card[data-size="third"],
  .cards-grid.context .card[data-size="quarter"],
  .cards-grid.context .card[data-size="sixth"] { grid-column: span 6; }
  .cards-grid.context .card[data-size="half"] { grid-column: span 12; }
  .cards-grid.zone { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Ranking tables: drop the least important column when the card is narrow ---------- */
.ranking-table-body, .cards-grid .table-card .table-body { container-type: inline-size; }
@container (max-width: 430px) {
  /* Without "Correct Calls" the table fits: drop its 380px minimum so Accuracy is always visible. */
  .data-table-ranking { min-width: 0; }
  .data-table-ranking th:nth-child(4), .data-table-ranking td:nth-child(4) { display: none; }
  .data-table-ranking th:first-child, .data-table-ranking td:first-child { width: 10%; }
  .data-table-ranking th:nth-child(2), .data-table-ranking td:nth-child(2) { width: 48%; overflow: hidden; text-overflow: ellipsis; }
  .data-table-ranking th:nth-child(3), .data-table-ranking td:nth-child(3) { width: 18%; }
  .data-table-ranking th:nth-child(5), .data-table-ranking td:nth-child(5) { width: 24%; }
}

/* ---------- Content that spilled out of its card on tablets ---------- */
.zone-consistency-summary { flex-wrap: wrap; row-gap: 10px; }
.zone-consistency-summary > * { min-width: 0; }
.profile-highlight strong small { display: inline-block; }
@media (max-width: 1024px) {
  .profile-highlight strong small { display: block; margin-top: 2px; }
  .metric-list { min-width: 0; }
  .metric-list dd { white-space: nowrap; }
}

/* ---------- Touch targets: at least 36–40px on touch screens, without changing the look ---------- */
@media (pointer: coarse), (max-width: 1024px) {
  .info-button { position: relative; }
  .info-button::after { position: absolute; inset: -11px; content: ""; }
  .segmented button { min-height: 36px; font-size: 12px; }
  .text-link { display: inline-flex; align-items: center; min-height: 40px; }
  .auth-reveal { width: 40px; height: 40px; margin-right: -10px; }
  .list-page-controls button { width: 40px; height: 40px; }
  .list-pagination select { height: 40px; }
  .game-log-detail-button, .game-log-open-button { width: 40px; height: 40px; }
  .game-log-open-game { min-height: 40px; }
  .missed-calls-filter button { min-height: 40px; }
  .rankings-name { min-height: 32px; }
  .rankings-tools input, .rankings-tools select, .game-log-tools input, .game-log-tools select { min-height: 40px; }
  .account-league select, .account-signout { min-height: 40px; }
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  /* Nothing under 10px on a phone. */
  .eyebrow { font-size: 10px; }
  .error-explanation, .error-explanation span, .error-stat span,
  .impact-support-metric span, .impact-support-label, .impact-outcome-copy small,
  .home-away-summary, .home-away-summary strong,
  .batter-side-caption, .batter-side-counts span, .batter-side-comparison p,
  .zone-consistency-summary small, .zone-consistency-summary span,
  .egregious-stat p, .egregious-donut-wrap strong, .egregious-donut-wrap span,
  .card small, .rankings-row span, .rankings-leader span, .rankings-profile span,
  .game-log-table small, .game-log-table th,
  .game-log-table td .game-log-team-name small, .game-log-table td small, .game-log-team-fallback,
  .batter-side-note p, .zone-scale-note span, .rankings-change span, .egregious-note p strong,
  .error-type .error-stat > span,
  .rankings-change > span:last-child, .rankings-leader-metrics span, .rankings-profile-metrics span { font-size: 10px; }
  .dashboard { padding-inline: 12px; }
}

/* ---------- Game Log on phones: each game becomes a card with every metric visible ---------- */
@media (max-width: 760px) {
  .game-log-scroll-hint { display: none !important; }
  .game-log-table-scroll { overflow: visible; }
  .game-log-table { min-width: 0; table-layout: auto; }
  /* Each cell carries its own label (data-label), so the header row isn't needed. */
  .game-log-table thead { display: none; }
  .game-log-table, .game-log-table tbody { display: block; }
  .game-log-row {
    position: relative;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px 8px;
    padding: 14px 14px 12px;
    border-bottom: 1px solid #5a6d7a;
  }
  .game-log-row.is-loading { display: block; }
  .game-log-row td { display: block; height: auto; padding: 0; border: 0; text-align: left !important; }
  .game-log-row td[data-label="Date"] { grid-column: 1 / -1; padding-right: 48px; }
  .game-log-row td[data-label="Matchup"],
  .game-log-row td[data-label="Plate umpire"] { grid-column: 1 / -1; }
  .game-log-row .game-log-matchup { max-width: none; }
  .game-log-row td[data-label="Pitches"],
  .game-log-row td[data-label="Correct"],
  .game-log-row td[data-label="Missed"],
  .game-log-row td[data-label="Impact"] { grid-column: span 1; }
  .game-log-row td[data-label="Accuracy"] { grid-column: span 1; }
  .game-log-row td[data-label="Pitches"]::before,
  .game-log-row td[data-label="Correct"]::before,
  .game-log-row td[data-label="Accuracy"]::before,
  .game-log-row td[data-label="Missed"]::before,
  .game-log-row td[data-label="Impact"]::before {
    display: block;
    margin-bottom: 3px;
    color: #b7cbd8;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    content: attr(data-label);
  }
  .game-log-row .game-log-accuracy-track { width: 100%; }
  .game-log-row .game-log-detail-cell { position: absolute; top: 10px; right: 10px; }
  .game-log-detail-row, .game-log-detail-row td { display: block; }
  .game-log-detail { gap: 12px 20px; }
  .game-log-detail .game-log-report { margin-left: 0; }
  .game-log-table td.game-log-empty { display: block; }
}

/* ---------- Rulebook Zone vs. Called Zone: stack the metrics under the chart on narrow cards ---------- */
/* Beside a 104px metrics column the equal-scale zone chart shrank to a thumbnail on tablets (1180px) and phones. */
.card:has(> .zone-comparison-layout) { container-type: inline-size; }
@container (max-width: 400px) {
  .zone-comparison-layout { grid-template-columns: minmax(0, 1fr); gap: 4px; min-height: 0; }
  .cards-grid.zone .canvas-slot.zone-comparison-slot { height: 300px; }
  .zone-expansion-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 10px 0 0; border-top: 1px solid #aebbc326; border-left: 0; text-align: center; }
  .zone-expansion-metrics strong { font-size: 15px; }
  .zone-expansion-metrics span { font-size: 10px; }
}

/* ---------- Decision Heatmap: shorter slot on narrow cards ---------- */
/* The plot keeps its real proportions and is limited by width there, which left ~100px empty above and below it. */
.card:has(.decision-heatmap-slot) { container-type: inline-size; }
@container (max-width: 340px) { .cards-grid.zone .decision-heatmap-slot { height: 300px; } }

/* Pitch filters: a select sizes to its longest option, so a long player name widened the grid column
   past the card on phones. Let the column shrink and the select fill it (the name is clipped). */
.pitch-filter { grid-template-columns: minmax(0, 1fr); }
.pitch-filter select { width: 100%; min-width: 0; text-overflow: ellipsis; }
@media (max-width: 600px) {
  .pitch-filters { min-width: 0; }
}
