:root {
  --ink: #FFFFFF;
  --muted: rgba(255,255,255,.66);
  --card: rgba(255,255,255,.09);
  --card-line: rgba(255,255,255,.16);
  --accent: #FFC93C;
  --accent-ink: #2A1800;
  --good: #4ADE80;
  --bad: #FF6B6B;
  --r: 18px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px));
  --bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0B1026; color: var(--ink); font-family: var(--font); }
body { user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }

#cv { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* Меню поверх живого фону */
#ui { position: fixed; inset: 0; display: flex; flex-direction: column; }
.tab {
  flex: 1; overflow-y: auto; touch-action: pan-y;
  padding: calc(var(--top) + 14px) 16px 16px; display: flex; flex-direction: column; gap: 14px;
  max-width: 520px; width: 100%; margin: 0 auto;
}
.top { text-align: center; display: grid; gap: 6px; }
h1 { margin: 0; font-size: 34px; font-weight: 900; letter-spacing: -.5px;
     background: linear-gradient(180deg, #FFF 20%, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
     filter: drop-shadow(0 3px 0 rgba(0,0,0,.35)); }
h2 { margin: 0; font-size: 26px; font-weight: 800; }
.world { font-size: 14px; color: var(--muted); }
.world b { color: var(--ink); }
.world .ev { display: inline-block; margin-top: 4px; padding: 3px 10px; border-radius: 99px; background: rgba(255,201,60,.18); color: var(--accent); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--card-line); border-radius: var(--r); padding: 12px 14px; backdrop-filter: blur(6px); }
.team { display: flex; align-items: center; gap: 12px; }
.team .ic { font-size: 28px; }
.team .tx { flex: 1; min-width: 0; }
.team .tx b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team .tx span { font-size: 13px; color: var(--muted); }
.team .rank { font-size: 22px; font-weight: 900; color: var(--accent); }
.team .btn { padding: 10px 14px; font-size: 14px; }

.ship-stage { height: 140px; display: grid; place-items: center; }
.ship { width: 110px; height: 110px; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 10px 18px rgba(0,0,0,.45)); }
.ship img, .ship span { width: 100%; height: 100%; display: grid; place-items: center; font-size: 84px; line-height: 1; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-3deg); } }

.row { display: flex; gap: 10px; }
.stats .stat { flex: 1; text-align: center; background: var(--card); border: 1px solid var(--card-line); border-radius: 14px; padding: 10px 4px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.boosts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.boost { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 70px; padding: 8px 10px; border-radius: 14px;
         background: var(--card); border: 2px solid transparent; font-size: 12px; color: var(--muted); }
.boost i { font-style: normal; font-size: 24px; width: 30px; height: 30px; display: grid; place-items: center; }
.boost i img, .item .pic img, .ship img { width: 100%; height: 100%; display: block; }
.boost i span, .item .pic span { display: grid; place-items: center; width: 100%; height: 100%; }
.boost.on { border-color: var(--accent); color: var(--ink); background: rgba(255,201,60,.14); }
.boost[disabled] { opacity: .35; }
.boost .q { font-weight: 800; color: var(--ink); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 20px; border-radius: 16px;
       background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 17px;
       box-shadow: 0 5px 0 #B9851A, 0 10px 24px rgba(0,0,0,.35); transition: transform .08s; text-decoration: none; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #B9851A; }
.btn.big { font-size: 22px; padding: 18px; width: 100%; }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: none; border: 1px solid var(--card-line); }
.btn[disabled] { filter: grayscale(1); opacity: .6; }
.links { justify-content: center; flex-wrap: wrap; gap: 2px 6px; }
.link { color: var(--muted); font-size: 14px; padding: 8px 6px; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }

/* Ліга */
.seg { display: flex; background: var(--card); border-radius: 14px; padding: 4px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 10px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board li { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 10px 12px; }
.board li.me { outline: 2px solid var(--accent); }
.board .n { width: 28px; text-align: center; font-weight: 800; color: var(--muted); }
.board .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board .pt { font-weight: 800; font-variant-numeric: tabular-nums; }
.board .sk { width: 26px; height: 26px; font-size: 20px; display: grid; place-items: center; }
.board .sk img { width: 100%; height: 100%; }
.board .empty { justify-content: center; color: var(--muted); }

/* Магазин і скіни */
.sale { text-align: center; padding: 10px; border-radius: 14px; background: linear-gradient(90deg, #FF3D6E, #FF9F1C); font-weight: 800; }
.shop, .skins { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.item { background: var(--card); border: 1px solid var(--card-line); border-radius: var(--r); padding: 14px 10px 12px;
        display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.item.wide { grid-column: 1 / -1; flex-direction: row; text-align: left; padding: 14px; background: linear-gradient(135deg, rgba(255,201,60,.22), rgba(255,92,170,.18)); }
.item.wide .tx { flex: 1; min-width: 0; }
.item.wide .btn { width: auto; flex: none; padding: 12px 16px; }
.item.wide .pic { width: 72px; height: 72px; flex: none; }
.item .pic { width: 64px; height: 64px; font-size: 46px; display: grid; place-items: center; }
.item .pic img { width: 100%; height: 100%; }
.item .nm { font-weight: 700; font-size: 15px; }
.item .sub { font-size: 12px; color: var(--muted); }
.item .btn { padding: 9px 14px; font-size: 15px; width: 100%; }
.item .old { text-decoration: line-through; opacity: .6; font-weight: 400; margin-right: 4px; }
.item.owned .btn { background: var(--card); color: var(--ink); box-shadow: none; }
.item.equipped { outline: 2px solid var(--good); }

/* Нижнє меню */
.tabs { display: flex; padding: 6px 8px calc(var(--bottom) + 6px); background: rgba(8,8,20,.72); backdrop-filter: blur(10px); border-top: 1px solid var(--card-line); }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--muted); font-size: 12px; }
.tabs i { font-style: normal; font-size: 22px; filter: grayscale(.7); }
.tabs button.on { color: var(--ink); }
.tabs button.on i { filter: none; transform: scale(1.1); }

/* Раунд */
#hud { position: fixed; left: 0; right: 0; top: calc(var(--top) + 8px); display: flex; justify-content: space-between; padding: 0 16px; pointer-events: none;
       font-weight: 900; text-shadow: 0 2px 6px rgba(0,0,0,.6); }
.hud-score { font-size: 38px; font-variant-numeric: tabular-nums; }
.hud-right { font-size: 22px; display: flex; gap: 6px; align-items: center; }
#hint { position: fixed; left: 0; right: 0; bottom: 22%; text-align: center; font-size: 20px; font-weight: 800; pointer-events: none;
        animation: pulse 1.2s ease-in-out infinite; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
@keyframes pulse { 50% { opacity: .45; } }

/* Вікна */
.modal { position: fixed; inset: 0; background: rgba(5,5,15,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { width: 100%; max-width: 520px; background: linear-gradient(180deg, #2A1F55, #17112F); border-radius: 26px 26px 0 0;
         padding: 24px 18px calc(var(--bottom) + 18px); display: flex; flex-direction: column; gap: 12px; text-align: center;
         animation: up .25s ease-out; border-top: 1px solid var(--card-line); }
@keyframes up { from { transform: translateY(40%); opacity: 0; } }
.sheet h3 { margin: 0; font-size: 22px; }
.sheet p { margin: 0; color: var(--muted); line-height: 1.45; white-space: pre-line; max-height: 50vh; overflow-y: auto; }
#mBtns { display: grid; gap: 8px; }
.big-score { font-size: 72px; font-weight: 900; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.rec { font-weight: 900; font-size: 18px; color: var(--good); animation: pulse 1s ease-in-out infinite; }
.r-line, .r-team { color: var(--muted); }
.r-team b { color: var(--ink); }

.toast { position: fixed; left: 50%; top: calc(var(--top) + 14px); transform: translateX(-50%); z-index: 20; max-width: 90%;
         padding: 10px 16px; border-radius: 14px; background: rgba(20,20,35,.92); border: 1px solid var(--card-line); font-weight: 600; text-align: center; }
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: #0B1026; z-index: 30; transition: opacity .3s; }
.spin { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--accent); animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .ship, #hint, .rec, .spin { animation: none; } }
