:root {
  --bg: #0e1116;
  --bg-2: #161a21;
  --bg-3: #1f242d;
  --border: rgba(255, 255, 255, .07);
  --text: #e9ecf1;
  --muted: #8c95a6;
  --accent: #7c8cff;
  --accent-2: #a5b0ff;
  --hover: #262c37;
  --r-common: #9aa3ad;
  --r-uncommon: #4ec96a;
  --r-rare: #4f8dff;
  --r-epic: #b05cff;
  --r-exotic: #ff9f2e;
  --r-mythical: #ff4d5e;
  --r-founder: #22d3c5;
  --radius: 14px;
  --chip-active-text: #fff;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-2: #ffffff;
  --bg-3: #eef0f5;
  --border: rgba(20, 24, 40, .08);
  --text: #171b26;
  --muted: #646d80;
  --accent: #4f5ee8;
  --accent-2: #3e4bd0;
  --hover: #e5e8f0;
  --r-common: #6b7480;
  --r-uncommon: #2f9e4a;
  --r-rare: #2f6fe0;
  --r-epic: #8a3fe0;
  --r-exotic: #e07a0c;
  --r-mythical: #e03445;
  --r-founder: #0f9c92;
  --chip-active-text: #fff;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex; flex-direction: column;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); display: flex; gap: 8px; align-items: center; white-space: nowrap; flex: none; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 32px; height: 32px; border-radius: 50%; flex: none; display: block; }
.nav { display: flex; gap: 6px; }
.nav a { padding: 5px 9px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
.nav a:hover { text-decoration: none; color: var(--text); background: var(--bg-3); }
.nav a.active { color: var(--accent); background: var(--bg-3); }
.topbar-right { margin-left: auto; display: flex; gap: 6px; }

.container { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 20px; }
.footer { padding: 14px 20px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); text-align: center; }
.footer-note { max-width: 900px; margin: 4px auto 0; font-size: 11px; opacity: .8; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

.btn {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.active { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

/* filters */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 16px;
}
.filters input[type=search], .filters select {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; color: var(--text);
}
.filters input[type=search] { min-width: 220px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--bg-3); color: var(--muted);
  padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.chip:hover { color: var(--text); }
.chip.active { color: var(--chip-active-text); border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 25%, var(--bg-3)); }
.filters .spacer { flex: 1; }
.filters-end { display: flex; gap: 8px; align-items: center; }
.count { color: var(--muted); font-size: 13px; }

/* rarity colors */
.rar-common { --c: var(--r-common); }
.rar-uncommon { --c: var(--r-uncommon); }
.rar-rare { --c: var(--r-rare); }
.rar-epic { --c: var(--r-epic); }
.rar-exotic { --c: var(--r-exotic); }
.rar-mythical { --c: var(--r-mythical); }
.rar-founder { --c: var(--r-founder); }
.rarity-text { color: var(--c); font-weight: 600; text-transform: capitalize; }

/* grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card {
  display: flex; gap: 12px; padding: 12px;
  background: var(--bg-2); border: 1px solid var(--border); border-left: 3px solid var(--c, var(--border));
  border-radius: var(--radius); color: var(--text); cursor: pointer;
  transition: transform .08s, border-color .08s;
}
.card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--c); }
.thumb {
  width: 64px; height: 64px; flex: none; border-radius: 8px;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--c, #555) 35%, transparent), var(--bg-3) 75%);
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  border: 1px solid color-mix(in srgb, var(--c, var(--border)) 50%, var(--border));
}
.thumb img, .thumb .thumb-img { width: 56px; height: 56px; object-fit: contain; image-rendering: auto; }
.thumb.lg { width: 140px; height: 140px; font-size: 64px; }
.thumb.lg img, .thumb.lg .thumb-img { width: 120px; height: 120px; }
.thumb-col { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: none; }
.thumb-id { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-body { min-width: 0; flex: 1; }
.card-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.card-power { color: var(--accent); font-weight: 700; font-size: 12px; }
.stat-list { list-style: none; margin: 4px 0 0; padding: 0; font-size: 12px; color: var(--muted); }
.stat-list li { display: flex; justify-content: space-between; gap: 8px; }
.stat-list li b { color: var(--text); font-weight: 600; }

/* table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-2); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--bg-3); color: var(--muted); font-weight: 600; position: sticky; top: 0; cursor: pointer; user-select: none; }
th.sorted { color: var(--accent); }
th.num, td.num { text-align: right; }
tbody tr:hover { background: var(--bg-3); }
tbody tr:last-child td { border-bottom: none; }
td.name a { color: var(--text); font-weight: 600; }
.mini { width: 32px; height: 32px; vertical-align: middle; object-fit: contain; }
.dim { color: var(--muted); }

/* detail */
.detail-head { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; }
.detail-head h1 { margin: 0 0 6px; font-size: 24px; }
.meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.meta b { color: var(--text); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg-3); border: 1px solid var(--border); color: var(--muted); }
.badge.warn { color: var(--r-mythical); border-color: color-mix(in srgb, var(--r-mythical) 50%, var(--border)); }
.badge.ability { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > * { min-width: 0; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }
.panel { min-width: 0; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.panel h2 { margin: 0 0 10px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats-big { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.stats-big li { display: flex; justify-content: space-between; padding: 6px 8px; background: var(--bg-3); border-radius: 6px; }
.stats-big li b { color: var(--accent-2); }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); }
.level-table td.cost { color: var(--r-epic); }
.item-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.item-row:last-child { border-bottom: none; }
.item-row .mini { width: 36px; height: 36px; }
.item-row.current { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 6px; padding-left: 6px; }
.item-row .r-name { font-weight: 600; color: var(--text); }
.item-row .r-sub { font-size: 12px; color: var(--muted); }

/* sets list */
.set-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.set-card h3 { margin: 0; font-size: 15px; }
.set-card h3 a { color: var(--text); }
.set-thumbs { display: flex; gap: 4px; flex-wrap: wrap; }
.set-thumbs .thumb { width: 44px; height: 44px; font-size: 20px; }
.set-thumbs .thumb img, .set-thumbs .thumb .thumb-img { width: 38px; height: 38px; }
.bonus-list { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.bonus-list li { display: flex; gap: 8px; }
.bonus-list .n { color: var(--accent); font-weight: 700; min-width: 34px; }
.bonus-list b { color: var(--text); font-weight: 600; }
.empty { color: var(--muted); padding: 30px; text-align: center; }
kbd { background: var(--bg-3); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font-size: 11px; }

/* shared extras */
.nav { flex-wrap: wrap; gap: 2px; }
@media (max-width: 1400px) { .brand .brand-title { display: none; } }
.brand-page { display: none; }
.menu-btn { display: none; }
.reward { display: inline-block; padding: 2px 8px; margin: 2px 2px 2px 0; border-radius: 6px; background: var(--bg-3); border: 1px solid var(--border); font-size: 12px; white-space: nowrap; }
.reward .rarity-text { text-transform: none; }
.page-title { margin: 0 0 14px; font-size: 22px; }
.page-title small { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 8px; }
.note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
h3.sub { margin: 14px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- mobile ---------- */
html { -webkit-text-size-adjust: 100%; }
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand { min-width: 0; flex: 1 1 auto; overflow: hidden; }
  .brand .brand-title { display: none; }
  .brand .brand-page { display: inline; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right { flex: none; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 34px; padding: 0; font-size: 18px; line-height: 1; }
  .nav { display: none; order: 10; flex-basis: 100%; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px;
    padding: 8px 0 4px; border-top: 1px solid var(--border); max-height: calc(100vh - 60px); overflow-y: auto; }
  body.nav-open .nav { display: grid; }
  .nav a { padding: 10px 12px; font-size: 14px; border-radius: 8px; background: var(--bg-3); color: var(--text); white-space: normal; }
  .nav a.active { color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
}
@media (max-width: 700px) {
  .container { padding: 12px 10px; }
  .footer { padding: 12px 10px; }
  .page-title { font-size: 20px; margin-bottom: 10px; }
  .page-title small { display: block; margin: 2px 0 0; font-size: 13px; }
  .detail-head { gap: 14px; margin-bottom: 14px; }
  .detail-head h1 { font-size: 20px; }
  .thumb.lg { width: 110px; height: 110px; font-size: 52px; }
  .thumb.lg img, .thumb.lg .thumb-img { width: 92px; height: 92px; }
  .panel { padding: 12px 10px; }
  .cols { gap: 12px; }
  /* фильтры: поиск во всю ширину, выпадающие списки по два в ряд, чипсы одной прокручиваемой строкой */
  .filters { padding: 10px; gap: 8px; margin-bottom: 12px; }
  .filters input[type=search] { min-width: 0; flex: 1 1 100%; width: 100%; font-size: 16px; }
  .filters select { flex: 1 1 calc(50% - 4px); min-width: 0; max-width: 100%; font-size: 16px; padding: 8px 10px; }
  .filters .chips { flex: 1 1 100%; width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .filters .chips::-webkit-scrollbar { display: none; }
  .filters .chip { flex: none; }
  .chip { padding: 6px 12px; font-size: 13px; }
  .filters .spacer { display: none; }
  .filters .count { margin-left: auto; }
  .filters-end { margin-left: auto; }
  .filters-end .count { margin-left: 0; }
  .btn { padding: 8px 12px; }
  .btn-sm { padding: 6px 10px; font-size: 13px; }
  .tabs .btn, .tabs .chip { padding: 7px 12px; }
  /* таблицы: компактнее, первая колонка закреплена при горизонтальной прокрутке */
  th, td { padding: 6px 8px; font-size: 12px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .table-wrap table th:first-child, .table-wrap table td:first-child { position: sticky; left: 0; z-index: 1; background: var(--bg-2); box-shadow: 1px 0 0 var(--border); }
  .table-wrap table th:first-child { background: var(--bg-2); z-index: 3; }
  .table-wrap table th:first-child, .table-wrap table td:first-child { white-space: normal; max-width: 46vw; }
  .table-wrap table td.num:first-child, .table-wrap table th.num:first-child { white-space: nowrap; }
  .table-wrap table th { z-index: 2; }
  .table-wrap table th[colspan] { position: static; }
  .mini { width: 28px; height: 28px; }
  .reward { white-space: normal; }
  body .kv, body .leagues-season, body .bosses-kv, body .clans-kv, body .quests-kv, body .abilities-resist dl { grid-template-columns: minmax(0, max-content) minmax(50%, 1fr); gap: 6px 10px; }
  .kv dt, .quests-kv dt { white-space: normal; }
  .kv dd, .bosses-kv dd { overflow-wrap: anywhere; }
  .stats-big { grid-template-columns: 1fr; }
  .stats-big li { flex-wrap: wrap; }
  .card-title { font-size: 13px; }
  .note, .footer-note { overflow-wrap: anywhere; }
}
@media (max-width: 480px) {
  /* плитка предметов: две колонки, карточка вертикальная */
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { flex-direction: column; gap: 6px; padding: 10px 8px 8px; }
  .card .thumb-col { align-self: center; }
  .card-body { width: 100%; }
  .card-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stat-list li { gap: 6px; }
  .stat-list li span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .set-thumbs .thumb { width: 40px; height: 40px; font-size: 18px; }
  .set-thumbs .thumb img, .set-thumbs .thumb .thumb-img { width: 34px; height: 34px; }
}

/* ---------- flat components: с префиксом html, чтобы перебивать стили страниц (они вставляются после styles.css) ---------- */
html body { font-size: 14.5px; letter-spacing: .005em; }
html .topbar { border-bottom: none; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); padding: 10px 20px; }
html .brand { font-weight: 800; letter-spacing: -.01em; }
html .nav a { border-radius: 999px; padding: 6px 12px; }
html .nav a.active { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.btn, .chip, .filters input[type=search], .filters select,
html .forge-calc input, html .bosses-levels input { border-color: transparent; }
html .btn { border-radius: 10px; }
html .btn:hover, html .chip:hover { background: var(--hover); border-color: transparent; }
html .btn.active { background: var(--accent); color: #fff; }
html .btn-ghost { background: var(--bg-3); }
html .chip.active { background: var(--c, var(--accent)); color: #fff; border-color: transparent; }
html .chip.rar-common.active { color: #111; }
.filters, .panel, .set-card, .table-wrap,
html .abilities-card, html .shop-card, html .bosses-diffcard { border-color: transparent; }
html .card { border: none; border-left: none; background: var(--bg-2); box-shadow: inset 0 0 0 1px var(--border); }
html .card:hover { transform: none; background: var(--hover); box-shadow: inset 0 0 0 2px var(--c, var(--accent)); }
html .card-power { color: var(--accent-2); }
html .thumb { border: none; background: color-mix(in srgb, var(--c, var(--muted)) 16%, var(--bg-3)); border-radius: 12px; }
html .set-thumbs .thumb, html .abilities-item .thumb { border-radius: 10px; }
html .panel h2, html h3.sub, html .forge-rarity h3, html .abilities-sub, html .bosses-sub {
  text-transform: none; letter-spacing: -.01em; font-size: 16px; font-weight: 700; color: var(--text); }
html .panel h2 { margin-bottom: 12px; }
html h3.sub { font-size: 14px; color: var(--muted); }
html .page-title, html .detail-head h1 { font-weight: 800; letter-spacing: -.02em; }
html th { background: var(--bg-2); text-transform: uppercase; font-size: 11px; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
html .table-wrap th:first-child, html .table-wrap td:first-child, html .bosses-table th:first-child { box-shadow: none; background: var(--bg-2); }
html .table-wrap { background: var(--bg-2); }
html .table-wrap table { background: transparent; }
html tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.stats-big li, .skills-meta div, .abilities-stat, .bosses-price,
html .chests-card, html .forge-pitem { border-radius: 10px; border-color: transparent; }
html .chests-card, html .forge-pitem, html .abilities-card, html .abilities-card.abilities-boss, html .abilities-resist, html .bosses-ability, html .bosses-table td.bosses-name { border-left: none; }
html .bosses-rule, html .bosses-diffcard { border-top: none; }
html .bosses-table th.bosses-hl { color: var(--muted); }
.badge, .reward, .gems-other, .shop-item, .leagues-item,
html .shop-price, html .quests-count, html .shop-count, html .bosses-diff { border-color: transparent; }
html .badge.warn { background: color-mix(in srgb, var(--r-mythical) 14%, var(--bg-3)); }
html .badge.ability { background: color-mix(in srgb, var(--accent) 14%, var(--bg-3)); }
html .item-row.current { background: color-mix(in srgb, var(--accent) 12%, transparent); }
html .footer { border-top: none; }
html .chip.active .dim, html .chip.active small, html .btn.active .dim { color: rgba(255, 255, 255, .78); }
.skills-graph-wrap, .abilities-effects code, .bosses-kv code, .clans-page code,
html .quests-formula code, html .bosses-growth code, html kbd { border-color: transparent; }
html .leagues-client-head .ld { border-color: transparent; }
@media (max-width: 820px) {
  html .nav { border-top: none; }
  html .nav a { border-radius: 10px; }
  html .nav a.active { box-shadow: none; background: color-mix(in srgb, var(--accent) 22%, var(--bg-3)); }
}
