/* KV WALLET — окно оплаты.
   Дизайн один в один с KV SHOP: холодный графит и шлифованный металл,
   вид точного прибора. Цвета намеренно монохромные — единственное
   цветное пятно на экране это анимированные эмодзи. */

@font-face {
  font-family: "Unbounded";
  src: url("/fonts/unbounded-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
  font-weight: 400 800;
  font-display: swap;
}
@font-face {
  font-family: "Unbounded";
  src: url("/fonts/unbounded-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}
@font-face {
  font-family: "Golos";
  src: url("/fonts/golos-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "Golos";
  src: url("/fonts/golos-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --ink: #0a0c0e;
  --panel: #14171b;
  --panel-hi: #1c2126;
  --edge: rgba(255, 255, 255, 0.09);
  --edge-bright: rgba(255, 255, 255, 0.22);
  --steel: #e8edf2;
  --steel-dim: #9aa5b1;
  --steel-mute: #5d6772;
  --sheen: rgba(190, 226, 255, 0.55);
  --r: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  background: var(--ink);
  color: var(--steel);
  font: 400 16px/1.5 "Golos", -apple-system, BlinkMacSystemFont, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.muted { color: var(--steel-mute); font-size: 14px; }

/* ---------- Фон ---------- */
.bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

.bg-glow {
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(46% 32% at 50% 22%, rgba(122, 176, 224, 0.20), transparent 70%),
    radial-gradient(38% 26% at 82% 74%, rgba(96, 122, 148, 0.14), transparent 72%);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(-3%, -2%, 0) scale(1); }
  to   { transform: translate3d(3%, 3%, 0) scale(1.09); }
}

/* Тонкая вертикальная шлифовка — как на металле */
.bg-brush {
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.022) 0 1px,
    transparent 1px 3px
  );
  mask-image: radial-gradient(60% 50% at 50% 30%, #000 30%, transparent 100%);
}

/* Зерно: гасит банding градиентов и добавляет фактуру */
.bg-grain {
  position: absolute;
  inset: 0;
  opacity: 0.32;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

/* ---------- Каркас ---------- */
.shell {
  position: relative;
  z-index: 1;
  height: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 20px 20px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* Экран занят целиком: ввод суммы сверху, кнопки внизу, всё лишнее место
   забирает середина с суммой. Прокрутки нет — размеры на clamp(). */
#pay {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.4vh, 20px);
}

.hero {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.6vh, 26px);
}

.controls {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.8vh, 16px);
}

.reveal {
  opacity: 0;
  transform: translateY(14px);
  animation: rise 620ms cubic-bezier(0.16, 0.9, 0.24, 1) forwards;
  animation-delay: var(--d, 0ms);
}
@keyframes rise { to { opacity: 1; transform: none; } }

/* ---------- Ввод суммы ---------- */
/* Карточка на месте бывшей шапки заказа: сумма в долларах и быстрые кнопки. */
.entry {
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 var(--edge-bright), 0 12px 30px rgba(0, 0, 0, 0.45);
}

.entry-label {
  color: var(--steel-mute);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.entry-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.entry-usd {
  font-family: "Unbounded", sans-serif;
  font-weight: 600;
  font-size: 19px;
  color: var(--steel-dim);
  flex: none;
}

.entry-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  outline: none;
  color: var(--steel);
  font-family: "Unbounded", sans-serif;
  font-weight: 600;
  font-size: 24px;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  caret-color: var(--sheen);
}
.entry-input::placeholder { color: var(--steel-mute); }

.entry-clear {
  flex: none;
  align-self: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, #101317, #171b20);
  color: var(--steel-mute);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms ease, color 140ms ease;
}
.entry-clear:active { transform: scale(0.92); color: var(--steel-dim); }

/* Быстрые суммы: +1 +5 +10 +20 */
.presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 11px;
}

.preset {
  padding: 8px 4px;
  border-radius: 11px;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, #262c33, #191e23);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 12px rgba(0, 0, 0, 0.35);
  color: var(--steel-dim);
  font-family: "Unbounded", sans-serif;
  font-weight: 500;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform 120ms ease, color 140ms ease, border-color 140ms ease;
}
.preset:active {
  transform: translateY(1px) scale(0.97);
  color: var(--steel);
  border-color: var(--edge-bright);
}

.amount-note {
  margin-top: 8px;
  color: var(--steel-mute);
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---------- Медальон с анимацией ---------- */
.medallion {
  position: relative;
  width: clamp(150px, 40vw, 208px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  flex: none;
}

/* Ободок: тонкое кольцо с бегущим по нему бликом */
.medallion-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  padding: 1px;
  background: conic-gradient(
    from 0deg,
    rgba(255, 255, 255, 0.04),
    rgba(190, 226, 255, 0.55),
    rgba(255, 255, 255, 0.04) 45%,
    rgba(255, 255, 255, 0.04) 100%
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: spin 9s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

/* Свечение под анимацией — чтобы фигурка не висела в пустоте */
.medallion-glow {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, rgba(190, 226, 255, 0.16), transparent 62%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
  box-shadow: inset 0 1px 0 var(--edge-bright), 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: breathe 4.5s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: 0.8; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.03); }
}

.medallion-anim {
  position: relative;
  width: 74%;
  height: 74%;
}

/* ---------- Сумма ---------- */
.amount { text-align: center; }

.amount-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}

.amount-value {
  font-family: "Unbounded", sans-serif;
  font-weight: 700;
  font-size: clamp(44px, 16vw, 68px);
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  /* Полированный металл: светлая полоса по центру глифов */
  background: linear-gradient(176deg, #ffffff 8%, #cfd8e2 38%, #7f8b98 56%, #eef3f8 78%, #b6c1cd 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(150, 196, 240, 0.28));
  /* Цифры одной ширины — иначе при пересчёте строка дёргается по горизонтали */
  font-variant-numeric: tabular-nums;
  will-change: opacity, transform;
}

.amount-cur {
  font-family: "Unbounded", sans-serif;
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--steel-dim);
}

/* Пересчёт суммы — лёгкий подъём вместо резкой подмены цифр.
   Трогаем только прозрачность и сдвиг: их считает видеокарта. Размытие
   отсюда убрано намеренно — filter каждый кадр перерисовывал крупный текст
   вместе со свечением, и на телефоне прокрутка цифр дёргалась. По той же
   причине filter тут вообще не задаём: иначе он перекрыл бы подсветку. */
.amount-value.flip { animation: flip 380ms cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes flip {
  0% { opacity: 0.35; transform: translateY(-6px); }
  100% { opacity: 1; transform: none; }
}

/* ---------- Переключатель валют ---------- */
.switch {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 15px;
  background: linear-gradient(180deg, #101317, #171b20);
  border: 1px solid var(--edge);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.55);
}

.switch-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 11px;
  background: linear-gradient(180deg, #313943, #232a32);
  border: 1px solid var(--edge-bright);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transition: transform 320ms cubic-bezier(0.16, 0.9, 0.24, 1), width 320ms cubic-bezier(0.16, 0.9, 0.24, 1);
  pointer-events: none;
}

.cur {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: 0;
  color: var(--steel-mute);
  font-family: "Golos", sans-serif;
  font-weight: 600;
  font-size: 14.5px;
  padding: 9px 4px;
  border-radius: 11px;
  cursor: pointer;
  transition: color 220ms ease;
}
.cur[aria-pressed="true"] { color: var(--steel); }
.cur:disabled { opacity: 0.55; cursor: default; }

/* Сумма прямо на кнопке — видно оба варианта, не переключая наугад */
.cur-price {
  font-size: 12px;
  font-weight: 500;
  color: var(--steel-mute);
  font-variant-numeric: tabular-nums;
  transition: color 220ms ease;
  min-height: 15px;
}
.cur[aria-pressed="true"] .cur-price { color: var(--steel-dim); }

/* ---------- Кошелёк ---------- */
/* TON Connect рисует свою кнопку внутри — растягиваем её на всю ширину,
   чтобы она стояла в одну колонку с «Оплатить», а не висела по центру. */
.wallet { min-height: 46px; }
.wallet #ton-connect > div,
.wallet #ton-connect > div > div,
#ton-connect button { width: 100% !important; }

/* Кошелёк уже подключён — вместо большой кнопки компактная плашка,
   чтобы не занимала место и было видно, куда всё уйдёт. */
.wallet-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  border-radius: 13px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 var(--edge-bright);
}
.wallet-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6ee7a8;
  box-shadow: 0 0 10px rgba(110, 231, 168, 0.75);
  flex: none;
  animation: blink 2.4s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }

.wallet-addr {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  letter-spacing: 0.02em;
  color: var(--steel-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wallet-change {
  flex: none;
  background: none;
  border: 0;
  color: var(--steel-mute);
  font: inherit;
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ---------- Кнопка оплаты ---------- */
.cta {
  position: relative;
  width: 100%;
  padding: 17px 20px;
  border: 1px solid var(--edge-bright);
  border-radius: var(--r);
  background: linear-gradient(180deg, #e9eef4 0%, #c3ccd6 48%, #aab5c1 52%, #dbe3ea 100%);
  color: #10141a;
  font-family: "Unbounded", sans-serif;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.01em;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  transition: transform 140ms ease, box-shadow 220ms ease, opacity 220ms ease;
}
.cta:active:not(:disabled) { transform: translateY(2px) scale(0.995); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }
.cta:disabled { opacity: 0.4; cursor: default; }
.cta-label { position: relative; z-index: 1; }

/* Блик, пробегающий по металлу */
.cta-sheen {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 38%;
  left: -45%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.9), transparent);
  animation: sweep 3.6s ease-in-out infinite;
}
.cta:disabled .cta-sheen { animation: none; opacity: 0; }
@keyframes sweep {
  0%, 62% { left: -45%; }
  100% { left: 115%; }
}

.cta-ghost {
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  color: var(--steel);
  border-color: var(--edge);
  box-shadow: inset 0 1px 0 var(--edge-bright), 0 10px 26px rgba(0, 0, 0, 0.4);
  margin-top: 22px;
}

.hint {
  text-align: center;
  color: var(--steel-mute);
  font-size: 12.5px;
  letter-spacing: 0.01em;
}

/* ---------- Состояния ---------- */
.stage { text-align: center; padding: 30px 8px; }
.stage-icon { font-size: 46px; margin-bottom: 10px; }
.stage-title {
  font-family: "Unbounded", sans-serif;
  font-weight: 700;
  font-size: 25px;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

/* ---------- Предупреждение о балансе ---------- */
.warn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  border-radius: 13px;
  font-size: 13.5px;
  line-height: 1.35;
  color: #ffd7a8;
  background: rgba(255, 176, 92, 0.08);
  border: 1px solid rgba(255, 176, 92, 0.28);
  animation: rise 380ms cubic-bezier(0.16, 0.9, 0.24, 1);
}
.warn::before { content: "⚠"; flex: none; font-size: 15px; }

.manual-toggle {
  background: none;
  border: 0;
  color: var(--steel-mute);
  font: inherit;
  font-size: 13.5px;
  padding: 4px;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
.manual-toggle:active { color: var(--steel-dim); }

/* ---------- Ручная оплата ---------- */
/* Шапка со стрелкой прибита к верху экрана, остальное центрируется в остатке. */
#manual { gap: clamp(12px, 2.4vh, 20px); justify-content: flex-start; }

.sheet-head { display: flex; align-items: center; gap: 12px; flex: none; }
.back {
  width: 40px; height: 40px;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  box-shadow: inset 0 1px 0 var(--edge-bright);
  color: var(--steel);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms ease;
}
.back:active { transform: scale(0.94); }
.sheet-title {
  font-family: "Unbounded", sans-serif;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.sheet-sub { color: var(--steel-mute); font-size: 12.5px; letter-spacing: 0.03em; }

.sheet-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(12px, 2.2vh, 18px);
}

/* QR в оправе.
   line-height: 0 — чтобы снизу не набегал лишний отступ от строчного бокса.
   Пластина строго белая: сам QR рисует под собой белый прямоугольник, и любой
   другой оттенок вылезал бы каймой по краям. */
.qr-frame {
  position: relative;
  align-self: center;
  padding: 15px;
  border-radius: 24px;
  line-height: 0;
  background: linear-gradient(158deg, #333c46 0%, #1a1f25 42%, #0f1216 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    0 24px 54px rgba(0, 0, 0, 0.6);
}

/* Мягкий блик по верхней кромке оправы — намёк на скруглённый металл */
.qr-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(120% 70% at 22% -10%, rgba(190, 226, 255, 0.16), transparent 60%);
  pointer-events: none;
}

.qr {
  position: relative;
  width: clamp(150px, 46vw, 194px);
  aspect-ratio: 1;
  padding: 12px;
  border-radius: 14px;
  background: #fff;
  display: grid;
  place-items: center;
  line-height: 0;
}
.qr svg, .qr img, .qr canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.field {
  padding: 11px 13px;
  border-radius: 13px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 var(--edge-bright);
}
.field-accent { border-color: rgba(190, 226, 255, 0.3); }
.field-label {
  color: var(--steel-mute);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 5px;
}
.field-row { display: flex; align-items: center; gap: 10px; }
.field-value {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  color: var(--steel);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-value.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.copy {
  flex: none;
  background: none;
  border: 0;
  color: var(--sheen);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  padding: 4px 2px;
}
.copy.done { color: #6ee7a8; }

/* ---------- Салют ---------- */
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -12px;
  width: 7px;
  height: 11px;
  border-radius: 1px;
  opacity: 0;
  animation: fall var(--t) cubic-bezier(0.25, 0.6, 0.4, 1) forwards;
  animation-delay: var(--delay);
}
@keyframes fall {
  0% { opacity: 0; transform: translateY(-10px) rotate(0deg); }
  12% { opacity: 1; }
  100% { opacity: 0; transform: translateY(105vh) rotate(var(--spin)); }
}

/* ---------- Ожидание блокчейна ---------- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#waiting, #done { align-items: center; justify-content: center; gap: 4px; }
.medallion-wait { margin-bottom: 14px; }

/* Полоса «идёт процесс»: длительность неизвестна, поэтому бегунок, а не шкала */
.track {
  width: min(220px, 70%);
  height: 3px;
  margin-top: 20px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.track-run {
  width: 42%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--sheen), transparent);
  animation: run 1.5s ease-in-out infinite;
}
@keyframes run {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(250%); }
}

/* ---------- Чек ---------- */
.receipt {
  margin-top: 18px;
  padding: 12px 16px;
  border-radius: 13px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 var(--edge-bright);
  font-size: 14px;
  color: var(--steel-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.receipt b { color: var(--steel); font-weight: 600; }

/* ---------- Успех ---------- */
.done-anim { width: 120px; height: 120px; margin: 0 auto 6px; }
.done-burst {
  position: absolute;
  left: 50%;
  top: 34%;
  width: 220px;
  height: 220px;
  margin: -110px 0 0 -110px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--sheen), transparent 62%);
  opacity: 0;
  animation: burst 1100ms ease-out forwards;
  pointer-events: none;
}
@keyframes burst {
  0% { opacity: 0.85; transform: scale(0.3); }
  100% { opacity: 0; transform: scale(1.5); }
}

/* На низких экранах ужимаем медальон, чтобы всё влезло без прокрутки */
@media (max-height: 660px) {
  .medallion { width: clamp(112px, 26vh, 160px); }
  .amount-value { font-size: clamp(36px, 11vh, 52px); }
  .entry { padding: 10px 12px; }
  .presets { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal, .amount-value.flip, .done-burst { animation: none; opacity: 1; transform: none; }
  .cta-sheen, .bg-glow, .medallion-ring, .medallion-glow { animation: none; }
}
