/* Цвета берутся из темы Telegram пользователя (их подставляет telegram-web-app.js), ниже — запасные. */
@font-face { font-family: "Nick"; src: url("nick.otf") format("opentype"); font-weight: 800; font-display: swap; }
:root {
  --bg: var(--tg-theme-bg-color, #f4f5f9);
  --bg2: var(--tg-theme-secondary-bg-color, #e9ebf2);
  --card: var(--tg-theme-section-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #14161d);
  --hint: var(--tg-theme-hint-color, #7c8292);
  --acc: var(--tg-theme-button-color, #3478f6);
  --acc-fg: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--fg) 10%, transparent);
  --glow: color-mix(in srgb, var(--acc) 22%, transparent);
  --r: 18px;
  --display: "Nick", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 var(--body); }
body { min-height: 100vh; }
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(150px + env(safe-area-inset-bottom, 0px)); }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: var(--fg); }
[hidden] { display: none !important; }

/* шапка */
.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0 10px; background: linear-gradient(var(--bg) 70%, transparent); }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px 12px 4px 4px; border-radius: 99px; background: var(--card); }
.ava { width: 28px; height: 28px; border-radius: 50%; background: var(--acc) center/cover; flex: none;
  display: grid; place-items: center; color: var(--acc-fg); font-weight: 700; font-size: 13px; }
.uname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bal { display: flex; align-items: center; gap: 6px; border: 0; border-radius: 99px; background: var(--card); padding: 4px 4px 4px 12px; font-variant-numeric: tabular-nums; }
.gem { width: 14px; height: 14px; border-radius: 4px; background: var(--acc); transform: rotate(45deg) scale(.8); }
.plus { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--acc); color: var(--acc-fg); font-weight: 700; }

/* типографика */
h1, h2, h3 { font-family: var(--display); font-weight: 800; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
h1 { font-size: 30px; line-height: 1.08; }
h2 { font-size: 22px; line-height: 1.15; }
h3 { font-size: 16px; }
.hand { margin: 0 0 2px; color: var(--acc); font-style: italic; font-size: 13px; }
.sub { color: var(--hint); margin: 10px 0 14px; max-width: 46ch; }
.note, small { color: var(--hint); font-size: 12px; }
.empty { color: var(--hint); text-align: center; padding: 24px 0; margin: 0; }

/* главная */
.hero { margin: 6px 0 22px; padding: 18px; border-radius: 22px; background:
  radial-gradient(120% 80% at 100% 0%, var(--glow), transparent 60%), var(--card); }
.nickfield { display: grid; gap: 4px; padding: 10px 14px; border-radius: 14px; background: var(--bg2); }
.nickfield span { font-size: 12px; color: var(--hint); }
.nickfield input { border: 0; background: transparent; outline: 0; font: 800 20px/1.2 var(--display); padding: 0; }
.nickerr { color: #e5484d; font-size: 13px; margin: 6px 2px 0; }
.colors { display: flex; gap: 8px; margin-top: 12px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.colors::-webkit-scrollbar { display: none; }
.dot { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--line); }
.dot[aria-checked="true"] { box-shadow: 0 0 0 2px var(--acc); }
.dot.orig { background: conic-gradient(#ff6aa0, #ffb020, #33d699, #4c9aff, #9d66ff, #ff6aa0); }
.sechead { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 10px; }
.ghost { border: 0; background: var(--bg2); border-radius: 99px; padding: 8px 14px; font-weight: 600; font-size: 13px; }
.btn { border: 0; background: var(--acc); color: var(--acc-fg); border-radius: 14px; padding: 12px 18px; font-weight: 700; }
.btn:disabled { opacity: .5; }
.search input { width: 100%; border: 0; border-radius: 14px; background: var(--card); padding: 11px 14px; outline: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 13px; }
.chip.on { background: var(--acc); color: var(--acc-fg); }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tile { position: relative; aspect-ratio: 1; border-radius: var(--r); background: var(--card); border: 0; padding: 6px; overflow: hidden; }
.tile .anim { width: 100%; height: 100%; }
.tile .anim svg { display: block; }
.tile.on { box-shadow: 0 0 0 2.5px var(--acc) inset, 0 6px 18px var(--glow); }
.tile .chk { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--acc);
  color: var(--acc-fg); display: none; place-items: center; font-size: 13px; font-weight: 800; }
.tile.on .chk { display: grid; }
.tile .em { position: absolute; left: 7px; bottom: 5px; font-size: 13px; opacity: .8; }
.tile .ph { position: absolute; inset: 22%; border-radius: 50%; background: var(--bg2); }

/* плашка выбора и вкладки */
.cart { position: fixed; z-index: 6; left: 50%; transform: translateX(-50%); width: min(528px, calc(100% - 24px));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px)); display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 12px; border-radius: 20px; background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 8px 30px rgba(0,0,0,.18); }
.thumbs { display: flex; }
.thumbs span { width: 26px; height: 26px; border-radius: 50%; background: var(--bg2); display: grid; place-items: center;
  font-size: 14px; margin-left: -8px; border: 2px solid var(--card); }
.thumbs span:first-child { margin-left: 0; }
.cnt { flex: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.tabs { position: fixed; z-index: 7; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px max(12px, env(safe-area-inset-left, 0px)) calc(8px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); }
.tab { border: 0; background: none; display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--hint); padding: 6px 0; border-radius: 12px; }
.tab.on { color: var(--acc); }
.ic { width: 22px; height: 22px; display: block; background: currentColor;
  -webkit-mask: var(--m) center/contain no-repeat; mask: var(--m) center/contain no-repeat; }
.ic-home { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3l9 7.5V21h-6v-6H9v6H3V10.5z'/%3E%3C/svg%3E"); }
.ic-packs { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z'/%3E%3C/svg%3E"); }
.ic-me { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='8' r='4.5'/%3E%3Cpath d='M3 21c0-5 4-8 9-8s9 3 9 8z'/%3E%3C/svg%3E"); }

/* наборы и профиль */
.view > h2 { margin-bottom: 14px; }
.list { display: grid; gap: 10px; }
.pack { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--r); background: var(--card); }
.pack div { flex: 1; min-width: 0; }
.pack b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { padding: 14px; border-radius: var(--r); background: var(--card); display: grid; gap: 2px; }
.stat span { color: var(--hint); font-size: 13px; }
.stat b { font: 800 26px/1.1 var(--display); font-variant-numeric: tabular-nums; }
.card { padding: 16px; border-radius: var(--r); background: var(--card); margin-bottom: 12px; display: grid; gap: 12px; }
.cardhead { display: grid; gap: 2px; }
.pkgs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pkg { border: 0; border-radius: 14px; background: var(--bg2); padding: 12px 6px; display: grid; gap: 2px; justify-items: center; position: relative; }
.pkg b { font: 800 22px/1 var(--display); }
.pkg .price { font-weight: 700; }
.pkg .badge { position: absolute; top: -8px; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 99px; background: var(--acc); color: var(--acc-fg); }
.row2 { display: flex; gap: 8px; flex-wrap: wrap; }
.row2 > * { flex: 1 1 140px; }
.row2 input { border: 0; border-radius: 14px; background: var(--bg2); padding: 12px 14px; outline: 0; min-width: 0; }

/* лист */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheetbox { position: relative; width: min(560px, 100%); max-height: 88vh; overflow: auto; background: var(--bg);
  border-radius: 24px 24px 0 0; padding: 22px 16px calc(22px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 14px; }
.x { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--bg2); font-size: 20px; line-height: 1; }
.sumrow { display: flex; justify-content: space-between; padding: 12px 14px; border-radius: 14px; background: var(--card); }
.sumrow b { font-variant-numeric: tabular-nums; }
.big { width: 100%; padding: 15px; font-size: 16px; }
.progress { display: grid; justify-items: center; gap: 12px; padding: 18px 0 6px; text-align: center; }
.ring { width: 92px; height: 92px; border-radius: 50%; border: 6px solid var(--bg2); border-top-color: var(--acc); animation: spin 1s linear infinite; }
.ring.done { animation: none; border-color: #2fbf71; display: grid; place-items: center; font-size: 40px; color: #2fbf71; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(140px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 32px); text-align: center; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .ring { animation-duration: 3s; } }
