:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dde1e8;
  --text: #15181e;
  --muted: #646b78;
  --accent: #5865f2;
  --accent-ink: #ffffff;
  --accent-soft: #e6e8ff;
  --hit: #1f9d55;
  --hit-soft: #ddf5e6;
  --near: #b7791f;
  --near-soft: #fdf1d8;
  --miss: #c53030;
  --miss-soft: #fde4e4;
  --d1: #7c3aed;
  --d2: #0891b2;
  --d3: #65a30d;
  --gold: #b7791f;
  --gold-soft: #fdf1d8;
  --radius: 10px;
  --header-h: 57px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaef;
    --muted: #9099a8;
    --accent: #7983ff;
    --accent-ink: #0f1115;
    --accent-soft: #262b52;
    --hit: #48c97a;
    --hit-soft: #163223;
    --near: #e0a53a;
    --near-soft: #3a2d14;
    --miss: #f06b6b;
    --miss-soft: #3d1a1a;
    --d1: #a78bfa;
    --d2: #22d3ee;
    --d3: #a3e635;
    --gold: #f2c14e;
    --gold-soft: #3a2d14;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, sans-serif;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.pad { padding: 24px 16px; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(135deg, var(--d1), var(--d2) 55%, var(--d3)); }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 8px;
  color: var(--muted); font-weight: 600;
}
.tab[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.account { display: flex; align-items: center; gap: 10px; }
.countdown {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  cursor: default; white-space: nowrap;
}
.countdown[hidden] { display: none; }
.cd-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.clock { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.countdown.soon { background: var(--near-soft); border-color: var(--near); }
.countdown.soon .clock { color: var(--near); }
.countdown.urgent { background: var(--miss-soft); border-color: var(--miss); }
.countdown.urgent .clock { color: var(--miss); }
.countdown.closed { background: var(--surface-2); border-color: var(--border); color: var(--muted); font-weight: 600; font-size: 13px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); flex: none; }
.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 8px 14px;
  border-radius: 8px; font-weight: 600;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-discord { background: #5865f2; color: #fff; border-color: #5865f2; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn-small { padding: 5px 10px; font-size: 13px; }

.banner { padding: 10px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--border); font-weight: 500; }
.banner.warn { background: var(--near-soft); }

/* Hero */
.hero { max-width: 560px; margin: 48px auto; padding: 0 16px; text-align: center; }
.hero h2 { font-size: 28px; letter-spacing: -0.02em; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0 0 24px; }
.format { display: flex; justify-content: center; gap: 8px; margin-bottom: 24px; flex-wrap: wrap; }
.pill { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-weight: 600; font-size: 13px; }

/* Editor */
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.toolbar .grow { flex: 1; }
.progress { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--muted); white-space: nowrap; }
.progress b { color: var(--text); font-weight: 500; }
.meter { display: flex; align-items: center; gap: 10px; }
.bar { width: 140px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .2s; }
.hint { color: var(--muted); font-size: 13px; }

.editor { display: grid; grid-template-columns: 280px 1fr; gap: 0; align-items: start; }
.pool {
  position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h));
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--surface);
}
.pool-head { padding: 12px; border-bottom: 1px solid var(--border); }
.pool-head input {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.pool-count { display: block; margin-top: 8px; font-size: 12px; color: var(--muted); }
.pool-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.chip {
  width: 100%; text-align: left; border: 1px solid var(--border); background: var(--surface);
  padding: 7px 10px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.chip:hover { border-color: var(--accent); }
.chip.selected { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-meta { display: flex; align-items: center; gap: 4px; flex: none; }
.chip small { opacity: .7; font-size: 11px; margin-right: 2px; }
.filters { display: flex; align-items: center; gap: 4px; margin-top: 10px; }
.filters-label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .04em; margin-right: 2px; }
.filter {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.filter.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* S17 badges */
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 11px; font-weight: 700;
  line-height: 16px; white-space: nowrap;
}
.b-d1 { background: color-mix(in srgb, var(--d1) 22%, transparent); color: var(--d1); }
.b-d2 { background: color-mix(in srgb, var(--d2) 22%, transparent); color: var(--d2); }
.b-d3 { background: color-mix(in srgb, var(--d3) 22%, transparent); color: var(--d3); }
.b-champ { background: var(--gold-soft); color: var(--gold); }
.b-new { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.chip.selected .badge { background: rgb(255 255 255 / .2); color: inherit; }

/* Board: one row per team, in predicted draft order */
.board-host { min-width: 0; padding: 16px; }
.board-hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 18px; }
.board { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.team-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--team);
  border-radius: var(--radius); padding: 10px 12px;
  transition: border-color .15s, opacity .15s;
}
.board.editable .team-row { cursor: grab; }
.team-row.dragging { opacity: .4; }
.team-row.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.order-ctl { display: flex; flex-direction: column; gap: 2px; }
.move {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  width: 24px; height: 18px; border-radius: 4px; font-size: 9px; line-height: 1; padding: 0;
}
.move:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.move:disabled { opacity: .3; cursor: default; }
@media (hover: hover) and (pointer: fine) {
  .order-ctl { opacity: 0; transition: opacity .15s; }
  .team-row:hover .order-ctl, .order-ctl:focus-within { opacity: 1; }
}
.pick-no {
  font-family: 'JetBrains Mono', monospace; font-size: 20px; font-weight: 500; color: var(--muted);
  width: 28px; text-align: center; flex: none;
}
.logo {
  width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex: none;
  background: var(--surface-2); box-shadow: 0 0 0 2px var(--team);
}
.logo-fallback { display: grid; place-items: center; font-weight: 700; font-size: 20px; color: var(--team); }
.team-meta { display: flex; flex-direction: column; min-width: 0; width: 190px; flex: none; }
.team-meta strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-meta small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-slots { display: flex; gap: 8px; flex: 1; min-width: 0; }
.slot {
  flex: 1; min-width: 0; min-height: 52px; text-align: left; padding: 6px 10px; border-radius: 8px;
  border: 1px dashed var(--border); background: var(--surface-2); color: var(--muted);
  display: flex; flex-direction: column; justify-content: center; gap: 2px; cursor: pointer;
}
.slot-label { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); }
.slot-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.slot-badges { display: flex; gap: 4px; }
.slot:not(.filled) .slot-name { font-weight: 500; }
.slot.filled { border-style: solid; color: var(--text); background: var(--surface); }
.slot.filled .slot-name { color: var(--text); }
.board.editable .slot:hover { border-color: var(--accent); }
.board.picking .slot:not(.filled) { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.board:not(.editable) .slot { cursor: default; }
.slot.hit { background: var(--hit-soft); border-color: var(--hit); }
.slot.near { background: var(--near-soft); border-color: var(--near); }
.slot.miss { background: var(--miss-soft); border-color: transparent; }
.slot.miss .slot-name { text-decoration: line-through; text-decoration-color: var(--miss); }

/* Leaderboard */
.wrap { max-width: 980px; margin: 0 auto; padding: 20px 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: 'JetBrains Mono', monospace; }
.who { display: flex; align-items: center; gap: 10px; }
.who small { color: var(--muted); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.me td { background: var(--accent-soft); }
.rank-1 td:first-child { color: var(--near); font-weight: 700; }
.detail { margin-top: 16px; }
.detail .board { padding: 16px 0 0; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .l-hit::before { background: var(--hit); }
.legend .l-near::before { background: var(--near); }
.legend .l-miss::before { background: var(--miss); }

.admin-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--miss); color: #fff; }

@media (max-width: 760px) {
  .editor { grid-template-columns: 1fr; }
  .pool { position: static; height: auto; max-height: 42vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .board-host { padding: 12px; }
  .team-row { flex-wrap: wrap; gap: 8px 10px; padding: 10px; }
  .order-ctl { flex-direction: row; order: 9; }
  .logo { width: 36px; height: 36px; }
  .team-meta { width: auto; flex: 1; }
  .row-slots { flex: 1 1 100%; }
  .top { gap: 8px 12px; }
  .account { order: 1; }
  .account > span { display: none; }
  .countdown { order: 2; width: 100%; justify-content: center; }
  .tabs { order: 3; width: 100%; }
  .toolbar { gap: 10px; }
  .toolbar .meter { flex: 1 1 100%; }
  .meter .bar { flex: 1; }
  .toolbar .grow { flex: 1; }
}
