:root {
  color-scheme: light;
  --ink: #152032;
  --muted: #607086;
  --line: #d9e1ea;
  --surface: #ffffff;
  --paper: #f4f7fb;
  --blue: #1155cc;
  --green: #18795b;
  --amber: #a15c00;
  --red: #b42318;
  --shadow: 0 12px 34px rgba(21, 32, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: "Inter", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px);
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

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

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 20px;
}

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

.actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--blue);
  border-radius: 6px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.primary:disabled {
  cursor: wait;
  opacity: 0.7;
}

.refresh-icon {
  display: inline-block;
  font-size: 20px;
  line-height: 1;
}

.loading .refresh-icon {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.muted,
.hint {
  color: var(--muted);
  font-size: 13px;
}

main {
  display: grid;
  gap: 20px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 32px) 48px;
}

main > * {
  min-width: 0;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-band > div {
  display: grid;
  gap: 8px;
  min-height: 86px;
  padding: 18px;
  background: #ffffff;
}

.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-band strong {
  font-size: 22px;
}

.panel {
  min-width: 0;
  padding: 20px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.section-actions {
  display: grid;
  gap: 10px;
  justify-items: end;
  min-width: 0;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.secondary {
  min-height: 34px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
}

.secondary:hover {
  background: #f8fafc;
}

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

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

.group-card > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.group-record {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.mini-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) repeat(6, 34px) 58px;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid #edf1f5;
  font-size: 13px;
}

.mini-row.head {
  min-height: 34px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 11px;
  font-weight: 800;
}

.team-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 800;
}

.team-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flag {
  width: 24px;
  height: 18px;
  flex: 0 0 24px;
  overflow: hidden;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #edf1f5;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  font-weight: 900;
}

.rank-badge.direct {
  color: #ffffff;
  background: var(--green);
}

.rank-badge.third-in {
  color: #ffffff;
  background: var(--blue);
}

.rank-badge.third-out {
  color: #ffffff;
  background: var(--amber);
}

.metric {
  text-align: center;
}

.tie-note {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.matches {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #fbfcfe;
}

.match-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.match-team {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-team:first-child {
  text-align: right;
}

.score {
  min-width: 46px;
  padding: 4px 6px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 900;
  text-align: center;
}

.table-shell {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 11px;
  font-weight: 900;
}

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

.bracket-table {
  min-width: 680px;
}

.bracket-table td {
  height: 54px;
}

.slot-code,
.placeholder-team {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  font-weight: 900;
}

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

.versus {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.rules-table-shell {
  max-height: 620px;
}

.rules-table {
  min-width: 1480px;
}

.rules-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.rules-table td:not(:nth-child(2)),
.rules-table th:not(:nth-child(2)) {
  text-align: center;
}

.rule-matchup {
  display: grid;
  gap: 4px;
  justify-items: stretch;
  min-width: 148px;
  font-size: 12px;
  line-height: 1.3;
}

.rule-team {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  min-width: 0;
  white-space: nowrap;
}

.rule-separator {
  display: block;
  width: 34px;
  margin-left: 22px;
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  line-height: 0.65;
  text-align: center;
}

.team-token {
  overflow: hidden;
  color: var(--ink);
  font-weight: 800;
  text-overflow: ellipsis;
}

.tiny-flag {
  width: 18px;
  height: 14px;
  flex-basis: 18px;
}

.rules-table .active-rule td {
  background: #edf7f2;
  box-shadow: inset 0 1px 0 #b9decf, inset 0 -1px 0 #b9decf;
}

.rules-table .active-rule td:first-child {
  color: var(--green);
  font-weight: 900;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.status-in {
  color: #ffffff;
  background: var(--green);
}

.status-wait {
  color: #ffffff;
  background: var(--amber);
}

.status-out {
  color: #ffffff;
  background: var(--red);
}

.rules {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.8;
}

.error {
  padding: 18px;
  border: 1px solid #ffc9c9;
  border-radius: 8px;
  color: var(--red);
  background: #fff5f5;
}

@media (max-width: 1120px) {
  .groups-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .section-heading {
    align-items: start;
    flex-direction: column;
  }

  .section-actions {
    width: 100%;
    justify-items: start;
  }

  .export-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .actions {
    width: 100%;
    justify-items: stretch;
  }

  .primary {
    width: 100%;
  }

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

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

  .panel {
    padding: 14px;
  }

  .mini-row {
    grid-template-columns: 28px minmax(84px, 1fr) repeat(6, 27px) 42px;
    padding: 0 8px;
    font-size: 12px;
  }
}
