:root {
  --bg: #f5f6fb;
  --bg-2: #eceef7;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e1e4ef;
  --text: #171a2c;
  --muted: #646a85;
  --accent: #6d4dff;
  --accent-2: #9b7bff;
  --accent-soft: rgba(109, 77, 255, 0.1);
  --good: #12a150;
  --good-soft: rgba(18, 161, 80, 0.12);
  --bad: #d93a3a;
  --bad-soft: rgba(217, 58, 58, 0.12);
  --warn: #c98500;
  --warn-soft: rgba(201, 133, 0, 0.14);
  --gold: #d9a400;
  --rainbow: linear-gradient(90deg, #ff5f6d, #ffc371, #47e891, #4facfe, #b06bff);
  --shadow: 0 1px 2px rgba(20, 22, 45, 0.05), 0 4px 16px rgba(20, 22, 45, 0.05);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f1a;
    --bg-2: #141628;
    --surface: #171a2c;
    --surface-2: #1d2036;
    --border: #2a2e4a;
    --text: #eceefa;
    --muted: #9298b8;
    --accent: #8f74ff;
    --accent-2: #b39dff;
    --accent-soft: rgba(143, 116, 255, 0.16);
    --good: #3ddc84;
    --good-soft: rgba(61, 220, 132, 0.14);
    --bad: #ff6b6b;
    --bad-soft: rgba(255, 107, 107, 0.14);
    --warn: #ffc247;
    --warn-soft: rgba(255, 194, 71, 0.14);
    --gold: #ffd34d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e0f1a;
  --bg-2: #141628;
  --surface: #171a2c;
  --surface-2: #1d2036;
  --border: #2a2e4a;
  --text: #eceefa;
  --muted: #9298b8;
  --accent: #8f74ff;
  --accent-2: #b39dff;
  --accent-soft: rgba(143, 116, 255, 0.16);
  --good: #3ddc84;
  --good-soft: rgba(61, 220, 132, 0.14);
  --bad: #ff6b6b;
  --bad-soft: rgba(255, 107, 107, 0.14);
  --warn: #ffc247;
  --warn-soft: rgba(255, 194, 71, 0.14);
  --gold: #ffd34d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }

.container { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 800; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #ff6fb5);
  color: #fff; font-size: 14px; font-weight: 900;
}
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface); border-radius: 9px;
  width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; color: var(--muted); flex: none;
}
.theme-toggle:hover { color: var(--text); }

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px; padding-bottom: 6px; }
  .nav { order: 3; flex-basis: 100%; }
  .brand { flex: 1; }
}

/* ---------- Layout ---------- */
main { padding-top: 24px; padding-bottom: 40px; min-height: 70vh; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid-tiles { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 14px 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Controls ---------- */
.input, .select {
  height: 38px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); outline: none; min-width: 0;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.lg { height: 46px; font-size: 16px; padding: 0 16px; }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap .input { width: 100%; padding-left: 36px; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.btn {
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; border-color: var(--border); color: inherit; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 30px; padding: 0; justify-content: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 34px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.seg button + button { border-left: 1px solid var(--border); }

/* ---------- Chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.golden { background: rgba(255, 196, 0, 0.16); color: var(--gold); border-color: transparent; }
.chip.rainbow { background: var(--rainbow); color: #fff; border-color: transparent; text-shadow: 0 1px 1px rgba(0,0,0,.25); }
.chip.shiny { background: rgba(120, 220, 255, 0.16); color: #2aa6d8; border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }
.live-dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- Stat tiles ---------- */
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile .value { font-size: 22px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; background: var(--surface-2); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.rank { font-weight: 800; color: var(--muted); width: 48px; }
.rank.r1 { color: #e0a800; } .rank.r2 { color: #9aa3b5; } .rank.r3 { color: #cd7f32; }
.clickable { cursor: pointer; }

/* ---------- Item visuals ---------- */
.thumb {
  width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
  flex: none; object-fit: contain; display: grid; place-items: center; overflow: hidden;
}
.thumb.sm { width: 32px; height: 32px; border-radius: 8px; }
.thumb.lg { width: 72px; height: 72px; border-radius: 16px; }
.thumb.xl { width: 96px; height: 96px; border-radius: 20px; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb .ph { font-size: 11px; font-weight: 800; color: var(--muted); }
.thumb.v-golden { border-color: var(--gold); background: rgba(255,196,0,0.1); }
.thumb.v-rainbow { border: 2px solid transparent; background: linear-gradient(var(--surface-2), var(--surface-2)) padding-box, var(--rainbow) border-box; }

.item-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }

.price-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.price-card {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); min-width: 0;
}
.price-card .info { flex: 1; min-width: 0; }
.price-card .nums { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 4px; font-size: 13px; font-variant-numeric: tabular-nums; }
.price-card .nums b { font-weight: 700; }
.price-card .nums > span { white-space: nowrap; }
.price-card .actions { display: flex; flex-direction: column; gap: 4px; }
.gem { color: #39b7ff; }

/* ---------- Trade calculator ---------- */
.trade-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: start; }
.trade-mid { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 40px; min-width: 170px; }
@media (max-width: 900px) { .trade-grid { grid-template-columns: 1fr; } .trade-mid { padding-top: 0; } }
.verdict { font-size: 32px; font-weight: 900; letter-spacing: -0.02em; }
.verdict.win { color: var(--good); } .verdict.loss { color: var(--bad); } .verdict.fair { color: var(--warn); }
.side-total { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.trade-items { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; min-height: 60px; }
.trade-item { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.qty { width: 64px; height: 30px; text-align: center; padding: 0 4px; }
.empty-drop { border: 2px dashed var(--border); border-radius: var(--radius-sm); padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Autocomplete ---------- */
.ac { position: relative; }
.ac-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0,0,0,0.18); max-height: 340px; overflow-y: auto; display: none;
}
.ac-list.open { display: block; }
.ac-opt { display: flex; align-items: center; gap: 10px; padding: 7px 10px; cursor: pointer; }
.ac-opt:hover, .ac-opt.hl { background: var(--accent-soft); }
.ac-opt .r { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Player ---------- */
.profile-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.avatar {
  width: 84px; height: 84px; border-radius: 22px; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #ff6fb5); color: #fff; font-size: 32px; font-weight: 900;
}
.player-card { display: flex; align-items: center; gap: 12px; padding: 12px; color: var(--text); }
.player-card:hover { text-decoration: none; border-color: var(--accent); }
.mini-avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; color: #fff; flex: none; }
.equipped { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.equipped .pet { text-align: center; font-size: 12px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.feed-entry { padding: 12px 0; border-bottom: 1px solid var(--border); }
.feed-entry:last-child { border-bottom: 0; }
.mini-items { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.mini-item { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; max-width: 100%; }
.mini-item .thumb { width: 22px; height: 22px; border-radius: 50%; }

/* ---------- Release / diffs ---------- */
.release-card { display: block; color: var(--text); }
.release-card:hover { text-decoration: none; border-color: var(--accent); }
.diff { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; overflow-x: auto; }
.diff .path { color: var(--accent); }
.diff .before { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff .after { color: var(--good); }
.diff div + div { margin-top: 4px; }
pre.json {
  font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; overflow: auto; max-height: 460px; margin: 0; white-space: pre;
}

/* ---------- Bars ---------- */
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* ---------- States ---------- */
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 30px 0; justify-content: center; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--bg-2), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.error-box { border: 1px solid var(--bad); background: var(--bad-soft); color: var(--text); border-radius: var(--radius); padding: 14px 16px; }
.error-box b { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.hero {
  border-radius: 20px; padding: 22px; color: #fff; position: relative; overflow: hidden;
  background: radial-gradient(circle at 85% 20%, rgba(255,111,181,.55), transparent 45%), linear-gradient(135deg, #5b3df5, #8b5cf6 60%, #c04df0);
}
.hero h1 { color: #fff; }
.hero p { color: rgba(255,255,255,.85); margin: 6px 0 0; }
.hero .chip { background: rgba(255,255,255,.18); color: #fff; border-color: transparent; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  pointer-events: none; transition: all .2s ease; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.footer { color: var(--muted); font-size: 13px; padding-top: 10px; padding-bottom: 30px; border-top: 1px solid var(--border); }
details summary { cursor: pointer; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.reward-band { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.reward-band:last-child { border-bottom: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
