:root {
  color-scheme: dark light;
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #181c25;
  --surface-3: #1f2430;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .14);
  --text: #f3f4f8;
  --muted: #8b92a5;
  --accent: #818cf8;
  --accent-strong: #6366f1;
  --accent-soft: rgba(129, 140, 248, .14);
  --good: #34d399;
  --good-bg: rgba(52, 211, 153, .13);
  --edge: #fbbf24;
  --edge-bg: rgba(251, 191, 36, .14);
  --bad: #fb7185;
  --bad-bg: rgba(251, 113, 133, .14);
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #f59e6b;
  --shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 12px 40px rgba(0, 0, 0, .35);
  --radius: 18px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", "Cascadia Mono", Consolas, monospace;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #f6f7fb;
    --surface-3: #eceef5;
    --border: rgba(15, 23, 42, .08);
    --border-strong: rgba(15, 23, 42, .15);
    --text: #0f172a;
    --muted: #64708a;
    --accent: #4f46e5;
    --accent-strong: #4f46e5;
    --accent-soft: rgba(79, 70, 229, .09);
    --good: #047857;
    --good-bg: rgba(16, 185, 129, .13);
    --edge: #b45309;
    --edge-bg: rgba(245, 158, 11, .17);
    --bad: #be123c;
    --bad-bg: rgba(244, 63, 94, .11);
    --gold: #d97706;
    --silver: #64748b;
    --bronze: #c2410c;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 30px rgba(15, 23, 42, .06);
  }
}

* { box-sizing: border-box; }

body {
  min-width: 360px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 50% at 15% -10%, rgba(99, 102, 241, .22), transparent 70%),
    radial-gradient(45% 40% at 95% 0%, rgba(52, 211, 153, .09), transparent 70%);
  pointer-events: none;
}

button, input { font: inherit; color: inherit; }
h1, h2, p { margin: 0; }

.shell {
  width: min(100% - 48px, 1480px);
  margin: 0 auto;
  padding: 32px 0 56px;
  display: grid;
  gap: 24px;
}

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(140deg, #818cf8, #6366f1 55%, #4f46e5);
  box-shadow: 0 8px 22px rgba(99, 102, 241, .38);
}
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
h1 { font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.sync-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  white-space: nowrap;
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-bg); }
.sync-busy .sync-dot { background: var(--edge); box-shadow: 0 0 0 3px var(--edge-bg); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
}
.btn-primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(180deg, #7c83f7, #5b5ff0);
  box-shadow: 0 6px 18px rgba(99, 102, 241, .35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(99, 102, 241, .45); }
.btn:active { transform: translateY(0); }
.btn:disabled { cursor: progress; opacity: .6; transform: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.stat-label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 500; }
.stat strong {
  display: block;
  overflow: hidden;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stat strong.accent {
  background: linear-gradient(90deg, var(--accent), var(--good));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stat strong.small { font-size: 16px; font-weight: 600; line-height: 1.9; }

/* Podium */
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.podium[hidden] { display: none; }
.podium-card {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 4px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.podium-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--tone);
}
.podium-card::after {
  content: "";
  position: absolute;
  top: -50px;
  right: -50px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: var(--tone);
  opacity: .1;
  filter: blur(24px);
}
.place-1 { --tone: var(--gold); }
.place-2 { --tone: var(--silver); }
.place-3 { --tone: var(--bronze); }
.podium-rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: 8px;
  border-radius: 9px;
  color: #1a1305;
  background: var(--tone);
  font-size: 13px;
  font-weight: 800;
}
.podium-name { overflow: hidden; font-size: 18px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.podium-points { font-size: 30px; font-weight: 750; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.podium-meta { color: var(--muted); font-size: 12px; }

/* Card + toolbar */
.card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.toolbar-title, .toolbar-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.target-pill {
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 650;
}
.segmented { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button {
  height: 30px;
  padding: 0 13px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: color .15s, background .15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.is-active { color: var(--text); background: var(--surface-3); box-shadow: 0 1px 3px rgba(0, 0, 0, .18); }
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 240px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--muted);
  background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 13px; }
.search input::placeholder { color: var(--muted); }

/* Table */
.table-scroll { overflow: auto; max-height: 72vh; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
table { width: 100%; min-width: 1100px; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
th, td { padding: 0 10px; text-align: center; border-bottom: 1px solid var(--border); }
thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 44px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}
tbody td { height: 54px; font-size: 13px; }
tbody tr { transition: background .12s ease; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.col-rank { width: 64px; }
.col-player { width: 190px; text-align: left; }
.col-day { width: 92px; }
.col-total { width: 150px; }
.col-avg { width: 100px; }
.col-crit { width: 110px; }
.col-status { width: 120px; }

.col-rank, .col-player, .cell-rank, .cell-player { position: sticky; z-index: 2; background: var(--surface); }
.col-rank, .cell-rank { left: 0; }
.col-player, .cell-player { left: 64px; box-shadow: 1px 0 0 var(--border); }
thead .col-rank, thead .col-player { z-index: 4; background: var(--surface-2); }
tbody tr:hover .cell-rank, tbody tr:hover .cell-player { background: var(--surface-2); }

.cell-player { text-align: left; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }
.rank-badge {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 26px;
  padding: 0 6px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 700;
}
.rank-1 { color: #1a1305; background: var(--gold); }
.rank-2 { color: #0f172a; background: var(--silver); }
.rank-3 { color: #1c0d05; background: var(--bronze); }

.chip {
  display: inline-block;
  min-width: 62px;
  padding: 5px 8px;
  border-radius: 9px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}
.chip-good { color: var(--good); background: var(--good-bg); }
.chip-edge { color: var(--edge); background: var(--edge-bg); }
.chip-bad { color: var(--bad); background: var(--bad-bg); }
.chip-empty { color: var(--muted); opacity: .6; }

.total { display: grid; gap: 6px; justify-items: center; }
.total-value { font-family: var(--mono); font-size: 13px; font-weight: 700; }
.total-bar { width: 100%; max-width: 110px; height: 4px; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
.total-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent-strong), var(--good)); }
.cell-avg { color: var(--muted); font-family: var(--mono); font-size: 12px; }

.count { font-family: var(--mono); font-size: 12px; font-weight: 700; }
.count-clear { color: var(--good); }
.count-some { color: var(--edge); }
.count-high { color: var(--bad); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-ok { color: var(--good); background: var(--good-bg); }
.status-warning { color: var(--edge); background: var(--edge-bg); }
.status-remove { color: var(--bad); background: var(--bad-bg); }
.row-remove .cell-player { color: var(--bad); }

.loading-cell { height: 120px; color: var(--muted); }
.empty-state { padding: 40px 12px; color: var(--muted); text-align: center; font-size: 13px; }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.legend { display: flex; gap: 16px; margin: 0; padding: 0; list-style: none; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-good { background: var(--good); }
.dot-edge { background: var(--edge); }
.dot-bad { background: var(--bad); }

/* Toast */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  padding: 13px 18px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--good);
  border-radius: 12px;
  background: var(--surface-3);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-error { border-left-color: var(--bad); }

/* Responsive */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .podium { grid-template-columns: 1fr; }
  .podium-card { grid-template-columns: auto 1fr auto; align-items: center; column-gap: 14px; }
  .podium-rank { margin: 0; grid-row: span 2; }
  .podium-points { grid-column: 3; grid-row: 1 / span 2; font-size: 22px; }
  .podium-meta { grid-column: 2; }
}

@media (max-width: 640px) {
  .shell { width: min(100% - 28px, 640px); padding-top: 20px; gap: 18px; }
  .topbar { flex-wrap: wrap; }
  .sync-state { display: none; }
  .stat { padding: 14px 16px; }
  .stat strong { font-size: 19px; }
  .toolbar-controls, .search { width: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 0 6px; }
  .col-player, .cell-player { max-width: 130px; width: 130px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
