:root {
  color-scheme: dark;
  --bg: #080504;
  --panel: #211614;
  --panel-2: #301e1a;
  --panel-3: #42291f;
  --line: #a66f53;
  --line-soft: #654337;
  --text: #fff8ec;
  --muted: #d8c1a8;
  --accent: #f7c948;
  --upper: #22c55e;
  --lower: #f97316;
  --grand: #e11d48;
  --surface: #120c0b;
  --button: #4b2a22;
  --button-hover: #6d392a;
  --disabled: #2a211f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 0%, rgba(247, 201, 72, .14), transparent 280px),
    linear-gradient(180deg, #1a100d 0, var(--bg) 230px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 32px;
  background: #17100f;
  border-bottom: 1px solid #7c4f3c;
  box-shadow: 0 14px 32px rgba(0, 0, 0, .28);
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

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

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

a, button {
  color: var(--text);
}

nav a, button {
  border: 1px solid #b9805f;
  border-radius: 6px;
  background: var(--button);
  padding: 9px 12px;
  text-decoration: none;
  cursor: pointer;
}

button:hover, nav a:hover {
  border-color: #f7c948;
  background: var(--button-hover);
}

nav a[href="/group-a"] {
  border-color: rgba(34, 197, 94, .78);
  background:
    linear-gradient(135deg, rgba(34, 197, 94, .34), rgba(34, 197, 94, .10)),
    #1b2719;
}

nav a[href="/group-a"]:hover {
  border-color: #22c55e;
  background:
    linear-gradient(135deg, rgba(34, 197, 94, .46), rgba(34, 197, 94, .16)),
    #1f331f;
}

nav a[href="/group-b"] {
  border-color: rgba(56, 189, 248, .78);
  background:
    linear-gradient(135deg, rgba(56, 189, 248, .34), rgba(56, 189, 248, .10)),
    #172832;
}

nav a[href="/group-b"]:hover {
  border-color: #38bdf8;
  background:
    linear-gradient(135deg, rgba(56, 189, 248, .46), rgba(56, 189, 248, .16)),
    #1a3442;
}

nav a[href="/playoffs"] {
  border-color: rgba(244, 63, 94, .82);
  background:
    linear-gradient(135deg, rgba(244, 63, 94, .34), rgba(251, 146, 60, .14)),
    #32191b;
}

nav a[href="/playoffs"]:hover {
  border-color: #f43f5e;
  background:
    linear-gradient(135deg, rgba(244, 63, 94, .46), rgba(251, 146, 60, .20)),
    #432023;
}

#discord-auth-link {
  border-color: #7983f5;
  background:
    linear-gradient(135deg, rgba(88, 101, 242, .98), rgba(71, 82, 196, .92)),
    #5865f2;
}

#discord-auth-link:hover {
  border-color: #c7d2fe;
  background:
    linear-gradient(135deg, rgba(105, 118, 255, 1), rgba(88, 101, 242, .96)),
    #6976ff;
}

#admin-inline-open {
  border-color: #facc15;
  background:
    linear-gradient(135deg, rgba(250, 204, 21, .86), rgba(180, 83, 9, .82)),
    #854d0e;
  color: #1f1306;
  font-weight: 800;
}

#admin-inline-open:hover {
  border-color: #fef08a;
  background:
    linear-gradient(135deg, rgba(253, 224, 71, .96), rgba(217, 119, 6, .88)),
    #a16207;
  color: #160d04;
}

main {
  padding: 22px 32px 40px;
}

.home-main {
  min-height: calc(100vh - 89px);
  display: grid;
  place-items: center;
  padding: 32px;
}

.home-actions {
  width: min(860px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.home-button {
  min-height: 160px;
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 28px;
  border: 1px solid #9f6b4d;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .38);
}

.home-button:hover {
  transform: translateY(-2px);
}

.home-button span {
  font-size: 34px;
  font-weight: 800;
}

.home-button small {
  color: var(--muted);
  font-size: 14px;
}

.playoffs-button {
  grid-column: 1 / -1;
}

.group-a-button {
  border-color: rgba(34, 197, 94, .7);
  background:
    linear-gradient(135deg, rgba(34, 197, 94, .26), rgba(34, 197, 94, .06)),
    var(--panel);
}

.group-a-button:hover {
  border-color: #22c55e;
}

.group-b-button {
  border-color: rgba(56, 189, 248, .7);
  background:
    linear-gradient(135deg, rgba(56, 189, 248, .28), rgba(56, 189, 248, .06)),
    var(--panel);
}

.group-b-button:hover {
  border-color: #38bdf8;
}

.playoffs-button {
  border-color: rgba(244, 63, 94, .75);
  background:
    linear-gradient(135deg, rgba(244, 63, 94, .26), rgba(251, 146, 60, .12)),
    var(--panel);
}

.playoffs-button:hover {
  border-color: #f43f5e;
}

section + section {
  margin-top: 28px;
}

.teams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.overview-section {
  margin-bottom: 22px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.standings {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid #9f6b4d;
  border-radius: 8px;
  background: #211614;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .24);
}

.standings th,
.standings td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: right;
  white-space: nowrap;
}

.standings th {
  background: #40281f;
  color: #f6dfbd;
  font-size: 12px;
  text-transform: uppercase;
}

.standings tbody tr {
  background: #201513;
}

.standings tbody tr:nth-child(even) {
  background: #2a1b17;
}

.standings tbody tr.qualifying {
  background: linear-gradient(90deg, rgba(34, 197, 94, .28), #1f2d1e 34%, #241915);
}

.standings tbody tr.qualifying:nth-child(even) {
  background: linear-gradient(90deg, rgba(34, 197, 94, .32), #253723 34%, #2c1d18);
}

.standings tbody tr.eliminated {
  background: linear-gradient(90deg, rgba(225, 29, 72, .26), #32191b 34%, #241915);
}

.standings tbody tr.eliminated:nth-child(even) {
  background: linear-gradient(90deg, rgba(225, 29, 72, .30), #3a1d1f 34%, #2c1d18);
}

.standings tbody tr.qualifying td:first-child {
  border-left: 4px solid #22c55e;
}

.standings tbody tr.eliminated td:first-child {
  border-left: 4px solid #f43f5e;
}

.standings th:nth-child(2),
.standings td:nth-child(2) {
  width: 100%;
  min-width: 220px;
  text-align: left;
  white-space: normal;
}

.standings td span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.group-matches {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.group-match {
  display: grid;
  gap: 2px;
  padding: 6px 10px 6px 12px;
  background: #241713;
  border: 1px solid #80543f;
  border-left: 3px solid #f7c948;
  border-radius: 6px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .08) inset,
    0 8px 18px rgba(0, 0, 0, .18);
}

.group-match.complete {
  border-left-color: #22c55e;
  background: #1e2b1d;
}

.group-fixture {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.group-team {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-team:last-child {
  text-align: right;
}

.group-vs {
  color: #f7c948;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.group-result-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 15px;
}

.group-match-label {
  color: #d8c1a8;
  font-size: 10px;
}

.group-score {
  color: #fff8ec;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.team-card, .match-card, .admin-card {
  background: var(--panel);
  border: 1px solid #9f6b4d;
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, .2);
}

.team-card {
  padding: 12px;
}

.seed {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  margin-right: 8px;
  border-radius: 999px;
  background: #4d2d22;
  color: var(--accent);
  font-weight: 700;
}

.team-name {
  font-weight: 700;
}

.players {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.bracket {
  display: block;
  padding-bottom: 16px;
}

.bracket-board {
  display: grid;
  grid-template-columns:
    minmax(250px, 1fr)
    minmax(250px, 1fr)
    minmax(250px, 1fr)
    minmax(250px, 1fr)
    minmax(250px, 1fr);
  grid-template-rows: 554px 280px;
  gap: 18px 14px;
  align-items: start;
}

.bracket-track {
  min-width: 0;
}

.upper-track {
  grid-row: 1;
}

.upper-qf {
  grid-column: 1;
}

.upper-sf {
  grid-column: 2;
}

.upper-final {
  grid-column: 3;
}

.lower-track {
  grid-row: 2;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.lower-r1 {
  grid-column: 1;
}

.lower-r2 {
  grid-column: 2;
}

.lower-semi {
  grid-column: 3;
}

.lower-final {
  grid-column: 4;
}

.final-track {
  grid-column: 5;
  grid-row: 1 / 3;
  align-self: stretch;
}

.round {
  min-width: 0;
}

.upper-track .round {
  display: grid;
  height: 554px;
  grid-template-rows: 18px repeat(4, 124px);
  gap: 10px;
}

.upper-track .match-card {
  margin-bottom: 0;
  min-height: 124px;
}

.upper-qf .round {
  align-content: start;
}

.upper-sf .round {
  align-content: start;
}

.upper-final .round {
  align-content: start;
}

.upper-sf .match-card:nth-of-type(1) {
  grid-row: 2 / 4;
  align-self: center;
}

.upper-sf .match-card:nth-of-type(2) {
  grid-row: 4 / 6;
  align-self: center;
}

.upper-final .match-card:nth-of-type(1) {
  grid-row: 2 / 6;
  align-self: center;
}

.final-track .round {
  display: grid;
  height: 852px;
  grid-template-rows: 1fr 18px 124px 1fr;
  gap: 10px;
}

.final-track .round-title {
  grid-column: 1;
  grid-row: 2;
  align-self: end;
  margin-bottom: 0;
}

.final-track .match-card {
  grid-column: 1;
  grid-row: 3;
  align-self: start;
}

.lower-track .round {
  display: grid;
  width: 100%;
  height: 268px;
  grid-template-rows: 18px repeat(2, 116px);
  gap: 9px;
}

.lower-track .match-card {
  min-height: 116px;
  margin-bottom: 0;
}

.lower-track .match-head {
  padding: 5px 9px;
  font-size: 11px;
}

.lower-track .slot {
  padding: 5px 9px;
}

.lower-track .slot-name strong {
  font-size: 13px;
}

.lower-track .slot-name span {
  font-size: 10px;
}

.lower-semi .round,
.lower-final .round {
  grid-template-rows: 18px 1fr;
}

.lower-semi .match-card,
.lower-final .match-card {
  align-self: center;
}

.round-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.match-card {
  min-height: 124px;
  margin-bottom: 9px;
  overflow: visible;
}

.match-card.upper {
  border-top: 3px solid var(--upper);
}

.match-card.lower {
  border-top: 3px solid var(--lower);
}

.match-card.grand {
  border-top: 3px solid var(--grand);
}

.match-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: #3b271f;
  font-weight: 700;
  font-size: 11px;
}

.status {
  color: var(--muted);
  font-weight: 600;
}

.slot {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-top: 1px solid var(--line-soft);
}

.slot.winner {
  background: rgba(34, 197, 94, .2);
}

.slot-name {
  min-width: 0;
}

.slot-name strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.slot-name span {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score {
  min-width: 28px;
  text-align: right;
  font-weight: 800;
  font-size: 16px;
}

.admin-login {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid #9f6b4d;
  border-radius: 8px;
}

.admin-shell {
  width: min(900px, 100%);
  margin: 0 auto;
}

.admin-panel {
  padding: 18px;
  background: #1c1210;
  border: 1px solid #9f6b4d;
  border-radius: 8px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, .24);
}

.hidden {
  display: none;
}

.result-action-dock {
  display: grid;
  gap: 12px;
  padding: 14px 32px;
  background: linear-gradient(90deg, #24120e, #140b09);
  border-bottom: 1px solid #8f5e45;
  box-shadow: 0 14px 28px rgba(0, 0, 0, .22);
}

.result-action-dock.hidden {
  display: none;
}

.result-action-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.result-action-head strong {
  margin-right: 8px;
}

.result-group-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-group-buttons button.active {
  border-color: #f7c948;
  background: #7a3d2a;
}

.inline-result-editor {
  display: grid;
  max-width: 920px;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
}

.inline-result-editor #result-ticket-inputs,
.inline-result-editor .admin-actions {
  grid-column: 1 / -1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 5, 4, .72);
  backdrop-filter: blur(3px);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  background: #211614;
  border: 1px solid #b9805f;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}

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

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

.admin-choice {
  min-height: 116px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 20px;
  border-color: #b9805f;
  background: linear-gradient(135deg, #5a2f22, #2b1915);
  text-align: left;
}

.admin-choice:hover {
  border-color: #f7c948;
  background: linear-gradient(135deg, #7a3d2a, #3a2018);
}

.admin-choice span {
  font-size: 22px;
  font-weight: 800;
}

.admin-choice small {
  color: var(--muted);
  font-size: 13px;
}

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

input, select {
  min-height: 38px;
  border: 1px solid #9f6b4d;
  border-radius: 6px;
  background: #120c0b;
  color: var(--text);
  padding: 8px;
}

input:focus,
select:focus {
  border-color: #f7c948;
  outline: 2px solid rgba(247, 201, 72, .25);
}

option:disabled {
  color: #8c7562;
}

.danger {
  border-color: #b91c1c;
  background: #3f1212;
}

.admin-matches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.admin-group-block {
  display: grid;
  gap: 12px;
}

.admin-group-block + .admin-group-block {
  margin-top: 22px;
}

.admin-group-block > h3 {
  margin: 0;
}

.admin-card {
  padding: 12px;
}

.admin-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.admin-row {
  display: grid;
  grid-template-columns: 1fr 70px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.ticket-row {
  display: grid;
  grid-template-columns: 70px 86px 1fr 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.admin-ticket-row {
  grid-template-columns: 64px 86px minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
  margin-top: 12px;
}

.ticket-row span {
  color: var(--muted);
  font-size: 13px;
}

.admin-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.player-panel {
  display: grid;
  gap: 12px;
}

.player-message {
  min-height: 18px;
  color: #f7c948;
  font-weight: 700;
}

.discord-login-button {
  display: inline-flex;
  width: fit-content;
  min-height: 42px;
  align-items: center;
  border: 1px solid #f7c948;
  border-radius: 6px;
  background: #5a2f22;
  color: var(--text);
  padding: 10px 14px;
  font-weight: 800;
  text-decoration: none;
}

.discord-login-button:hover {
  background: #7a3d2a;
}

.player-result-form {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}

.player-ticket-row {
  display: grid;
  grid-template-columns: 52px 86px minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.player-ticket-row > span {
  padding-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.player-ticket-row label {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-ticket-row input,
.player-ticket-row select,
.admin-ticket-row select {
  width: 100%;
  min-height: 34px;
}

.player-result-form button {
  justify-self: start;
}

.player-result-form button:disabled {
  cursor: progress;
  opacity: .65;
}

.player-match-note {
  margin-top: 6px;
  font-size: 12px;
}

.load-error {
  padding: 16px 32px;
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  main {
    padding: 20px 18px 36px;
  }

  .standings {
    display: block;
    overflow-x: auto;
  }

  .admin-grid,
  .group-match,
  .admin-choice-grid,
  .admin-ticket-row,
  .player-ticket-row,
  .inline-result-editor {
    grid-template-columns: 1fr;
  }

  .home-main {
    min-height: auto;
    place-items: stretch;
  }

  .home-actions {
    grid-template-columns: 1fr;
  }

  .home-button {
    min-height: 130px;
  }

  .home-button span {
    font-size: 28px;
  }
}
