:root {
  --bg-0: #0b0b0d;
  --bg-1: #161619;
  --line: rgba(255, 255, 255, 0.10);
  --line-2: rgba(255, 255, 255, 0.18);
  --text: #f4f5f7;
  --text-dim: #9a9ca3;
  --silver: #e7e9ee;
  --silver-dim: #c2c5cc;
  --glow: rgba(255, 255, 255, 0.30);
  --glass-bg: rgba(255, 255, 255, 0.045);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-height: 100%;   /* реальную высоту вьюпорта Telegram кладёт JS (syncViewport) */
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-0);
  user-select: none;
}
.hidden { display: none !important; }

/* ---------- Фон ---------- */
.bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(120% 85% at 50% -12%, #2b2c33 0%, #18181c 46%, var(--bg-0) 100%);
}
.bg::after { /* виньетка */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 100% at 50% 38%, transparent 52%, rgba(0,0,0,.55) 100%);
}
.orb {
  position: absolute; border-radius: 50%;
  filter: blur(58px); opacity: .5; will-change: transform;
}
.orb-a { width: 64vw; height: 64vw; left: -18vw; top: -12vh;
  background: radial-gradient(circle, #3b3e47 0%, transparent 70%);
  animation: drift-a 19s ease-in-out infinite; }
.orb-b { width: 58vw; height: 58vw; right: -20vw; bottom: -10vh;
  background: radial-gradient(circle, #24262d 0%, transparent 70%);
  animation: drift-b 24s ease-in-out infinite; }
.orb-c { width: 40vw; height: 40vw; left: 30vw; top: 34vh;
  background: radial-gradient(circle, rgba(255,255,255,.06) 0%, transparent 72%);
  animation: drift-c 16s ease-in-out infinite; }
.grain {
  position: absolute; inset: 0; opacity: .045; mix-blend-mode: overlay;
  background-image: radial-gradient(rgba(255,255,255,.7) 1px, transparent 1px);
  background-size: 3px 3px;
}
@keyframes drift-a { 50% { transform: translate(8vw, 6vh) scale(1.08); } }
@keyframes drift-b { 50% { transform: translate(-7vw, -5vh) scale(1.1); } }
@keyframes drift-c { 50% { transform: translate(-6vw, 4vh) scale(1.15); opacity: .9; } }

/* ---------- Glass ---------- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(120%);
  -webkit-backdrop-filter: blur(16px) saturate(120%);
  border: 1px solid var(--line);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  background: radial-gradient(circle at 50% 40%, #1c1c20, var(--bg-0));
  transition: opacity 0.5s ease;
}
.loader.fade { opacity: 0; pointer-events: none; }
.loader-ring { width: 58px; height: 58px; border-radius: 50%; border: 3px solid rgba(255,255,255,.12); border-top-color: var(--silver); animation: spin 0.9s linear infinite; }
.loader-title { font-size: 26px; font-weight: 800; letter-spacing: 8px; padding-left: 8px; background: linear-gradient(180deg,#fff,#9a9ca3); -webkit-background-clip: text; background-clip: text; color: transparent; }
.loader-text { color: var(--text-dim); font-size: 13px; letter-spacing: 1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- App layout ---------- */
.app {
  height: var(--app-height);
  display: grid; grid-template-rows: auto 1fr auto; gap: 12px;
  padding: calc(var(--safe-top) + 14px) 16px calc(var(--safe-bottom) + 16px);
  animation: appear 0.6s ease both;
}
@keyframes appear { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Profile ---------- */
.profile { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 16px; }
.pf-avatar {
  width: 46px; height: 46px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(145deg,#3a3d44,#1d1e22) center/cover no-repeat;
  border: 1px solid var(--line-2);
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px; color: var(--silver);
}
.pf-info { flex: 1; min-width: 0; }
.pf-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-user { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-right { display: flex; align-items: center; gap: 8px; }
.spins-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 11px; border-radius: 12px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
}
.ico-star { width: 18px; height: 18px; color: var(--silver); }
.spins-value { font-size: 17px; font-weight: 800; transition: transform .2s ease; }
.spins-value.bump { transform: scale(1.3); }
.spins-label { font-size: 11px; color: var(--text-dim); }

.icon-btn { position: relative; width: 44px; height: 44px; border-radius: 13px; color: var(--silver); display: flex; align-items: center; justify-content: center; cursor: pointer; background: rgba(255,255,255,.05); border: 1px solid var(--line); flex-shrink: 0; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.small { width: 36px; height: 36px; border-radius: 11px; color: var(--text-dim); }
.icon-btn.small svg { width: 18px; height: 18px; }
.badge { position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--silver); color: #16161a; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.5); }

/* ---------- Wheel ---------- */
.wheel-stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; }
.wheel-wrap { position: relative; width: min(82vw, 46vh, 360px); aspect-ratio: 1 / 1; }
.wheel-svg { width: 100%; height: 100%; display: block; }
.wheel-wrap.spinning .wheel-svg { filter: drop-shadow(0 0 18px rgba(255,255,255,.10)); }

.wheel-pointer {
  position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; z-index: 8;
  border-left: 13px solid transparent; border-right: 13px solid transparent; border-top: 22px solid var(--silver);
  filter: drop-shadow(0 2px 5px rgba(0,0,0,.6));
  transform-origin: 50% 0;  /* шарнир у самого кончика — стрелку «откидывает» о край */
  will-change: transform, opacity;
}

#wheelRotor { transform-box: fill-box; transform-origin: center; }
.seg-num { font-size: 17px; font-weight: 800; fill: #f4f5f7; }
.seg-star { fill: rgba(255,255,255,.55); }
.wheel-glow { transition: opacity .4s ease; opacity: 0; }
.wheel-wrap.win .wheel-glow { opacity: 1; animation: glowpulse .5s ease 2; }
@keyframes glowpulse { 50% { opacity: .35; } }

/* ---------- Центральная кнопка-звезда (спин) ---------- */
.hub-btn {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 37%; aspect-ratio: 1; border: none; background: none; padding: 0;
  display: grid; place-items: center; cursor: pointer; z-index: 7; touch-action: none;
}
.hub-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.hub-ring-bg { fill: none; stroke: rgba(255,255,255,.12); stroke-width: 5; }
.hub-ring-fill { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 276.46; stroke-dashoffset: 276.46; transition: stroke-dashoffset .05s linear; filter: drop-shadow(0 0 4px var(--glow)); }
.hub-core {
  grid-area: 1 / 1; width: 66%; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 36%, #f6f7f9, #9a9ca3);
  box-shadow: 0 5px 16px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.85);
  transition: transform .15s ease, box-shadow .15s ease;
}
.hub-star { width: 48%; color: #15151a; }
.hub-hint { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-dim); white-space: nowrap; }
.hub-btn.charging .hub-core { transform: scale(1.14); box-shadow: 0 6px 22px rgba(255,255,255,.35), inset 0 1px 0 rgba(255,255,255,.9); }
.hub-btn:active .hub-core { transform: scale(1.06); }
.hub-btn.disabled { opacity: .45; cursor: not-allowed; }
.hub-btn.nudge { animation: nudge .4s ease; }
@keyframes nudge { 20% { transform: translate(-54%,-50%); } 60% { transform: translate(-46%,-50%); } 100% { transform: translate(-50%,-50%); } }

/* ---------- Win banner (сверху) ---------- */
.win-banner {
  position: fixed; top: calc(var(--safe-top) + 10px); left: 50%;
  transform: translate(-50%, -180%); z-index: 60;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px 11px 14px; border-radius: 16px;
  transition: transform .5s cubic-bezier(.2,1.25,.3,1);
}
.win-banner.show { transform: translate(-50%, 0); }
.wb-star { width: 30px; height: 30px; color: var(--silver); filter: drop-shadow(0 0 8px var(--glow)); }
.wb-title { font-size: 12px; color: var(--text-dim); letter-spacing: .5px; }
.wb-amount { font-size: 19px; font-weight: 800; }

/* ---------- Leaderboard placeholder ---------- */
.leaderboard { position: relative; border-radius: 16px; padding: 13px 15px; overflow: hidden; }
.lb-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.lb-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.ico-trophy { width: 18px; height: 18px; color: var(--silver); }
.lb-soon { font-size: 10px; font-weight: 800; color: #15151a; background: var(--silver); padding: 3px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .5px; }
.lb-rows { display: flex; flex-direction: column; gap: 9px; filter: blur(2.5px); opacity: .45; }
.lb-row { display: flex; align-items: center; gap: 10px; }
.lb-rank { width: 22px; height: 22px; border-radius: 7px; background: rgba(255,255,255,.1); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.lb-bar { height: 11px; border-radius: 6px; background: linear-gradient(90deg, rgba(255,255,255,.22), rgba(255,255,255,.06)); }
.lb-overlay { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--text); letter-spacing: .3px; }

/* ---------- Inventory modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.6); animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card { width: 100%; max-width: 520px; max-height: 78vh; border-radius: 22px 22px 0 0; padding: 18px 16px calc(var(--safe-bottom) + 18px); display: flex; flex-direction: column; animation: slideup .3s ease; }
@keyframes slideup { from { transform: translateY(40px); } to { transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 700; }
.inventory-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.inv-empty { color: var(--text-dim); text-align: center; padding: 34px 0; font-size: 14px; }
.inv-item { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-radius: 14px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.inv-stars { display: flex; align-items: center; gap: 7px; font-size: 17px; font-weight: 800; }
.inv-stars svg { width: 17px; height: 17px; color: var(--silver-dim); }
.inv-right { display: flex; align-items: center; gap: 12px; }
.inv-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.inv-status svg { width: 14px; height: 14px; }
.inv-status.st-withdrawn { color: var(--silver); }
.inv-status.st-failed { color: #c98a8a; }
.withdraw-btn { border: 1px solid var(--line-2); border-radius: 11px; padding: 8px 15px; font-weight: 700; font-size: 13px; color: #15151a; cursor: pointer; background: linear-gradient(180deg,#fff,#c6c9d0); }
.withdraw-btn:disabled { color: var(--text-dim); background: rgba(255,255,255,.06); border-color: var(--line); cursor: default; }

.confetti { position: fixed; inset: 0; z-index: 45; pointer-events: none; }

/* ---------- Адаптация под экран ---------- */
/* Узкие телефоны — ужимаем профиль/шрифты, чтобы шапка не ломалась */
@media (max-width: 360px) {
  .app { gap: 10px; padding: calc(var(--safe-top) + 12px) 12px calc(var(--safe-bottom) + 12px); }
  .profile { gap: 9px; padding: 9px 10px; }
  .pf-avatar { width: 40px; height: 40px; border-radius: 12px; font-size: 15px; }
  .pf-name { font-size: 14px; }
  .spins-pill { padding: 6px 9px; }
  .spins-value { font-size: 15px; }
  .icon-btn { width: 40px; height: 40px; }
}

/* Низкие экраны (альбомная ориентация, маленькие устройства, развёрнутая клавиатура) —
   прячем лидерборд-заглушку и отдаём всё место колесу */
@media (max-height: 600px) {
  .app { gap: 8px; padding: calc(var(--safe-top) + 8px) 14px calc(var(--safe-bottom) + 8px); }
  .leaderboard { display: none; }
  .profile { padding: 7px 11px; }
  .wheel-wrap { width: min(78vw, 78vh, 340px); }
  .hub-hint { bottom: -17px; }
}
@media (max-height: 430px) {
  .wheel-wrap { width: min(52vw, 86vh, 300px); }
}

/* Очень крупные экраны — не растягиваем колесо до неприличия */
@media (min-width: 600px) {
  .app { max-width: 540px; margin: 0 auto; }
}
