:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --text: #1c1b19;
  --muted: #69655d;
  --border: #e3e0d8;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --accent-soft: #fdeee6;
  --pos: #15803d;
  --neg: #b91c1c;
  --warn-bg: #fff7e0;
  --warn-text: #7a4b00;
  --focus: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1e1d1a;
    --surface-2: #262420;
    --text: #ecebe7;
    --muted: #a39f96;
    --border: #34312c;
    --accent: #f07a3e;
    --accent-text: #1a0d05;
    --accent-soft: #3a2214;
    --pos: #4ade80;
    --neg: #f87171;
    --warn-bg: #3a2f12;
    --warn-text: #f5d58a;
    --focus: #60a5fa;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

a {
  color: inherit;
}

h1 {
  font-size: 1.5rem;
  line-height: 1.25;
  margin: 0 0 0.25rem;
}

h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

p {
  margin: 0 0 0.5rem;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

main.wrap {
  padding-top: 20px;
  padding-bottom: 48px;
}

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

.small {
  font-size: 0.82rem;
}

.mono {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  word-break: break-all;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- header */

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

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.brand-sub {
  font-weight: 500;
  color: var(--muted);
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: url('/favicon.svg') center / cover;
  flex: none;
}

.top-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- buttons, inputs */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

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

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-danger {
  background: var(--neg);
  color: #fff;
}

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

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: transparent;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin: 12px 0 4px;
}

.form-error {
  color: var(--neg);
  font-weight: 600;
}

/* ---------------------------------------------------------------- cards, layout */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section {
  padding: 16px;
  margin-top: 16px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
}

.back {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.back:hover {
  color: var(--text);
}

.search {
  margin-bottom: 12px;
}

.search input {
  max-width: 480px;
}

.empty {
  padding: 32px 16px;
  text-align: center;
}

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  padding: 32px 0;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

.notice {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
}

.notice-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

/* ---------------------------------------------------------------- login */

.login-wrap {
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 24px;
}

.login-card h1 {
  margin: 16px 0 4px;
}

.login-card .btn {
  margin-top: 20px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

/* ---------------------------------------------------------------- tables */

.table-card {
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: var(--surface-2);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

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

.table .actions {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}

.wrap-text {
  overflow-wrap: anywhere;
}

.row-link {
  cursor: pointer;
}

.row-link:hover td {
  background: var(--accent-soft);
}

.cell-player a {
  font-weight: 600;
  text-decoration: none;
}

.cell-player a:hover {
  text-decoration: underline;
}

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.amount.pos {
  color: var(--pos);
}

.amount.neg {
  color: var(--neg);
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.pager-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: middle;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge-flagged,
.badge-pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge-banned,
.badge-rejected {
  background: color-mix(in srgb, var(--neg) 16%, transparent);
  color: var(--neg);
}

.badge-applied {
  background: color-mix(in srgb, var(--pos) 16%, transparent);
  color: var(--pos);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
}

.chip-reject {
  color: var(--neg);
}

/* ---------------------------------------------------------------- detail */

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

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.stat-sub {
  font-size: 0.82rem;
  margin-top: 2px;
}

.adjust {
  display: grid;
  grid-template-columns: auto minmax(160px, 220px) 1fr;
  gap: 12px;
  align-items: end;
}

.adjust .field label {
  margin-top: 0;
}

.adjust .form-error,
.adjust .form-foot {
  grid-column: 1 / -1;
}

#amount-preview {
  display: block;
  min-height: 1.2em;
  margin-top: 2px;
}

.form-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.form-foot p {
  margin: 0;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  background: var(--surface-2);
  align-self: end;
  margin-bottom: 1.2em;
}

.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  min-height: 0;
  pointer-events: none;
}

.segmented label {
  margin: 0;
  padding: 0 14px;
  min-height: 34px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
}

.segmented input:checked + label {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.segmented input:focus-visible + label {
  outline: 2px solid var(--focus);
}

.reports,
.devices {
  list-style: none;
  margin: 0;
  padding: 0;
}

.reports li,
.devices li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.reports li:last-child,
.devices li:last-child {
  border-bottom: 0;
}

.devices li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.report-head {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ---------------------------------------------------------------- dialog, toast */

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(460px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.dialog-body {
  padding: 20px;
}

.dialog-body h2 {
  font-size: 1.1rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.sum {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px 0;
}

.sum-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

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

.sum-row.pos .amount {
  color: var(--pos);
}

.sum-row.neg .amount {
  color: var(--neg);
}

.sum-row.total {
  font-weight: 700;
  background: var(--surface-2);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  z-index: 20;
}

.toast[data-kind='error'] {
  background: var(--neg);
  color: #fff;
}

/* ---------------------------------------------------------------- phone */

@media (max-width: 760px) {
  h1 {
    font-size: 1.3rem;
  }

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

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

  .segmented {
    margin-bottom: 0;
    justify-self: start;
  }

  .form-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .search input {
    max-width: none;
  }

  /* tables become stacked cards: each cell shows its column name */
  .table.responsive thead {
    display: none;
  }

  .table.responsive,
  .table.responsive tbody,
  .table.responsive tr,
  .table.responsive td {
    display: block;
    width: 100%;
  }

  .table.responsive tr {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

  .table.responsive tbody tr:last-child {
    border-bottom: 0;
  }

  .table.responsive td {
    border: 0;
    padding: 3px 12px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    text-align: right;
  }

  .table.responsive td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    text-align: left;
    flex: none;
  }

  .table.responsive td.cell-player {
    display: block;
    text-align: left;
    padding-bottom: 6px;
  }

  .table.responsive td.cell-player::before,
  .table.responsive td.actions::before {
    content: none;
  }

  .table.responsive td.actions {
    justify-content: flex-end;
  }

  .section .table.responsive td {
    padding-left: 0;
    padding-right: 0;
  }
}

@media (max-width: 420px) {
  .stats {
    gap: 8px;
  }

  .stat {
    padding: 10px 12px;
  }

  .stat-value {
    font-size: 1.05rem;
  }

  .brand-sub {
    display: none;
  }
}

/* player counts above the list (app.ts loadStats) */
.stats.summary {
  margin-bottom: 16px;
}

.stats.summary .stat-value {
  font-size: 1.6rem;
}
