/* ============================================================
   КОМПОНЕНТИ — бутони, карти-панели, модали, тостове, форми
   ============================================================ */

/* ---------- Бутони ---------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bd: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-5);
  border: 2px solid var(--btn-bd); border-radius: var(--r-md);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 800; font-size: 1rem; letter-spacing: .01em;
  cursor: pointer; user-select: none; text-decoration: none;
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease), background var(--dur) var(--ease);
  box-shadow: var(--shadow-1);
}
.btn:active:not(:disabled) { transform: translateY(2px) scale(.985); filter: brightness(.94); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn.primary   { --btn-bg: var(--brand); --btn-fg: var(--brand-ink); --btn-bd: transparent; }
.btn.gold      { --btn-bg: var(--gold);  --btn-fg: #23180a;         --btn-bd: transparent; }
.btn.danger    { --btn-bg: var(--danger);--btn-fg: #fff;            --btn-bd: transparent; }
.btn.ghost     { --btn-bg: transparent;  --btn-bd: var(--line); box-shadow: none; }
.btn.subtle    { --btn-bg: var(--surface-2); --btn-bd: transparent; box-shadow: none; }
.btn.block     { display: flex; width: 100%; }
.btn.lg        { min-height: calc(var(--tap) + 10px); font-size: 1.12rem; padding: 0 var(--sp-6); }
.btn.sm        { min-height: 40px; padding: 0 var(--sp-3); font-size: .9rem; border-radius: var(--r-sm); }
.btn.icon      { padding: 0; width: var(--tap); min-height: var(--tap); border-radius: var(--r-md); }
.btn .ic       { font-size: 1.25em; line-height: 1; }
.btn-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }

/* ---------- Панели / карти ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-4);
  box-shadow: var(--shadow-1);
}
.panel.pad0 { padding: 0; overflow: hidden; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.panel-h h2, .panel-h h3 { margin: 0; }

.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--sp-3); display: flex; flex-direction: column; gap: 2px;
}
.tile .k { font-size: .82rem; color: var(--text-mut); text-transform: uppercase; letter-spacing: .06em; }
.tile .v { font-size: 1.25rem; font-weight: 900; }

.grid { display: grid; gap: var(--sp-3); }
.grid.g2 { grid-template-columns: repeat(2, 1fr); }
.grid.g3 { grid-template-columns: repeat(3, 1fr); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (max-width: 460px) { .grid.g3 { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Значки / чипове ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .82rem; font-weight: 800; white-space: nowrap;
}
.badge.gold  { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); }
.badge.brand { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.badge.new   { background: var(--danger); border-color: transparent; color: #fff; }

.chipsel { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.chipsel button {
  min-height: 44px; padding: 0 var(--sp-4); border-radius: var(--r-pill);
  background: var(--surface-2); border: 2px solid transparent; color: var(--text);
  font-weight: 800; cursor: pointer;
}
.chipsel button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* ---------- Форми ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field > label { font-weight: 800; font-size: .95rem; }
.field .hint { font-size: .84rem; color: var(--text-mut); }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap);
  padding: 0 var(--sp-4);
  background: var(--surface-2); color: var(--text);
  border: 2px solid var(--line); border-radius: var(--r-md);
  outline: none;
}
textarea.input { padding: var(--sp-3) var(--sp-4); min-height: 90px; resize: vertical; line-height: 1.4; }
.input:focus { border-color: var(--brand); }
.input.err { border-color: var(--danger); }
.err-txt { color: var(--danger); font-size: .88rem; font-weight: 700; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  min-height: var(--tap); padding: var(--sp-2) 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 62px; height: 34px; border-radius: 99px; background: var(--surface-3);
  border: 2px solid var(--line); position: relative; flex: 0 0 auto; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 99px; background: var(--text-dim); transition: transform var(--dur) var(--ease), background var(--dur);
}
.switch input:checked + .track { background: var(--brand); border-color: var(--brand); }
.switch input:checked + .track::after { transform: translateX(28px); background: #fff; }

/* ---------- Сегментиран избор (варианти) ---------- */
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 4px; gap: 4px; }
.seg button {
  flex: 1; min-height: 44px; border: 0; border-radius: calc(var(--r-md) - 4px);
  background: transparent; color: var(--text-dim); font-weight: 800; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* ---------- Списъци ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--tap); padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line); background: var(--surface);
  text-align: left; width: 100%; border-left: 0; border-right: 0; border-top: 0;
  color: var(--text); cursor: pointer;
}
.list-item:last-child { border-bottom: 0; }
.list-item:active { background: var(--surface-2); }
.list-item .t { font-weight: 800; }
.list-item .s { font-size: .86rem; color: var(--text-mut); }

/* ---------- Топбар ---------- */
.topbar {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: calc(var(--safe-t) + var(--sp-3)) var(--sp-4) var(--sp-3);
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.topbar .brandmark { font-weight: 900; letter-spacing: .04em; font-size: 1.05rem; display: flex; gap: 6px; align-items: center; }
.topbar .brandmark .sfx { color: var(--brand); }
.wallet { display: flex; gap: var(--sp-2); margin-left: auto; align-items: center; }
.wallet .pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 6px 12px; font-weight: 900; font-size: .92rem;
  cursor: pointer;
}
.wallet .pill.coins { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }
.wallet .pill.tokens { color: var(--accent); }
.wallet .pill .plus { background: var(--brand); color: var(--brand-ink); border-radius: 99px;
  width: 22px; height: 22px; display: grid; place-content: center; font-size: .9rem; }

/* ---------- Таббар ---------- */
.tabbar {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--bg-2); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); position: sticky; bottom: 0; z-index: 40;
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 62px; border: 0; background: transparent; color: var(--text-mut);
  font-size: .74rem; font-weight: 800; cursor: pointer; position: relative;
}
.tabbar button .ic { font-size: 1.5rem; line-height: 1; display: grid; place-content: center; height: 28px; }
.tabbar button .ic svg { display: block; }
.tabbar button[aria-current="page"] { color: var(--brand); }
.tabbar button[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 4px;
  background: var(--brand); border-radius: 0 0 6px 6px;
}
.tabbar .dot { position: absolute; top: 8px; right: 26%; width: 10px; height: 10px;
  border-radius: 99px; background: var(--danger); }

/* ---------- Модали ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.62); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: var(--sp-4);
  animation: fade .18s var(--ease);
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: min(560px, 100%); max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: var(--sp-5);
  box-shadow: var(--shadow-3);
  animation: pop .24s var(--ease);
}
@keyframes pop { from { transform: translateY(18px) scale(.96); opacity: 0 } to { transform: none; opacity: 1 } }
.modal h2 { margin-bottom: var(--sp-2); }
.modal .modal-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); }
.modal .modal-actions .btn { flex: 1; }
.modal .x { position: sticky; top: 0; float: right; }

/* ---------- Тостове ---------- */
.toast-root {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b)); z-index: 300;
  display: flex; flex-direction: column; gap: var(--sp-2); align-items: center;
  pointer-events: none; width: min(520px, 92vw);
}
.toast {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 12px var(--sp-5); font-weight: 800; box-shadow: var(--shadow-2);
  animation: toastIn .25s var(--ease); text-align: center;
}
.toast.ok   { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.toast.bad  { background: var(--danger); color: #fff; border-color: transparent; }
.toast.gold { background: var(--gold); color: #23180a; border-color: transparent; }
@keyframes toastIn { from { transform: translateY(14px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- Аватари / рамки ---------- */
.ava {
  --size: 56px;
  width: var(--size); height: var(--size); flex: 0 0 auto;
  border-radius: 50%; display: grid; place-content: center;
  font-size: calc(var(--size) * .5); overflow: hidden; position: relative;
  background: var(--surface-3); border: 2px solid var(--line);
  background-size: cover; background-position: center;
}
.ava.xs { --size: 38px; } .ava.sm { --size: 46px; }
.ava.lg { --size: 92px; } .ava.xl { --size: 118px; }
.ava[data-frame="gold"]   { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft), 0 0 16px rgba(255,197,49,.5); }
.ava[data-frame="neon"]   { border-color: #29e0ff; box-shadow: 0 0 0 3px #0b3a45, 0 0 18px rgba(41,224,255,.6); }
.ava[data-frame="royal"]  { border-color: #b57bff; box-shadow: 0 0 0 3px #2b1b45, 0 0 18px rgba(181,123,255,.55); }
.ava[data-frame="fire"]   { border-color: #ff7a29; box-shadow: 0 0 0 3px #3d1c07, 0 0 20px rgba(255,122,41,.6); }
.ava[data-frame="laurel"] { border-color: #3ddc84; box-shadow: 0 0 0 3px #0f3b2b; }
.ava .lvl {
  position: absolute; bottom: -2px; right: -2px;
  background: var(--brand); color: var(--brand-ink); font-size: .62rem; font-weight: 900;
  border-radius: 99px; padding: 1px 6px; border: 2px solid var(--surface);
}

/* ---------- Прогрес ---------- */
.bar { height: 12px; border-radius: 99px; background: var(--surface-3); overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width .4s var(--ease); }

/* ---------- Празно състояние ---------- */
.empty { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--text-mut); }
.empty .em { font-size: 3rem; margin-bottom: var(--sp-3); }

/* ---------- Скролер хоризонтален ---------- */
.hscroll { display: flex; gap: var(--sp-3); overflow-x: auto; padding-bottom: var(--sp-2);
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
.hscroll > * { scroll-snap-align: start; flex: 0 0 auto; }
.hscroll::-webkit-scrollbar { height: 6px; }
.hscroll::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
