:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0A0A0A;
  --surface-hover: #0F0F0F;
  --surface-elevated: #121212;
  --surface-pill: #161616;
  --surface-active: #1C1C1C;
  --border: #1F1F1F;
  --border-strong: #2A2A2A;
  --border-dim: #333333;
  --border-hover: #444444;
  --text: #FFFFFF;
  --text-secondary: #A1A1A1;
  --text-dim: #777777;
  --text-muted: #666666;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-secondary);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.col-actions {
  text-align: right;
  white-space: nowrap;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 1px solid var(--text);
  outline-offset: 2px;
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
}

.login-title {
  margin: 0 0 24px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.login-card input {
  width: 100%;
  margin-bottom: 16px;
}

.login-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px dashed var(--border-hover);
  color: var(--text);
  font-size: 13px;
}

input,
select {
  height: 36px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0 12px;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 13px;
  transition: border-color 150ms ease, background-color 150ms ease;
}

input::placeholder {
  color: var(--text-muted);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--text);
}

select {
  appearance: none;
  padding-right: 32px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23A1A1A1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: transform 150ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-dim {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  min-height: 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.tab {
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: transform 150ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.tab:active {
  transform: scale(0.98);
}

.tab.active {
  background: var(--surface-pill);
  border-color: var(--border-strong);
  color: var(--text);
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
}

.content {
  max-width: 1280px;
  margin: 28px auto;
  padding: 0 24px 64px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.inline-form input {
  flex: 1 1 180px;
  min-width: 160px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  text-align: left;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface);
  white-space: nowrap;
}

td {
  font-size: 13px;
  color: var(--text);
}

tbody tr {
  transition: background-color 120ms ease;
}

.cell-stack {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.player-name {
  font-weight: 500;
  color: var(--text);
}

.telemetry-line {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.empty-cell {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  background: var(--surface-pill);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
}

.badge-solid {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
  font-weight: 600;
}

.badge-emphasis {
  background: var(--surface-elevated);
  border-color: var(--border-hover);
  color: var(--text);
}

.badge-neutral {
  background: var(--surface-pill);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.badge-dim {
  background: transparent;
  border: 1px dashed var(--border-dim);
  color: var(--text-dim);
}

.secret-box {
  margin: 16px 20px 0;
  padding: 14px 16px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--text);
}

.secret-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

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

code {
  display: inline-block;
  background: var(--surface-pill);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.meta-card {
  margin: 20px;
  padding: 16px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  font-size: 13px;
}

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

.metric-box {
  padding: 12px 14px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.metric-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dataset-path {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-secondary);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  max-width: 400px;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-hover);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  transition: opacity 180ms var(--ease-out);
}

.modal-card {
  width: 100%;
  max-width: 680px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 24px;
  transform-origin: center;
  opacity: 1;
  transform: scale(1);
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}

@starting-style {
  .modal-backdrop {
    opacity: 0;
  }

  .modal-card {
    opacity: 0;
    transform: scale(0.97);
  }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.modal-title-wrap {
  min-width: 0;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.modal-subtitle {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.meta-item {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  min-width: 0;
}

.meta-item.span-2 {
  grid-column: span 2;
}

.meta-key {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.meta-val {
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
}

.modal-section {
  margin-top: 20px;
}

.modal-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.vote-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vote-item {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

.vote-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.vote-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.vote-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.empty-inline {
  padding: 16px;
  border-radius: 6px;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.control-block {
  padding: 14px;
  border-radius: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  margin-top: 10px;
}

.control-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.col-actions .action-group {
  justify-content: flex-end;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) {
    background: var(--surface-active);
    border-color: var(--border-hover);
  }

  .btn-primary:hover:not(:disabled) {
    background: #E5E5E5;
    border-color: #E5E5E5;
    color: var(--bg);
  }

  .btn-ghost:hover:not(:disabled) {
    background: var(--surface-elevated);
    border-color: var(--border-strong);
    color: var(--text);
  }

  .btn-dim:hover:not(:disabled) {
    background: var(--surface-elevated);
    border-color: var(--text);
    color: var(--text);
  }

  .tab:hover:not(.active) {
    color: var(--text);
    background: var(--surface-elevated);
  }

  tbody tr:not(.empty-row):hover {
    background: var(--surface-hover);
  }

  input:hover:not(:focus),
  select:hover:not(:focus) {
    border-color: var(--border-hover);
  }
}

@media (max-width: 820px) {
  .topbar-inner {
    grid-template-columns: auto auto;
    padding: 10px 16px;
  }

  .tabs {
    grid-column: 1 / -1;
    order: 3;
    padding-bottom: 4px;
  }

  .content {
    margin: 16px auto;
    padding: 0 16px 48px;
  }

  th,
  td {
    padding: 10px 12px;
  }

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

  .meta-item.span-2 {
    grid-column: span 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .tab,
  .toast,
  .modal-backdrop,
  .modal-card {
    transition: opacity 120ms ease, background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  }

  .btn:active,
  .tab:active {
    transform: none;
  }

  @starting-style {
    .modal-card {
      transform: none;
    }
  }
}
