:root {
  --bg: #12161b;
  --panel: #1b2128;
  --panel-2: #222a33;
  --line: #2c3742;
  --gold: #E2B25A;
  --steel: #C9D4DC;
  --cream: #EDE3C8;
  --dim: #9AA7B0;
  --accent: #5AA9E2;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--steel);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.dim { color: var(--dim); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--gold); font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
button.ghost, a.ghost {
  background: transparent; color: var(--steel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 13px;
  text-decoration: none; display: inline-block;
}
button.ghost:hover, a.ghost:hover { border-color: var(--gold); color: var(--gold); }

/* ---- layout ---- */
main { max-width: 1200px; margin: 0 auto; padding: 20px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px;
}
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: var(--gold); letter-spacing: .3px; }
@media (max-width: 780px) { .grid { grid-template-columns: 1fr; } }

/* ---- stat tiles ---- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 780px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
}
.tile-val { font-size: 26px; font-weight: 700; color: var(--cream); }
.tile-lbl { font-size: 12px; color: var(--dim); margin-top: 2px; }
.tile-sub { font-size: 11px; color: var(--accent); margin-top: 2px; }

/* ---- charts ---- */
.chart { width: 100%; overflow-x: auto; }
.svgchart { display: block; }
.bar-label { fill: var(--steel); font-size: 12px; }
.bar-value { fill: var(--cream); font-size: 12px; font-weight: 600; }
.legend { fill: var(--steel); font-size: 12px; }
.donut-total { fill: var(--cream); font-size: 22px; font-weight: 700; }
.donut-cap { fill: var(--dim); font-size: 11px; }
.grid { }
line.grid { stroke: var(--line); stroke-width: 1; }
.axis { fill: var(--dim); font-size: 10px; }
.inline-legend { display: flex; gap: 18px; margin-top: 8px; font-size: 12px; color: var(--dim); }
.inline-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.empty { color: var(--dim); font-style: italic; padding: 16px 0; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--dim); font-weight: 600; font-size: 12px; }
tbody tr:hover { background: var(--panel-2); }

.foot { max-width: 1200px; margin: 0 auto; padding: 16px 20px 32px; font-size: 12px; }

/* ---- leaderboard ---- */
.grid.three { grid-template-columns: repeat(3, 1fr); margin-top: 0; }
@media (max-width: 1020px) { .grid.three { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 780px) { .grid.three { grid-template-columns: 1fr; } }
ol.lb { list-style: none; margin: 0; padding: 0; }
ol.lb li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
ol.lb li:last-child { border-bottom: none; }
.lb-rank {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; background: var(--panel-2); color: var(--dim);
}
.lb-rank.r1 { background: var(--gold); color: #201a0c; }
.lb-rank.r2 { background: var(--steel); color: #20262c; }
.lb-rank.r3 { background: #C98A5A; color: #201a0c; }
.lb-name { flex: 1; color: var(--cream); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-val { font-weight: 700; color: var(--gold); white-space: nowrap; }
.lb-note { font-weight: 400; font-size: 11px; }
.lb-champ-label { color: var(--steel); font-weight: 600; }

/* ---- admin page ---- */
main.narrow { max-width: 720px; }
main.narrow .card { margin-bottom: 16px; }
.card p { margin: 0 0 12px; }
.card code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.keyrow { display: flex; gap: 8px; align-items: center; }
.keyrow input {
  flex: 1; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--cream); font-size: 13px; min-width: 0;
}
.cta { color: var(--gold); font-weight: 600; text-decoration: none; }
.cta:hover { text-decoration: underline; }
.cta-btn {
  border: none; border-radius: 8px; cursor: pointer; padding: 9px 16px;
  background: var(--gold); color: #201a0c; font-weight: 700; font-size: 13px;
}
#pwform label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--dim); }
#pwform input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--cream); font-size: 14px;
}
#pwform input:focus { outline: none; border-color: var(--gold); }
.formmsg { margin-left: 12px; font-size: 13px; }
.formmsg.ok { color: #7FD08A; }
.formmsg.err { color: #E27D5A; }

/* ---- login ---- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 32px; width: 320px; display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.login-card h1 { font-size: 18px; color: var(--gold); margin: 6px 0 0; }
.login-card .sub { color: var(--dim); margin: 0 0 8px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--cream); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--gold); }
.login-card button[type=submit] {
  width: 100%; padding: 10px; border: none; border-radius: 8px; cursor: pointer;
  background: var(--gold); color: #201a0c; font-weight: 700; font-size: 14px;
}
.login-card .err { color: #E27D5A; font-size: 13px; margin: 0; }
