:root {
  --bg: #0a0b13;
  --bg2: #10111c;
  --card: #151624;
  --field: #1c1d2e;
  --line: rgba(255, 255, 255, .09);
  --text: #f4f5fa;
  --muted: #9a9fb5;
  --accent: #9b4dff;
  --ok: #5fd39a;
  --bad: #ff6b81;
  --r: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(900px 420px at 80% -10%, rgba(120, 70, 255, .20), transparent 60%),
    radial-gradient(700px 380px at -10% 10%, rgba(40, 90, 255, .12), transparent 60%),
    var(--bg);
  min-height: 100vh;
}
#app { max-width: 620px; margin: 0 auto; padding: 0 16px calc(120px + var(--safe-b)); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 40px; line-height: 1.02; letter-spacing: -.035em; margin: 18px 0 6px; font-weight: 800; }
h2 { font-size: 22px; letter-spacing: -.02em; margin: 0; font-weight: 750; }
.lead { color: var(--muted); margin: 0 0 22px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 16px 0 4px; }
.brand { font-weight: 800; font-size: 26px; letter-spacing: -.04em; }
.brand span { color: var(--muted); font-weight: 600; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #fff; color: #111; display: grid; place-items: center; font-weight: 800; border: 4px solid rgba(255, 255, 255, .12); background-clip: padding-box; }

/* шаблоны */
.tpl {
  display: block; width: 100%; text-align: left; border: 0; cursor: pointer; position: relative; overflow: hidden;
  border-radius: 32px; padding: 26px 24px 24px; margin: 0 0 14px; min-height: 168px; color: #fff;
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .7);
}
.tpl::before { content: ""; position: absolute; width: 260px; height: 260px; border-radius: 50%; right: -70px; top: -90px; background: rgba(255, 255, 255, .16); }
.tpl small { display: block; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; opacity: .8; position: relative; }
.tpl b { display: block; font-size: 38px; letter-spacing: -.04em; line-height: 1.05; margin: 4px 0 18px; position: relative; }
.tpl .go { position: relative; display: inline-flex; align-items: center; gap: 8px; background: #fff; color: #10101a; border-radius: 99px; padding: 12px 20px; font-weight: 700; }
.tpl.gold { background: linear-gradient(135deg, #6b3f06, #d9962a 58%, #ffd983); }
.tpl.legendary { background: linear-gradient(135deg, #3b36ff, #9b4dff 56%, #ff5fa2); }
.tpl.silver { background: linear-gradient(135deg, #343e52, #8497b0 58%, #dbe4ee); }

/* верхняя строка экрана */
.bar { display: flex; align-items: center; gap: 10px; margin: 10px 0 16px; }
.chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 99px; font-weight: 650; font-size: 14px; }
.chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.back { border: 1px solid var(--line); background: var(--card); width: 42px; height: 42px; border-radius: 50%; cursor: pointer; font-size: 20px; line-height: 1; }
.spacer { flex: 1; }
.ghost { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 99px; padding: 8px 14px; cursor: pointer; font-size: 14px; }

/* секции формы */
details.sec { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin: 0 0 12px; overflow: hidden; }
details.sec > summary { list-style: none; cursor: pointer; padding: 18px 18px; display: flex; align-items: center; justify-content: space-between; font-weight: 750; font-size: 18px; letter-spacing: -.01em; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after { content: "＋"; color: var(--muted); font-weight: 400; }
details.sec[open] > summary::after { content: "−"; }
.body { padding: 2px 16px 18px; display: grid; gap: 12px; }
label.f { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input[type=text], input:not([type]), input[type=number], select, textarea {
  width: 100%; background: var(--field); border: 1px solid transparent; border-radius: 14px; padding: 13px 14px; outline: none; color: var(--text); font-size: 16px;
}
textarea { resize: vertical; min-height: 78px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9a9fb5 50%), linear-gradient(135deg, #9a9fb5 50%, transparent 50%); background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 96px; gap: 10px; }

.dot { flex: none; width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--field); cursor: pointer; display: grid; place-items: center; padding: 0; }
.dot i { width: 18px; height: 18px; border-radius: 50%; display: block; }
.dot.g i, .dot.go i { background: #2fbf74; }
.dot.p i { background: #9b4dff; }
.dot.o i { background: #eeaa3e; }
.dot.gr i { background: #68d680; }
.line { display: flex; gap: 8px; align-items: center; }
.line input { flex: 1; min-width: 0; }

.stat { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 12px; display: grid; gap: 10px; }
.stat .head { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 14px; }
.stat .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--field); display: grid; place-items: center; font-size: 11px; font-weight: 800; color: var(--muted); overflow: hidden; }
.stat .ico img { width: 100%; height: 100%; object-fit: contain; }
.stat .vals { display: flex; gap: 8px; align-items: center; }
.stat .vals input[type=text] { flex: 1; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); }
.stat textarea { min-height: 64px; font-size: 14px; }

.item { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 12px; display: grid; gap: 8px; }
.item .t { font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.thumb { width: 54px; height: 54px; border-radius: 12px; object-fit: cover; background: var(--field); }

.portrait { display: flex; gap: 14px; align-items: center; }
.portrait .ph { width: 84px; height: 100px; border-radius: 14px; background: var(--field); border: 1px dashed rgba(255, 255, 255, .25); display: grid; place-items: center; color: var(--muted); font-size: 12px; overflow: hidden; flex: none; }
.portrait .ph img { width: 100%; height: 100%; object-fit: cover; }

/* кнопки */
.btn { border: 0; cursor: pointer; border-radius: 99px; padding: 16px 22px; font-weight: 750; font-size: 17px; background: #fff; color: #10101a; display: inline-flex; gap: 10px; justify-content: center; align-items: center; }
.btn.block { width: 100%; }
.btn.alt { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.primary { background: linear-gradient(135deg, #4a3bff, #9b4dff 60%, #ff5fa2); color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(14px + var(--safe-b)); background: linear-gradient(to top, var(--bg) 55%, transparent); display: flex; justify-content: center; z-index: 5; }
.dock .btn { width: 100%; max-width: 588px; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .8); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }

/* превью */
.shot { position: relative; background: #000; border-radius: 18px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 16 / 9; }
.shot img { width: 100%; height: 100%; display: block; }
.shot .wait { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 9, 16, .72); color: var(--muted); }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: sp .8s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--field); border-radius: 99px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 11px; border-radius: 99px; cursor: pointer; color: var(--muted); font-weight: 650; }
.seg button.on { background: #fff; color: #10101a; }
.count { text-align: right; font-size: 12px; color: var(--muted); }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 12px; }

.done { text-align: center; padding: 40px 6px; }
.done .ok { width: 84px; height: 84px; border-radius: 50%; background: rgba(95, 211, 154, .14); color: var(--ok); display: grid; place-items: center; font-size: 42px; margin: 0 auto 18px; }

/* кроппер */
.modal { position: fixed; inset: 0; background: rgba(5, 6, 12, .92); z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px; }
.view { position: relative; overflow: hidden; border-radius: 16px; background: #000; touch-action: none; outline: 2px solid var(--accent); cursor: grab; }
.view canvas { display: block; }
.modal input[type=range] { width: min(340px, 86vw); accent-color: var(--accent); }
.modal .actions { width: min(340px, 86vw); margin: 0; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #fff; color: #10101a; padding: 12px 18px; border-radius: 99px; font-weight: 650; opacity: 0; pointer-events: none; transition: .25s; z-index: 30; max-width: 92vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }

@media (min-width: 560px) { h1 { font-size: 48px; } }

/* окно выбора спрайта */
.modal.pick { justify-content: flex-start; align-items: stretch; overflow-y: auto; padding: 0; background: rgba(6, 7, 13, .97); }
.sheet { width: 100%; max-width: 620px; margin: 0 auto; padding: 12px 16px 40px; display: grid; gap: 12px; align-content: start; }
.sheet .bar { margin: 0; position: sticky; top: 0; background: rgba(6, 7, 13, .97); padding: 8px 0; z-index: 2; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.cell { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 8px; cursor: pointer; display: grid; gap: 4px; justify-items: center; text-align: center; font-size: 12px; line-height: 1.2; min-width: 0; }
.cell img { width: 76px; height: 76px; object-fit: contain; }
.cell span { overflow-wrap: anywhere; }
.cell small { color: var(--muted); font-size: 11px; }
.cell.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.pickbtn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: var(--field); border: 1px solid transparent; border-radius: 14px; padding: 8px 12px; cursor: pointer; text-align: left; }
.pickbtn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb.plus { display: grid; place-items: center; color: var(--muted); font-size: 24px; border: 1px dashed rgba(255, 255, 255, .25); background: transparent; }
.thumb { object-fit: contain; }
.line.wrap { flex-wrap: wrap; }
input[type=color] { width: 100%; height: 46px; padding: 4px; background: var(--field); border: 0; border-radius: 14px; }
input[type=search] { width: 100%; background: var(--field); border: 1px solid transparent; border-radius: 14px; padding: 13px 14px; outline: none; color: var(--text); font-size: 16px; }
input[type=search]:focus { border-color: var(--accent); }
[hidden] { display: none !important; }
.modal.pick { background: #06070d; }
.sheet h2 { font-size: 18px; line-height: 1.15; }
.sheet .bar .small { white-space: nowrap; }
