/* Цвета берутся из темы Telegram (переменные --tg-theme-* ставит telegram-web-app.js); запасные — светлая тема. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --text: var(--tg-theme-text-color, #16181d);
  --muted: var(--tg-theme-hint-color, #7d8592);
  --accent: var(--tg-theme-button-color, #3d7ff5);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #3d7ff5);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --warn-bg: rgba(245, 166, 35, .14);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17191e);
    --bg2: var(--tg-theme-secondary-bg-color, #22252c);
    --text: var(--tg-theme-text-color, #f2f3f5);
    --muted: var(--tg-theme-hint-color, #8b93a1);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; user-select: none;
}
#app { display: flex; flex-direction: column; height: 100%; max-width: 560px; margin: 0 auto; overflow-x: hidden; }
main { flex: 1; overflow-y: auto; padding: 0 16px 16px; }
h2 { font-size: 20px; margin: 16px 0 8px; }
h3 { font-size: 16px; margin: 18px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.tab { display: none; }
.tab.active { display: block; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 16px; background: var(--bg);
}
.who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance { font-size: 18px; white-space: nowrap; }

.card { background: var(--bg); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.card.warn { background: var(--warn-bg); margin: 12px 16px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row.gap { justify-content: flex-start; margin-top: 8px; flex-wrap: wrap; }

.btn {
  border: 0; border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 600;
  background: var(--accent); color: var(--accent-text); cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; color: var(--link); white-space: normal; text-align: left; }
.btn.wide { width: 100%; margin-top: 8px; }
input {
  flex: 1; min-width: 0; font: inherit; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--bg2); background: var(--bg2); color: var(--text); user-select: text;
}

/* --- кнопка добычи: кристалл в «шахте» с вращающимся радужным кольцом --- */
.tap-area {
  position: relative; display: flex; flex-direction: column; align-items: center;
  padding: 28px 0 8px; margin: 12px 0 0; border-radius: 24px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 42%, rgba(98, 76, 255, .28), transparent 62%),
              radial-gradient(ellipse at 50% 110%, rgba(54, 209, 255, .18), transparent 60%);
}
.tap-halo {
  position: absolute; top: 28px; width: 236px; height: 236px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(124, 92, 255, .55), rgba(54, 209, 255, .18) 55%, transparent 70%);
  animation: halo 2.6s ease-in-out infinite;
}
.tap {
  position: relative; width: 236px; height: 236px; border-radius: 50%; border: 0; padding: 0;
  background: none; cursor: pointer; touch-action: manipulation; outline: none;
  filter: drop-shadow(0 14px 28px rgba(40, 20, 120, .55));
}
.tap-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, #7c5cff, #36d1ff, #5effc1, #ffd86e, #ff7ad9, #7c5cff);
  animation: spin 7s linear infinite;
}
.tap-core {
  position: absolute; inset: 9px; border-radius: 50%; overflow: hidden; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 32%, #33388a 0%, #181b45 52%, #0a0c20 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .08), inset 0 0 36px rgba(124, 92, 255, .55),
              inset 0 -14px 34px rgba(0, 0, 0, .65);
  transition: transform .08s ease-out;
}
.tap-rays {
  position: absolute; inset: -30%; pointer-events: none; opacity: .35;
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, .16) 0 6deg, transparent 6deg 24deg);
  animation: spin 22s linear infinite reverse;
  -webkit-mask: radial-gradient(circle, #000 20%, transparent 62%); mask: radial-gradient(circle, #000 20%, transparent 62%);
}
.gem-hit { position: relative; width: 64%; display: block; transition: transform .09s ease-out; }
.gem { width: 100%; display: block; overflow: visible; animation: bob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 10px 18px rgba(54, 209, 255, .6)) drop-shadow(0 0 2px rgba(255, 255, 255, .6)); }
.twinkle { transform-box: fill-box; transform-origin: center; animation: twinkle 2.4s ease-in-out infinite; }
.twinkle.t2 { animation-delay: 1.2s; }
.tap-shine {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, transparent 38%, rgba(255, 255, 255, .28) 48%, transparent 58%);
  transform: translateX(-120%); animation: shine 3.8s ease-in-out infinite;
}
.tap:active .tap-core { transform: scale(.965); }
.tap.hit .gem-hit { transform: scale(.88) translateY(3px); }
.tap.empty .tap-ring { filter: grayscale(1) brightness(.6); animation-play-state: paused; }
.tap.empty .gem { filter: grayscale(.85) brightness(.75); animation-play-state: paused; }
.tap-area:has(.tap.empty) .tap-halo { opacity: .15; animation: none; }
.tap-label {
  margin-top: 14px; font-weight: 700; letter-spacing: .3px; font-size: 15px;
  background: linear-gradient(90deg, #ffd86e, #ff7ad9, #36d1ff); -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.tap.empty ~ .tap-label { background: none; color: var(--muted); }

#floats { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.float {
  position: absolute; font-weight: 800; font-size: 24px; color: #ffe27a;
  text-shadow: 0 2px 0 #b8741a, 0 0 12px rgba(255, 200, 80, .7);
  animation: up .95s cubic-bezier(.2, .7, .3, 1) forwards;
}
.spark {
  position: absolute; width: 9px; height: 9px; border-radius: 2px; transform: rotate(45deg);
  background: linear-gradient(135deg, #fff, #7fe3ff); box-shadow: 0 0 8px #7fe3ff;
  animation: spark .6s ease-out forwards;
}
@keyframes up { 0% { transform: translateY(0) scale(.8); } 20% { transform: translateY(-14px) scale(1.15); }
  100% { transform: translateY(-110px) scale(1); opacity: 0; } }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) rotate(225deg) scale(.2); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes halo { 50% { transform: scale(1.08); opacity: .75; } }
@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes twinkle { 0%, 100% { transform: scale(.3); opacity: 0; } 50% { transform: scale(1); opacity: 1; } }
@keyframes shine { 0%, 55% { transform: translateX(-120%); } 85%, 100% { transform: translateX(120%); } }
@media (prefers-reduced-motion: reduce) {
  .tap-ring, .tap-rays, .gem, .tap-halo, .tap-shine, .twinkle { animation: none; }
}

.energy { margin: 8px 0; }
.bar { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
#energy-fill { height: 100%; width: 0; background: linear-gradient(90deg, #f5c542, #f59e0b); transition: width .2s; }
.energy-text { margin-top: 6px; text-align: center; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.stats div { background: var(--bg); border-radius: 12px; padding: 8px; text-align: center; display: flex; flex-direction: column; }
.stats .muted { font-size: 12px; }

.item { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.item + .item { border-top: 1px solid var(--bg2); padding-top: 10px; margin-top: 10px; }
.item .desc { min-width: 0; }

.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badges .btn { font-size: 18px; }

.seg { display: flex; gap: 6px; margin: 8px 0; overflow-x: auto; }
.seg button {
  flex: 1; border: 0; border-radius: 10px; padding: 8px 6px; font: inherit; cursor: pointer;
  background: var(--bg); color: var(--text); white-space: nowrap;
}
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.top-list { list-style: none; margin: 0; padding: 0; background: var(--bg); border-radius: var(--radius); }
.top-list li { display: flex; gap: 8px; align-items: center; padding: 10px 12px; }
.top-list li + li { border-top: 1px solid var(--bg2); }
.top-list .place { width: 28px; text-align: right; flex: none; }
.top-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-list .val { white-space: nowrap; font-weight: 600; }
.top-list li.you { background: var(--warn-bg); }
#top-me { margin-top: 10px; }

.link { font-family: ui-monospace, monospace; font-size: 13px; background: var(--bg2); border-radius: 8px;
  padding: 8px; word-break: break-all; user-select: text; margin-top: 8px; }

.tabs {
  display: flex; background: var(--bg); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--bg2);
}
.tabs button {
  flex: 1; border: 0; background: none; color: var(--muted); font: 11px/1.2 inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
}
.tabs button span { font-size: 20px; }
.tabs button.on { color: var(--accent); font-weight: 600; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: 84px; margin: 0 auto; max-width: 480px;
  background: rgba(20, 22, 28, .92); color: #fff; padding: 10px 14px; border-radius: 12px;
  text-align: center; z-index: 10; white-space: pre-line;
}
#blocker {
  position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; z-index: 20;
}
