:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #d7dde5;
  --text: #19212a;
  --muted: #607080;
  --accent: #116b5b;
  --accent-strong: #0b5347;
  --danger: #a12c2c;
  --ok: #17643b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2 {
  margin: 0 0 14px;
  line-height: 1.2;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

h3 {
  margin: 0;
  font-size: 14px;
}

button, input, select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.floating-save {
  position: fixed;
  right: max(18px, calc((100vw - 1280px) / 2 + 18px));
  top: 92px;
  z-index: 20;
  box-shadow: 0 10px 24px rgba(25, 33, 42, .18);
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #7f2020;
}

input, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 7px 9px;
}

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

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

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  min-height: 60px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
}

.brand {
  color: var(--text);
  font-weight: 800;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page {
  width: min(1280px, calc(100vw - 32px));
  margin: 24px auto 48px;
}

.narrow {
  width: min(820px, calc(100vw - 32px));
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel, .panel, .table-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.login-panel {
  width: min(420px, 100%);
}

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.score {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
}

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

.section-head p {
  margin: 0;
  color: var(--muted);
}

.flash {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  width: fit-content;
  max-width: min(720px, calc(100vw - 32px));
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--surface);
  overflow-wrap: anywhere;
  transition: opacity .18s ease, transform .18s ease;
}

.flash.is-dismissing {
  opacity: 0;
  transform: translate(-50%, -4px);
}

.flash.error {
  border-color: #efb4b4;
  color: var(--danger);
}

.flash.success {
  border-color: #a7d8bd;
  color: var(--ok);
}

.date-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding-bottom: 4px;
}

.date-filter button {
  white-space: nowrap;
}

.date-filter .is-active,
.wizard-steps .is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.rule-card,
.score-rules {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.rule-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 17px;
}

.match-list, .admin-list, .day-panel {
  display: grid;
  gap: 10px;
}

.match-list > .floating-save {
  position: sticky;
  top: 12px;
  right: auto;
  bottom: auto;
  justify-self: end;
  align-self: start;
}

.day-panel h2 {
  margin-top: 8px;
}

.is-hidden {
  display: none !important;
}

.match-row {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(430px, auto);
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.match-row.is-good {
  border-color: #97cfa8;
  background: #eff8f2;
}

.match-row.is-partial {
  border-color: #e2ca7b;
  background: #fff9e5;
}

.match-row.is-bad {
  border-color: #efb4b4;
  background: #fff4f4;
}

.match-main {
  display: grid;
  gap: 3px;
}

.match-main small, .muted {
  color: var(--muted);
}

.match-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--danger);
  font-weight: 800;
  letter-spacing: 0;
}

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

.live-score,
.final-score strong {
  color: var(--text);
  font-size: 16px;
}

.final-score {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f9fb;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.lock-badge.is-closed::before {
  content: "🔒";
}

.lock-badge.is-open::before {
  content: "🔓";
}

.pick-form {
  display: grid;
  grid-template-columns: 64px auto 64px minmax(140px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.result-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f9fb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.result-pill.is-good {
  border-color: #97cfa8;
  background: #e3f3e8;
  color: #17643b;
}

.result-pill.is-partial {
  border-color: #e2ca7b;
  background: #fff1c7;
  color: #7a5d00;
}

.result-pill.is-bad {
  border-color: #efb4b4;
  background: #fbe4e4;
  color: #a12c2c;
}

.pick-form .muted {
  grid-column: 1 / -1;
}

.pick-form input {
  text-align: center;
}

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

.group-box {
  display: grid;
  gap: 10px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.group-box legend {
  padding: 0 4px;
  font-weight: 700;
}

.group-title {
  font-size: 14px;
}

.blind-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  align-items: center;
}

.blind-summary .score {
  margin: 4px 0 0;
}

.blind-review {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.blind-pick-list {
  display: grid;
  gap: 6px;
}

.blind-pick-row,
.readonly-pick {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
}

.blind-pick-row > span:first-child {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.standings-table {
  font-size: 13px;
}

.standings-table th,
.standings-table td {
  padding: 6px;
}

.blind-wizard {
  display: grid;
  gap: 18px;
}

.wizard-steps {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.wizard-steps button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
}

.wizard-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.wizard-panel.is-active {
  display: grid;
  gap: 16px;
}

.pick-group-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.team-card-grid, .third-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.team-card, .third-card, .bracket-slot {
  position: relative;
  min-height: 52px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.team-card:hover, .third-card:hover, .bracket-slot:hover {
  background: #eef7f4;
  border-color: #75b7aa;
}

.team-card.is-picked, .third-card.is-picked, .bracket-slot.is-picked {
  background: #dff0eb;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.team-card.is-good,
.third-card.is-good,
.bracket-match.is-good,
.blind-pick-row.is-good {
  border-color: #97cfa8;
  background: #eff8f2;
}

.team-card.is-partial,
.third-card.is-partial,
.bracket-match.is-partial,
.blind-pick-row.is-partial {
  border-color: #e2ca7b;
  background: #fff9e5;
}

.team-card.is-bad,
.third-card.is-bad,
.bracket-match.is-bad,
.blind-pick-row.is-bad {
  border-color: #efb4b4;
  background: #fff4f4;
}

.rank-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 24px;
  height: 24px;
  display: none;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.team-card.is-picked .rank-badge {
  display: grid;
}

.team-flag {
  min-width: 26px;
  font-size: 22px;
  line-height: 1;
}

.team-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

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

.bracket-top-actions {
  position: sticky;
  top: 12px;
  z-index: 10;
  justify-content: flex-end;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.third-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.leaderboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.bracket-board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(260px, 1fr);
  gap: 14px;
  overflow-x: auto;
  padding: 4px 0 14px;
  cursor: grab;
  user-select: none;
}

.bracket-board.is-dragging {
  cursor: grabbing;
}

.bracket-round {
  min-width: 260px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.bracket-round h3 {
  position: sticky;
  top: 0;
  z-index: 1;
  min-height: 34px;
  display: grid;
  align-items: center;
  border-bottom: 2px solid var(--accent);
  background: var(--surface);
}

.bracket-round-matches {
  display: grid;
  gap: 12px;
}

.bracket-round[data-round-column="Round of 16"] .bracket-round-matches {
  padding-top: 38px;
  gap: 38px;
}

.bracket-round[data-round-column="Quarter-final"] .bracket-round-matches {
  padding-top: 96px;
  gap: 96px;
}

.bracket-round[data-round-column="Semi-final"] .bracket-round-matches {
  padding-top: 214px;
  gap: 214px;
}

.bracket-round[data-round-column="Third place"] .bracket-round-matches,
.bracket-round[data-round-column="Final"] .bracket-round-matches {
  padding-top: 260px;
}

.bracket-match {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.bracket-match.is-next {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #cde9e3;
}

.bracket-picks {
  display: grid;
  gap: 8px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) 140px auto;
  gap: 10px;
  align-items: end;
}

.admin-page {
  display: grid;
  gap: 18px;
}

.admin-panel {
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

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

.admin-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(160px, auto));
  gap: 10px;
}

.admin-day-list {
  display: grid;
  gap: 18px;
}

.admin-day-section {
  display: grid;
  gap: 10px;
}

.admin-day-section h3 {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.user-action-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 250px;
}

.admin-match {
  display: grid;
  grid-template-columns: 180px repeat(4, minmax(130px, 1fr)) 120px 110px 110px 140px auto;
  gap: 8px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.admin-match-title {
  display: grid;
  gap: 4px;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .summary-grid, .match-row, .inline-form, .admin-match, .user-action-form, .admin-filters {
    grid-template-columns: 1fr;
  }

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

  .pick-form {
    grid-template-columns: 64px auto 64px;
  }

  .pick-form select, .pick-form button, .pick-form .muted {
    grid-column: 1 / -1;
  }

  .floating-save {
    top: auto;
    right: 12px;
    bottom: 12px;
  }

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

  .team-card-grid {
    grid-template-columns: 1fr;
  }

  .wizard-actions {
    display: grid;
  }
}
