:root {
  color-scheme: dark;
  --bg: #101214;
  --surface: #181b1f;
  --surface-2: #20252a;
  --surface-3: #262d33;
  --line: #343c43;
  --text: #edf0f2;
  --muted: #9aa5ad;
  --quiet: #707d86;
  --green: #35c46f;
  --green-bg: #143322;
  --amber: #e4a226;
  --amber-bg: #382a12;
  --red: #ef6262;
  --red-bg: #3a1d1d;
  --cyan: #58b8d9;
  --focus: #d6ad4b;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(88, 184, 217, 0.08), transparent 220px),
    linear-gradient(90deg, rgba(228, 162, 38, 0.06), transparent 360px),
    var(--bg);
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

#app {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  font-size: 1.85rem;
  line-height: 1.15;
}

h2 {
  font-size: 1rem;
}

h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(360px, 1.1fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(24, 27, 31, 0.95);
  overflow: hidden;
}

.wide {
  grid-column: 1 / -1;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.panel-title span {
  color: var(--quiet);
  font-size: 0.82rem;
}

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

label {
  display: grid;
  gap: 6px;
}

label > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.control {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111417;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

.control:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px rgba(214, 173, 75, 0.18);
}

.compact {
  min-height: 34px;
  padding: 6px 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  align-self: end;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111417;
}

.button-label {
  align-self: end;
}

.full-btn {
  width: 100%;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--focus);
}

.primary-btn,
.ghost-btn,
.team-pick {
  min-height: 36px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.primary-btn {
  padding: 8px 14px;
  background: var(--focus);
  color: #17120a;
  font-weight: 800;
}

.primary-btn:hover {
  background: #edc45f;
}

.primary-btn:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ghost-btn {
  padding: 7px 11px;
  border: 1px solid var(--line);
  background: #111417;
  color: var(--muted);
  font-weight: 700;
}

.ghost-btn:hover {
  border-color: var(--focus);
  color: var(--text);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111417;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
}

.icon-btn:hover {
  border-color: var(--red);
  color: #ffb1b1;
}

.table-wrap {
  overflow-x: auto;
}

.ranking-wrap {
  max-height: 430px;
  overflow: auto;
}

.ranking-tools {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 12px 14px 4px;
}

.ranking-tools label {
  width: min(240px, 100%);
}

.ranking-tools .table-note {
  margin: 0 0 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--quiet);
  font-size: 0.75rem;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

td:first-child {
  color: var(--text);
}

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

.rank-team-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: #bfe6f5;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.rank-team-btn:hover {
  color: var(--text);
  text-decoration: underline;
}

.delta-text {
  display: inline-block;
  min-width: 54px;
  margin-left: 6px;
  color: currentColor;
  font-size: 0.76rem;
  opacity: 0.86;
}

.total-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  color: var(--muted);
}

.total-strip strong {
  color: var(--amber);
  font-size: 1.1rem;
}

.participant-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  padding: 14px;
}

.bracket-board {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.bracket-phase {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #13171a;
  content-visibility: auto;
  contain-intrinsic-size: 520px;
  overflow: hidden;
}

.phase-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.phase-toggle {
  display: inline-grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.phase-toggle > span {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--amber);
  font-weight: 900;
  line-height: 1;
}

.phase-toggle > strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phase-toggle:hover > span {
  border-color: var(--focus);
}

.phase-head > span {
  color: var(--quiet);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.bracket-phase.is-collapsed .phase-head {
  border-bottom: 0;
}

.phase-rounds {
  display: grid;
  gap: 22px;
  max-height: 760px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 24px;
  scrollbar-gutter: stable;
}

.phase-rounds[hidden] {
  display: none;
}

.lp-row {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.lp-row h3 {
  color: #bed28d;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: none;
}

.lp-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(190px, 230px);
  align-items: start;
  gap: 36px;
  min-width: max-content;
  overflow: visible;
  padding: 2px 28px 22px 2px;
  position: relative;
  isolation: isolate;
}

.lp-lane {
  display: grid;
  grid-template-rows: 22px auto;
  gap: 8px;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.lp-lane-title {
  display: grid;
  place-items: center;
  min-height: 22px;
  border: 1px solid #646c72;
  background: #d3d5d6;
  color: #25292c;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.lp-lane-items {
  display: flex;
  flex-direction: column;
  gap: 11px;
  justify-content: flex-start;
}

.lp-lane.spread .lp-lane-items {
  gap: 72px;
  padding-top: 42px;
}

.lp-lane.qualified .lp-lane-items {
  gap: 11px;
  padding-top: 0;
}

.lp-lane.qualified.spread .lp-lane-items {
  gap: 72px;
  padding-top: 42px;
}

.lp-lane.deep .lp-lane-items {
  gap: 72px;
  padding-top: 126px;
}

.lp-lane.qualified.deep .lp-lane-items {
  gap: 72px;
  padding-top: 126px;
}

.lp-match,
.qualified-card {
  position: relative;
  z-index: 2;
}

.lp-match {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  min-width: 0;
  border: 1px solid #8a9196;
  background: #f1f2f3;
  color: #111417;
}

.lp-match-id {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 32px;
  align-items: center;
  min-height: 20px;
  border-bottom: 1px solid #c0c4c7;
  background: #e3e5e6;
}

.lp-match-id > span {
  display: grid;
  place-items: center;
  width: 42px;
  color: #5a6268;
  font-size: 0.68rem;
  font-weight: 700;
}

.lp-match-id .icon-btn {
  width: 24px;
  height: 20px;
  border: 0;
  border-left: 1px solid #c0c4c7;
  border-radius: 0;
  background: transparent;
  color: #6b7379;
  font-size: 0.88rem;
}

.team-slot {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 2px 6px;
  border-bottom: 1px solid #cdd1d3;
  background: #f8f9f9;
}

.team-slot > span {
  color: #6b7379;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
}

.team-slot > strong {
  min-width: 0;
  overflow: hidden;
  color: #293035;
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-slot > em {
  display: grid;
  place-items: center;
  width: 20px;
  height: 18px;
  border-left: 1px solid #c0c4c7;
  background: transparent;
  color: #111417;
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 800;
}

.team-slot.winner {
  background: #ffffff;
}

.team-slot.winner > strong,
.team-slot.winner > span {
  color: #111417;
  font-weight: 800;
}

.match-edit {
  position: relative;
  background: #f1f2f3;
  padding: 0 6px 4px;
}

.match-edit summary {
  color: #5a6268;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.match-edit-grid {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  position: absolute;
  top: 100%;
  left: 0;
  width: min(260px, 80vw);
  padding: 8px;
  border: 1px solid #8a9196;
  background: #f1f2f3;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.match-edit-grid label {
  display: grid;
  gap: 4px;
}

.match-edit-grid label > span {
  color: #5a6268;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.qualified-card {
  display: grid;
  align-items: center;
  min-height: 28px;
  border: 1px solid #8a9196;
  background: #eeeeef;
  padding: 4px 8px;
}

.qualified-card strong {
  min-width: 0;
  overflow: hidden;
  color: #293035;
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* bracket 连线由 JS+SVG 动态绘制，见 drawBracketConnectors() */
.lp-bracket-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

.lp-bracket-line {
  stroke-linecap: square;
  shape-rendering: crispEdges;
}

.compact-empty {
  min-height: 120px;
}

.result-panel {
  min-height: 220px;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 170px;
  color: var(--quiet);
}

.empty-state strong {
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  padding: 14px;
}

.metric {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #14181b;
}

.metric span {
  color: var(--quiet);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  font-size: 1.05rem;
}

.metric em {
  color: var(--muted);
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

.model-note {
  margin: 0 14px 14px;
  padding: 10px 12px;
  border: 1px solid rgba(228, 162, 38, 0.35);
  border-radius: 6px;
  background: var(--amber-bg);
  color: #f0d69a;
  font-size: 0.88rem;
}

.table-note {
  margin: 10px 14px 14px;
  color: var(--quiet);
  font-size: 0.84rem;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 14px 14px;
}

.positive {
  color: var(--green) !important;
}

.negative {
  color: var(--red) !important;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
}

.tag.win {
  background: var(--green-bg);
  color: var(--green);
}

.tag.loss {
  background: var(--red-bg);
  color: var(--red);
}

.click-row {
  cursor: pointer;
}

.click-row:hover,
.active-row {
  background: var(--surface-3);
}

.detail-split {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.ranking-detail {
  border-top: 1px solid var(--line);
  padding: 14px;
  background: rgba(17, 20, 23, 0.72);
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.detail-head h3 {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 0.95rem;
  text-transform: none;
}

.detail-head p,
.quiet {
  color: var(--quiet);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.75fr) minmax(0, 1.25fr);
  align-items: start;
  gap: 14px;
  margin-bottom: 14px;
}

.detail-grid.three {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr));
  overflow: visible;
}

.ranking-detail section {
  min-width: 0;
  max-width: 100%;
}

.ranking-detail table {
  width: 100%;
}

.detail-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-gutter: stable;
}

.compact-detail-table table {
  min-width: 340px;
}

.detail-fixed-table {
  min-width: 760px;
  table-layout: fixed;
}

.prize-detail-table {
  min-width: 790px;
}

.contribution-table {
  min-width: 820px;
}

.detail-fixed-table th,
.detail-fixed-table td {
  font-size: 0.78rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prize-detail-table th:nth-child(1),
.prize-detail-table td:nth-child(1),
.contribution-table th:nth-child(1),
.contribution-table td:nth-child(1) {
  width: 118px;
  min-width: 118px;
  overflow: visible;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-overflow: clip;
}

.prize-detail-table th:nth-child(2),
.prize-detail-table td:nth-child(2) {
  width: 285px;
}

.contribution-table th:nth-child(2),
.contribution-table td:nth-child(2) {
  width: 245px;
}

.contribution-table th:nth-child(3),
.contribution-table td:nth-child(3) {
  width: 170px;
}

.prize-detail-table th:nth-child(n+3),
.prize-detail-table td:nth-child(n+3),
.contribution-table th:nth-child(n+4),
.contribution-table td:nth-child(n+4) {
  width: 78px;
}

.detail-date-cell {
  white-space: nowrap;
}

.detail-event-cell,
.detail-opponent-cell {
  min-width: 0;
}

.ranking-detail details {
  margin-top: 12px;
}

.ranking-detail summary {
  cursor: pointer;
  color: var(--amber);
  font-weight: 800;
  margin-bottom: 10px;
}

.detail-match-wrap {
  max-height: 520px;
  overflow: auto;
}

.detail-match-wrap table {
  min-width: 880px;
}

.error-line {
  margin: 0 14px 14px;
  padding: 10px 12px;
  border: 1px solid rgba(239, 98, 98, 0.45);
  border-radius: 6px;
  background: var(--red-bg);
  color: #ffb1b1;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  padding: 18px 0 0;
  color: var(--quiet);
  font-size: 0.8rem;
}

.site-footer a {
  color: var(--muted);
  font-weight: 800;
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--focus);
}

@media (max-width: 980px) {
  #app {
    width: min(100% - 20px, 1480px);
  }

  .layout,
  .split,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid,
  .participant-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }
}
