:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg2: var(--tg-theme-secondary-bg-color, #181b22);
  --card: var(--tg-theme-section-bg-color, #1c2029);
  --text: var(--tg-theme-text-color, #f2f4f8);
  --hint: var(--tg-theme-hint-color, #8a93a6);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --mrkt: #3b82f6; --portals: #8b5cf6; --tonnel: #f59e0b; --getgems: #06b6d4;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: 24px; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--hint); font-weight: 400; }
.hint { color: var(--hint); font-size: 12px; margin: 8px 16px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 12px 6px; }
.tabs { display: flex; background: var(--bg2); border-radius: 12px; padding: 3px; }
.tab { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 10px; color: var(--hint); font-weight: 600; }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px #0003; }

.page { padding: 0 12px; }
.toolbar { display: flex; gap: 8px; margin-top: 6px; }
.collection-btn { flex: 1; display: flex; justify-content: space-between; align-items: center;
  background: var(--bg2); border: 0; border-radius: 12px; padding: 11px 14px; font-weight: 600; min-width: 0; }
.collection-btn span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--hint); }
.icon-btn { position: relative; width: 44px; border: 0; border-radius: 12px; background: var(--bg2); display: grid; place-items: center; }
.dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; flex-wrap: nowrap; }
.chips::-webkit-scrollbar { display: none; }
.selected-chips { flex-wrap: wrap; }
.chip { flex: none; border: 1px solid var(--line); background: none; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--hint); }
.chip.on { color: var(--text); border-color: transparent; background: var(--bg2); }
.chip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.chip .x { margin-left: 6px; color: var(--hint); }

.sortbar { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 10px; }
.sortbar select { background: none; border: 0; font-weight: 600; padding: 4px 0; }
.sortbar option { background: var(--bg2); }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.item { background: var(--card); border-radius: 14px; overflow: hidden; cursor: pointer; position: relative; }
.item img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--bg2); }
.item .body { padding: 8px 10px 10px; }
.item .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .num { color: var(--hint); font-weight: 500; }
.item .attrs { color: var(--hint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item .price { margin-top: 8px; display: flex; justify-content: space-between; align-items: center; }
.price-btn { background: var(--accent); color: var(--accent-text); border-radius: 9px; padding: 5px 9px; font-weight: 700; font-size: 13px; }
.badge { position: absolute; top: 8px; left: 8px; font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 7px; color: #fff; }
.ago { position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 3px 6px; border-radius: 7px; background: #0009; color: #fff; }
.b-mrkt { background: var(--mrkt); } .b-portals { background: var(--portals); }
.b-tonnel { background: var(--tonnel); } .b-getgems { background: var(--getgems); }

.empty { text-align: center; color: var(--hint); padding: 48px 0; }
.loader { display: flex; justify-content: center; gap: 6px; padding: 20px; }
.loader span { width: 8px; height: 8px; border-radius: 50%; background: var(--hint); animation: b 1s infinite ease-in-out; }
.loader span:nth-child(2) { animation-delay: .15s; } .loader span:nth-child(3) { animation-delay: .3s; }
@keyframes b { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.sheet { position: fixed; inset: 0; z-index: 20; background: #0008; display: flex; align-items: flex-end; }
.sheet-body { width: 100%; max-height: 88vh; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px 24px; animation: up .18s ease-out; }
.sheet-body.tall { height: 80vh; display: flex; flex-direction: column; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h3, .page h3 { margin: 14px 0 6px; font-size: 15px; }
.sheet label { display: block; color: var(--hint); font-size: 12px; margin-top: 10px; }
input, select { width: 100%; background: var(--bg2); border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; margin-top: 4px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.list { overflow-y: auto; margin-top: 8px; flex: 1; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-item img, .list-item .ph { width: 36px; height: 36px; border-radius: 9px; object-fit: cover; background: var(--bg2); flex: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .sub { color: var(--hint); font-size: 12px; }
.list-item.sel { color: var(--accent); }

.main-btn, .ghost-btn { width: 100%; border: 0; border-radius: 12px; padding: 12px; font-weight: 700; margin-top: 12px; }
.main-btn { background: var(--accent); color: var(--accent-text); }
.ghost-btn { background: var(--bg2); }
.card-block { background: var(--bg2); border-radius: 12px; padding: 4px 14px; margin-top: 8px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; font-weight: 600; position: relative; }
.switch-row input { display: none; }
.switch { width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; transition: .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; }
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { left: 21px; }

.detail img { width: 100%; max-width: 320px; display: block; margin: 0 auto; border-radius: 16px; aspect-ratio: 1; object-fit: cover; }
.detail h2 { margin: 12px 0 2px; text-align: center; }
.detail .mk { text-align: center; color: var(--hint); }
.detail table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.detail td { padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail td:last-child { text-align: right; font-weight: 600; }

/* v2: пикеры атрибутов, теги номера/монохрома */
.attr-row { display: flex; align-items: center; gap: 10px; background: var(--bg2); border-radius: 10px; padding: 11px 12px; margin-top: 8px; cursor: pointer; }
.attr-row.disabled { opacity: .45; pointer-events: none; }
.attr-name { color: var(--hint); font-size: 13px; width: 64px; flex: none; }
.attr-val { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.attr-val img, .attr-val .swatch { width: 22px; height: 22px; border-radius: 6px; flex: none; }
.swatch { display: inline-block; border-radius: 50%; }
.list-item .swatch { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.list-item .right { text-align: right; font-size: 12px; color: var(--hint); flex: none; }
.list-item .right b { color: var(--text); font-weight: 600; }
.picker-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 4px; }
.tier-select { margin-bottom: 4px; }
.tags { position: absolute; top: 34px; left: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 7px; background: #000a; color: #fff; }
.chip .sw { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.sheet .switch-row { display: flex; color: var(--text); font-size: 14px; margin-top: 0; }
.sheet .card-block { margin-top: 10px; }
#pickerSheet { z-index: 30; }
