:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #182026;
  --muted: #66727c;
  --line: #dfe5e8;
  --teal: #2f6f73;
  --blue: #315f9f;
  --amber: #a26712;
  --red: #a43f3f;
  --green: #24734c;
  --shadow: 0 8px 28px rgba(24, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.admin-shell {
  width: min(1600px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 240px;
  gap: 12px;
}

.brand-lockup img {
  width: 44px;
  height: 44px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.15;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
}

.brand-lockup p,
.muted {
  color: var(--muted);
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f3;
}

.nav-tab {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #3f4b54;
  cursor: pointer;
}

.nav-tab.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(24, 32, 38, 0.1);
}

.status-panel,
.panel,
.kpi {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.status-panel {
  padding: 18px;
}

.hidden {
  display: none !important;
}

.dashboard {
  display: grid;
  gap: 16px;
}

.dashboard-section {
  display: none;
}

.dashboard-section.active {
  display: grid;
  gap: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 10px;
}

.kpi {
  min-height: 94px;
  padding: 14px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

.kpi small {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  line-height: 1.35;
}

.kpi.is-blue {
  border-top: 3px solid var(--blue);
}

.kpi.is-teal {
  border-top: 3px solid var(--teal);
}

.kpi.is-amber {
  border-top: 3px solid var(--amber);
}

.kpi.is-green {
  border-top: 3px solid var(--green);
}

.kpi.is-red {
  border-top: 3px solid var(--red);
}

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

.players-grid {
  align-items: start;
  grid-template-columns: 1fr;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.accordion-toggle {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  color: #3f4b54;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.accordion-toggle:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.player-accordion.collapsed .panel-header {
  border-bottom: 0;
}

.accordion-body[hidden] {
  display: none;
}

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

.compact-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: #3f4b54;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.compact-toggle input {
  width: 14px;
  height: 14px;
  accent-color: var(--teal);
}

.toolbar input {
  width: min(520px, 100%);
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}

.table-wrap {
  overflow: auto;
  max-height: 640px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.compact-player-table {
  table-layout: fixed;
  min-width: 1040px;
}

.compact-player-table th:nth-child(1) {
  width: 16%;
}

.compact-player-table th:nth-child(2) {
  width: 21%;
}

.compact-player-table th:nth-child(3) {
  width: 15%;
}

.compact-player-table th:nth-child(4) {
  width: 7%;
}

.compact-player-table th:nth-child(5),
.compact-player-table th:nth-child(6) {
  width: 12%;
}

.compact-player-table th:nth-child(7) {
  width: 17%;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf1f3;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafb;
  color: #4f5a63;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: inherit;
  font-weight: inherit;
  text-align: left;
  text-transform: inherit;
}

.sort-button::after {
  width: 10px;
  color: #9aa5ab;
  content: "-";
  font-size: 10px;
}

.sort-button.active {
  color: var(--ink);
}

.sort-button.active[data-direction="asc"]::after {
  color: var(--teal);
  content: "^";
}

.sort-button.active[data-direction="desc"]::after {
  color: var(--teal);
  content: "v";
}

tbody tr {
  cursor: default;
}

tbody tr.selectable {
  cursor: pointer;
}

tbody tr.selectable:hover {
  background: #f7fbfb;
}

tbody tr.selectable.selected {
  background: #eef8f7;
  box-shadow: inset 3px 0 0 var(--teal);
}

.compact-player-row td {
  height: 38px;
  padding: 6px 8px;
  vertical-align: middle;
  white-space: nowrap;
}

.inline-cell,
.relative-time,
.solved-count {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.solved-count {
  color: var(--ink);
  font-size: 13px;
}

.country-cell,
.client-line,
.client-badge,
.location-inline {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.country-cell {
  gap: 6px;
  max-width: 100%;
}

.country-flag {
  width: 22px;
  height: 16px;
  flex: 0 0 auto;
  border: 1px solid #d8e1e5;
  border-radius: 3px;
  object-fit: cover;
}

.country-code {
  overflow: hidden;
  color: #3f4b54;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.client-line {
  width: 100%;
  gap: 6px;
  overflow: hidden;
}

.client-badge {
  gap: 4px;
  max-width: 50%;
  overflow: hidden;
}

.mini-icon {
  display: inline-grid;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  place-items: center;
  border: 1px solid #d6e0e4;
  border-radius: 6px;
  background: #f8fafb;
  color: #42505a;
}

.mini-icon svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mini-icon.chrome {
  border-color: #cfe4d8;
  background: #f0faf4;
  color: #1f6c43;
}

.mini-icon.safari,
.mini-icon.edge {
  border-color: #cbdcf3;
  background: #f1f6fd;
  color: var(--blue);
}

.mini-icon.firefox,
.mini-icon.opera {
  border-color: #f0dec2;
  background: #fff8ed;
  color: var(--amber);
}

.client-label {
  min-width: 0;
  overflow: hidden;
  color: #3f4b54;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity {
  display: grid;
  gap: 3px;
}

.identity strong {
  font-weight: 700;
}

.identity code,
code {
  color: #41505b;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  word-break: break-all;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid #d8e1e5;
  border-radius: 999px;
  background: #f8fafb;
  color: #3f4b54;
  font-size: 12px;
}

.pill.green {
  border-color: #cfe8dc;
  background: #eff9f4;
  color: var(--green);
}

.pill.amber {
  border-color: #f0dec2;
  background: #fff8ed;
  color: var(--amber);
}

.pill.red {
  border-color: #ead0d0;
  background: #fff3f3;
  color: var(--red);
}

.detail-output {
  min-height: 220px;
  max-height: 680px;
  overflow: auto;
  background: #fbfcfd;
}

.detail-empty {
  margin: 0;
  padding: 16px;
  color: var(--muted);
}

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

.player-detail {
  display: grid;
  gap: 14px;
  padding: 14px;
}

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

.detail-avatar {
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: #eef2f3;
}

.detail-avatar.fallback {
  display: grid;
  place-items: center;
  color: var(--teal);
  font-size: 22px;
  font-weight: 800;
}

.detail-title {
  min-width: 0;
}

.detail-title h3 {
  margin: 0;
  overflow: hidden;
  font-size: 20px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-title p {
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-hero-meta {
  display: grid;
  justify-items: end;
  gap: 6px;
  min-width: 220px;
}

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

.detail-stat {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #edf1f3;
  border-radius: 8px;
  background: #fff;
}

.detail-stat span,
.summary-item > span,
.detail-section h3 {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.detail-stat strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-stat small {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 14px;
  padding-top: 2px;
}

.summary-item {
  min-width: 0;
}

.summary-item strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: #27333b;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-item .pill-row {
  flex-wrap: nowrap;
  overflow: hidden;
}

.detail-section {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-table-wrap {
  overflow: auto;
  max-height: 360px;
  border: 1px solid #edf1f3;
  border-radius: 8px;
}

.detail-table {
  min-width: 820px;
  table-layout: fixed;
}

.detail-table th,
.detail-table td {
  padding: 7px 9px;
  vertical-align: middle;
  white-space: nowrap;
}

.detail-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-table code {
  white-space: nowrap;
}

.location-inline {
  gap: 8px;
  width: 100%;
  overflow: hidden;
}

.puzzle-detail-table {
  min-width: 620px;
}

.ua {
  display: block;
  max-width: 320px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

  .admin-nav {
    width: 100%;
    overflow-x: auto;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

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

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

@media (max-width: 680px) {
  .admin-shell {
    width: min(100% - 18px, 1600px);
    padding-top: 8px;
  }

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

  .kpi {
    min-height: 86px;
    padding: 12px;
  }

  .kpi strong {
    font-size: 22px;
  }

  .detail-hero {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .detail-hero-meta {
    grid-column: 1 / -1;
    justify-items: start;
    min-width: 0;
  }

  .detail-stats,
  .detail-summary-grid {
    grid-template-columns: 1fr;
  }
}
