:root {
  --bg: #f4f7f2;
  --card: #ffffff;
  --ink: #152018;
  --muted: #66756b;
  --line: #d8e0d8;
  --green: #0f5132;
  --green-soft: #e5f3ea;
  --red: #c00000;
  --red-soft: #ffecec;
  --shadow: 0 10px 26px rgba(18, 36, 24, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 16px 14px;
  color: #fff;
  background: linear-gradient(135deg, #0b3d28, #137647);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: #ccebd7;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 4px;
  font-size: clamp(20px, 5vw, 30px);
}

.sub-title {
  margin-bottom: 0;
  color: #dff4e5;
  font-size: 13px;
}

.sync-badge {
  align-self: flex-start;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
}

.tabs {
  position: sticky;
  top: 86px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px;
  background: rgba(244, 247, 242, 0.95);
  backdrop-filter: blur(8px);
}

.tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--green);
  background: #fff;
  font-weight: 700;
}

.tab.active {
  color: #fff;
  background: var(--green);
}

main {
  padding: 0 12px 80px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 12px 0;
}

.search,
.select {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 13px;
  background: #fff;
  color: var(--ink);
}

.match-list,
.team-list {
  display: grid;
  gap: 12px;
}

.match-card,
.panel,
.team-card,
.champion-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.match-card {
  padding: 14px;
}

.match-head,
.side,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.match-id {
  display: inline-block;
  margin-right: 6px;
  color: var(--muted);
  font-size: 12px;
}

.match-round {
  font-size: 14px;
}

.status-pill {
  border-radius: 999px;
  padding: 5px 9px;
  background: #edf1ed;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-pill.done {
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.waiting {
  background: #fff3cd;
  color: #856404;
}

.side {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 12px;
  background: #fbfdfb;
}

.side.winner {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
  font-weight: 800;
}

.side.withdrawn {
  color: var(--muted);
  text-decoration: line-through;
}

.team-main {
  font-weight: 800;
}

.team-sub {
  color: var(--muted);
  font-size: 12px;
}

.team-score {
  min-width: 36px;
  text-align: right;
  font-size: 22px;
  font-weight: 900;
}

.score-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin-top: 8px;
}

.score-btn,
.withdraw-btn,
.clear-btn,
.secondary,
.danger,
.file-button {
  min-height: 42px;
  border: 0;
  border-radius: 13px;
  padding: 0 12px;
  color: #fff;
  background: var(--green);
  font-weight: 800;
}

.score-btn.selected {
  outline: 3px solid rgba(192, 0, 0, 0.24);
  background: var(--red);
}

.score-btn.win {
  background: #146c43;
}

.withdraw-btn {
  flex: 1;
  background: #8a1c1c;
}

.clear-btn,
.secondary,
.file-button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--green);
  background: var(--green-soft);
}

.danger {
  width: 100%;
  margin-top: 12px;
  background: var(--red);
}

.file-button input {
  display: none;
}

.versus {
  margin-top: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.champion-card {
  margin: 12px 0;
  padding: 14px;
  text-align: center;
}

.champion-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.champion-card strong {
  display: block;
  margin-top: 4px;
  color: var(--red);
  font-size: 18px;
}

.bracket-help {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.bracket {
  display: grid;
  gap: 14px;
}

.block-bracket {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

.block-title {
  position: sticky;
  left: 0;
  z-index: 1;
  margin: 0;
  padding: 12px 14px;
  background: #fff;
  color: var(--green);
  font-size: 15px;
}

.tournament-like {
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(90deg, rgba(15, 81, 50, 0.04) 0 1px, transparent 1px 44px);
}

.tournament-rounds {
  display: grid;
  grid-auto-columns: 214px;
  grid-auto-flow: column;
  gap: 34px;
  min-width: 1470px;
  padding: 0 28px 20px 14px;
}

.tournament-round {
  --match-gap: 12px;
  display: grid;
  gap: var(--match-gap);
  align-content: start;
}

.tournament-round.round-2 {
  padding-top: 32px;
  --match-gap: 70px;
}

.tournament-round.round-3 {
  padding-top: 82px;
  --match-gap: 168px;
}

.tournament-round.round-4 {
  padding-top: 180px;
  --match-gap: 364px;
}

.tournament-round.round-5 {
  padding-top: 376px;
  --match-gap: 756px;
}

.tournament-round.round-6 {
  padding-top: 768px;
}

.block-bracket:has(.round-2:last-child) .tournament-round.round-2 {
  padding-top: 82px;
}

.round-name {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 7px;
  border-radius: 10px;
  background: var(--green-soft);
  color: var(--green);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.bracket-match {
  position: relative;
  min-height: 76px;
  padding-right: 24px;
}

.match-chip {
  position: absolute;
  top: -8px;
  left: 7px;
  z-index: 1;
  border-radius: 999px;
  padding: 2px 7px;
  background: #fff;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  box-shadow: 0 0 0 1px var(--line);
}

.match-box {
  position: relative;
  overflow: hidden;
  border: 1px solid #b8c7bb;
  border-radius: 8px;
  background: #fff;
}

.entrant {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  grid-template-areas:
    "no name score"
    "no school score";
  gap: 0 6px;
  min-height: 37px;
  padding: 5px 6px;
  border-left: 4px solid transparent;
  background: #fff;
  font-size: 11px;
}

.entrant + .entrant {
  border-top: 1px solid #b8c7bb;
}

.entrant.winner {
  border-left-color: var(--red);
  color: var(--red);
  background: var(--red-soft);
  font-weight: 800;
}

.entrant.withdrawn {
  color: var(--muted);
  text-decoration: line-through;
}

.entrant-no {
  grid-area: no;
  align-self: center;
  font-weight: 900;
}

.entrant-name {
  grid-area: name;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.entrant-school {
  grid-area: school;
  overflow: hidden;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.entrant-score {
  grid-area: score;
  align-self: center;
  min-width: 18px;
  text-align: right;
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
}

.entrant-score.retired {
  color: var(--red);
}

.connector {
  position: absolute;
  display: block;
  background: #1c2b20;
}

.connector.horizontal {
  top: 38px;
  right: 0;
  width: 24px;
  height: 2px;
}

.connector.vertical {
  top: 19px;
  right: 0;
  width: 2px;
  height: 40px;
}

.bracket-match.decided .connector,
.bracket-match.decided .match-box::after {
  background: var(--red);
}

.match-box::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -1px;
  width: 14px;
  height: 2px;
  background: #1c2b20;
}

.team-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
}

.team-no {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 900;
}

.team-card.withdrawn {
  opacity: 0.65;
}

.team-card button {
  min-height: 38px;
  border: 0;
  border-radius: 12px;
  padding: 0 10px;
  color: #fff;
  background: var(--green);
  font-weight: 800;
}

.team-card.withdrawn button {
  background: var(--red);
}

.panel {
  margin: 12px 0;
  padding: 16px;
}

.panel li {
  margin: 7px 0;
}

.excel-preview {
  padding: 14px;
}

.preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.preview-head h2 {
  margin-bottom: 4px;
  color: var(--green);
  font-size: 16px;
}

.preview-head p {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 999px;
  padding: 0 12px;
  color: #fff;
  background: var(--green);
  text-decoration: none;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

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

.refresh-preview-btn {
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  color: #fff;
  background: var(--red);
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

.refresh-preview-btn:disabled {
  color: var(--muted);
  background: #edf1ed;
}

.download-link.disabled {
  pointer-events: none;
  color: var(--muted);
  background: #edf1ed;
}

#excelPreviewFrame {
  width: 100%;
  height: min(72vh, 760px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8faf8;
}

#excelPreviewFrame[hidden] {
  display: none;
}

@media (min-width: 760px) {
  .toolbar {
    grid-template-columns: 1fr 220px;
  }

  main {
    max-width: 1180px;
    margin: 0 auto;
  }

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

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