* {
  box-sizing: border-box;
}

body {
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  color: #172033;
  background: #f7f8fb;
}

header,
section {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 28px;
}

section {
  padding-top: 20px;
  padding-bottom: 20px;
}

header {
  padding-top: 34px;
  padding-bottom: 10px;
}

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

h1 {
  font-size: 34px;
  line-height: 1.15;
  margin-bottom: 0;
}

h2 {
  font-size: 22px;
  margin-bottom: 16px;
}

h3 {
  font-size: 17px;
  margin-bottom: 10px;
}

/* ---- Tab navigation ---- */
.tab-nav {
  display: flex;
  gap: 4px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px 0;
}

.tab-btn {
  height: 40px;
  padding: 0 22px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: #e5e7eb;
  color: #475569;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover {
  background: #d1d5db;
  color: #1f2937;
}

.tab-btn.active {
  background: #fff;
  color: #2563eb;
  box-shadow: 0 -2px 0 #2563eb inset;
}

/* ---- Tab panels ---- */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.controls {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0 12px 12px 12px;
  margin-bottom: 20px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 150px;
  font-size: 13px;
  font-weight: 700;
  color: #4b5563;
}

input {
  height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
  color: #172033;
  background: #fff;
}

input:focus {
  border-color: #2563eb;
  outline: 3px solid rgba(37, 99, 235, 0.14);
}

.search-combobox {
  position: relative;
}

.search-combobox input {
  width: 100%;
}

.event-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 280px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.14);
}

.event-suggestions .event-suggestion {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  height: auto;
  min-height: auto;
  padding: 10px 12px;
  background: transparent;
  color: #172033;
  border: none;
  border-bottom: 1px solid #e5e7eb;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
}

.event-suggestions .event-suggestion:last-child {
  border-bottom: none;
}

.event-suggestions .event-suggestion:hover,
.event-suggestions .event-suggestion.is-active {
  background: #eff6ff;
}

.event-suggestion-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.event-suggestion-key {
  font-size: 13px;
  font-weight: 800;
  color: #1d4ed8;
}

.event-suggestion-year {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
}

.event-suggestion-name {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

.event-suggestion-key mark,
.event-suggestion-name mark {
  padding: 0;
  background: #fef08a;
  color: inherit;
}

.event-suggestion-empty {
  padding: 12px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
}

select {
  height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
  color: #172033;
  background: #fff;
}

label.auto-refresh {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 40px;
}

label.auto-refresh input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
}

button {
  height: 40px;
  background: #2563eb;
  border: none;
  color: #fff;
  padding: 0 16px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button:hover {
  background: #1d4ed8;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

#refresh {
  color: #1f2937;
  background: #e5e7eb;
}

#refresh:hover {
  background: #d1d5db;
}

#status {
  min-width: 140px;
  font-weight: 700;
  color: #4b5563;
}

.error-panel {
  margin-top: 8px;
  margin-bottom: 0;
  color: #7f1d1d;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
}

.prediction-panel {
  padding-top: 14px;
}

.prediction-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.match-tag {
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  font-weight: 700;
  font-size: 13px;
}

/* Win-probability bar */
.winbar {
  display: flex;
  height: 34px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  background: #f1f5f9;
}

.winbar-seg {
  display: flex;
  align-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  min-width: 0;
  transition: width 0.4s ease;
  white-space: nowrap;
}

.winbar-seg.red {
  justify-content: flex-start;
  padding-left: 10px;
  background: #dc2626;
}

.winbar-seg.blue {
  justify-content: flex-end;
  padding-right: 10px;
  background: #2563eb;
}

.winner-callout {
  margin: 8px 0 16px;
  font-weight: 700;
  color: #475569;
}

.winner-callout.red {
  color: #b91c1c;
}

.winner-callout.blue {
  color: #1d4ed8;
}

/* Red-left / blue-right comparison */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.compare-side {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px;
}

.compare-side.red {
  border-top: 3px solid #dc2626;
}

.compare-side.blue {
  border-top: 3px solid #2563eb;
}

.compare-side h3 {
  margin: 0 0 6px;
}

.compare-side.red h3 {
  color: #b91c1c;
}

.compare-side.blue h3 {
  color: #1d4ed8;
}

.compare-side .teams {
  margin: 0;
  min-height: 22px;
  color: #334155;
  font-weight: 700;
}

.metric {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 16px;
}

.m-red {
  text-align: right;
  font-weight: 800;
  color: #b91c1c;
  font-variant-numeric: tabular-nums;
}

.m-blue {
  text-align: left;
  font-weight: 800;
  color: #1d4ed8;
  font-variant-numeric: tabular-nums;
}

.m-label {
  padding: 0 16px;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

dt {
  color: #64748b;
  font-weight: 700;
}

dd {
  margin: 0;
  font-weight: 800;
}

.chart-container {
  position: relative;
  height: 320px;
  margin: 8px 0 18px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
}

#statsChart {
  /* Sizing is driven by .chart-container; Chart.js manages the canvas box. */
  display: block;
  width: 100%;
  height: 100%;
}

.match-teams {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 4px 0 12px;
  font-size: 14px;
  color: #475569;
}

.chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
}

.chip-red {
  background: rgba(220, 38, 38, 0.12);
  color: #b91c1c;
}

.chip-blue {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

.self-pad {
  margin: 8px 0 18px;
  padding: 18px 20px;
  background: linear-gradient(135deg, #ecfdf5, #ffffff);
  border: 1px solid #a7f3d0;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.12);
}

.self-pad-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.self-pad-eyebrow {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #059669;
}

.self-pad-team {
  font-size: 28px;
  font-weight: 800;
  color: #064e3b;
}

.self-pad-tag {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #047857;
  background: rgba(16, 185, 129, 0.15);
}

.self-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.self-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #d1fae5;
  border-radius: 10px;
}

.self-tile-value {
  font-size: 22px;
  font-weight: 800;
  color: #0f172a;
}

.self-tile-label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
}

tr.row-red td {
  background: rgba(220, 38, 38, 0.08);
}

tr.row-blue td {
  background: rgba(37, 99, 235, 0.08);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.table-wrap table {
  border: none;
  border-radius: 0;
}

th,
td {
  border-bottom: 1px solid #e5e7eb;
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: #475569;
  background: #f1f5f9;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:last-child td {
  border-bottom: 0;
}

/* Zebra striping + hover for table readability */
tbody tr:nth-child(even) td {
  background: #f8fafc;
}

tbody tr:hover td {
  background: #eef2ff;
}

/* History badge + roles + alliance */
.history-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: #ecfeff;
  color: #0e7490;
  border: 1px solid #a5f3fc;
  font-weight: 700;
  font-size: 12px;
}

.history-toggle,
.auto-refresh {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.roles-note {
  margin: 8px 0 0;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}

.role-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
  background: #f1f5f9;
  color: #475569;
}
.role-offense { background: #fee2e2; color: #b91c1c; }
.role-auto { background: #dbeafe; color: #1d4ed8; }
.role-endgame { background: #ede9fe; color: #6d28d9; }
.role-defense { background: #dcfce7; color: #15803d; }

.alliance-result {
  margin-top: 12px;
}

.alliance-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.alliance-card {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px;
  background: #fff;
}
.alliance-card.red { border-top: 4px solid #dc2626; }
.alliance-card.blue { border-top: 4px solid #2563eb; }

.alliance-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.alliance-card-head h3 { margin: 0; font-size: 16px; }
.alliance-teams { color: #64748b; font-size: 13px; }

.alliance-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.alliance-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f8fafc;
  border-radius: 8px;
  padding: 8px 4px;
}
.alliance-stat-value { font-weight: 700; font-size: 18px; color: #0f172a; }
.alliance-stat-label { font-size: 11px; color: #64748b; text-transform: uppercase; }
.alliance-note { margin: 10px 0 0; color: #475569; font-size: 13px; }
.alliance-matchup {
  margin: 12px 0 0;
  font-weight: 700;
  color: #0f172a;
}

.team-trio {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.team-select {
  min-width: 7rem;
}

/* Disabled / in-flight controls give clear feedback during async calls. */
button:disabled,
select:disabled,
input:disabled {
  opacity: 0.6;
  cursor: progress;
}
button.is-busy {
  cursor: progress;
}

@media (max-width: 820px) {
  header,
  section {
    padding-left: 14px;
    padding-right: 14px;
  }

  .tab-nav {
    padding-left: 14px;
    padding-right: 14px;
    gap: 2px;
  }

  .tab-btn {
    padding: 0 14px;
    font-size: 13px;
    height: 36px;
  }

  .controls {
    align-items: stretch;
    padding: 10px 12px;
  }

  label,
  button,
  #status {
    width: 100%;
  }

  .compare {
    grid-template-columns: 1fr;
  }

  table {
    font-size: 13px;
  }

  th,
  td {
    padding: 8px 10px;
  }

  .chart-container {
    height: 240px;
  }

  h1 {
    font-size: 28px;
  }

  h2 {
    font-size: 19px;
  }
}

@media (max-width: 480px) {
  .tab-nav {
    padding-left: 10px;
    padding-right: 10px;
  }

  .tab-btn {
    padding: 0 10px;
    font-size: 12px;
    height: 34px;
  }

  .controls {
    gap: 8px;
    padding: 8px 10px;
  }

  label {
    min-width: 0;
  }

  .alliance-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .alliance-cards {
    grid-template-columns: 1fr;
  }

  .chart-container {
    height: 200px;
  }

  .winbar {
    height: 28px;
  }

  .winbar-seg {
    font-size: 11px;
  }
}
