:root {
  --surface: rgba(2, 10, 13, 0.92);
  --ink: #dbfbff;
  --muted: #78acb2;
  --accent: #28e6db;
  --accent-soft: rgba(40, 230, 219, 0.16);
  --line: rgba(40, 230, 219, 0.28);
  --page-bg:
    linear-gradient(rgba(40, 230, 219, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(40, 230, 219, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 50% 0%, rgba(40, 230, 219, 0.14), transparent 36%),
    linear-gradient(180deg, #03080a 0%, #010304 100%);
  --panel-border: rgba(40, 230, 219, 0.22);
  --table-head: rgba(40, 230, 219, 0.08);
  --table-alt: rgba(40, 230, 219, 0.045);
  --cell-line: rgba(40, 230, 219, 0.16);
  --hover-row: rgba(40, 230, 219, 0.12);
  --link: #8efcf7;
  --detail-bg: rgba(40, 230, 219, 0.055);
  --inline-detail-bg: rgba(40, 230, 219, 0.07);
  --modal-overlay: rgba(0, 5, 8, 0.78);
  --shadow: 0 18px 54px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-bg);
  background-size: 44px 44px, 44px 44px, auto, auto;
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(50px);
  opacity: 0.3;
  pointer-events: none;
}

.bg-orb-a {
  width: 260px;
  height: 260px;
  background: #ff8f5a;
  top: -60px;
  right: -40px;
}

.bg-orb-b {
  width: 230px;
  height: 230px;
  background: #1b8f9f;
  bottom: -40px;
  left: -20px;
}

.bg-orb {
  display: none;
}

.shell {
  width: min(1100px, 92vw);
  margin: 48px auto;
  position: relative;
  animation: fade-up 480ms ease-out;
}

.header h1 {
  margin: 0;
  font: 700 clamp(1.8rem, 3.8vw, 3rem) / 1.1 "Sora", sans-serif;
  letter-spacing: -0.02em;
}

.kicker {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.78rem;
}

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

.controls {
  margin-top: 26px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.tab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 160ms ease;
}

.tab.active {
  background: var(--accent);
  color: color-mix(in srgb, var(--ink) 18%, #000);
  border-color: var(--accent);
}

.filters {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.filters label {
  display: grid;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.filters select,
.filters input,
.reset {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
  font: 500 0.9rem/1.2 "Space Grotesk", sans-serif;
}

.filters .toggle-filter {
  min-height: 38px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.filters .toggle-filter input {
  width: auto;
}

.reset {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.panel {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
}

#metrics-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  table-layout: fixed;
}

#metrics-table[data-view="players"] {
  table-layout: auto;
}

#metrics-table thead th {
  text-align: left;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--line);
  background: var(--table-head);
}

#metrics-table thead th button {
  all: unset;
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  color: inherit;
}

#metrics-table tbody tr {
  animation: fade-up 300ms ease both;
}

#metrics-table tbody tr:nth-child(even) {
  background: var(--table-alt);
}

#metrics-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--cell-line);
}

#metrics-table > tbody > tr:not(.detail-row) > td {
  height: 82px;
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

#metrics-table .col-__rank {
  width: 56px;
}

#metrics-table > tbody > tr:not(.detail-row) > td.rank-col {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
}

#metrics-table .col-player_name {
  width: 22%;
}

#metrics-table > tbody > tr:not(.detail-row) > td.col-player_name {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

#metrics-table[data-view="players"] > tbody > tr:not(.detail-row) > td {
  height: auto;
  min-height: 52px;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

#metrics-table[data-view="players"] .col-player_name {
  min-width: 190px;
  white-space: nowrap;
}

#metrics-table[data-view="players"] .col-player_name .link-button {
  white-space: nowrap;
}

#metrics-table[data-view="players"] > tbody > tr:not(.detail-row) > td.num,
#metrics-table[data-view="players"] > tbody > tr:not(.detail-row) > td.rank-col {
  white-space: nowrap;
}

#metrics-table[data-view="players"] .status {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

#metrics-table .col-team_name {
  width: 30%;
}

#metrics-table .col-primary_team_name,
#metrics-table .col-faction_id,
#metrics-table .col-primary_faction_id {
  width: 18%;
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rank-col {
  width: 1%;
  min-width: 44px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #0c5550;
  font-weight: 600;
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.team-badge {
  --team-icon-bg: currentColor;
  --team-icon-fg: var(--surface);
  display: inline-flex;
  gap: 7px;
  align-items: stretch;
  justify-content: flex-start;
  min-width: 116px;
  min-height: 42px;
  padding: 0 9px 0 0;
  cursor: pointer;
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
  border-radius: 999px;
  line-height: 1.1;
  overflow: hidden;
  white-space: normal;
}

.team-badge-compact {
  display: inline-flex;
  flex-direction: row;
  gap: 7px;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
  min-height: 28px;
  padding: 0 10px 0 0;
  border-radius: 999px;
  line-height: 1.2;
  white-space: normal;
}

.team-badge-wide {
  min-width: 136px;
  width: min(100%, 220px);
  min-height: 34px;
  align-items: center;
  padding-right: 11px;
}

.faction-badge {
  min-height: 24px;
}

.team-badge-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  width: 42px;
  min-height: 42px;
  border-radius: 999px;
  background: var(--team-icon-bg);
  color: var(--team-icon-fg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--team-icon-bg) 38%, transparent);
  flex: 0 0 42px;
}

.badge-icon {
  font-weight: 800;
  line-height: 1;
  font-size: 0.74rem;
  letter-spacing: 0.03em;
}

.team-badge .badge-icon-image {
  width: 29px;
  height: 29px;
  object-fit: contain;
  flex: 0 0 auto;
}

.team-badge-mark-compact {
  width: 28px;
  min-height: 28px;
  flex-basis: 28px;
}

.team-badge-compact .badge-icon {
  font-size: 0.64rem;
}

.team-badge-compact .badge-icon-image {
  width: 20px;
  height: 20px;
}

.faction-badge .badge-icon-image {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: 0 0 auto;
}

.team-badge-label {
  display: -webkit-box;
  align-self: center;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  line-height: 1.1;
  max-height: 2.2em;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.team-badge .team-badge-label-compact {
  display: block;
  max-height: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  -webkit-line-clamp: unset;
}

.link-button {
  all: unset;
  color: var(--link);
  font-weight: 700;
  cursor: pointer;
}

.link-button:hover,
.team-badge:hover {
  text-decoration: underline;
}

.faction-badge {
  border: 1px solid color-mix(in srgb, currentColor 24%, transparent);
  letter-spacing: 0.01em;
}

.faction-adepta-sororitas { background: #f6d6dc; color: #7b1025; }
.faction-adeptus-custodes { background: #f7e6a7; color: #6f4c00; }
.faction-adeptus-mechanicus { background: #f3c5bf; color: #8e1f18; }
.faction-aeldari { background: #f2d8ad; color: #7a3f00; }
.faction-astra-militarum { background: #d9e8c7; color: #31551d; }
.faction-black-templars { background: #d7dce2; color: #1e2630; }
.faction-blood-angels { background: #f3c7c3; color: #8f1712; }
.faction-chaos-daemons { background: #e8c7d9; color: #75224d; }
.faction-chaos-knights { background: #decce8; color: #4e2667; }
.faction-chaos-space-marines { background: #d9cedf; color: #4b245f; }
.faction-dark-angels { background: #c8dfcf; color: #164628; }
.faction-death-guard { background: #d8ddbb; color: #53600f; }
.faction-deathwatch { background: #d6dbe2; color: #202936; }
.faction-drukhari { background: #d8c4e6; color: #55206f; }
.faction-emperor-s-children { background: #f1c4df; color: #792553; }
.faction-genestealer-cult { background: #ddd1e7; color: #4a2c66; }
.faction-grey-knights { background: #d8e4ea; color: #315c70; }
.faction-imperial-agents { background: #ead8bc; color: #634115; }
.faction-imperial-knights { background: #e6d8b8; color: #624717; }
.faction-leagues-of-votann { background: #c9e3df; color: #165b55; }
.faction-necrons { background: #cce8c6; color: #15611f; }
.faction-orks { background: #cfe6bd; color: #34620d; }
.faction-space-marines-astartes { background: #c7d9f2; color: #153f7d; }
.faction-space-wolves { background: #d6e4ee; color: #31546b; }
.faction-t-au-empire { background: #f0dfc4; color: #735120; }
.faction-thousand-sons { background: #c6e6ee; color: #086372; }
.faction-tyranids { background: #ead0e0; color: #6e2a55; }
.faction-world-eaters { background: #f1c4bc; color: #871e11; }
.faction-unknown-faction,
.faction-imperium,
.faction-xenos { background: #e2e7ec; color: #4a5561; }

.team-row {
  cursor: pointer;
}

.team-row:hover,
.click-row:hover {
  background: var(--hover-row);
}

.team-detail {
  margin-top: 14px;
  padding: 18px;
}

.team-detail.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.team-detail h2 {
  margin: 0;
  font: 700 1.3rem/1.2 "Sora", sans-serif;
}

.team-detail h3 {
  margin: 12px 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.team-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.team-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.team-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--cell-line);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--detail-bg);
}

.team-list li small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  margin-right: 8px;
  font-size: 0.72rem;
  font-weight: 600;
}

.pill-on {
  background: #d9f2ef;
  color: #0c5550;
}

.pill-off {
  background: #f1e7df;
  color: #7b4b2f;
}

.detail-row td {
  background: var(--inline-detail-bg);
}

.inline-detail {
  padding: 10px 2px;
}

.inline-detail h4 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.nested-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.nested-table th,
.nested-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--cell-line);
  text-align: left;
}

.nested-table th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--modal-overlay);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(1180px, 94vw);
  max-height: 86vh;
  overflow: auto;
  padding: 22px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 26px 80px rgba(10, 20, 35, 0.32);
  border: 1px solid var(--panel-border);
}

.modal-card h2,
.modal-card h3 {
  margin: 0;
  font-family: "Sora", sans-serif;
}

.modal-card h3 {
  margin-top: 18px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.modal-close {
  float: right;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  font-weight: 700;
  cursor: pointer;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.modal-grid > div {
  padding: 12px;
  border-radius: 14px;
  background: var(--detail-bg);
  border: 1px solid var(--cell-line);
}

.modal-grid p {
  margin: 6px 0 0;
  color: var(--muted);
}

.modal-table-wrap {
  overflow: auto;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .shell {
    margin: 28px auto;
  }

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

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

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