/* ============================================================
   Magic Upgrade — вертикальная мини-аппа 9:16
   Пиксельная стилистика: шрифт Press Start 2P, блочные рамки,
   никаких скруглений. У шрифта одно начертание, поэтому
   font-weight везде 400 — синтетический жир мылит пиксели.
   ============================================================ */
:root {
  --sky-0: #0b0a2a;
  --violet: #8b4cf0;
  --violet-soft: #b98bff;
  --violet-dark: #4a1fa0;
  --gold: #ffc043;
  --gold-soft: #ffe08a;
  --gold-dark: #a86d00;
  --green: #35d67f;
  --green-dark: #148a4a;
  --red: #ff5d6c;
  --text: #f2edff;
  --muted: #a99fd4;
  --card: rgba(28, 20, 66, 0.8);
  --card-line: #6b4bb8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--sky-0);
  color: var(--text);
  font-family: "Press Start 2P", "Courier New", monospace;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
  font-synthesis: none;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button, input { font-family: inherit; font-weight: 400; }

/* Пиксельные иконки из спрайта */
.ic {
  width: 1em;
  height: 1em;
  fill: currentColor;
  shape-rendering: crispEdges;
  display: block;
  flex: 0 0 auto;
}

/* ---------------------------------------------------------- сцена и фон */
.stage {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-width: 480px;           /* 9:16 на широких экранах */
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  /* clip вместо hidden: фон шире кадра, и с hidden браузер прокручивал
     контейнер вбок, когда кнопка получала фокус. clip запрещает прокрутку. */
  overflow: hidden;
  overflow: clip;
  isolation: isolate;
}

.bg-sky, .bg-art, .bg-stars, .bg-vignette {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.bg-sky {
  background:
    radial-gradient(120% 60% at 78% 8%,  rgba(120, 90, 220, 0.35) 0%, transparent 60%),
    radial-gradient(90% 50% at 20% 0%,   rgba(70, 50, 170, 0.35) 0%, transparent 65%),
    linear-gradient(180deg, #0a0926 0%, #140f44 38%, #1b1355 62%, #241a6b 100%);
}

/* Арт квадратный, а кадр вертикальный: прижимаем его к низу собственным
   блоком и растворяем верх в небе — маска считается от размеров картинки,
   поэтому шва не видно на любой высоте экрана. */
.bg-art {
  inset: auto auto 0 50%;
  width: 132%;
  transform: translateX(-50%);
  aspect-ratio: 1;
  background-image: url("assets/bg.webp");
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: 100% 100%;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,.28) 20%, rgba(0,0,0,.8) 42%, #000 60%);
          mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,.28) 20%, rgba(0,0,0,.8) 42%, #000 60%);
  opacity: .96;
}

.bg-stars { overflow: hidden; }
.bg-stars i {
  position: absolute;
  width: 2px; height: 2px;
  background: #fff;
  opacity: 0;
  animation: twinkle 3.6s steps(3, end) infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: .12; }
  50%      { opacity: .95; }
}

.bg-vignette {
  background:
    radial-gradient(80% 55% at 50% 42%, transparent 0%, rgba(6, 4, 24, .55) 100%),
    linear-gradient(180deg, rgba(6,4,24,.55) 0%, transparent 22%, transparent 70%, rgba(6,4,24,.72) 100%);
}

/* ---------------------------------------------------------------- шапка */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 8px;
  flex: 0 0 auto;
}

.balance {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  background: var(--card);
  border: 2px solid var(--card-line);
  font-size: 15px;
  line-height: 1;
}
.balance .cur { color: var(--muted); font-size: 10px; }
.ton-ico { width: 17px; height: 17px; display: block; image-rendering: pixelated; }

.wallet-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 12px;
  font-size: 11px;
  line-height: 1;
  color: #2a1a00;
  background: var(--gold);
  border: 2px solid var(--gold-dark);
  box-shadow: inset 2px 2px 0 var(--gold-soft), inset -2px -2px 0 var(--gold-dark);
  cursor: pointer;
  white-space: nowrap;
}
.wallet-btn .ic { font-size: 14px; }
.wallet-btn:active { transform: translate(1px, 1px); }
.wallet-btn.connected {
  background: var(--card);
  border-color: var(--card-line);
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.1), inset -2px -2px 0 rgba(0,0,0,.35);
  color: var(--text);
  font-size: 10px;
}

/* -------------------------------------------------------------- контент */
.content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-overflow-scrolling: touch;
  padding: 2px 14px 14px;
}

.view { display: flex; flex-direction: column; align-items: center; }
.view[hidden] { display: none; }

.title {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.3;
  color: var(--gold);
  text-shadow: 3px 3px 0 #5a2a00;
}
.subtitle { margin: 4px 0 10px; font-size: 10px; color: var(--muted); text-align: center; }
.subtitle span { color: var(--violet-soft); }

/* --------------------------------------------------------------- колесо */
.wheel-wrap {
  position: relative;
  width: min(66vw, 250px);
  aspect-ratio: 1;
  margin: 0 0 12px;
  display: grid;
  place-items: center;
}

.wheel-glow {
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(150, 100, 255, .38) 0%, transparent 62%);
  filter: blur(14px);
  animation: pulse 3.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity:.55; } 50% { opacity:1; } }

.wheel { position: absolute; inset: 0; width: 100%; height: 100%; }

.ring-base {
  fill: rgba(12, 8, 38, .6);
  stroke: var(--card-line);
  stroke-width: 2;
}
.ring-arc {
  fill: none;
  stroke-width: 18;
  stroke-linecap: butt;
  transition: stroke-dasharray .25s steps(6, end);
}

.pointer { transform-origin: 150px 150px; transform: rotate(0deg); }
.pointer.spinning { transition: transform 3.6s cubic-bezier(.12, .72, .12, 1); }
.pointer-stem { stroke: #fff; stroke-width: 4; opacity: .92; }
.pointer-head { fill: var(--gold); }
.pointer-hub  { fill: #fff; stroke: var(--gold-dark); stroke-width: 3; }

.wheel-center {
  position: relative;
  width: 46%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(60, 35, 130, .85) 0%, rgba(20, 12, 52, .92) 70%);
  border: 2px solid var(--card-line);
  box-shadow: inset 0 0 26px rgba(140, 90, 255, .35);
}
.hat {
  width: 76%;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .6));
  animation: float 3.2s steps(8, end) infinite;
}
@keyframes float { 0%,100% { transform: translateY(-3px); } 50% { transform: translateY(4px); } }

.wheel-wrap.rolling .hat { animation: shake .24s steps(2, end) infinite; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  50%     { transform: translate(-2px, 2px); }
}

/* ------------------------------------------------- ползунок режимов */
.mode-picker {
  width: 100%;
  padding: 10px 12px 6px;
  margin-bottom: 12px;
  background: var(--card);
  border: 2px solid var(--card-line);
}

.mode-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  line-height: 1;
}
.mode-cost   { font-size: 17px; color: var(--gold); }
.mode-chance { font-size: 17px; color: var(--green); }

/* Пиксельный range: квадратный трек и квадратный ползунок */
#modeSlider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
#modeSlider::-webkit-slider-runnable-track {
  height: 12px;
  background: #1a1040;
  border: 2px solid var(--violet-dark);
  box-shadow: inset 2px 2px 0 rgba(0,0,0,.5);
}
#modeSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px;
  margin-top: -9px;
  background: var(--gold);
  border: 2px solid var(--gold-dark);
  box-shadow: inset 2px 2px 0 var(--gold-soft), inset -2px -2px 0 var(--gold-dark);
}
#modeSlider::-moz-range-track {
  height: 12px;
  background: #1a1040;
  border: 2px solid var(--violet-dark);
}
#modeSlider::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 0;
  background: var(--gold);
  border: 2px solid var(--gold-dark);
}
#modeSlider:active::-webkit-slider-thumb { background: var(--gold-soft); }
#modeSlider:disabled { opacity: .5; cursor: default; }

.mode-marks { display: flex; }
.mode-mark {
  flex: 1;
  background: none;
  border: 0;
  padding: 2px 0;
  font-size: 9px;
  line-height: 1.5;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}
.mode-mark:first-child { text-align: left; }
.mode-mark:last-child  { text-align: right; }
.mode-mark b { display: block; font-size: 11px; font-weight: 400; }
.mode-mark.active   { color: var(--text); }
.mode-mark.active b { color: var(--gold); }

/* --------------------------------------------------------------- кнопки */
.cta {
  width: 100%;
  padding: 15px 8px;
  font-size: 14px;
  line-height: 1.3;
  color: #fff;
  background: var(--violet);
  border: 2px solid #2d1370;
  box-shadow: inset 3px 3px 0 #b07bff, inset -3px -3px 0 var(--violet-dark);
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0,0,0,.45);
}
.cta:active { transform: translate(1px, 1px); box-shadow: inset 2px 2px 0 var(--violet-dark); }
.cta:disabled {
  background: #3b3360;
  border-color: #241f3d;
  box-shadow: inset 3px 3px 0 #544a80, inset -3px -3px 0 #241f3d;
  color: #a79ecf;
  cursor: default;
}

.ghost {
  width: 100%;
  margin-top: 8px;
  padding: 12px 8px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--card-line);
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.08), inset -2px -2px 0 rgba(0,0,0,.4);
  cursor: pointer;
}
.ghost:active { transform: translate(1px, 1px); }

/* -------------------------------------------------------------- профиль */
.profile-head {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px;
  margin: 6px 0 10px;
  background: var(--card);
  border: 2px solid var(--card-line);
}
.avatar {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 28px;
  color: var(--violet-soft);
  background: var(--violet-dark);
  border: 2px solid var(--card-line);
  flex: 0 0 auto;
}
.profile-meta { min-width: 0; }
.pname { font-size: 13px; line-height: 1.5; }
.pwallet {
  font-size: 9px; color: var(--muted); line-height: 1.6;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.stats-row { display: flex; gap: 8px; width: 100%; margin-bottom: 12px; }
.stat {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px;
  background: var(--card);
  border: 2px solid var(--card-line);
}
.stat b { font-size: 16px; font-weight: 400; color: var(--gold); line-height: 1; }
.stat small { font-size: 9px; color: var(--muted); line-height: 1; }

.section-title {
  align-self: flex-start;
  margin: 2px 0 8px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.prize-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}

.prize-card {
  padding: 7px 5px 6px;
  background: var(--card);
  border: 2px solid var(--card-line);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  /* Без fill-mode: карточка видна сама по себе, анимация — только украшение.
     С `both` карточки, отрисованные на скрытой вкладке, залипали на opacity 0. */
  animation: popIn .2s steps(4, end);
}
@keyframes popIn { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }

.prize-card .thumb {
  width: 100%;
  aspect-ratio: 1;
  background: radial-gradient(circle at 50% 40%, rgba(120, 70, 220, .5), rgba(16, 10, 44, .9));
  display: grid; place-items: center;
  border: 2px solid var(--violet-dark);
}
.prize-card .thumb img { width: 82%; image-rendering: pixelated; }
.prize-card .pv { font-size: 9px; color: var(--gold); line-height: 1; }

.wd-btn {
  width: 100%;
  padding: 6px 1px;
  font-size: 8px;
  line-height: 1.2;
  color: #05230f;
  background: var(--green);
  border: 2px solid var(--green-dark);
  box-shadow: inset 2px 2px 0 #9dffc8, inset -2px -2px 0 var(--green-dark);
  cursor: pointer;
}
.wd-btn:active { transform: translate(1px, 1px); }
.wd-btn.pending {
  background: #3a2f10;
  border-color: var(--gold-dark);
  box-shadow: none;
  color: var(--gold-soft);
  cursor: default;
}

.empty { color: var(--muted); font-size: 10px; text-align: center; margin-top: 16px; line-height: 1.8; }
.empty[hidden] { display: none; }

/* --------------------------------------------------------------- таббар */
.tabbar {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 7px 10px calc(7px + var(--safe-bottom));
  background: rgba(10, 6, 32, .9);
  border-top: 2px solid var(--card-line);
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 0;
  border: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
}
.tab .ic { font-size: 20px; }
.tab.active {
  color: var(--gold);
  background: var(--violet-dark);
  border-color: var(--card-line);
}

/* -------------------------------------------------------------- модалки */
.modal {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid; place-items: center;
  padding: 18px;
  background: rgba(5, 3, 20, .85);
  animation: fade .15s steps(3, end);
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 340px;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 20px 16px 16px;
  text-align: center;
  background: #1b1350;
  border: 3px solid var(--card-line);
  box-shadow: inset 3px 3px 0 rgba(255,255,255,.08), inset -3px -3px 0 rgba(0,0,0,.45),
              0 16px 0 rgba(0,0,0,.35);
  animation: rise .18s steps(4, end);
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.modal-card h2 { margin: 0 0 10px; font-size: 16px; font-weight: 400; color: var(--gold); line-height: 1.4; }
.modal-card p { margin: 0 0 14px; font-size: 10px; color: var(--muted); line-height: 1.8; }

.modal-hat {
  width: 112px;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 26px rgba(255, 192, 67, .6));
  animation: prizePop .4s steps(6, end);
}
@keyframes prizePop { from { transform: scale(.2); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-card.lose .modal-hat { filter: grayscale(1) brightness(.5); animation: none; opacity: .5; }
.modal-card.lose h2 { color: var(--muted); }

.burst {
  position: absolute;
  top: 70px; left: 50%;
  width: 220px; height: 220px;
  transform: translate(-50%, -50%);
  background: repeating-conic-gradient(from 0deg,
              rgba(255, 192, 67, .22) 0deg 5deg,
              transparent 5deg 24deg);
  border-radius: 50%;
  -webkit-mask-image: radial-gradient(circle, #000 18%, rgba(0,0,0,.55) 45%, transparent 72%);
          mask-image: radial-gradient(circle, #000 18%, rgba(0,0,0,.55) 45%, transparent 72%);
  animation: spinSlow 12s steps(60, end) infinite;
  pointer-events: none;
}
.modal-card.lose .burst { display: none; }
@keyframes spinSlow { to { transform: translate(-50%,-50%) rotate(360deg); } }

.amount-row { display: flex; gap: 6px; margin-bottom: 10px; }
.amt {
  flex: 1; padding: 11px 0;
  border: 2px solid var(--card-line);
  background: #150e3d;
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.amt.active { background: var(--violet-dark); border-color: var(--violet-soft); color: var(--gold); }

#depositAmount {
  width: 100%;
  padding: 13px;
  margin-bottom: 12px;
  border: 2px solid var(--card-line);
  background: #0d0830;
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  text-align: center;
}

.manual { margin: 14px 0 6px; text-align: left; }
.manual summary { cursor: pointer; font-size: 10px; color: var(--violet-soft); margin-bottom: 8px; line-height: 1.8; }
.modal-card label {
  display: block;
  margin: 9px 0 5px;
  font-size: 9px; color: var(--muted);
  text-align: left;
  line-height: 1.6;
}
.copy-row { display: flex; gap: 6px; align-items: stretch; }
.copy-row code {
  flex: 1; min-width: 0;
  padding: 9px;
  background: #0d0830;
  border: 2px solid var(--card-line);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: left;
}
.copy-row button {
  flex: 0 0 auto;
  border: 2px solid var(--card-line);
  padding: 0 10px;
  background: var(--violet-dark);
  color: var(--text);
  font-size: 9px;
  cursor: pointer;
}
.warn { margin-top: 10px !important; font-size: 9px !important; color: var(--gold-soft) !important; }

/* ----------------------------------------------------------------- тост */
.toast {
  position: fixed;
  left: 50%; bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 90;
  max-width: 88vw;
  padding: 11px 14px;
  background: #1b1350;
  border: 2px solid var(--card-line);
  font-size: 10px;
  line-height: 1.6;
  box-shadow: 0 8px 0 rgba(0,0,0,.35);
  animation: rise .15s steps(3, end);
}
.toast[hidden] { display: none; }
.toast.err { border-color: var(--red); color: #ffc9ce; }

@media (max-height: 700px) {
  .wheel-wrap { width: min(50vw, 195px); }
  .title { font-size: 18px; }
  .cta { padding: 12px 8px; font-size: 12px; }
  .mode-cost, .mode-chance { font-size: 14px; }
}
