/* Карточный картель — мини-приложение. Цвета берутся из темы Telegram (светлая/тёмная), акцент — красный картеля. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16171a);
  --muted: var(--tg-theme-hint-color, #8a8d93);
  --line: color-mix(in srgb, var(--text) 9%, transparent);
  --accent: #d6322f;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --have: #2f9e5b;
  --have-soft: color-mix(in srgb, var(--have) 14%, transparent);
  --want: #e2862a;
  --want-soft: color-mix(in srgb, var(--want) 16%, transparent);
  --r1: #8f949c; --r2: #3d7ff0; --r3: #9b59e6; --r4: #e3a21a; --r5: #9fb4c7;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { overscroll-behavior-y: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
img { display: block; }

.app { max-width: 720px; margin: 0 auto; padding: 12px 12px calc(84px + var(--safe-b)); }
.boot { min-height: 70vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── карточки-секции ── */
.section { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 4px 8px; }
.section-head h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0; font-weight: 600; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; }

/* ── профиль ── */
.hero { position: relative; overflow: hidden; padding: 0; }
.hero-band { height: 64px; background: linear-gradient(105deg, #b8221f 0%, var(--accent) 55%, #ef5a3c 100%); position: relative; }
.hero-band::after { content: "КАРТОЧНЫЙ КАРТЕЛЬ"; position: absolute; right: 14px; top: 12px; color: #fff; font-weight: 900;
  font-size: 12px; letter-spacing: .14em; opacity: .9; transform: rotate(-3deg); }
.hero-body { padding: 0 16px 16px; margin-top: -34px; position: relative; }
.avatar { width: 76px; height: 76px; border-radius: 50%; border: 4px solid var(--surface); background: #2b2d33; color: #fff;
  display: grid; place-items: center; font-size: 28px; font-weight: 700; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.hero-name { margin: 10px 0 2px; font-size: 22px; font-weight: 750; letter-spacing: -.01em; }
.hero-nick { color: var(--muted); font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--text) 6%, transparent); }
.chip.gold { background: color-mix(in srgb, #e3a21a 18%, transparent); color: #b17700; }
.chip.green { background: var(--have-soft); color: var(--have); }
.chip.grey { color: var(--muted); }
.bio { margin-top: 14px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.bio.empty { color: var(--muted); }
.bio-edit { margin-top: 12px; }
.bio-edit textarea { width: 100%; min-height: 84px; resize: vertical; border-radius: 12px; border: 1px solid var(--line); padding: 10px 12px;
  background: var(--bg); outline: none; }
.bio-edit .row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; color: var(--muted); font-size: 12px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 12px 10px; }
.stat b { display: block; font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.totals { display: flex; gap: 8px; }
.totals > div { flex: 1; text-align: center; padding: 10px 6px; border-radius: 12px; background: var(--bg); }
.totals b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.totals span { font-size: 12px; color: var(--muted); }
.totals .t-have b { color: var(--have); } .totals .t-want b { color: var(--want); } .totals .t-dupes b { color: var(--r2); }

/* ── список коллекций ── */
.coll { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--surface); border-radius: var(--radius);
  margin-bottom: 8px; width: 100%; text-align: left; }
.coll:active { opacity: .75; }
.coll-cover { width: 54px; height: 76px; border-radius: 8px; overflow: hidden; flex: none; background: var(--bg); }
.coll-cover img { width: 100%; height: 100%; object-fit: cover; }
.coll-main { flex: 1; min-width: 0; }
.coll-title { font-weight: 700; font-size: 16px; }
.coll-sub { color: var(--muted); font-size: 13px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; border-radius: 4px; background: color-mix(in srgb, var(--text) 8%, transparent); overflow: hidden; margin-top: 9px; }
.bar i { display: block; height: 100%; background: var(--have); border-radius: 4px; }
.coll-meta { display: flex; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.coll-meta .w { color: var(--want); } .coll-meta .d { color: var(--r2); }
.badge-on { font-size: 12px; font-weight: 700; color: var(--have); background: var(--have-soft); border-radius: 999px; padding: 4px 9px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 15px; line-height: 1.5; }
.empty .big { font-size: 40px; margin-bottom: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 46px; padding: 0 18px; border-radius: 12px;
  font-weight: 650; font-size: 15px; background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.small { height: 34px; width: auto; font-size: 14px; padding: 0 14px; border-radius: 10px; }
.btn:active { opacity: .85; }

/* ── экран коллекции ── */
.c-head { padding: 16px; }
.c-title { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.c-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.c-progress { display: flex; align-items: baseline; gap: 6px; margin-top: 14px; font-variant-numeric: tabular-nums; }
.c-progress b { font-size: 26px; }
.c-progress span { color: var(--muted); }
.c-actions { display: flex; gap: 8px; margin-top: 14px; }

.sticky { position: sticky; top: 0; z-index: 5; margin: 6px -12px 0; padding: 8px 12px 6px; background: var(--bg); }
.scroller { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.scroller::-webkit-scrollbar { display: none; }
.pill { flex: none; height: 32px; padding: 0 12px; border-radius: 999px; background: var(--surface); font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--text); }
.pill small { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.pill.on { background: var(--text); color: var(--surface); }
.pill.on small { color: color-mix(in srgb, var(--surface) 70%, transparent); }
.search { display: flex; gap: 6px; margin-top: 8px; }
.search input { flex: 1; height: 38px; border-radius: 11px; border: 0; background: var(--surface); padding: 0 12px; outline: none; font-size: 15px; min-width: 0; }
.mode { height: 38px; padding: 0 12px; border-radius: 11px; background: var(--surface); font-weight: 650; font-size: 14px; white-space: nowrap; }
.mode.on { background: var(--accent); color: #fff; }
.brushes { display: flex; gap: 6px; margin-top: 8px; }
.brush { flex: 1; height: 38px; border-radius: 11px; background: var(--surface); font-weight: 700; font-size: 14px; border: 2px solid transparent; }
.brush.on[data-b="have"] { border-color: var(--have); color: var(--have); background: var(--have-soft); }
.brush.on[data-b="want"] { border-color: var(--want); color: var(--want); background: var(--want-soft); }
.brush.on[data-b="none"] { border-color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 6px 2px 0; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 680px) { .grid { grid-template-columns: repeat(5, 1fr); } }
.card { position: relative; border-radius: 10px; overflow: hidden; background: var(--line); aspect-ratio: 2 / 3;
  content-visibility: auto; contain-intrinsic-size: auto 180px; }
.card:active { opacity: .7; }
.card img { width: 100%; height: 100%; object-fit: cover; }
.card .num { position: absolute; left: 5px; top: 5px; font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 6px;
  background: rgba(0,0,0,.62); color: #fff; font-variant-numeric: tabular-nums; }
.card .rar { position: absolute; right: 5px; top: 5px; font-size: 10px; font-weight: 800; padding: 2px 5px; border-radius: 6px; color: #fff; }
.card .mark { position: absolute; right: 5px; bottom: 5px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 900; border: 2px solid #fff; }
.card .dup { position: absolute; left: 5px; bottom: 5px; font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 6px;
  background: var(--r2); color: #fff; }
.card.have .mark { background: var(--have); }
.card.want { outline: 3px solid var(--want); outline-offset: -3px; }
.card.want .mark { background: var(--want); }
.card.missing img { opacity: .38; filter: grayscale(.7); }
.r1 { background: var(--r1); } .r2 { background: var(--r2); } .r3 { background: var(--r3); } .r4 { background: var(--r4); }
.r5 { background: linear-gradient(135deg, #8fa3b8, #d9e3ec 50%, #8fa3b8); color: #253241 !important; }
.more { margin: 14px 0 0; }

/* ── нижняя шторка карточки ── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; animation: fade .1s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 720px; margin: 0 auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 10px 16px calc(16px + var(--safe-b)); max-height: 92vh; overflow-y: auto; animation: up .14s ease-out; }
@keyframes fade { from { opacity: 0; } } @keyframes up { from { transform: translateY(24px); } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }
.sheet-x { position: absolute; right: 12px; top: 10px; width: 32px; height: 32px; border-radius: 50%; background: var(--bg);
  color: var(--muted); font-size: 15px; font-weight: 700; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet-card { display: flex; gap: 14px; }
.sheet-img { width: 42%; max-width: 220px; flex: none; border-radius: 12px; overflow: hidden; aspect-ratio: 2 / 3; background: var(--bg); }
.sheet-img img { width: 100%; height: 100%; object-fit: cover; }
.sheet-info { min-width: 0; }
.sheet-no { color: var(--muted); font-size: 13px; font-weight: 600; }
.sheet-name { font-size: 19px; font-weight: 750; margin: 4px 0 10px; line-height: 1.25; }
.kv { font-size: 14px; margin: 4px 0; } .kv span { color: var(--muted); }
.rpill { display: inline-block; padding: 3px 9px; border-radius: 999px; color: #fff; font-size: 12px; font-weight: 750; margin-top: 6px; }
.status3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.status3 button { height: 48px; border-radius: 12px; background: var(--bg); font-weight: 700; font-size: 15px; border: 2px solid transparent; }
.status3 button.on[data-s="none"] { border-color: var(--muted); }
.status3 button.on[data-s="have"] { border-color: var(--have); background: var(--have-soft); color: var(--have); }
.status3 button.on[data-s="want"] { border-color: var(--want); background: var(--want-soft); color: var(--want); }
.dupes { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--bg); }
.dupes .lbl { font-weight: 650; } .dupes .lbl small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 38px; height: 38px; border-radius: 10px; background: var(--surface); font-size: 20px; font-weight: 700; }
.stepper b { min-width: 30px; text-align: center; font-size: 18px; font-variant-numeric: tabular-nums; }
.sheet-nav { display: flex; gap: 8px; margin-top: 12px; }
.sheet-nav button { flex: 1; height: 42px; border-radius: 12px; background: var(--bg); font-weight: 650; }

.toast { position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); z-index: 60; max-width: 90vw;
  background: rgba(20,20,22,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; }
.err { text-align: center; padding: 40px 18px; color: var(--muted); line-height: 1.5; }
.err b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

/* ── тема: кнопка 🌗/🌙/☀️ в профиле ── */
.hero-band .theme-btn { position: absolute; right: 14px; bottom: -50px; width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg); font-size: 18px; line-height: 38px; text-align: center; z-index: 1; }
.hero-band .theme-btn:active { opacity: .7; }
html[data-theme="dark"] {
  --bg: #0f1115; --surface: #1a1d23; --text: #f2f3f5; --muted: #8b919c; color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #f1f1f4; --surface: #ffffff; --text: #16171a; --muted: #8a8d93; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  html.no-tg[data-theme="auto"] { --bg: #0f1115; --surface: #1a1d23; --text: #f2f3f5; --muted: #8b919c; color-scheme: dark; }
}
html[data-theme="dark"] .chip.gold, html.no-tg[data-theme="auto"] .chip.gold { color: #f0b93a; }

/* ── нижние вкладки ── */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding: 4px 8px calc(4px + var(--safe-b)); }
.tab { flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0;
  font-size: 11px; font-weight: 600; color: var(--muted); }
.tab span { font-size: 20px; line-height: 1.1; filter: grayscale(1); opacity: .7; }
.tab.on { color: var(--accent); }
.tab.on span { filter: none; opacity: 1; }

/* ── поиск участников ── */
.list { padding: 4px 0; }
.person { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; text-align: left; }
.list .person + .person { border-top: 1px solid var(--line); }
.person .ava { flex: none; width: 40px; height: 40px; border-radius: 50%; background: #2b2d33; color: #fff; display: grid;
  place-items: center; font-weight: 700; }
.person-main { flex: 1; min-width: 0; }
.person-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-name small { color: var(--muted); font-weight: 600; margin-left: 4px; }
.person-meta { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); font-size: 22px; }
.person.mini { padding: 8px 0; }
.person.mini .ava { width: 32px; height: 32px; font-size: 14px; }
.chip.city { background: var(--accent-soft); color: var(--accent); }
.field { width: 100%; height: 44px; border-radius: 12px; border: 0; background: var(--bg); padding: 0 12px; font-size: 16px; outline: none; }

/* ── чужая коллекция и владельцы карточки ── */
.c-owner { font-size: 13px; color: var(--accent); font-weight: 650; margin-bottom: 4px; }
.theirs { margin-top: 10px; font-size: 14px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); }
.mine-lbl { margin: 12px 2px 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.owners { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.owners-h { font-size: 13px; font-weight: 650; color: var(--have); margin-bottom: 2px; }
.owners-sum { font-size: 13px; color: var(--muted); margin-top: 6px; }
.owners-h.sell { color: var(--accent); }
.offer { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; color: var(--text);
  text-decoration: none; font-weight: 600; font-size: 14px; }
.offer + .offer { border-top: 1px solid var(--line); }
.offer + .owners-h, .owners-h + .person + .owners-h { margin-top: 10px; }
