:root {
  color-scheme: dark;
  --bg: #111312;
  --surface: #1a1d1a;
  --surface-2: #20251f;
  --line: #343b32;
  --text: #f0eee7;
  --muted: #aaa89d;
  --gold: #d8aa4c;
  --green: #75c58a;
  --red: #d86f5f;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar,
.controls,
.metrics,
.layout,
.panel-head,
.player-row,
.squad-head,
.commander {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(34px, 5vw, 64px);
  line-height: 0.95;
}

h2 {
  font-size: 22px;
}

.status-strip {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
}

.status-dot.ok {
  color: var(--green);
  border-color: rgba(117, 197, 138, 0.45);
}

.status-dot.fail {
  color: var(--red);
  border-color: rgba(216, 111, 95, 0.45);
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metrics article,
.gamestate-panel,
.panel,
.controls {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
}

.metrics span,
label,
.muted,
.sub {
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  line-height: 1;
}

.controls {
  grid-template-columns: auto 180px minmax(220px, 1fr) auto;
  align-items: end;
  padding: 14px;
  margin-bottom: 18px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button,
.primary,
select,
input {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.segmented button {
  border: 0;
  border-right: 1px solid var(--line);
  padding: 0 14px;
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active,
.primary {
  background: var(--gold);
  color: #17140d;
  font-weight: 800;
}

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

select,
input,
.primary {
  border-radius: 8px;
  padding: 0 12px;
}

.primary {
  cursor: pointer;
}

.gamestate-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  margin-bottom: 18px;
}

.gamestate-main,
.gamestate-teams,
.gamestate-meta {
  display: grid;
  gap: 14px;
}

.gamestate-main {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.gamestate-main h2 {
  font-size: clamp(24px, 3vw, 38px);
}

.gamestate-time {
  display: grid;
  justify-items: end;
}

.gamestate-time strong {
  color: var(--gold);
  font-size: 34px;
  line-height: 1;
}

.gamestate-time span,
.team-state span,
.team-state small,
.gamestate-meta span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.sector-track {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.sector {
  min-height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.sector.allies {
  background: #5b8def;
}

.sector.axis {
  background: #d86f5f;
}

.gamestate-teams {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
}

.team-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.team-state.leading {
  border-color: rgba(216, 170, 76, 0.55);
  background: rgba(216, 170, 76, 0.1);
}

.team-state strong {
  display: block;
  margin: 4px 0;
  font-size: 22px;
}

.gamestate-leader {
  min-width: 180px;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(216, 170, 76, 0.14);
  color: var(--gold);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.gamestate-meta {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gamestate-meta span {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--surface-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout {
  grid-template-columns: minmax(0, 1.35fr) minmax(380px, 0.65fr);
  align-items: start;
}

.history-mode .layout {
  grid-template-columns: minmax(0, 1fr);
}

.history-mode .teams {
  display: none;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.history-pager {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.history-pager button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.history-pager button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.history-pager span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.players-list,
.teams-view,
.history-list {
  display: grid;
}

.match-summary {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.match-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.match-score {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.match-score strong {
  color: var(--gold);
  font-size: 34px;
  line-height: 1;
}

.match-score span {
  color: var(--muted);
  font-size: 12px;
}

.match-grid,
.match-leaders {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

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

.match-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.match-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
}

.match-card span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.muted-card {
  opacity: 0.72;
}

.player-row {
  grid-template-columns: 40px minmax(180px, 1fr) repeat(6, minmax(72px, 0.12fr)) 76px;
  align-items: center;
  padding: 13px 18px;
  border-bottom: 1px solid rgba(52, 59, 50, 0.7);
}

.player-row:last-child {
  border-bottom: 0;
}

.rank {
  color: var(--gold);
  font-weight: 900;
}

.player-main {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--surface-2);
  object-fit: cover;
  flex: 0 0 auto;
}

.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--gold);
  font-weight: 900;
}

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat {
  text-align: right;
}

.stat b {
  display: block;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.profile-cell {
  display: flex;
  justify-content: flex-end;
}

.profile-button {
  min-height: 32px;
  border: 1px solid rgba(216, 170, 76, 0.4);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(216, 170, 76, 0.12);
  color: var(--gold);
  cursor: pointer;
  font-weight: 800;
}

.profile-button:hover {
  background: rgba(216, 170, 76, 0.2);
}

.profile-panel {
  padding: 18px;
  border-bottom: 1px solid rgba(52, 59, 50, 0.7);
  background: rgba(255, 255, 255, 0.025);
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.profile-avatar {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
  flex: 0 0 auto;
}

.profile-title {
  margin-bottom: 6px;
  font-size: 20px;
  font-weight: 900;
}

.profile-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.profile-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(216, 170, 76, 0.12);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.profile-current-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.profile-metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.profile-metric strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-metric span,
.profile-names span {
  color: var(--muted);
  font-size: 12px;
}

.profile-note {
  margin-top: 10px;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
}

.profile-note.good {
  background: rgba(117, 197, 138, 0.1);
  color: var(--green);
}

.profile-note.warn {
  background: rgba(216, 170, 76, 0.12);
  color: var(--gold);
}

.profile-names {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  border-top: 1px solid rgba(52, 59, 50, 0.7);
  padding-top: 12px;
}

.profile-names strong {
  font-size: 13px;
}

.side {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.side:last-child {
  border-bottom: 0;
}

.side-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.side-title strong {
  font-size: 20px;
}

.commander {
  grid-template-columns: 1fr auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.squad {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 10px;
  overflow: hidden;
}

.squad-head {
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.025);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(216, 170, 76, 0.14);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.team-player {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 9px 12px;
  border-top: 1px solid rgba(52, 59, 50, 0.7);
}

.hidden {
  display: none;
}

.map-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  border: 0;
  border-bottom: 1px solid rgba(52, 59, 50, 0.7);
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.map-row:hover,
.map-row.selected {
  background: rgba(216, 170, 76, 0.08);
}

.map-score {
  display: grid;
  justify-items: end;
  align-content: center;
}

.map-score strong {
  font-size: 22px;
}

.map-score span {
  color: var(--muted);
  font-size: 12px;
}

.empty,
.error {
  padding: 24px 18px;
  color: var(--muted);
}

.error {
  color: var(--red);
}

@media (max-width: 980px) {
  .topbar,
  .controls,
  .layout,
  .metrics,
  .gamestate-main,
  .gamestate-teams,
  .gamestate-meta {
    grid-template-columns: 1fr;
  }

  .gamestate-time {
    justify-items: start;
  }

  .player-row {
    grid-template-columns: 36px minmax(0, 1fr) repeat(2, 72px) 70px;
  }

  .player-row .optional {
    display: none;
  }

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

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

  .match-hero,
  .match-grid,
  .match-leaders {
    grid-template-columns: 1fr;
  }

  .match-score {
    justify-items: start;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100vw - 20px, 1480px);
    padding: 18px 0;
  }

  .player-row {
    grid-template-columns: 32px minmax(0, 1fr) 64px 66px;
  }

  .player-row .mobile-hide {
    display: none;
  }
}
