/* Destiny Hub — «Звёздный Рикошет» на сайте.
   Визуальные стили (.ab-*) — точная копия templates/components/head/78_astro_bubbles_styles.html
   (общий движок игры templates/js/config/44_astro_bubbles*.js скопирован без изменений
   в js/modules/, чтобы не рисковать точностью физики шара при ручном переносе).
   Изменены только правила, прячущие "хром" вокруг игры на полный экран: в Mini App это
   .app-header/.bottom-nav/.pet-widget, на сайте — #sidebar-container и шапка games.html. */

/* Не прячем шапку и вкладки игр — они должны быть видны так же, как в Кристалле */
body.ab-game-active .games-header,
body.ab-game-active .games-feature-sync,
body.ab-game-active #games-guest-notice {
    display: none !important;
}

/* Окно игры подгоняется под доступную высоту (--ab-avail выставляет games_page.js; fallback 100dvh − 250px),
   портретная пропорция сохраняется: ширина = 0.78 от высоты, не шире 760px. */
#ricochet-section {
    display: none !important;
    width: 100%;
    max-width: min(100%, calc(clamp(440px, var(--ab-avail, calc(100dvh - 250px)), 1500px) * 0.78), 1170px);
    margin: 0 auto;
}

#ricochet-section:not(.active),
#view-astro-bubbles:not(.active) {
    display: none !important;
}

#ricochet-section.active {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    width: 100% !important;
    max-width: min(100%, calc(clamp(440px, var(--ab-avail, calc(100dvh - 250px)), 1500px) * 0.78), 1170px) !important;
    margin: 0 auto !important;
    padding: 0 !important;
    background: transparent !important;
    position: relative !important;
    inset: auto !important;
    z-index: 10 !important;
    transform: none !important;
    animation: none !important;
}

#ricochet-section.active #view-astro-bubbles,
#view-astro-bubbles.active {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: clamp(440px, var(--ab-avail, calc(100dvh - 250px)), 1500px) !important;
    min-height: 0 !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: stretch !important;
    overflow: hidden !important;
    margin: 0 auto !important;
    border-radius: 20px;
    border: 1px solid rgba(117, 220, 255, 0.28);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.75), 0 0 30px rgba(78, 235, 255, 0.2);
    transform: none !important;
    animation: none !important;
}

@media (max-width: 600px) {
    #ricochet-section.active,
    #ricochet-section.active #view-astro-bubbles,
    #view-astro-bubbles.active {
        max-width: 100% !important;
        height: clamp(440px, var(--ab-avail, calc(100dvh - 250px)), 1500px) !important;
        min-height: 0 !important;
    }
}

#view-astro-bubbles::after { display: none !important; }

.ab-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100% !important;
    min-height: 100% !important;
    max-height: 100% !important;
    overflow: hidden;
    color: #f8fbff;
    border-radius: 20px;
    background:
        radial-gradient(circle at 50% 24%, rgba(78, 235, 255, 0.14), transparent 28%),
        linear-gradient(180deg, rgba(4, 4, 20, 0.26), rgba(4, 4, 20, 0.76)),
        url('/static/images/miniapp/astro_bubbles/astro_bubbles_bg.webp') center / cover no-repeat;
}

@media (min-width: 601px) {
    .ab-shell {
        max-width: 100%;
        margin: 0 auto;
        border-left: 1px solid rgba(117, 220, 255, 0.2);
        border-right: 1px solid rgba(117, 220, 255, 0.2);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(78, 235, 255, 0.2);
    }
}

.ab-topbar {
    position: relative;
    z-index: 5;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) repeat(5, 36px);
    gap: 6px;
    align-items: center;
    min-height: 52px;
    padding: 5px 8px 4px;
    background: linear-gradient(180deg, rgba(5, 6, 25, 0.98), rgba(7, 7, 31, 0.62));
    border-bottom: 1px solid rgba(117, 220, 255, 0.18);
}

.ab-title { min-width: 0; line-height: 1.05; }
.ab-title strong {
    display: block;
    color: #ffe75f;
    font-size: clamp(0.9rem, 3.8vw, 1.08rem);
    font-weight: 950;
    text-shadow: 0 0 15px rgba(255, 219, 80, 0.42);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ab-title span {
    display: block;
    margin-top: 2px;
    color: rgba(245, 248, 255, 0.86);
    font-size: 0.62rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ab-icon-btn,
.ab-message button,
.ab-settings button {
    min-height: 36px;
    border: 1px solid rgba(160, 180, 255, 0.28);
    border-radius: 9px;
    background: rgba(9, 10, 37, 0.72);
    color: #f8fbff;
    font-weight: 950;
    box-shadow: inset 0 0 16px rgba(120, 180, 255, 0.08), 0 0 12px rgba(0, 0, 0, 0.22);
}

.ab-stats {
    position: relative;
    z-index: 4;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 3px;
    padding: 4px 7px;
    background: rgba(3, 4, 18, 0.42);
    border-bottom: 1px solid rgba(117, 220, 255, 0.16);
}
.ab-stats div {
    min-width: 0;
    padding: 4px 2px;
    border: 1px solid rgba(125, 211, 252, 0.18);
    border-radius: 9px;
    background: rgba(7, 9, 34, 0.56);
    text-align: center;
}
.ab-stats span {
    display: block;
    color: rgba(248, 251, 255, 0.72);
    font-size: 0.5rem;
    font-weight: 950;
    text-transform: uppercase;
}
.ab-stats strong {
    display: block;
    margin-top: 1px;
    color: #6df7ff;
    font-size: clamp(0.72rem, 3.2vw, 0.94rem);
    font-weight: 950;
    text-shadow: 0 0 12px rgba(109, 247, 255, 0.48);
    white-space: nowrap;
}
.ab-stats div:nth-child(1) strong { color: #ffe75f; text-shadow: 0 0 12px rgba(255, 231, 95, 0.48); }
.ab-stats div:nth-child(2) strong { color: #53ffb4; text-shadow: 0 0 12px rgba(83, 255, 180, 0.42); }
.ab-stats div:nth-child(3) strong { color: #ff4b9b; text-shadow: 0 0 12px rgba(255, 75, 155, 0.44); }
.ab-stats div:nth-child(4) strong { color: #ffb84d; text-shadow: 0 0 12px rgba(255, 184, 77, 0.44); }

.ab-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    touch-action: none;
}
#ab-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.ab-combo {
    position: absolute;
    left: 50%;
    top: 42%;
    z-index: 8;
    transform: translate(-50%, -50%);
    padding: 7px 16px;
    border-radius: 999px;
    border: 1px solid rgba(255, 231, 95, 0.6);
    background: rgba(7, 7, 29, 0.78);
    color: #ffe75f;
    font-size: clamp(1rem, 5vw, 1.45rem);
    font-weight: 950;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 0 0 16px rgba(255, 231, 95, 0.75), 0 2px 10px rgba(0, 0, 0, 0.9);
    box-shadow: 0 0 34px rgba(255, 231, 95, 0.28);
    pointer-events: none;
    animation: abComboPop 0.9s ease both;
}
@keyframes abComboPop {
    0% { opacity: 0; transform: translate(-50%, -42%); }
    22% { opacity: 1; transform: translate(-50%, -50%); }
    70% { opacity: 1; transform: translate(-50%, -62%); }
    100% { opacity: 0; transform: translate(-50%, -82%); }
}

.ab-message,
.ab-settings {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(4, 3, 18, 0.72);
    backdrop-filter: blur(12px);
}
.ab-message[hidden], .ab-settings[hidden] { display: none !important; }
.ab-message > :not(.ab-message-actions),
.ab-settings-panel {
    position: relative;
}
.ab-message {
    flex-direction: column;
    text-align: center;
}
.ab-message-emoji {
    width: 76px;
    height: 76px;
    display: grid;
    place-items: center;
    margin: 0 auto 8px;
    color: #f8d45d;
    font-size: 3rem;
    filter: drop-shadow(0 0 18px rgba(255, 231, 95, 0.7));
}
.ab-message-emoji img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.ab-message strong,
.ab-settings-panel > strong {
    display: block;
    color: #fff;
    font-size: 1.25rem;
    font-weight: 950;
    text-shadow: 0 0 14px rgba(109, 247, 255, 0.4);
}
.ab-message span {
    display: block;
    max-width: 310px;
    margin: 8px auto 10px;
    color: rgba(248, 251, 255, 0.86);
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.35;
}
.ab-message-award { color: #ffe75f; font-size: 1.1rem; font-weight: 950; margin-bottom: 10px; }
.ab-message-actions { display: grid; gap: 8px; width: min(100%, 280px); }
.ab-primary { background: linear-gradient(135deg, #ffe75f, #6df7ff) !important; color: #09091d !important; border: 0 !important; }

.ab-settings-panel {
    width: min(100%, 320px);
    max-height: min(92%, 620px);
    overflow: auto;
    padding: 16px;
    border: 1px solid rgba(139, 184, 255, 0.34);
    border-radius: 14px;
    background: rgba(8, 8, 32, 0.94);
    box-shadow: 0 22px 54px rgba(0, 0, 0, 0.5);
}
.ab-settings-panel label {
    display: block;
    margin-top: 13px;
    color: rgba(248, 251, 255, 0.88);
    font-size: 0.78rem;
    font-weight: 900;
}
.ab-settings-panel label span { float: right; color: #6df7ff; }
.ab-settings-panel input[type="range"] { width: 100%; accent-color: #6df7ff; margin-top: 6px; }
.ab-reset { margin-top: 10px; width: 100%; color: #ff9bbc !important; }

.ab-shake { animation: abImpactGlow 0.28s ease; }
@keyframes abImpactGlow {
    0%, 100% { filter: brightness(1); }
    45% { filter: brightness(1.06); }
}

@media (prefers-reduced-motion: reduce) { .ab-combo, .ab-shake { animation: none !important; } }

@media (max-height: 690px) {
    .ab-title span { display: none; }
    .ab-topbar { min-height: 44px; grid-template-columns: 34px minmax(0, 1fr) repeat(5, 32px); }
    .ab-icon-btn { min-height: 32px; }
    .ab-stats { padding: 3px 5px; }
    .ab-stats div { padding: 3px 1px; }
}

@media (max-width: 360px) {
    .ab-topbar { grid-template-columns: 32px minmax(0, 1fr) repeat(5, 30px); gap: 4px; padding-inline: 6px; }
    .ab-stats span { font-size: 0.46rem; }
}

.ab-leaderboard {
    position: fixed;
    inset: 0;
    z-index: 99980;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(2, 3, 14, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.ab-leaderboard[hidden] { display: none !important; }
.ab-leaderboard-card {
    width: min(100%, 390px);
    max-height: min(86vh, 650px);
    overflow: auto;
    border: 1px solid rgba(109, 247, 255, 0.34);
    border-radius: 16px;
    padding: 18px;
    background: linear-gradient(180deg, rgba(10, 12, 40, 0.96), rgba(5, 7, 26, 0.98));
    box-shadow: 0 26px 72px rgba(0, 0, 0, 0.58), 0 0 32px rgba(109, 247, 255, 0.12);
    color: #f8fbff;
}
.ab-leaderboard-close {
    float: right;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    border: 1px solid rgba(109, 247, 255, 0.24);
    background: rgba(255, 255, 255, 0.08);
    color: #f8fbff;
    font-size: 1.45rem;
    font-weight: 950;
}
.ab-leaderboard-kicker {
    display: block;
    color: #ffe75f;
    font-size: 0.75rem;
    font-weight: 950;
    text-transform: uppercase;
}
.ab-leaderboard-card > strong {
    display: block;
    margin-top: 2px;
    color: #fff;
    font-size: 1.35rem;
    font-weight: 950;
}
.ab-leaderboard-card p {
    margin: 7px 0 14px;
    color: rgba(248, 251, 255, 0.76);
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.35;
}
.ab-leaderboard-row {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 58px;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid rgba(109, 247, 255, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.07);
}
.ab-leaderboard-row span,
.ab-leaderboard-row strong { color: #ffe75f; font-weight: 950; text-align: center; }
.ab-leaderboard-row b { min-width: 0; color: #f8fbff; line-height: 1.2; overflow-wrap: anywhere; }
.ab-leaderboard-name-line,
.ab-admin-username { display: block; }
.ab-admin-username { margin-top: 3px; color: #6df7ff; font-size: 0.68rem; font-weight: 850; }
.ab-leaderboard-row em { color: #53ffb4; font-style: normal; font-size: 0.72rem; }
.ab-leaderboard-empty,
.ab-leaderboard-current {
    margin-top: 10px;
    padding: 14px;
    border: 1px dashed rgba(109, 247, 255, 0.24);
    border-radius: 12px;
    color: rgba(248, 251, 255, 0.82);
    text-align: center;
    font-weight: 850;
}

.ab-story { position:absolute; inset:0; z-index:25; display:grid; place-items:center; padding:16px; background:rgba(3,4,18,.8); backdrop-filter:blur(10px); }
.ab-story[hidden] { display:none !important; }
.ab-story-card { position:relative; width:min(100%,340px); max-height:min(88dvh,650px); overflow:auto; padding:10px 14px 16px; border:1px solid rgba(139,184,255,.48); border-radius:12px; background:#0b1030; color:#f8fbff; box-shadow:0 24px 64px rgba(0,0,0,.6); text-align:center; }
.ab-story-card img { width:100%; aspect-ratio:16/11; object-fit:cover; border-radius:8px; display:block; }
.ab-story-close { position:absolute; top:16px; right:20px; width:34px; min-height:34px !important; border-radius:50% !important; }
.ab-story-card span { display:block; margin-top:10px; color:#6df7ff; font-size:.65rem; font-weight:900; text-transform:uppercase; }
.ab-story-card strong { display:block; margin:4px 28px 8px; color:#ffe75f; font-size:1.05rem; line-height:1.2; }
.ab-story-card p { margin:7px 0; color:rgba(248,251,255,.88); font-size:.78rem; line-height:1.4; font-weight:700; }
.ab-story-card p:last-of-type { color:#a7f3d0; }
.ab-story-card .ab-primary { width:100%; margin-top:6px; }

/* Гостевая CTA-плашка (как в pet_widget / durak) — сайт использует те же классы,
   что и остальные ported-игры (game-guest-cta уже определён в css/games.css). */
.game-guest-cta { margin: 0; }

@media (max-width: 380px) {
    .ab-topbar {
        grid-template-columns: 26px minmax(0, 1fr) repeat(5, 26px);
        gap: 3px;
        padding: 4px;
    }
    .ab-icon-btn {
        min-width: 0;
        padding: 0;
        font-size: 0.85rem;
    }
    .ab-hud {
        gap: 3px;
        padding: 3px 4px;
    }
}

