:root {
  --bg: #0a0a0d;
  --panel: #131217;
  --panel-2: #1c1a21;
  --line: #2c2a33;
  --text: #f4f1ec;
  --muted: #a49c92;
  --accent: #ff7a1a;
  --accent-2: #ff9a4a;
  --accent-ink: #1a0b00;
  --up: #4ade80;
  --down: #f87171;
  --a: #ff7a1a;
  --b: #4dd2ff;
  --danger: #ff5a4d;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 'Space Grotesk', system-ui, sans-serif; }
a { color: var(--accent-2); }
h1 { font-size: 34px; line-height: 1.1; margin: 0 0 10px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 10px; }
.lede { color: var(--muted); font-size: 17px; margin: 0 0 20px; max-width: 760px; }
.hint { color: var(--muted); font-size: 13px; }
.center { text-align: center; }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 24px; background: rgba(10,10,13,.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
nav button { background: none; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 999px; font: inherit; cursor: pointer; white-space: nowrap; }
nav button.on { background: var(--panel-2); color: var(--text); }

main { max-width: 1120px; margin: 0 auto; padding: 28px 24px 80px; }
.view.narrow { max-width: 720px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin: 0 0 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }

input, button, select { font: inherit; }
input[type=search], input:not([type]), select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 12px; min-width: 0;
}
input:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { cursor: pointer; border-radius: 10px; padding: 10px 16px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
button:disabled { opacity: .4; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.ghost:hover:not(:disabled) { border-color: var(--muted); }
.big { padding: 14px 22px; font-size: 17px; }
.small { padding: 4px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--muted); padding: 4px; font-size: 13px; text-decoration: underline; }
.danger { border-color: #4a2320; }
.danger-btn { background: transparent; color: var(--danger); border-color: var(--danger); }
kbd { font: 11px/1 ui-monospace, monospace; padding: 2px 5px; border: 1px solid currentColor; border-radius: 4px; opacity: .6; margin-left: 4px; }
details > summary { cursor: pointer; color: var(--muted); }
details.card > summary, details.about > summary { list-style: none; color: var(--text); }
details.about > summary h2 { display: inline; }
details.about > summary::after { content: ' ▾'; color: var(--muted); }

.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30;
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
#toast.err { border-color: var(--danger); }

/* Setup */
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.preset { text-align: left; padding: 12px 14px; }
.preset b { display: block; }
.preset span { color: var(--muted); font-size: 13px; }
.preset.on { border-color: var(--accent); background: rgba(255,122,26,.08); }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px 24px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field select, .field input:not([type]) { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; border-radius: 0; background: var(--panel-2); padding: 8px 12px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.checks { display: flex; flex-direction: column; gap: 6px; margin-top: 18px; }
.checks label, .toggle { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.checks input, .toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.teams { margin-top: 14px; }
.team-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.team-chips button { padding: 4px 10px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.team-chips button img { width: 18px; height: 18px; }
.team-chips button.on { border-color: var(--accent); background: rgba(255,122,26,.12); }
.pool-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.pool-head h2 { font-size: 24px; margin: 0; }
#pool-count { color: var(--accent-2); }
#pool-search { flex: 1 1 260px; }
.about p, .about li { color: var(--muted); }
.about b { color: var(--text); }

/* Player lists */
.plist { list-style: none; padding: 0; margin: 8px 0 0; }
.plist li {
  display: grid; grid-template-columns: auto 52px 1fr auto; gap: 12px; align-items: center;
  padding: 8px 6px; border-bottom: 1px solid var(--line);
}
.plist.compact li { grid-template-columns: 44px 1fr auto; padding: 6px 4px; }
.plist.ranked li, .plist.diff li { grid-template-columns: 3.2ch 52px 1fr auto; }
.plist.compact.diff li { grid-template-columns: 3.2ch 44px 1fr auto; }
.plist .pos { font-weight: 700; font-size: 18px; text-align: right; font-variant-numeric: tabular-nums; }
.plist.ranked li:nth-child(-n+3) .pos { color: var(--accent-2); }
.hs { width: 52px; height: 38px; object-fit: cover; object-position: top; border-radius: 8px; background: var(--panel-2); }
.compact .hs { width: 44px; height: 32px; }
.t-main { min-width: 0; }
.t-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-right { text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.t-right b { color: var(--text); font-size: 15px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; vertical-align: 1px; font-weight: 500; }
.badge.out { border-color: #6b2a24; color: #f39a8f; }
.badge.dtd { border-color: #6b5a1d; color: #e5c454; }
.delta { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.same { color: var(--muted); }
.plist li.clickable { cursor: pointer; }
.plist li.clickable:hover { background: rgba(255,255,255,.03); }
.in-pool { color: var(--up); }

/* Matchup */
.progress { margin-bottom: 14px; }
.progress-label { display: flex; gap: 14px; align-items: baseline; margin-bottom: 8px; flex-wrap: wrap; }
.progress-label span { color: var(--muted); font-size: 14px; }
.question { text-align: center; color: var(--muted); margin: 6px 0 14px; }
.matchup { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: stretch; }
.vs { align-self: center; font-weight: 700; font-size: 28px; color: var(--muted); }
.side {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  display: flex; flex-direction: column; min-width: 0; transition: transform .15s, border-color .15s;
}
.side[data-side=a] { border-top: 3px solid var(--a); }
.side[data-side=b] { border-top: 3px solid var(--b); }
.side.chosen { transform: scale(1.02); border-color: var(--accent); }
.photo { position: relative; aspect-ratio: 1.37; background: radial-gradient(circle at 50% 70%, var(--tc, #333) 0%, transparent 70%), var(--panel-2); }
.photo img.face { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top; }
.photo img.logo { position: absolute; right: 10px; top: 10px; width: 44px; height: 44px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.6)); }
.side-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.side h2 { font-size: 24px; margin: 0; line-height: 1.15; }
.side .sub { color: var(--muted); margin: 0; }
.statline { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.statline th { color: var(--muted); font-weight: 500; font-size: 12px; text-align: right; padding: 2px 4px; }
.statline td { text-align: right; padding: 3px 4px; border-top: 1px solid var(--line); }
.statline th:first-child, .statline td:first-child { text-align: left; }
.statline td:first-child { color: var(--muted); font-size: 12px; white-space: nowrap; }
.side .pick { margin-top: auto; width: 100%; }
.controls { display: flex; gap: 10px; justify-content: center; align-items: center; margin: 18px 0 8px; flex-wrap: wrap; }
.hide-stats .statline { display: none; }

/* Compare */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 10px 0 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .num { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .lbl { color: var(--muted); font-size: 13px; }
.cmp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
#scatter svg { width: 100%; height: auto; display: block; touch-action: manipulation; }
#scatter .dot { cursor: pointer; }
.side-by-side { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.side-by-side h3 { font-size: 14px; color: var(--muted); margin: 0 0 6px; font-weight: 500; }
.sbs-row { display: grid; grid-template-columns: 3ch 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sbs-row .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.sbs-row.match .name { color: var(--up); }

/* Share */
.img-wrap { margin: 14px 0; background: var(--panel-2); border-radius: 12px; min-height: 200px; display: grid; place-items: center; overflow: hidden; }
.img-wrap img { width: 100%; height: auto; display: block; }

/* Player dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg-body { padding: 16px 20px 20px; }
.dlg-body .row { justify-content: flex-end; margin-top: 14px; }
.robot-parts { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
.robot-parts td { padding: 4px 0; border-top: 1px solid var(--line); }
.robot-parts td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  main { padding: 18px 16px 60px; }
  .top { padding: 8px 10px; }
  body.started .brand { display: none; }
  body.started nav { width: 100%; justify-content: space-between; }
  nav button { padding: 8px 9px; font-size: 14px; }
  h1 { font-size: 27px; }
  .presets { grid-template-columns: 1fr 1fr; }
  .matchup { grid-template-columns: 1fr 1fr; gap: 8px; }
  .vs { display: none; }
  .side h2 { font-size: 16px; }
  .side .sub { font-size: 12px; }
  .side-body { padding: 10px; gap: 8px; }
  .photo img.logo { width: 28px; height: 28px; right: 6px; top: 6px; }
  .statline { font-size: 11.5px; letter-spacing: -.02em; }
  .statline th { font-size: 10px; }
  .statline th, .statline td { padding: 2px 1px; }
  .statline td:first-child { font-size: 10px; }
  .statline .wide { display: none; }
  .side .pick { padding: 12px 8px; font-size: 15px; }
  kbd { display: none; }
  .cmp-cols, .side-by-side { grid-template-columns: 1fr; }
  .plist.ranked li, .plist.diff li { grid-template-columns: 3ch 44px 1fr auto; gap: 8px; }
  .plist .hs { width: 44px; height: 32px; }
}
