:root {
  --bg: #0d0f14; --panel: #151922; --panel-2: #1c212d; --line: #262c3a;
  --text: #e8ebf2; --muted: #8a93a6; --accent: #8b5cf6; --accent-2: #a78bfa;
  --yes: #22c55e; --yes-bg: rgba(34,197,94,.12); --no: #ef4444; --no-bg: rgba(239,68,68,.12);
  --warn: #f59e0b; --radius: 12px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, system-ui, sans-serif; }
a { color: var(--accent-2); }
h2 { font-size: 20px; margin: 0 0 12px; } h3 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mt { margin-top: 28px; }
.error { color: var(--no); min-height: 1em; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: rgba(13,15,20,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; } .logo { color: var(--accent); }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--text); } .tabs button.active { color: var(--text); background: var(--panel-2); }
.account { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.account img { width: 28px; height: 28px; border-radius: 50%; }
.balance { font-family: var(--mono); font-weight: 600; background: var(--panel-2); padding: 4px 10px; border-radius: 999px; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2, .toolbar h3 { margin: 0; }

input, select, textarea { width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label input, label select, label textarea { margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: flex-end; } .row > * { flex: 1; } .row.end { justify-content: flex-end; } .row.end > * { flex: 0 0 auto; white-space: nowrap; }

button { font: inherit; cursor: pointer; border-radius: 8px; }
.primary { background: var(--accent); color: white; border: 0; padding: 9px 16px; font-weight: 600; }
.primary:hover { background: #7c4dee; } .primary:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 8px 14px; }
.ghost:hover { background: var(--panel-2); }
.link { background: none; border: 0; color: var(--accent-2); padding: 0; text-decoration: underline; }
.seg { display: inline-flex; background: var(--panel-2); border-radius: 8px; padding: 3px; gap: 2px; margin-bottom: 10px; }
.seg button { background: none; border: 0; color: var(--muted); padding: 6px 14px; border-radius: 6px; }
.seg button.active { background: var(--panel); color: var(--text); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.oc { flex: 1; min-width: 110px; display: flex; justify-content: space-between; gap: 8px; border: 0; padding: 8px 10px; font-weight: 600; }
.oc .p { font-family: var(--mono); }
.oc.y { background: var(--yes-bg); color: var(--yes); } .oc.n { background: var(--no-bg); color: var(--no); }
.oc:hover { filter: brightness(1.25); } .oc:disabled { opacity: .5; cursor: default; }

.split { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.um { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.um-top { display: flex; justify-content: space-between; gap: 10px; }
.um-q { font-weight: 600; } .um-c { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; height: fit-content; }
.badge.open { color: var(--yes); background: var(--yes-bg); } .badge.locked { color: var(--warn); background: rgba(245,158,11,.12); }
.badge.YES { color: var(--yes); background: var(--yes-bg); } .badge.NO { color: var(--no); background: var(--no-bg); }
.um-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.um-actions input { width: 100px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.bar > span { display: block; height: 100%; background: var(--accent); }

.tm { background: linear-gradient(180deg, rgba(139,92,246,.10), transparent 70%), var(--panel); border: 1px solid #3a3160; border-radius: var(--radius); padding: 16px; margin-bottom: 22px; }
.tm-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.tm-kicker { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2); }
.tm-q { font-weight: 600; font-size: 17px; margin-top: 2px; }
.tm-body { display: flex; align-items: flex-end; gap: 16px; margin: 12px 0; }
.tm-chance { font-family: var(--mono); font-size: 38px; font-weight: 600; line-height: 1; }
.tm-chips { font-size: 13px; color: var(--muted); margin-top: 6px; }
.tm-spark { flex: 1; height: 56px; min-width: 0; }
.tm-spark path.line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.tm-spark path.area { fill: rgba(139,92,246,.15); stroke: none; }
.tm-chips b { color: var(--text); font-family: var(--mono); }
.tm-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tm-controls .seg { margin: 0; }
.tm-sh { display: flex; align-items: center; gap: 8px; margin: 0; }
.tm-sh input { width: 100px; margin: 0; }
.tm-line { display: grid; grid-template-columns: minmax(0,1fr) 110px 70px 150px 150px; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.tm-line:first-of-type { margin-top: 12px; }
.tm-line.done { grid-template-columns: minmax(0,1fr) 110px auto; }
.tm-ll { font-weight: 600; }
.tm-lp { font-family: var(--mono); font-weight: 600; font-size: 17px; text-align: right; }
.tm-line .oc { min-width: 0; }
.tm-mine { font-size: 12px; color: var(--accent-2); }
.tm-foot { font-size: 12px; color: var(--muted); margin-top: 8px; }
.split > * { min-width: 0; }
@media (max-width: 820px) {
  .tm-line { grid-template-columns: 1fr 1fr; }
  .tm-line .spark { display: none; }
  .tm-line.done { grid-template-columns: 1fr auto; }
  .tm-line .oc { min-width: 0; padding: 8px; }
  .tm-body { flex-wrap: wrap; }
  .tm-spark { flex-basis: 100%; }
}
.badge.paused { color: var(--warn); background: rgba(245,158,11,.12); }

.store-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.prize { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.prize .price { font-family: var(--mono); font-weight: 600; color: var(--accent-2); font-size: 18px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; font-family: var(--mono); }
.pos { color: var(--yes); } .neg { color: var(--no); }

.leaderboard { list-style: none; padding: 0; margin: 0; max-width: 560px; counter-reset: lb; }
.leaderboard li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; counter-increment: lb; }
.leaderboard li::before { content: counter(lb); width: 24px; color: var(--muted); font-family: var(--mono); }
.leaderboard img { width: 30px; height: 30px; border-radius: 50%; background: var(--panel-2); }
.leaderboard .name { flex: 1; font-weight: 500; } .leaderboard .bal { font-family: var(--mono); font-weight: 600; }

#lb-season { width: auto; min-width: 200px; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.lb-table { font-size: 14px; }
.lb-table th, .lb-table td { white-space: nowrap; padding: 10px 10px; }
.lb-table th.sortable { cursor: pointer; user-select: none; }
.lb-table th.sortable:hover, .lb-table th.sorted { color: var(--text); }
.lb-table td.rank { font-family: var(--mono); color: var(--muted); width: 32px; }
.lb-table tr.me td { background: rgba(139,92,246,.10); }
.lb-table tr:last-child td { border-bottom: 0; }
.muted-rows td { color: var(--muted); }
.lb-player { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.lb-player img { width: 24px; height: 24px; border-radius: 50%; background: var(--panel-2); }
.parts { display: flex; gap: 6px; margin-top: 5px; }
.parts span { position: relative; font-size: 10px; color: var(--muted); background: var(--panel-2); border-radius: 4px; padding: 1px 5px; overflow: hidden; }
.parts i { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); }
.how { font-size: 14px; color: var(--muted); } .how b { color: var(--text); }
.how li { margin-bottom: 6px; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
#ad-grant input { min-width: 0; }
.admin-row { border-bottom: 1px solid var(--line); padding: 10px 0; }
.admin-row:last-child { border-bottom: 0; }
.admin-row .um-actions { margin-top: 6px; }
.btn-yes { background: var(--yes-bg); color: var(--yes); border: 0; padding: 6px 12px; font-weight: 600; }
.btn-no { background: var(--no-bg); color: var(--no); border: 0; padding: 6px 12px; font-weight: 600; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }

.auth-note { font-size: 13px; background: rgba(139,92,246,.10); border: 1px solid #3a3160; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; color: var(--muted); }
.auth-note b { color: var(--text); }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; margin: 0; }
#auth-seg { display: flex; } #auth-seg button { flex: 1; }
.account .link { color: var(--text); text-decoration: none; }
.account .link:hover { text-decoration: underline; }
code { font-family: var(--mono); background: var(--panel-2); padding: 1px 6px; border-radius: 4px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: 90vw; }
.toast.bad { border-color: var(--no); }
.empty { color: var(--muted); padding: 20px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; } main { padding: 18px 16px 50px; }
  .tabs { order: 3; flex-basis: 100%; }
}

/* Charts */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart.small .line { stroke-width: 1.5; }
.chart .area { fill: rgba(139,92,246,.14); stroke: none; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ylab, .chart .xlab { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.chart .cursor { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
.chart-empty { color: var(--muted); font-size: 12px; padding: 8px 0; }
.chart-tip { position: absolute; top: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 12px; font-family: var(--mono); pointer-events: none; white-space: nowrap; }
.spark { height: 30px; }
.tm-chart, .um-chart { position: relative; grid-column: 1 / -1; padding: 6px 0 12px; }
.um-chart { margin-top: 8px; }
.link-plain { background: none; border: 0; padding: 0; color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.link-plain:hover { color: var(--accent-2); }
.caret { color: var(--muted); font-size: 11px; }

/* Rules page */
.rules { max-width: 760px; line-height: 1.65; }
.rules h2 { font-size: 22px; margin: 0 0 12px; } .rules h3 { font-size: 17px; margin: 22px 0 8px; } .rules h4 { margin: 16px 0 6px; }
.rules p { margin: 0 0 12px; color: #c9cfdb; } .rules ul { margin: 0 0 12px; padding-left: 20px; color: #c9cfdb; } .rules li { margin-bottom: 4px; }
.mono-area { font-family: var(--mono); font-size: 13px; line-height: 1.5; }

/* Admin */
.card.wide { grid-column: 1 / -1; }
.btn-link { text-decoration: none; display: inline-flex; align-items: center; border-radius: 8px; font-size: 14px; }
.log-table { font-size: 13px; }
.log-table td, .log-table th { padding: 7px 8px; }
.log-table td:nth-child(2) { cursor: default; }
.nowrap { white-space: nowrap; } .mono { font-family: var(--mono); }
.tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; text-transform: capitalize; }
.tag.k-trade { color: var(--accent-2); } .tag.k-redemption { color: var(--yes); } .tag.k-payout { color: var(--yes); }
.tag.k-admin, .tag.e-coins_edit, .tag.e-admin { color: var(--warn); background: rgba(245,158,11,.12); }
.tag.e-login_failed, .tag.e-login_blocked, .tag.e-hook_bad_key { color: var(--no); background: var(--no-bg); }
.tag.e-password_reset, .tag.e-rename { color: var(--warn); }
.user-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.user-name { font-size: 18px; font-weight: 700; }
.user-stats { display: flex; gap: 20px; } .user-stats b { display: block; font-family: var(--mono); font-size: 18px; }
.user-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.sub-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.sub-card h4 { margin: 0 0 8px; } .sub-card input { background: var(--panel); }
h4 { font-size: 14px; margin: 0 0 8px; }
.dm-box { margin-top: 10px; } .dm-box textarea { background: var(--panel); font-size: 13px; margin: 4px 0 6px; }
.health-line { padding: 8px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.health-line.good { background: var(--yes-bg); color: var(--yes); } .health-line.bad { background: var(--no-bg); color: var(--no); }
#ad-log-filter select { flex: 0 0 200px; }

/* Peer-to-peer bets */
.bet-odds { display: flex; gap: 24px; flex-wrap: wrap; margin: 4px 0 8px; }
.bet-odds b { display: block; font-family: var(--mono); font-size: 15px; }
.mt-s { margin-top: 8px; }
