/* ==========================================================================
   HUD gry: ikony, chipy statystyk, kafelki akcji, karty klas, toasty, sklep.
   Ładowany po responsive.css, więc jego reguły mobilne mają ostatnie słowo.
   ========================================================================== */

/* --- Ikony (obrazek albo emotka zastępcza) ------------------------------ */
.game-icon,
.stat-icon {
    display: inline-grid;
    width: 1.25rem;
    height: 1.25rem;
    flex: none;
    place-items: center;
    vertical-align: middle;
}

.game-icon img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.game-icon-glyph {
    font-size: 0.875rem;
    line-height: 1;
}

/* Skróty tekstowe (AD, MR) zamiast emotki. */
.game-icon-glyph.is-text {
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.resource-label .stat-icon,
.stat-line .stat-icon {
    width: 1.125rem;
    height: 1.125rem;
}

/* --- Chipy statystyk ----------------------------------------------------- */
.stat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.375rem;
    margin: 0.375rem 0 0;
}

.stat-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem 0.125rem 0.1875rem;
    border: 1px solid var(--shop-border-color);
    border-radius: 999px;
    background: var(--shop-info-background);
    font-size: 0.875rem;
    line-height: 1;
    cursor: default;
}

.stat-chip b {
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}

/* Etykieta: po najechaniu, fokusie klawiaturą albo dotknięciu (telefon). */
.stat-chip::after {
    content: attr(data-label);
    position: absolute;
    bottom: calc(100% + 0.375rem);
    left: 50%;
    z-index: 8;
    width: max-content;
    max-width: 9.375rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    background: rgba(10, 14, 24, 0.96);
    color: #f2f5f8;
    font-size: 0.875rem;
    line-height: 1.25;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%);
    transition: opacity 120ms ease;
}

.stat-chip:first-child::after {
    left: 0;
    transform: none;
}

.stat-chip:last-child::after {
    right: 0;
    left: auto;
    transform: none;
}

.stat-chip:hover::after,
.stat-chip:focus-visible::after,
.stat-chip.show-label::after {
    opacity: 1;
    visibility: visible;
}

.stat-chip:focus-visible {
    outline: 2px solid var(--title-glow);
    outline-offset: 2px;
}

/* Statystyki gracza w walce: dwie grupy chipów płyną w jednym rzędzie (zawijają się dopiero, gdy brakuje miejsca). */
.chips-group {
    display: contents;
}

#battle-player-chips .stat-chip::after {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
}

#battle-player-weapon .stat-chip:first-child::after {
    left: 0;
    transform: none;
}

#battle-player-mana .stat-chip:last-child::after {
    right: 0;
    left: auto;
    transform: none;
}

#battle-player-chips {
    flex-wrap: wrap;
    gap: 0.25rem;
}

.weapon-name {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Kafelki akcji w walce ------------------------------------------------ */
.battle-dock {
    display: grid;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.battle-dock .battle-abilities,
.battle-dock .battle-potions {
    margin-top: 0;
}

.battle-potions:empty {
    display: none;
}

.ability-button,
.potion-button {
    position: relative;
    min-height: 0;
    padding: 0.625rem 0.25rem 0.375rem;
    justify-content: flex-start;
    gap: 0.3125rem;
    line-height: 1.15;
}

/* Wyłączony kafelek ma własne, czytelne stany (cooldown / brak many), więc nie przyciemniamy go całego. */
.ability-button:disabled,
.potion-button:disabled {
    opacity: 1;
}

.tile-frame {
    position: relative;
    display: grid;
    width: 3.25rem;
    height: 3.25rem;
    place-items: center;
    border: 1px solid var(--shop-border-color);
    border-radius: 6px;
    background: var(--shop-info-background);
}

.tile-frame .game-icon {
    width: 100%;
    height: 100%;
}

.tile-frame .tile-img img {
    padding: 0;
    box-sizing: border-box;
    border-radius: 5px;
}

.tile-frame .game-icon-glyph {
    font-size: 1.625rem;
}

.tile-frame .game-icon-glyph.is-text {
    font-size: 0.9375rem;
}

.tile-key,
.tile-cost,
.tile-count {
    position: absolute;
    display: flex;
    min-width: 1.125rem;
    height: 1.125rem;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    box-sizing: border-box;
    padding: 0 0.25rem;
    border: 1px solid #0b254b;
    border-radius: 6px;
    font-size: 0.875rem;
    line-height: 1;
}

.tile-key,
.tile-cost,
.tile-count {
    z-index: 2; /* plakietki zawsze nad nakładką cooldownu */
}

.tile-key {
    top: -0.4375rem;
    left: -0.4375rem;
    background: #f1f3f5;
    color: #14233d;
    font-weight: 700;
}

.tile-cost,
.tile-count {
    right: -0.4375rem;
    bottom: -0.4375rem;
    background: #1e5d94;
    color: #fff;
}

.tile-cost .game-icon {
    width: 0.75rem;
    height: 0.75rem;
}

.tile-cost .game-icon-glyph {
    font-size: 0.875rem;
}

.tile-count {
    background: #2c2f36;
}

.tile-name {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    overflow-wrap: anywhere;
    font-size: 0.875rem;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.tile-sub {
    font-size: 0.875rem;
    opacity: 0.85;
}

/* Cooldown: ciemna nakładka z liczbą tur. */
.tile-cooldown {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    border-radius: 5px;
    background: rgba(8, 10, 18, 0.7);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
}

.is-cooldown .tile-frame {
    border-style: dashed;
}

/* Brak many: przygaszona ikona i czerwony koszt. */
.is-no-mana .tile-frame > .game-icon {
    opacity: 0.4;
    filter: grayscale(0.8);
}

.is-no-mana .tile-cost {
    border-color: #4b0b12;
    background: #a3303a;
}

.is-no-mana .tile-name {
    opacity: 0.75;
}

.battle-abilities,
.battle-potions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* --- Karty wyboru klasy ---------------------------------------------------- */
.class-picker-label {
    margin-top: 0.25rem;
}

.class-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15.625rem, 1fr));
    gap: 0.5rem;
    padding: 0.125rem 0.375rem;
}

#login-screen .class-card {
    display: grid;
    grid-template-columns: 3.5rem minmax(0, 1fr);
    align-items: start;
    gap: 0.125rem 0.625rem;
    padding: 0.5rem;
    border: 1px solid var(--shop-border-color);
    text-align: left;
    background: var(--shop-card-background) !important;
}

#login-screen .class-card.is-selected {
    outline: 2px solid var(--title-glow);
    outline-offset: -2px;
    background: var(--shop-control-background) !important;
}

.class-card-icon {
    grid-row: 1 / span 3;
    width: 3.5rem;
    height: 3.5rem;
    border: 1px solid var(--shop-border-color);
    border-radius: 6px;
    background: var(--shop-info-background);
}

/* Ramki ikon przycinają obrazek do zaokrąglonych rogów (wcześniej rogi PNG wystawały poza ramkę). */
.class-card-icon,
.class-ability-icon {
    overflow: hidden;
}

.class-card-icon img,
.class-ability-icon img {
    border-radius: inherit;
}

.class-card-icon .game-icon-glyph {
    font-size: 1.875rem;
}

.class-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}

.class-card-name {
    font-family: var(--font-title);
    font-size: 1.125rem;
}

:root .class-stars {
    color: var(--star);
    font-size: 0.9375rem;
    letter-spacing: 1px;
    white-space: nowrap;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.7);
}

.class-card-role {
    font-size: 0.875rem;
    opacity: 0.9;
}

.class-card-abilities {
    display: flex;
    gap: 0.3125rem;
    margin-top: 0.25rem;
}

.class-ability-icon {
    width: 1.75rem;
    height: 1.75rem;
    border: 1px solid var(--shop-border-color);
    border-radius: 5px;
    background: var(--shop-info-background);
}

.class-ability-icon .game-icon-glyph {
    font-size: 1rem;
}

/* --- Toasty ---------------------------------------------------------------- */
#toast-host {
    position: fixed;
    bottom: calc(var(--footer-h, 2.75rem) + 0.875rem);
    left: 50%;
    z-index: 30;
    display: flex;
    width: min(92vw, 26.25rem);
    flex-direction: column;
    align-items: stretch;
    gap: 0.375rem;
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    padding: 0.625rem 0.875rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-left: 5px solid #8892a3;
    border-radius: 6px;
    background: rgba(10, 14, 24, 0.96);
    color: #f2f5f8;
    font-size: 0.875rem;
    line-height: 1.3;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    cursor: pointer;
    animation: toast-in 180ms ease both;
}

.toast.success { border-left-color: #3fbf6b; }
.toast.warning { border-left-color: #e0b63a; }
.toast.danger { border-left-color: #e0525a; }

.toast.is-leaving {
    opacity: 0;
    transition: opacity 200ms ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
}

/* --- Sklep ----------------------------------------------------------------- */
.shop-stats {
    margin: 0.125rem 0 0.375rem;
}

.shop-item .shop-meta {
    margin: 0.125rem 0 0.25rem;
    opacity: 0.85;
}

.shop-item .shop-price {
    margin: auto 0 0.375rem;
    font-size: 0.9375rem;
}

.shop-item .shop-price.is-short {
    color: var(--bad);
}

.shop-item.is-unaffordable {
    opacity: 0.72;
}

.delta {
    display: inline-flex;
    align-items: center;
    gap: 0.1875rem;
    height: 1.25rem;
    box-sizing: border-box;
    padding: 0 0.5rem;
    border-radius: 999px;
    font-size: 0.875rem;
    line-height: 1;
}

.delta.up::before { content: "▲"; font-size: 0.875rem; }
.delta.down::before { content: "▼"; font-size: 0.875rem; }

.delta.up { background: rgba(49, 158, 83, 0.55); }
.delta.down { background: rgba(179, 48, 58, 0.55); }
.delta.same { background: rgba(120, 120, 120, 0.4); }

/* --- Telefon: arena obok siebie i dock z akcjami przypięty nad stopką ----------- */
@media (max-width: 760px) {
    .battle-arena {
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 0.375rem;
    }

    .battle-versus {
        height: auto;
        font-size: 0.875rem;
    }

    .combatant {
        padding: 0.375rem;
    }

    .combatant h3 {
        min-height: 0;
        font-size: 0.875rem;
        overflow-wrap: anywhere;
    }

    .battle-model,
    .enemy-silhouette {
        height: 7.5rem;
        margin: 0.25rem 0 0.375rem;
    }

    .battle-model img {
        max-height: 7.5rem;
    }

    .battle-resource-bars {
        grid-template-columns: 1fr;
        gap: 0.125rem;
    }

    .stat-chip {
        padding-right: 0.375rem;
    }

    .battle-log {
        margin: 0.5rem 0 0.375rem;
    }

    .battle-dock {
        position: sticky;
        bottom: calc(var(--footer-h, 2.75rem) + 0.375rem);
        z-index: 4;
        margin: 0.5rem -0.125rem 0;
        padding: 0.625rem 0.375rem 0.375rem;
        border: 1px solid var(--shop-border-color);
        border-radius: 8px;
        background: var(--main-background);
        box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.3);
    }

    /* Gdy w docku nic nie ma (koniec walki), nie zostawiamy pustego paska. */
    .battle-dock:not(:has(> :not(.hidden))) {
        display: none;
    }

    .battle-abilities,
    .battle-potions {
        gap: 0.375rem;
    }

    .ability-button,
    .potion-button {
        padding: 0.5625rem 0.125rem 0.3125rem;
    }

    .tile-frame {
        width: 2.875rem;
        height: 2.875rem;
    }

    .tile-name {
        font-size: 0.875rem;
        -webkit-line-clamp: 3;
    }

    /* Mikstury są pomocnicze — mniejsze kafelki, żeby dock nie zasłaniał areny. */
    .potion-button {
        padding: 0.5rem 0.125rem 0.25rem;
        gap: 0.1875rem;
    }

    .potion-button .tile-frame {
        width: 2.25rem;
        height: 2.25rem;
    }

    .potion-button .tile-name {
        -webkit-line-clamp: 2;
    }

    .class-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 380px) {
    .tile-frame {
        width: 2.625rem;
        height: 2.625rem;
    }
}

/* --- Ikony statystyk: jasna "podkładka", bo grafiki są ciemne i ginęłyby w ciemnych motywach --- */
.stat-icon {
    padding: 0.1rem;
    box-sizing: border-box;
    border-radius: 0.35rem;
    background: #e6eaf2;
}

.stat-icon > .game-icon {
    width: 100%;
    height: 100%;
}

.tile-cost .stat-icon,
.tile-frame .stat-icon {
    padding: 0;
    background: none;
}

/* Ikony w chipach statystyk (walka): ta sama jasna podkładka. */
.stat-chip {
    padding-left: 0.2rem;
    font-size: 0.95rem;
}

.stat-chip .game-icon {
    width: 1.5rem;
    height: 1.5rem;
    padding: 0.1rem;
    box-sizing: border-box;
    border-radius: 999px;
    background: #e6eaf2;
}

/* Chipy efektów: ikona wypełnia koło i jest przycięta do jego kształtu, nic nie wystaje poza ramkę. */
.effect-icon-chip .game-icon {
    padding: 0;
    overflow: hidden;
}

.effect-icon-chip .game-icon img {
    border-radius: 999px;
    object-fit: cover;
}

.stat-line strong,
.resource-label strong {
    white-space: nowrap;
}
