:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --sec: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2a8bf2);
  --btn: var(--tg-theme-button-color, #2a8bf2);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: var(--tg-theme-accent-text-color, var(--btn));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: var(--text); }
#view { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; min-height: 100vh; }

/* нижние вкладки */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  background: var(--sec); border-top: 1px solid var(--sep); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); z-index: 10; }
#tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--hint); font-size: 11px; min-width: 72px; }
#tabs a .ti { font-size: 20px; filter: grayscale(1); opacity: .7; }
#tabs a.on { color: var(--accent); }
#tabs a.on .ti { filter: none; opacity: 1; }

/* общие блоки */
.section { background: var(--sec); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.h { font-size: 13px; text-transform: lowercase; color: var(--hint); margin: 16px 4px 8px; letter-spacing: .02em; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--hint); padding: 36px 16px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }
.btn { background: var(--btn); color: var(--btn-text); border-radius: 12px; padding: 10px 16px; font-weight: 600; text-align: center; }
.btn.ghost { background: color-mix(in srgb, var(--btn) 12%, transparent); color: var(--accent); }
.btn.wide { display: block; width: 100%; }
.more { display: block; margin: 8px auto 0; padding: 10px 18px; color: var(--accent); }

/* поиск и переключатели */
.search { display: flex; align-items: center; gap: 8px; background: var(--sec); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; }
.seg { display: flex; background: var(--sec); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; padding: 7px 4px; border-radius: 10px; color: var(--hint); font-size: 14px; }
.seg button.on { background: var(--btn); color: var(--btn-text); font-weight: 600; }
.chips { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.chips button { padding: 5px 12px; border-radius: 99px; background: var(--sec); color: var(--hint); font-size: 13px; white-space: nowrap; }
.chips button.on { color: var(--accent); background: color-mix(in srgb, var(--btn) 14%, var(--sec)); font-weight: 600; }

/* карточка набора */
.card { background: var(--sec); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.card .pv { display: block; width: 100%; aspect-ratio: 2 / 1; background: var(--sec); object-fit: contain; }
.card.st .pv { aspect-ratio: 5 / 3; }
.card .meta { padding: 10px 12px 12px; display: flex; gap: 10px; align-items: center; }
.card .t { font-weight: 600; }
.card .a { color: var(--accent); font-size: 13px; }
.like { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 99px; background: var(--bg2); font-size: 14px; color: var(--hint); }
.like.on { color: #e8487f; background: color-mix(in srgb, #e8487f 12%, var(--sec)); }
.like .hz { font-size: 16px; line-height: 1; }
.tags { color: var(--hint); font-size: 12px; margin-top: 2px; }

/* авторы */
.person { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--sep); }
.person:last-child { border-bottom: 0; }
.ava { width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center; overflow: hidden;
  background: var(--th-a, color-mix(in srgb, var(--btn) 20%, var(--sec))); font-weight: 700; color: #fff; font-size: 20px; }
.ava img { width: 100%; height: 100%; object-fit: cover; }
.ava.emo { background: var(--th-soft, #fff); }
.ava.emo img { width: 78%; height: 78%; object-fit: contain; }

/* профиль */
.hero { border-radius: 22px; padding: 22px 16px 16px; text-align: center; margin-bottom: 12px; position: relative; overflow: hidden;
  background: linear-gradient(160deg, var(--th-1), var(--th-2)); color: var(--th-ink); }
.hero::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55;
  background-image: radial-gradient(circle at 12% 20%, #fff 0 2px, transparent 3px), radial-gradient(circle at 85% 30%, #fff 0 1.5px, transparent 2.5px),
  radial-gradient(circle at 70% 80%, #fff 0 2px, transparent 3px), radial-gradient(circle at 25% 75%, #fff 0 1px, transparent 2px); }
.hero .ava { width: 96px; height: 96px; margin: 0 auto 10px; font-size: 40px; box-shadow: 0 6px 20px rgba(0,0,0,.12); border: 3px solid rgba(255,255,255,.85); }
.hero .nm { font-size: 22px; font-weight: 700; }
.hero .stt { margin-top: 4px; opacity: .85; font-size: 14px; word-break: break-word; }
.hero .stats { display: flex; justify-content: center; gap: 4px; margin-top: 14px; }
.hero .stats > * { flex: 1; max-width: 90px; padding: 6px 2px; border-radius: 12px; background: rgba(255,255,255,.35); color: inherit; }
.hero .stats b { display: block; font-size: 17px; }
.hero .stats span { font-size: 11px; opacity: .8; }
.hero .acts { display: flex; gap: 8px; justify-content: center; margin-top: 14px; position: relative; z-index: 1; }
.hero .acts .btn { background: var(--th-accent); color: #fff; min-width: 140px; }
.hero .acts .btn.ghost { background: rgba(255,255,255,.6); color: var(--th-ink); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { padding: 5px 10px; border-radius: 99px; background: var(--sec); font-size: 13px; }
.badge.off { opacity: .4; filter: grayscale(1); }

/* темы профиля */
.th-tg { --th-1: color-mix(in srgb, var(--btn) 55%, #fff); --th-2: color-mix(in srgb, var(--btn) 18%, #fff); --th-ink: #1d1d27; --th-accent: var(--btn); --th-a: var(--btn); --th-soft: #fff; }
.th-pink { --th-1: #ffc2da; --th-2: #fff0f6; --th-ink: #5a2340; --th-accent: #e8609a; --th-a: #f08cb6; --th-soft: #fff5f9; }
.th-sky { --th-1: #b9dcff; --th-2: #eef7ff; --th-ink: #1b3a5c; --th-accent: #3d8fe0; --th-a: #6aaaf0; --th-soft: #f3f9ff; }
.th-lavender { --th-1: #d6c6ff; --th-2: #f5f0ff; --th-ink: #3a2a63; --th-accent: #8a63d2; --th-a: #a98be6; --th-soft: #f8f5ff; }
.th-mint { --th-1: #b5ecd7; --th-2: #effcf6; --th-ink: #1d4a3b; --th-accent: #2fa882; --th-a: #5cc4a0; --th-soft: #f2fcf8; }
.th-peach { --th-1: #ffcfb5; --th-2: #fff4ec; --th-ink: #5c3220; --th-accent: #ef8a55; --th-a: #f5a77d; --th-soft: #fff7f2; }
.th-night { --th-1: #2a2140; --th-2: #4d3c73; --th-ink: #f4edff; --th-accent: #a985ff; --th-a: #7c62c9; --th-soft: #3a2e57; }
.th-night .hero .stats > *, .hero.th-night .stats > * { background: rgba(255,255,255,.12); }
.hero.th-night .acts .btn.ghost { background: rgba(255,255,255,.18); }

/* редактор */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.sw { width: 52px; height: 52px; border-radius: 16px; background: linear-gradient(160deg, var(--th-1), var(--th-2)); border: 3px solid transparent; }
.sw.on { border-color: var(--accent); }
.field { width: 100%; border: 1px solid var(--sep); background: var(--bg); border-radius: 12px; padding: 10px 12px; outline: 0; }
.counter { text-align: right; font-size: 12px; color: var(--hint); margin-top: 4px; }
.pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; margin-top: 10px; max-height: 300px; overflow-y: auto; }
.pick button { aspect-ratio: 1; border-radius: 12px; background: var(--bg2); padding: 6px; border: 2px solid transparent; }
.pick button.on { border-color: var(--accent); }
.pick img { width: 100%; height: 100%; object-fit: contain; }
.opt { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--sep); }
.opt:last-child { border-bottom: 0; }
.check { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--hint); flex: none; display: grid; place-items: center; color: #fff; font-size: 14px; }
.check.on { background: var(--btn); border-color: var(--btn); }
.switch { width: 46px; height: 28px; border-radius: 99px; background: var(--sep); position: relative; flex: none; transition: .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch.on { background: #34c759; }
.switch.on::after { left: 21px; }
select.field { appearance: none; }

/* окно выбора при первом входе */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: end center; z-index: 20; }
.modal .box { background: var(--sec); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); text-align: center; }
.modal .box .big { font-size: 46px; }
.modal .box h2 { margin: 6px 0 6px; font-size: 20px; }
.modal .box p { color: var(--hint); margin: 0 0 16px; }
.modal .box .btn { margin-top: 8px; }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,35,.92); color: #fff; padding: 9px 14px; border-radius: 12px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 60; max-width: 90%; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.skel { background: linear-gradient(90deg, var(--sec) 0%, color-mix(in srgb, var(--hint) 12%, var(--sec)) 50%, var(--sec) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); height: 200px; margin-bottom: 12px; }
@keyframes sk { to { background-position: -200% 0; } }

.card .nopv { display: grid; place-items: center; font-size: 40px; }
.fcount { text-align: center; min-width: 64px; color: var(--hint); }
.fcount b { display: block; color: var(--text); font-size: 15px; }
.fcount span { font-size: 11px; }
.savebar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--sec); border-top: 1px solid var(--sep); z-index: 10; }
.savebar .btn { max-width: 616px; margin: 0 auto; }

.foot { text-align: center; margin: 18px 0 6px; }
.foot button { color: var(--hint); font-size: 13px; padding: 8px 12px; }
#view:has(.savebar) { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }

/* редактор набора */
.egrid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; user-select: none; -webkit-user-select: none; }
.eit { position: relative; aspect-ratio: 1; border-radius: 9px; background: var(--bg2); padding: 3px; touch-action: pan-y; -webkit-touch-callout: none; }
.eit img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.eit .em { position: absolute; right: 1px; bottom: 0; font-size: 9px; line-height: 1; }
.eit .ck { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; border: 1.5px solid var(--hint); background: var(--sec);
  display: none; place-items: center; font-size: 9px; color: #fff; }
.egrid.multi .eit .ck { display: grid; }
.eit.on { outline: 2px solid var(--btn); }
.eit.on .ck { background: var(--btn); border-color: var(--btn); }
.eit.hole { opacity: .25; }
.eit.ghost { position: fixed; z-index: 50; pointer-events: none; transform: scale(1.5); box-shadow: 0 8px 24px rgba(0,0,0,.25); background: var(--sec); }
.chipbtn { padding: 5px 12px; border-radius: 99px; background: color-mix(in srgb, var(--btn) 14%, var(--sec)); color: var(--accent); font-size: 13px; font-weight: 600; }
.selbar { position: fixed; left: 0; right: 0; bottom: 0; display: none; gap: 8px; align-items: center; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--sec); border-top: 1px solid var(--sep); z-index: 12; }
.selbar.on { display: flex; }
.btn.danger { background: var(--danger); color: #fff; }
body.busy { cursor: progress; }
body.busy #view { opacity: .6; pointer-events: none; }
a.like { text-decoration: none; }

.flags { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.flags span { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--bg2); color: var(--hint); }
.flags span.fon { color: var(--accent); background: color-mix(in srgb, var(--btn) 12%, var(--sec)); }
.hero .acts { flex-wrap: wrap; }

.cbtns { display: flex; gap: 6px; flex: none; }

/* адаптивные эмодзи: Телеграм красит их в цвет текста - в светлой теме чёрные, в тёмной белые.
   Фильтр только на саму картинку: фон под ней прозрачный (иначе фильтр перекрасит и фон). */
.card.adapt .pv { background: transparent; }
.card.adapt .pv, .egrid.adapt img, .pick.adapt img, img.adimg { filter: brightness(0) invert(1); }
body.light .card.adapt .pv, body.light .egrid.adapt img, body.light .pick.adapt img, body.light img.adimg { filter: brightness(0); }
.ava.emo.adapt img { filter: brightness(0); }
.th-night .ava.emo.adapt img, .hero.th-night .ava.emo.adapt img { filter: brightness(0) invert(1); }

/* создание из файлов */
.kinds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kind { background: var(--bg2); border-radius: 14px; padding: 12px 6px 10px; text-align: center; border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text); }
.kind.on { border-color: var(--accent); }
.kind .ki { font-size: 26px; line-height: 1.2; }
.kind b { font-size: 14px; font-weight: 600; }
.kind span:last-child { font-size: 11px; color: var(--hint); }
.fgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ft { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden;
  background: repeating-conic-gradient(var(--bg2) 0 25%, color-mix(in srgb, var(--hint) 14%, var(--bg2)) 0 50%) 0 0 / 14px 14px; }
.ft img, .ft video { width: 100%; height: 100%; object-fit: contain; display: block; }
.ft .tgs { display: grid; place-items: center; height: 100%; font-weight: 700; color: var(--hint); }
.ft .x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.55);
  color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0; }
.ft .bd { position: absolute; left: 4px; bottom: 4px; font-size: 9px; background: rgba(0,0,0,.55); color: #fff; border-radius: 6px; padding: 2px 5px; }
.ft.add { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--accent); font-size: 26px;
  border: 2px dashed var(--sep); background: transparent; }
.ft.add span { font-size: 11px; }
.ft .st { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: #fff; pointer-events: none; }
.ft .st.ok { background: rgba(52,199,89,.35); }
.ft .st.bad { background: rgba(255,59,48,.45); }
.small-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; max-height: 180px; overflow-y: auto; }
.prog { height: 10px; border-radius: 99px; background: var(--sep); overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--btn); border-radius: 99px; transition: width .3s; }
.ft .ep { position: absolute; right: 4px; bottom: 4px; width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,.9);
  color: #222; font-size: 13px; display: grid; place-items: center; padding: 0; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.ft .ep.on { background: var(--btn); color: var(--btn-text); }
.ft[data-e] { cursor: pointer; }

/* редактор картинки */
body.noscroll { overflow: hidden; }
.ed { position: fixed; inset: 0; z-index: 40; background: var(--bg2); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top); }
.edtop { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; }
.edtop b { font-size: 16px; }
.edtop .btn { padding: 8px 14px; }
.edstage { padding: 0 12px; display: flex; justify-content: center; }
.edstage canvas { width: min(100%, 52vh, 420px); aspect-ratio: 1; border-radius: 18px; touch-action: none; display: block;
  background: repeating-conic-gradient(var(--sec) 0 25%, color-mix(in srgb, var(--hint) 18%, var(--sec)) 0 50%) 0 0 / 20px 20px;
  box-shadow: 0 0 0 1px var(--sep); }
.edhint { text-align: center; min-height: 18px; margin: 6px 12px 0; }
.edpanel { flex: 1; overflow-y: auto; padding: 8px 14px 10px; }
.edtabs { display: flex; justify-content: space-around; background: var(--sec); border-top: 1px solid var(--sep);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
.edtabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--hint); min-width: 58px; }
.edtabs button span { font-size: 19px; line-height: 1.2; font-weight: 700; }
.edtabs button.on { color: var(--accent); }
.esl { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; }
.esl i { font-style: normal; color: var(--hint); text-align: right; font-size: 12px; }
.esl input { width: 100%; accent-color: var(--btn); }
.erow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.eswatch { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.eswatch button, .eswatch .ecustom { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--sep); padding: 0; position: relative; overflow: hidden; }
.eswatch button.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.eswatch .ecustom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* создание: способы, составные, из набора */
.hows { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.hows button { background: var(--sec); border-radius: 14px; padding: 10px 4px; display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: 13px; font-weight: 600; color: var(--text); border: 2px solid transparent; }
.hows button span { font-size: 22px; }
.hows button.on { border-color: var(--accent); color: var(--accent); }
#tgtbox .h { margin-top: 4px; }
.srcrow { display: flex; gap: 8px; }
.srcrow .field { flex: 1; min-width: 0; }
.srcrow .btn { flex: none; }
.acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chipbtn.on { background: var(--btn); color: var(--btn-text); }
.sgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-height: 340px; overflow-y: auto; }
.sgrid.em { grid-template-columns: repeat(8, 1fr); }
.sgrid button { position: relative; aspect-ratio: 1; border-radius: 10px; background: var(--bg2); padding: 3px; border: 2px solid var(--accent); }
.sgrid button img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sgrid button .ck { position: absolute; top: 1px; right: 1px; width: 16px; height: 16px; border-radius: 50%; background: var(--btn);
  color: var(--btn-text); font-size: 10px; display: grid; place-items: center; }
.sgrid button .bd { position: absolute; left: 2px; bottom: 2px; font-size: 8px; background: rgba(0,0,0,.55); color: #fff; border-radius: 5px; padding: 1px 4px; }
.sgrid button.off { border-color: transparent; opacity: .4; }
.sgrid button.off .ck { display: none; }
.sgrid.adapt img { filter: brightness(0) invert(1); }
body.light .sgrid.adapt img { filter: brightness(0); }
.gwrap { display: flex; justify-content: center; margin-top: 12px; }
.gwrap canvas { border-radius: 10px; touch-action: none; cursor: grab;
  background: repeating-conic-gradient(var(--bg2) 0 25%, color-mix(in srgb, var(--hint) 14%, var(--bg2)) 0 50%) 0 0 / 14px 14px; }
.steps { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 10px 0 4px; font-size: 13px; flex-wrap: wrap; }
.steps span { color: var(--hint); }
.steps button { width: 30px; height: 30px; border-radius: 50%; background: color-mix(in srgb, var(--btn) 14%, var(--sec)); color: var(--accent); font-size: 18px; font-weight: 700; padding: 0; }
.steps b { min-width: 14px; text-align: center; }
.seg a { flex: 1; padding: 7px 4px; border-radius: 10px; color: var(--hint); font-size: 14px; text-align: center; }
.seg a.on { background: var(--btn); color: var(--btn-text); font-weight: 600; }
.modal .box { position: relative; }
.modal .box .mx { position: absolute; top: 10px; right: 12px; width: 30px; height: 30px; border-radius: 50%; padding: 0;
  background: color-mix(in srgb, var(--hint) 18%, transparent); color: var(--hint); font-size: 14px; display: grid; place-items: center; }
