:root {
  color-scheme: light dark;
  --bg: #ffffe0;
  --surface: #fff;
  --surface2: #eef1f6;
  --text: #1a1d24;
  --muted: #5c6475;
  --accent: #6aa423;
  --accent-dim: #3d8f6a;
  --danger: #b83232;
  --radius: 12px;
  --tap: 48px;
  --bottom-bar-h: calc(12px + var(--tap) + max(12px, env(safe-area-inset-bottom)));
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1812;
    --surface: #14241a;
    --surface2: #1b3024;
    --text: #e8f0ea;
    --muted: #8fa896;
    --accent: #5cb88a;
    --accent-dim: #3d8f6a;
    --danger: #e07070;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  z-index: 0;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(600px, calc(100vw - 24px));
  max-width: 600px;
  aspect-ratio: 1;
  background: url("/soccerball.svg") no-repeat center / contain;
  opacity: 0.2;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  body::before {
    filter: invert(1);
    opacity: 0.32;
  }
}

body > * {
  position: relative;
  z-index: 1;
}

.top {
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
}

.top__brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.top__session {
  margin: 4px 0 0;
  white-space: nowrap;
  text-align: right;
}

.top__about-row {
  margin: 2px 0 0;
  text-align: right;
}

.top__register.btn--icon {
  margin-top: 2px;
  width: var(--tap);
  min-width: var(--tap);
  height: var(--tap);
  min-height: var(--tap);
  padding: 0;
}

.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 10px;
}

.btn--icon svg {
  width: 1.35rem;
  height: 1.35rem;
  display: block;
}

.title {
  margin: 0;
  font-size: clamp(1.5rem, 8vw, 3.0rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #1b3403;
}

@media (prefers-color-scheme: dark) {
  .title {
    color: var(--text);
  }
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.logout-link {
  all: unset;
  margin-left: 10px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  touch-action: manipulation;
}

.logout-link:hover {
  text-decoration-thickness: 2px;
}

.logout-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

main:has(#home-shell:not([hidden])) {
  padding-bottom: var(--bottom-bar-h);
}

.home-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.home-shell[hidden] {
  display: none !important;
}

.auth-view {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-view[hidden] {
  display: none !important;
}

.auth-card {
  width: min(420px, 100%);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  background: var(--surface);
}

.tab-stack {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.tab-bar {
  display: flex;
  margin: 0;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--text) 5%, var(--surface2));
  border-bottom: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
}

.tab-bar__tab {
  flex: 1;
  min-height: var(--tap);
  padding: 0 14px;
  border: none;
  border-radius: 0;
  border-right: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.tab-bar__tab:first-child {
  border-top-left-radius: var(--radius);
}

.tab-bar__tab:last-child {
  border-top-right-radius: var(--radius);
  border-right: none;
}

.tab-bar__tab[aria-selected="false"] {
  background: color-mix(in srgb, var(--text) 4%, var(--surface2));
  color: var(--muted);
}

.tab-bar__tab[aria-selected="false"]:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 7%, var(--surface2));
}

.tab-bar__tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  box-shadow: inset 0 -3px 0 0 var(--accent);
}

.tab-bar__tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

/* [hidden] must win: .tab-panel { display: flex } otherwise overrides the attribute */
.tab-panel[hidden] {
  display: none !important;
}

.tab-panel:not([hidden]) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#match-setup-overlay {
  z-index: 46;
}

.overlay__panel--match-setup {
  width: min(500px, 100vw);
  max-width: 500px;
  max-height: min(92dvh, 720px);
}

.match-flow-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.match-flow {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.match-flow__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
}

.match-flow__pane {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.match-flow-wrap[data-step="slots"] .match-flow__pane--slots,
.match-flow-wrap[data-step="lineup"] .match-flow__pane--lineup,
.match-flow-wrap[data-step="result"] .match-flow__pane--result {
  display: flex;
}

.match-flow__scroll--result {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.match-result-teams {
  width: min(300px, 100%);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.match-flow__pane--result .match-result__headline {
  flex-shrink: 0;
  margin: 0;
  padding: 0 12px 10px;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
  color: var(--text);
}

.match-result-team__label {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.7;
  margin: 0 0 0.35rem;
}

.match-result-team {
  width: 100%;
}

.match-result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 10px;
}

.match-result__row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 12px;
  padding: 0.45rem 0;
}

.match-result__name {
  font-weight: 600;
  grid-column: 1;
  grid-row: 1;
}

.match-result__meta {
  grid-column: 1;
  grid-row: 2;
  font-size: 0.85rem;
  opacity: 0.75;
}

.match-result__elo {
  grid-column: 2;
  grid-row: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  color: var(--text);
  white-space: nowrap;
}

.match-result__elo--up {
  color: var(--ok, #6ee7a8);
}

.match-result__elo--down {
  color: var(--bad, #f87171);
}

.match-result__rank {
  grid-column: 2;
  grid-row: 2;
  font-size: 0.85rem;
  text-align: right;
  opacity: 0.9;
  color: var(--text);
  white-space: nowrap;
}

.match-setup-grid {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 500px;
  margin: 0 auto 16px;
  padding-left: 8px;
}

.team-block {
  display: flex;
  gap: 6px;
  width: 100%;
}

.team-label {
  position: relative;
  flex: 0 0 2.5rem;
  align-self: stretch;
  border-right: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
}

.team-label__inner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  white-space: nowrap;
  font-size: 1.25em;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.team-slots {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.team-elo,
.match-setup__expected {
  flex: 0 0 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.team-elo__inner,
.match-setup__expected-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.team-elo__label,
.match-setup__expected-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  line-height: 1.15;
}

.team-elo__value,
.match-setup__expected-score {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.team-elo__value {
  letter-spacing: -0.02em;
}

.team-slots .slot-btn-wrap--wide {
  grid-column: 1 / -1;
}

.team-slots .slot-btn-wrap {
  min-width: 0;
  display: flex;
  align-items: center;
  min-height: calc(var(--tap) + 8px);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  background: var(--surface);
  color: var(--text);
  transition:
    border-color 0.15s,
    background 0.15s;
}

.team-slots .slot-btn-wrap:has(.slot-btn--empty) {
  border: 2px dashed color-mix(in srgb, var(--muted) 75%, transparent);
  color: var(--muted);
}

.team-slots .slot-btn-wrap:has(.slot-btn--filled) {
  border: 2px solid color-mix(in srgb, var(--text) 22%, transparent);
  color: var(--text);
}

.team-slots .slot-btn-wrap:has(.slot-btn:disabled) {
  opacity: 0.38;
  cursor: not-allowed;
}

.team-slots .slot-btn-wrap:has(.slot-btn--dragging) {
  opacity: 0.55;
}

.team-slots .slot-btn-wrap:has(.slot-btn--drop-target) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.team-slots .slot-btn-wrap > .slot-btn {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  outline: none;
  border-radius: 0;
  font: inherit;
  color: inherit;
  text-align: center;
  cursor: pointer;
  /* `none` lets our touch drag handlers take over instead of the browser
     scrolling/zooming when a drag starts on a filled slot. */
  touch-action: none;
}

.team-slots .slot-btn-wrap > .slot-btn:disabled {
  opacity: 1;
}

.team-slots .slot-btn-wrap .slot-btn[draggable="true"] {
  cursor: grab;
  user-select: none;
}

.team-slots .slot-btn-wrap .slot-btn[draggable="true"]:active {
  cursor: grabbing;
}

.team-slots .slot-btn__clear {
  flex: 0 0 auto;
  align-self: center;
  min-width: 1.75rem;
  min-height: 1.75rem;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  background: transparent;
  color: inherit;
  outline: none;
  box-shadow: none;
}

.team-slots .slot-btn__clear:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.team-slots .slot-btn__clear:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.team-slots .slot-btn__clear[hidden] {
  display: none !important;
}

.match-setup__gap {
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.match-setup__gap-spacer--label {
  flex: 0 0 2.5rem;
  align-self: stretch;
}

.match-setup__field {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  display: block;
}

.match-setup__expected[hidden] {
  display: flex;
  visibility: hidden;
}

.match-setup__expected-score {
  white-space: nowrap;
}

.match-setup__expected-sep {
  margin: 0 1px;
}

.team-slots .slot-btn__text {
  display: block;
  pointer-events: none;
}

.team-slots .slot-btn__placeholder {
  font-weight: 500;
  font-size: 0.92rem;
}

.match-setup__actions {
  flex-shrink: 0;
  margin-top: 0;
  padding-top: 12px;
  padding-bottom: 2px;
}

#slot-picker-overlay {
  z-index: 55;
}

#register-overlay {
  z-index: 52;
}

.overlay__panel--register {
  width: min(420px, 100vw);
}

.overlay__panel--picker {
  max-height: min(70dvh, 560px);
}

.overlay__body--picker {
  max-height: min(55dvh, 420px);
  padding-top: 0;
}

.picker-player-btn {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  margin-bottom: 8px;
  text-align: left;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.picker-player-btn:last-child {
  margin-bottom: 0;
}

.picker-player-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.overlay[hidden] {
  display: none;
}

.overlay__backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, #000 55%, transparent);
}

.overlay__panel {
  position: relative;
  z-index: 1;
  width: min(960px, 100vw);
  max-height: min(95dvh, 100%);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  border-bottom: none;
  box-shadow: 0 -8px 32px color-mix(in srgb, #000 35%, transparent);
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

@media (min-width: 520px) {
  .overlay {
    align-items: center;
    padding: 24px 16px;
  }

  .overlay__panel {
    border-radius: var(--radius);
    border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
    max-height: min(90dvh, 100%);
  }
}

.overlay__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
}

.overlay__header--match-setup {
  display: grid;
  grid-template-columns: minmax(var(--tap), 1fr) auto minmax(var(--tap), 1fr);
  align-items: center;
  gap: 8px;
}

.overlay__header--match-setup .overlay__back {
  grid-column: 1;
  justify-self: start;
}

.overlay__header--match-setup .overlay__title {
  grid-column: 2;
  margin: 0;
  justify-self: center;
  text-align: center;
  max-width: min(100%, 18rem);
  font-size: 1.38rem;
  font-weight: 700;
  line-height: 1.2;
}

.overlay__header--match-setup .overlay__close {
  grid-column: 3;
  justify-self: end;
}

.overlay__title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.overlay__title-group {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.overlay__title-group .overlay__title {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overlay__icon-btn {
  flex: 0 0 auto;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  outline: none;
  box-shadow: none;
}

.overlay__icon-btn[hidden] {
  display: none;
}

.overlay__icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
}

.overlay__title-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 12px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  background: var(--surface2);
  color: var(--text);
}

.overlay__title-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.overlay__close,
.overlay__back {
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 8px;
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  outline: none;
  box-shadow: none;
  cursor: pointer;
  touch-action: manipulation;
}

.overlay__close:hover,
.overlay__back:hover,
.overlay__icon-btn:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

.overlay__close:focus-visible,
.overlay__back:focus-visible,
.overlay__icon-btn:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.overlay__body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay__body.overlay__body--match-setup {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
  overflow: hidden;
}

.elo-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
}

.about-body p,
.about-body h3,
.about-body h4 {
  margin: 0 0 8px;
}

.about-body h3 {
  margin-top: 16px;
  font-size: 1rem;
}

.about-body h4 {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.about-license-details > summary {
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
}

.about-license-details > summary::-webkit-details-marker {
  display: none;
}

.about-license-details > summary::before {
  content: "▸ ";
}

.about-license-details[open] > summary::before {
  content: "▾ ";
}

.about-license {
  margin: 8px 0 0;
  padding: 12px;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface2);
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-x: auto;
  color: var(--muted);
}

.elo-grid dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

.elo-grid dd {
  margin: 0;
  font-weight: 600;
}

.leaderboard-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: min(960px, 100vw);
  max-width: 100%;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.bottom-bar .btn--block {
  display: block;
  width: 100%;
}

.banner {
  margin: 0 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.banner--error {
  background: color-mix(in srgb, var(--danger) 22%, var(--surface));
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
}

.view-title {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.hint {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.actions--stack {
  flex-direction: column;
}

.actions--stack .btn {
  width: 100%;
}

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #fff;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  background: var(--surface);
}

.tab-stack .table-wrap {
  border: none;
  border-radius: 0;
  background: transparent;
}

.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.leaderboard th,
.leaderboard td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  white-space: nowrap;
}

.leaderboard th {
  background: var(--surface2);
  font-weight: 600;
  vertical-align: middle;
}

.leaderboard tbody tr:last-child td {
  border-bottom: none;
}

.leaderboard .leaderboard__player-name {
  all: unset;
  display: block;
  width: 100%;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 50%, transparent);
  text-underline-offset: 3px;
  touch-action: manipulation;
}

.leaderboard .leaderboard__player-name:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.leaderboard .leaderboard__player-name:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.leaderboard tbody tr.leaderboard-row--gold td {
  background: color-mix(in srgb, #d4af37 18%, var(--surface));
}

.leaderboard tbody tr.leaderboard-row--silver td {
  background: color-mix(in srgb, #a8a8a8 16%, var(--surface));
}

.leaderboard tbody tr.leaderboard-row--bronze td {
  background: color-mix(in srgb, #b87333 16%, var(--surface));
}

@media (prefers-color-scheme: dark) {
  .leaderboard tbody tr.leaderboard-row--gold td {
    background: color-mix(in srgb, #d4af37 26%, var(--surface));
  }

  .leaderboard tbody tr.leaderboard-row--silver td {
    background: color-mix(in srgb, #b8b8b8 22%, var(--surface));
  }

  .leaderboard tbody tr.leaderboard-row--bronze td {
    background: color-mix(in srgb, #b87333 24%, var(--surface));
  }
}

.leaderboard.match-history th.match-history__col-team1,
.leaderboard.match-history td.match-history__col-team1 {
  text-align: right;
}

.leaderboard.match-history th.match-history__score,
.leaderboard.match-history td.match-history__score {
  text-align: center;
  width: 1%;
  max-width: 5.5rem;
  padding-left: 8px;
  padding-right: 8px;
}

.match-history__team--winner {
  font-weight: 700;
}

.match-history__empty {
  text-align: center;
  color: color-mix(in srgb, var(--text) 55%, transparent);
  padding: 24px 14px;
}

.leaderboard-mobile-header {
  display: none;
}

@media (max-width: 519px) {
  .leaderboard thead {
    display: none;
  }

  .leaderboard-mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
  }
  .leaderboard-mobile-header__rank {
    width: 2.75rem;
    flex: none;
  }
  .leaderboard-mobile-header__sort {
    flex: 1;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
  }
  .leaderboard-mobile-header__sort select {
    font: inherit;
    padding: 4px 8px;
    border-radius: var(--radius);
    border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
    background: var(--surface);
    color: var(--text);
  }

  .leaderboard tbody tr {
    display: grid;
    grid-template-columns: 2.75rem 1fr 1fr 1fr;
    grid-template-areas:
      "rank name name avg"
      "rank atk  def  solo";
    align-items: baseline;
    column-gap: 12px;
    row-gap: 4px;
    padding: 10px 14px;
    border-bottom: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
  }

  .leaderboard tbody tr td {
    padding: 0;
    border-bottom: none;
    white-space: nowrap;
  }

  .leaderboard tbody td:nth-child(1) {
    grid-area: rank;
    align-self: center;
    font-weight: 700;
  }
  .leaderboard tbody td:nth-child(2) {
    grid-area: name;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .leaderboard tbody td:nth-child(6) {
    grid-area: avg;
    text-align: right;
    font-weight: 700;
  }
  .leaderboard tbody td:nth-child(3),
  .leaderboard tbody td:nth-child(4),
  .leaderboard tbody td:nth-child(5) {
    font-size: 0.85rem;
    color: var(--muted);
    text-align: left;
  }
  .leaderboard tbody td:nth-child(3) { grid-area: atk; }
  .leaderboard tbody td:nth-child(4) { grid-area: def; }
  .leaderboard tbody td:nth-child(5) { grid-area: solo; }

  .leaderboard:not(.match-history) tbody td:nth-child(3)::before { content: "A:"; }
  .leaderboard:not(.match-history) tbody td:nth-child(4)::before { content: "D:"; }
  .leaderboard:not(.match-history) tbody td:nth-child(5)::before { content: "S:"; }
  .leaderboard:not(.match-history) tbody td:nth-child(3)::before,
  .leaderboard:not(.match-history) tbody td:nth-child(4)::before,
  .leaderboard:not(.match-history) tbody td:nth-child(5)::before {
    margin-right: 2px;
  }

  .leaderboard.match-history tbody tr {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas: none;
  }
  .leaderboard.match-history tbody td:nth-child(1) {
    grid-row: 1;
    grid-column: 1 / -1;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 500;
  }
  .leaderboard.match-history tbody td:nth-child(2) {
    grid-row: 2;
    grid-column: 1;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .leaderboard.match-history tbody td:nth-child(3) {
    grid-row: 2;
    grid-column: 2;
    text-align: center;
    font-weight: 700;
  }
  .leaderboard.match-history tbody td:nth-child(4) {
    grid-row: 2;
    grid-column: 3;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .leaderboard tbody td.match-history__empty {
    grid-row: 1;
    grid-column: 1 / -1;
    text-align: center;
  }

  .leaderboard tbody tr:last-child {
    border-bottom: none;
  }

  .leaderboard tbody tr.leaderboard-row--gold td,
  .leaderboard tbody tr.leaderboard-row--silver td,
  .leaderboard tbody tr.leaderboard-row--bronze td {
    background: transparent;
  }
  .leaderboard tbody tr.leaderboard-row--gold {
    background: color-mix(in srgb, #d4af37 18%, var(--surface));
  }
  .leaderboard tbody tr.leaderboard-row--silver {
    background: color-mix(in srgb, #a8a8a8 16%, var(--surface));
  }
  .leaderboard tbody tr.leaderboard-row--bronze {
    background: color-mix(in srgb, #b87333 16%, var(--surface));
  }
}

@media (max-width: 519px) {
  /* On phones the fixed side columns crowd the Attack/Defense/field column,
     cutting off player names. Slim both side columns so the middle gets the
     extra width. Desktop keeps the roomier sizes. */
  .match-setup-grid {
    /* The left padding shifts the grid off the slimmed Team label column. */
    padding-left: 0;
  }

  .team-label,
  .match-setup__gap-spacer--label {
    flex-basis: 1.5rem;
  }

  /* Rotate the Elo / Expected readout vertically so this column can be as
     slim as the Team label column instead of needing room for horizontal text.
     Position the rotated content absolutely (like the Team label) so it doesn't
     bleed outside the slim column and stays centered on the same axis. */
  .team-elo,
  .match-setup__expected {
    flex-basis: 1.5rem;
    position: relative;
  }

  .team-elo__inner,
  .match-setup__expected-inner {
    position: absolute;
    left: 50%;
    top: 50%;
    flex-direction: row;
    gap: 5px;
    white-space: nowrap;
    transform: translate(-50%, -50%) rotate(-90deg);
  }

  .team-elo__label,
  .match-setup__expected-label {
    font-size: 0.7rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
  }

  .team-elo__value,
  .match-setup__expected-score {
    font-size: 1.2rem;
  }

  /* Shorter, tighter name buttons on mobile. */
  .team-slots .slot-btn-wrap {
    min-height: var(--tap);
    padding: 8px 10px;
  }

  /* Keep the playfield from dominating the screen; cap it at 30% of the
     viewport height. `contain` preserves the aspect ratio within the shorter box. */
  .match-setup__field {
    max-height: 30vh;
    object-fit: contain;
  }
}

@media (max-width: 519px) and (prefers-color-scheme: dark) {
  .leaderboard tbody tr.leaderboard-row--gold {
    background: color-mix(in srgb, #d4af37 26%, var(--surface));
  }
  .leaderboard tbody tr.leaderboard-row--silver {
    background: color-mix(in srgb, #b8b8b8 22%, var(--surface));
  }
  .leaderboard tbody tr.leaderboard-row--bronze {
    background: color-mix(in srgb, #b87333 24%, var(--surface));
  }
}

.th-btn {
  all: unset;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 55%, transparent);
  text-underline-offset: 4px;
  touch-action: manipulation;
}

.th-btn[data-active="true"] {
  color: var(--accent);
  text-decoration-color: var(--accent);
  font-weight: 700;
}

.leaderboard td.leaderboard__cell--sorted {
  font-weight: 700;
}

.leaderboard td.leaderboard__cell--sorted .leaderboard__player-name {
  font-weight: 700;
}

.match-card {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

@media (min-width: 520px) {
  .match-card {
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
  }

  .vs {
    text-align: center;
  }
}

.side {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
}

.side-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.side-body {
  font-size: 1.05rem;
  font-weight: 600;
}

.side-body .role {
  font-size: 0.82em;
  font-weight: 500;
  color: var(--muted);
}

.vs {
  font-weight: 800;
  color: var(--muted);
  text-align: center;
  padding: 4px 0;
}

.matchup-expected {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
}

.matchup-expected[hidden] {
  display: none;
}

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

.matchup-expected__score {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.matchup-expected__sep {
  margin: 0 2px;
}

.score-inputs {
  display: grid;
  gap: 16px;
}

@media (min-width: 480px) {
  .score-inputs {
    grid-template-columns: 1fr 1fr;
  }
}

.score-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 600;
}

.matchup-goals {
  margin-top: 20px;
  padding-bottom: 6px;
  width: 100%;
  min-width: 0;
}

.matchup-goals .score-inputs--matchup {
  width: 100%;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 480px) {
  .matchup-goals .score-inputs--matchup {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.score-inputs--matchup {
  gap: 20px;
}

.score-inputs--matchup .score-field {
  gap: 10px;
  min-width: 0;
}

.score-field--matchup {
  align-items: center;
}

.score-field__label {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  word-break: break-word;
}

.score-field--matchup .score-field__label {
  cursor: default;
}

.goal-input-row {
  position: relative;
  width: 75%;
  margin-left: auto;
  margin-right: auto;
}

.goal-input__controls {
  position: absolute;
  top: 4px;
  right: 5px;
  bottom: 4px;
  width: 2.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  z-index: 1;
}

.goal-input__btn {
  flex: 1 1 0;
  min-height: 1.2rem;
  min-width: 0;
  padding: 0 4px;
  margin: 0;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  background: color-mix(in srgb, var(--surface2) 55%, transparent);
  color: var(--text);
  outline: none;
  box-shadow: none;
}

.goal-input__btn--ten {
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.goal-input__btn:hover {
  background: color-mix(in srgb, var(--text) 12%, transparent);
}

.goal-input__btn:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--text) 14%, transparent);
}

.score-inputs--matchup .goal-input {
  --goal-input-h: 4.25rem;
  --goal-input-side: calc(3rem + 18px);
  display: block;
  width: 100%;
  min-width: 0;
  height: var(--goal-input-h);
  min-height: var(--goal-input-h);
  margin: 0;
  padding: 0 var(--goal-input-side);
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  background: var(--surface2);
  color: var(--text);
  font-size: clamp(1.75rem, 8vw, 2.35rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: calc(var(--goal-input-h) - 2px);
}

.score-inputs--matchup .goal-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.text-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.text-field-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.text-field input {
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  background: var(--surface2);
  color: var(--text);
  font-size: 1.05rem;
  width: 100%;
}

.text-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
