:root {
  --blue: #192c66;
  --gold: #c9a227;
  --light: #f4f6fa;
  --grid: #d8dce2;
  --ink: #172033;
  --muted: #657086;
  --white: #ffffff;
}

.pdf-button { background: white; color: var(--blue); border: 1px solid var(--gold); padding: 10px 14px; font: bold 14px Arial, sans-serif; cursor: pointer; flex-shrink: 0; }
.pdf-button:disabled { opacity: .55; cursor: wait; }
#pdfDialog { width: min(440px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--grid); border-top: 4px solid var(--gold); border-radius: 4px; color: var(--ink); }
#pdfDialog::backdrop { background: rgba(0, 0, 0, .55); }
#pdfForm { display: grid; gap: 18px; }
#pdfTitle { font-size: 22px; }
#pdfForm label { display: grid; gap: 6px; font-size: 14px; font-weight: bold; }
#pdfForm .pdf-checkbox { display: flex; align-items: center; gap: 8px; }
#pdfCharts, #pdfBlankFirst { width: 18px; height: 18px; accent-color: var(--blue); }
#pdfForm select { width: 100%; height: 40px; background: white; color: var(--ink); border: 1px solid var(--grid); font: 15px Arial, sans-serif; padding: 6px; }
#pdfProgress { min-height: 32px; font-size: 14px; line-height: 1.4; }
.pdf-actions { display: flex; justify-content: flex-end; gap: 12px; }
.pdf-actions button { font: bold 14px Arial, sans-serif; padding: 10px 14px; cursor: pointer; border: 1px solid var(--blue); background: white; color: var(--blue); }
#pdfSubmit { color: white; background: var(--blue); }
.pdf-actions button:disabled { opacity: .5; cursor: wait; }
.pdf-exporting .shell { width: 1400px; max-width: none; }
.pdf-exporting .controls { pointer-events: none; }
@media (max-width: 700px) { .topbar { flex-wrap: wrap; } }

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--white);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 106px;
  padding: 13px 32px;
  background: var(--blue);
  color: var(--white);
  border-bottom: 3px solid var(--gold);
}

.brand { display: flex; align-items: center; gap: 20px; min-width: 0; }
.brand-logo { display: block; width: 210px; height: auto; object-fit: contain; flex-shrink: 0; max-width: 100%; }
.brand .eyebrow { margin: 0; color: white; font-weight: 400; font-size: 12px; line-height: normal; }
.brand h1 { margin: 5px 0 0; font-size: 22px; font-weight: 700; line-height: normal; }

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0;
}

h3 {
  font-size: 18px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 22px auto 44px;
}

.controls {
  display: grid;
  grid-template-columns: auto minmax(210px, 1fr) minmax(260px, 1.5fr);
  gap: 14px;
  align-items: end;
  margin-bottom: 16px;
}

.tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  height: 42px;
  border: 1px solid var(--blue);
  background: var(--white);
}

.tab {
  min-width: 110px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  cursor: pointer;
}

.tab.active {
  background: var(--blue);
  color: var(--white);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

select,
.search-select input {
  width: 100%;
  height: 42px;
  border: 1px solid #b9c0cc;
  border-radius: 0;
  background: var(--white);
  color: var(--ink);
  font-size: 15px;
  padding: 0 12px;
}

.search-select { position: relative; min-width: 0; }
.search-select input { box-sizing: border-box; }
.search-select input:focus { outline: 2px solid var(--gold); outline-offset: -2px; }
.search-options { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 10; max-height: 300px; overflow-y: auto; background: var(--white); border: 1px solid #b9c0cc; box-shadow: 0 4px 12px #00000018; text-transform: none; font-size: 15px; font-weight: 400; color: var(--ink); }
.search-option { padding: 10px 12px; cursor: pointer; overflow-wrap: anywhere; }
.search-option:hover, .search-option[aria-selected="true"] { background: var(--blue); color: var(--white); }
.search-empty { padding: 10px 12px; color: var(--muted); }

.player-head,
.panel {
  background: var(--white);
  border: 0;
}

.player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--grid);
  margin-bottom: 18px;
}

.player-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.player-heading > span { min-width: 0; overflow-wrap: anywhere; }
.player-heading small { color: var(--muted); font-size: 16px; font-weight: 400; white-space: nowrap; }

.subtle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
}

.badge {
  min-width: 116px;
  padding: 12px 16px;
  background: var(--light);
  border-left: 3px solid var(--gold);
  color: var(--blue);
  text-align: center;
  font-weight: 900;
}

.statistics { margin-bottom: 20px; }
.statistics h3 { color: var(--blue); margin-bottom: 8px; }
.statistics th, .statistics td { text-align: center; }

.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.report-grid .panel:first-child { order: 2; }
.report-grid .panel:last-child { order: 1; }

.panel {
  min-width: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  background: var(--white);
  color: var(--blue);
}

.panel-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mix-bars {
  display: grid;
  gap: 12px;
  padding: 12px 0;
}

.mix-row {
  display: grid;
  grid-template-columns: 145px minmax(0, 1fr) 58px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
}

.bar-track {
  height: 14px;
  background: #ebedf2;
  border: 1px solid var(--grid);
}

.bar-fill {
  height: 100%;
  min-width: 2px;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.panel, .statistics { min-width: 0; max-width: 100%; }

.pitch-view-toggle { display: inline-flex; flex-shrink: 0; border: 1px solid var(--blue); }
.pitch-view-toggle button { padding: 7px 10px; border: 0; background: var(--white); color: var(--blue); font-size: 12px; cursor: pointer; }
.pitch-view-toggle button[aria-pressed="true"] { background: var(--blue); color: var(--white); }
.pitch-view-toggle button:focus-visible { outline: 2px solid var(--gold); outline-offset: -3px; }

.hitting-spray { margin-top: 16px; min-width: 0; }
.spray-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.spray-surface { position: relative; width: 100%; aspect-ratio: 1.3; }
.spray-surface canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.spray-grid > .plot { position: relative; }
.spray-direction { position: absolute; inset: 0; pointer-events: none; color: var(--blue); font-size: 12px; font-weight: 700; }
.spray-direction span { position: absolute; white-space: nowrap; padding: 2px 3px; background: var(--white); transform-origin: center; }
.zones-toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; text-transform: none; color: var(--blue); cursor: pointer; }
.zones-toggle input { accent-color: var(--blue); width: 16px; height: 16px; }
#sprayLegend { justify-content: center; margin-top: 8px; margin-bottom: 8px; }
#sprayStatus:empty { display: none; }
@media (max-width: 700px) { .spray-grid { grid-template-columns: minmax(0, 1fr); } }

table {
  width: 100%;
  min-width: 588px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

table:has(thead th:nth-child(18)) {
  min-width: 1310px;
}

.pitching-splits table {
  min-width: 540px;
}

.pitching-splits table:has(thead th:nth-child(9)) {
  min-width: 680px;
}

table th:first-child {
  width: 120px;
}

#metricGrid table {
  min-width: 780px;
}

#metricGrid table:has(thead th:nth-child(12)) {
  min-width: 840px;
}

#metricGrid table:has(thead th:nth-child(14)) {
  min-width: 980px;
}

table:has(thead th:nth-child(18)) th,
table:has(thead th:nth-child(18)) td {
  padding-left: 4px;
  padding-right: 4px;
}

#metricGrid th:first-child {
  width: auto;
}


th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--blue);
  color: var(--white);
  font-weight: 500;
  border-bottom: 3px solid var(--gold);
}

th,
td {
  border: 1px solid var(--grid);
  padding: 9px 6px;
  text-align: center;
}

th:first-child,
td:first-child {
  text-align: left;
}

thead th { border-bottom: 3px solid var(--gold); }

tbody tr:nth-child(even) {
  background: var(--light);
}

.report-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; padding-top: 10px; border-top: 1px solid var(--grid); color: var(--muted); font-size: 11px; text-transform: uppercase; }

.pitch-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: -1px;
}

[hidden] { display: none !important; }
.pitching-splits { margin-top: 24px; }
.pitching-splits .statistics th { text-align: center; }
.pitching-splits .statistics th, .pitching-splits .statistics td { padding: 9px 6px; }
.pitching-splits .statistics th:first-child, .pitching-splits .statistics td:first-child { text-align: left; }
.pitching-splits tfoot { background: var(--light); color: var(--blue); font-weight: 700; border-top: 2px solid var(--gold); }
table:has(#pitchTypeHead) tfoot { background: var(--light); color: var(--blue); font-weight: 700; border-top: 2px solid var(--gold); }
.handed-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(5, auto); column-gap: 32px; }
.handed-side { min-width: 0; display: grid; grid-row: 1 / span 5; grid-template-rows: subgrid; }
.handed-side > * { align-self: start; }
.hitting-splits .handed-grid { grid-template-rows: repeat(6, auto); }
.hitting-splits .handed-side { grid-row: 1 / span 6; }
.hitting-splits table { min-width: 456px; }
.hitting-splits table:has(thead th:nth-child(9)) { min-width: 760px; }
table:has(#pitchTypeHead th:nth-child(10)):not(:has(th:nth-child(18))) { min-width: 822px; }
@media (max-width: 980px) {
  .hitting-splits .handed-grid { grid-template-rows: auto; }
  .hitting-splits .handed-side { grid-row: auto; }
}
.count-tree { margin: 24px 0 0; min-width: 0; }
.count-tree h3 { color: var(--blue); margin-bottom: 14px; }
.tree-surface { width: min(100%, 420px); aspect-ratio: 1; position: relative; margin: 0 auto; }
.tree-surface canvas { display: block; width: 100%; height: 100%; }
.heatmaps { margin: 24px 0; }
.heatmaps > h3 { color: var(--blue); margin-bottom: 12px; }
.heatmap-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 10px; }
.heatmap { margin: 0; min-width: 0; }
.heatmap figcaption { font-size: 12px; font-weight: 700; color: var(--blue); margin-bottom: 4px; overflow-wrap: anywhere; }
.heatmap-surface { position: relative; width: 100%; aspect-ratio: 0.8; }
.heatmap canvas { display: block; width: 100%; height: 100%; }
@media (max-width: 1150px) {
  .topbar { padding-left: 24px; padding-right: 24px; }
}

@media (max-width: 700px) {
  .topbar { min-height: 120px; padding: 12px 16px; gap: 12px; }
  .brand { flex-direction: column; align-items: flex-start; gap: 8px; }
  .brand-logo { width: 165px; }
}

@media (max-width: 540px) {
  .heatmap-grid.result-grid { grid-template-columns: minmax(0, 1fr); }
  .result-grid .heatmap { width: min(100%, 300px); justify-self: center; }
}
.pitching-plots { margin-top: 24px; }
.plot-legend { display: flex; flex-wrap: wrap; gap: 10px 20px; margin-bottom: 18px; font-size: 12px; }
.plot-legend span { display: inline-flex; align-items: center; }
#plotLegend { justify-content: center; margin: 18px 0 0; }
.plot-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.plot { margin: 0; min-width: 0; }
.plot h3 { color: var(--blue); font-size: 16px; text-align: center; margin-bottom: 8px; }
.plot-surface { position: relative; width: 100%; aspect-ratio: 1; }
.plot-second-row { margin-top: 28px; }
.plot-second-row > .plot { display: flex; flex-direction: column; }
.plot-second-row canvas { position: absolute; inset: 0; }
.plot-side { grid-column: span 2; }
.plot-side .plot-surface { aspect-ratio: auto; flex: 1; min-height: 0; }
.plot canvas { display: block; width: 100%; height: 100%; }
.plot-tooltip { position: absolute; z-index: 2; max-width: 220px; padding: 7px 9px; background: white; border: 1px solid var(--grid); color: var(--ink); font-size: 12px; line-height: 1.5; pointer-events: none; white-space: pre-line; box-shadow: 0 2px 6px #00000012; }
.percentile-tooltip { position: fixed; z-index: 20; width: min(220px, calc(100vw - 16px)); max-width: none; box-sizing: border-box; }

@media (max-width: 980px) {
  .handed-grid { grid-template-columns: 1fr; grid-template-rows: auto; row-gap: 32px; }
  .handed-side { display: block; grid-row: auto; }
  .plot-grid { grid-template-columns: 1fr; }
  .plot-side { grid-column: auto; }
  .plot-side .plot-surface { aspect-ratio: 1.6; flex: none; }
  .player-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls,
  .report-grid {
    grid-template-columns: minmax(0, 1fr);
  }

}

@media (max-width: 540px) {
  .heatmap-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plot-side .plot-surface { aspect-ratio: 1; }
  h1 { font-size: 20px; }
  h2 { font-size: 24px; }
  .player-heading small { font-size: 14px; }
}

@media (max-width: 420px) {
  .brand-logo { width: 135px; }
  .brand .eyebrow { font-size: 10px; }
  .brand h1 { font-size: 18px; }
}

.pdf-exporting .handed-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pdf-exporting .heatmap-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pdf-exporting .plot-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pdf-exporting .spray-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pdf-exporting .plot-side { grid-column: span 2; }
.pdf-exporting .plot-side .plot-surface { aspect-ratio: 2.1; flex: none; }
.report-loading > section:not(.controls):not(.player-head),
.report-loading .player-head .badge {
  visibility: hidden;
}

