:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --ink: #17211d;
  --muted: #64706a;
  --line: #d7ded8;
  --green: #1d7a4b;
  --green-dark: #115c38;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #b42318;
  --shadow: 0 12px 28px rgba(23, 33, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: #aeb9b1;
  background: #fafbf9;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button i {
  width: 17px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 17px;
}

button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 11px;
}

input[type="file"] {
  padding: 8px 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.app-header {
  position: relative;
  min-height: 190px;
  overflow: hidden;
  background: #173526;
  color: #fff;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 36vw);
  align-items: stretch;
}

.header-copy {
  position: relative;
  z-index: 1;
  padding: 34px clamp(18px, 5vw, 64px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.eyebrow {
  margin: 0 0 4px;
  color: #b9dec5;
  font-size: 13px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 18px;
  max-width: 720px;
  font-size: clamp(34px, 4.2vw, 58px);
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.2;
}

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

.header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-pill,
.score-pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  font-size: 13px;
  font-weight: 720;
}

.status-muted {
  color: #dce7df;
}

.pitch-strip {
  position: relative;
  min-height: 190px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.2) 0 2px, transparent 2px),
    repeating-linear-gradient(90deg, #1f7a4b 0 52px, #246f48 52px 104px);
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}

.pitch-strip::before,
.pitch-strip::after,
.pitch-circle,
.pitch-box {
  position: absolute;
  display: block;
  content: "";
  border-color: rgba(255, 255, 255, 0.62);
}

.pitch-strip::before {
  inset: 22px;
  border: 2px solid rgba(255, 255, 255, 0.62);
}

.pitch-strip::after {
  top: 22px;
  bottom: 22px;
  left: 50%;
  border-left: 2px solid rgba(255, 255, 255, 0.62);
}

.pitch-circle {
  width: 112px;
  height: 112px;
  top: 50%;
  left: 50%;
  border: 2px solid rgba(255, 255, 255, 0.62);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.pitch-box {
  top: 50%;
  width: 72px;
  height: 96px;
  border: 2px solid rgba(255, 255, 255, 0.62);
  transform: translateY(-50%);
}

.pitch-box-left {
  left: 22px;
  border-left: 0;
}

.pitch-box-right {
  right: 22px;
  border-right: 0;
}

.shell {
  width: min(1400px, calc(100% - 32px));
  margin: -28px auto 42px;
  position: relative;
  z-index: 2;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  min-height: 104px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 28px;
  line-height: 1.08;
}

.tool-band,
.panel,
.tabs,
.admin-drawer,
.prediction-status {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tool-band {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
}

.upload-form,
.tool-actions,
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.prediction-status {
  margin: 12px 0 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.upload-form label {
  min-width: 180px;
}

.file-label {
  min-width: 260px;
  flex: 1 1 260px;
}

.primary-button {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.ghost-danger {
  color: var(--red);
}

.message {
  min-height: 24px;
  margin: 10px 2px 8px;
  color: var(--muted);
  font-weight: 650;
}

.message.is-error {
  color: var(--red);
}

.tabs {
  border-radius: 8px;
  padding: 6px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.tab-button {
  flex: 0 0 auto;
  min-width: 132px;
  border-color: transparent;
  background: transparent;
}

.tab-button.active {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--green-dark);
}

.panel {
  display: none;
  margin-top: 12px;
  border-radius: 8px;
  overflow: hidden;
}

.panel.active {
  display: block;
}

.admin-drawer {
  margin-top: 14px;
  border-radius: 8px;
  overflow: hidden;
}

.admin-drawer summary {
  min-height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 780;
}

.admin-drawer summary::marker {
  color: var(--muted);
}

.admin-drawer summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.admin-drawer .tool-band {
  border-width: 1px 0 0;
  border-radius: 0;
  box-shadow: none;
}

.panel-heading {
  min-height: 66px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.filter-heading {
  align-items: end;
}

.filters label {
  min-width: 170px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f9faf8;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

tbody tr:hover {
  background: #fbfcfb;
}

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#leaderboard-panel table {
  min-width: 640px;
}

#leaderboard-panel th:nth-child(1),
#leaderboard-panel td:nth-child(1) {
  width: 70px;
}

#leaderboard-panel th:nth-child(2),
#leaderboard-panel td:nth-child(2) {
  width: 180px;
}

#leaderboard-panel th:nth-child(3),
#leaderboard-panel td:nth-child(3),
#leaderboard-panel th:nth-child(4),
#leaderboard-panel td:nth-child(4),
#leaderboard-panel th:nth-child(5),
#leaderboard-panel td:nth-child(5),
#leaderboard-panel th:nth-child(6),
#leaderboard-panel td:nth-child(6),
#leaderboard-panel th:nth-child(7),
#leaderboard-panel td:nth-child(7) {
  width: 78px;
}

#leaderboard-panel td:nth-child(2),
#leaderboard-panel th:nth-child(2) {
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.match-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-weight: 760;
}

.match-title .versus {
  color: var(--muted);
  font-weight: 650;
}

.score-pill {
  background: #eef7f0;
  color: var(--green-dark);
  border-color: #cde7d4;
}

.score-pill.empty {
  background: #f5f5f2;
  color: var(--muted);
  border-color: var(--line);
}

.score-pill.warn {
  background: #fff7e6;
  color: var(--amber);
  border-color: #f2d08a;
}

.score-pill.bad {
  background: #fff0ee;
  color: var(--red);
  border-color: #f1c6bf;
}

.groups-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.group-card,
.advancing-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.group-card h3 {
  margin: 0;
  padding: 12px 14px;
  background: #f9faf8;
  border-bottom: 1px solid var(--line);
}

.group-card table {
  min-width: 0;
}

.group-card th,
.group-card td {
  padding: 9px 10px;
}

.rank {
  width: 34px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.qualified-row {
  background: #f1f8f2;
}

.third-row {
  background: #fff8e8;
}

.team-cell {
  min-width: 140px;
  font-weight: 720;
}

.advancing-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.advancing-card-heading {
  min-height: 52px;
  padding: 12px 14px;
  background: #f9faf8;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.advancing-card-heading h3 {
  margin: 0;
}

.advancing-card-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  white-space: nowrap;
}

.advancing-groups {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.advancing-group {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fcfdfb;
}

.advancing-group h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
  text-transform: uppercase;
  letter-spacing: 0;
}

.team-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.team-chip {
  max-width: 100%;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef2ee;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  font-weight: 720;
  overflow-wrap: anywhere;
}

.team-chip.correct {
  background: #eef7f0;
  border-color: #cde7d4;
  color: var(--green-dark);
}

.team-chip.empty {
  color: var(--muted);
  background: #f5f5f2;
}

.empty-panel {
  margin: 0;
  padding: 18px;
}

.rules-grid {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.rules-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.rules-grid ul {
  margin: 0;
  padding-left: 20px;
}

.rules-grid li + li {
  margin-top: 8px;
}

@media (max-width: 980px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .pitch-strip {
    min-height: 94px;
  }

  .pitch-strip::before {
    inset: 14px;
  }

  .pitch-strip::after {
    top: 14px;
    bottom: 14px;
  }

  .pitch-circle {
    width: 58px;
    height: 58px;
  }

  .pitch-box {
    width: 46px;
    height: 52px;
  }

  .pitch-box-left {
    left: 14px;
  }

  .pitch-box-right {
    right: 14px;
  }

  .summary-grid,
  .groups-grid,
  .advancing-grid,
  .rules-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tool-band {
    grid-template-columns: 1fr;
  }

  .tool-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 18px, 1400px);
    margin-top: -18px;
  }

  .header-copy {
    padding: 28px 18px;
  }

  .summary-grid,
  .groups-grid,
  .advancing-grid,
  .advancing-groups,
  .rules-grid {
    grid-template-columns: 1fr;
  }

  .upload-form,
  .tool-actions,
  .filters {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .upload-form label,
  .file-label,
  .filters label,
  .tool-actions button,
  .upload-form button {
    width: 100%;
    min-width: 0;
  }

  .panel-heading {
    display: grid;
  }

  .admin-drawer summary {
    padding: 0 12px;
  }

  .tab-button {
    min-width: 116px;
  }

  #leaderboard-panel table {
    min-width: 520px;
  }

  #leaderboard-panel th,
  #leaderboard-panel td {
    padding: 10px 8px;
  }

  #leaderboard-panel th {
    font-size: 10px;
  }

  #leaderboard-panel th:nth-child(1),
  #leaderboard-panel td:nth-child(1) {
    width: 44px;
  }

  #leaderboard-panel th:nth-child(2),
  #leaderboard-panel td:nth-child(2) {
    width: 132px;
  }

  #leaderboard-panel th:nth-child(3),
  #leaderboard-panel td:nth-child(3),
  #leaderboard-panel th:nth-child(4),
  #leaderboard-panel td:nth-child(4),
  #leaderboard-panel th:nth-child(5),
  #leaderboard-panel td:nth-child(5),
  #leaderboard-panel th:nth-child(6),
  #leaderboard-panel td:nth-child(6),
  #leaderboard-panel th:nth-child(7),
  #leaderboard-panel td:nth-child(7) {
    width: 68px;
  }
}
