:root {
    --bg: #0f1115;
    --panel: #171a21;
    --muted: #8a8f98;
    --accent: #6ee7b7;
    --accent2: #60a5fa;
    --danger: #ef4444;
    --ok: #22c55e;
    --btn: #242833;
    --btn2: #2d3342;
    --gold: #ffd166;
    --topbar-h: 56px;
    --bottomnav-h: 88px;
}
:root {
    --safe: env(safe-area-inset-bottom, 0px);
}
* {
    box-sizing: border-box;
}
html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: #e5e7eb;
    font-family:
        system-ui,
        -apple-system,
        Segoe UI,
        Roboto,
        Ubuntu,
        Cantarell,
        "Helvetica Neue",
        Arial,
        "Noto Sans";
    display: flex;
    flex-direction: column;
    padding-top: var(--topbar-h);
    padding-bottom: var(--bottomnav-h);
}

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0 0.8rem;
    background: var(--panel);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    z-index: 10;
}
.top-left,
.top-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.user-name {
    font-weight: 800;
    font-size: 1rem;
}
.stat {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: #0b0e14;
    border: 1px solid #202431;
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    font-weight: 800;
}
.stat .icon {
    width: 16px;
    height: 16px;
}
.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #333;
    object-fit: cover;
}
html.tg-ios .bottomNav {
    padding-bottom: 1rem;
}
html.tg-ios .abilityBar {
    bottom: 6px;
}
.screen {
    display: none;
    position: relative;
}
.screen.active {
    display: block;
}
.screenTitle {
    margin: 0.3rem 0 0.7rem;
    font-size: 1.05rem;
    font-weight: 800;
}
.pad {
    padding: 0.8rem;
    padding-bottom: calc(var(--bottomnav-h) + var(--safe));
}

#gameWrap {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-h) - var(--bottomnav-h));
}
#canvasWrap {
    flex: 1;
    position: relative;
}
#gameCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: #121520;
}

.abilityBar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(var(--safe) + 6px);
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    padding-left: 10px;
    pointer-events: auto;
}
.ability {
    position: relative;
    width: 68px;
    height: 68px;
    border: 0;
    background: transparent;
    border-radius: 0.6rem;
    display: grid;
    place-items: center;
    color: #e5e7eb;
    font-weight: 800;
    overflow: hidden;
}
.ability > span {
    display: none;
}
.ability .lock {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: grid;
    place-items: center;
}
.ability:not([unlocked="true"]) {
    filter: grayscale(0.25) brightness(0.82);
}
.ability[unlocked="true"] .lock {
    display: none;
}
.ability .cd {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.ability .cd .cdFill {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    transform-origin: bottom;
    transform: scaleY(0);
    border-radius: inherit;
}
.ability .cd .cdLabel {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    text-align: center;
    font-weight: 900;
    line-height: 1;
    color: #e5e7eb;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    font-size: 0.7rem;
}
.ability.ready {
    box-shadow:
        0 0 0 2px rgba(120, 200, 120, 0.25) inset,
        0 0 12px rgba(120, 200, 120, 0.25);
}
.ability:disabled {
    opacity: 0.65;
    box-shadow: none;
}

.controls {
    padding: 0.6rem 0.6rem 1.2rem;
    background: var(--panel);
}
.charge-btn {
    position: relative;
    width: 100%;
    height: 56px;
    border: 0;
    border-radius: 1rem;
    background: #1f8a46;
    overflow: hidden;
    color: #08110a;
    font-size: 1.05rem;
    font-weight: 900;
}
.charge-btn:disabled {
    opacity: 0.7;
}
.charge-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.15);
    transition: width 0.15s linear;
}
.charge-label {
    position: relative;
    z-index: 2;
}

.bottomNav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    gap: 0.45rem;
    background: var(--panel);
    padding: 0.5rem 0.45rem calc(1rem + var(--safe));
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.25);
    z-index: 9;
}
.navItem {
    flex: 1;
    background: #0b0e14;
    border: 1px solid #2f3545;
    padding: 0.2rem 0;
    border-radius: 0.7rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    color: #e5e7eb;
}
.navItem.active {
    outline: 2px solid #2b7fff;
}
.navIcon {
    width: 28px;
    height: 28px;
    border-radius: 0.35rem;
    background-size: cover;
    background-position: center;
}
.bottomNav .navItem:nth-child(1) .navIcon {
    background-image: url("menu1.svg");
}
.bottomNav .navItem:nth-child(2) .navIcon {
    background-image: url("menu2.svg");
}
.bottomNav .navItem:nth-child(3) .navIcon {
    background-image: url("menu3.svg");
}
.bottomNav .navItem:nth-child(4) .navIcon {
    background-image: url("menu4.svg");
}
.navLabel {
    font-size: 0.8rem;
    color: #b8c0cc;
}

.card {
    background: var(--panel);
    border-radius: 1rem;
    padding: 0.9rem;
    margin-bottom: 0.8rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.card h3 {
    margin: 0.2rem 0 0.5rem;
    font-size: 1rem;
}
.hint {
    color: var(--muted);
    font-size: 0.85rem;
}

.upgradeList,
.pepeList {
    display: grid;
    gap: 0.6rem;
}
.upgradeCard,
.pepeCard {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 0.6rem;
    background: var(--panel);
    border-radius: 0.9rem;
    padding: 0.6rem;
    border: 1px solid #202431;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    min-height: 100px;
}
.pepeCard {
    grid-template-columns: 72px 1fr;
    padding: 0.8rem;
}
.desc {
    font-style: italic;
    color: var(--muted);
}

.thumb {
    width: 100%;
    aspect-ratio: 1/1;
    border-radius: 0.6rem;
    overflow: hidden;
    background: #0b0e14;
    border: 1px solid #202431;
    display: grid;
    place-items: center;
    color: #b7bfd0;
    font-weight: 900;
    font-size: 0.9rem;
}
.thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.pepeCard .thumb {
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        0 0 0 3px rgba(0, 0, 0, 0.35) inset,
        0 6px 16px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}
.pepeCard .thumb img {
    -webkit-mask-image: radial-gradient(
        closest-side,
        #000 95%,
        transparent 100%
    );
    mask-image: radial-gradient(closest-side, #000 98%, transparent 100%);
    filter: saturate(0.9) brightness(0.95);
}

.upRight {
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 0.25rem;
    min-height: 64px;
}

.price {
    justify-self: end;
    background: #0b0e14;
    border: 1px solid #202431;
    padding: 0.15rem 0.45rem;
    border-radius: 0.5rem;
    font-weight: 800;
}

.actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    align-items: end;
    flex-wrap: wrap;
}

.buy {
    background: var(--btn2);
    border: 1px solid #3a4156;
    color: #e5e7eb;
    padding: 0.45rem 0.7rem;
    border-radius: 0.6rem;
    font-weight: 700;
    white-space: nowrap;
    display: grid;
    grid-template-rows: auto auto;
    align-items: center;
    justify-items: center;
    gap: 0.15rem;
    min-width: 120px;
    min-height: 56px;
}
.buy .btnTop {
    font-weight: 900;
}
.buy .btnPrice {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
}
.buy .goldIcon {
    width: 16px;
    height: 16px;
    display: inline-block;
}
.buy.ok {
    background: #1f8a46;
    color: #08110a;
    box-shadow:
        0 0 0 2px rgba(120, 200, 120, 0.25) inset,
        0 0 12px rgba(120, 200, 120, 0.25);
}
.buy:disabled {
    opacity: 0.7;
    filter: grayscale(0.2);
}
.buy.mini {
    min-width: auto;
    min-height: auto;
    padding: 0.35rem 0.6rem;
    border-radius: 0.5rem;
}

.pepeCard.locked {
    opacity: 0.9;
    position: relative;
    filter: grayscale(0.2) brightness(0.95);
}
.pepeCard.locked .upRight {
    display: none;
}
.pepeCard.locked .centerLock {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    gap: 0.6rem;
    padding: 0.6rem;
    text-align: center;
    color: #cbd5e1;
    background: rgba(0, 0, 0, 0.5);
}

.pepeCard.rarity-common {
    background: #141820;
    border-color: #202431;
}
.pepeCard.rarity-rare {
    background: #172235;
    border-color: #263650;
}
.pepeCard.rarity-epic {
    background: #231a33;
    border-color: #3a2e4d;
}
.pepeCard.rarity-legendary {
    background: #2a2314;
    border-color: #50421e;
}

.upgradeCard.rarity-rare {
    background: #172235;
    border-color: #263650;
}
.upgradeCard.rarity-epic {
    background: #231a33;
    border-color: #3a2e4d;
}
.upgradeCard.rarity-legendary {
    background: #2a2314;
    border-color: #50421e;
}

.stat.gold span,
.goldAmt {
    color: var(--gold);
}

.ability[data-rarity="rare"],
.ability[data-rarity="legendary"] {
    box-shadow: none;
    border: 0;
}

#screen-wallet .field {
    min-height: 56px;
}
#screen-wallet .field > input,
#screen-wallet .field > .value,
#screen-wallet .field > button.buy.mini {
    height: 100%;
}
#screen-wallet .field.address {
    display: flex !important;
    align-items: center !important;
}
#screen-wallet .amountToken .value,
#screen-wallet .wdAmount > div {
    align-items: center !important;
}
#screen-wallet .buy {
    font-family:
        "Segoe UI",
        system-ui,
        -apple-system,
        Roboto,
        Arial !important;
    font-size: 1.05rem !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    height: var(--wallet-field-h, 56px);
}
#screen-wallet .amountToken .value {
    display: flex;
    align-items: center !important;
    width: 100%;
}
#screen-wallet #convTokenOut {
    flex: 1 1 auto;
    min-width: 0;
}
#screen-wallet #convUsdOut {
    margin-left: auto !important;
    white-space: nowrap !important;
    text-align: left !important;
}
#screen-wallet #wdUsd {
    margin-left: auto !important;
    white-space: nowrap !important;
    text-align: right !important;
}
#screen-wallet .wdAmount {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto !important;
    align-items: center;
    column-gap: 0.5rem;
}

#screen-wallet .wdAmount > div {
    display: flex !important;
    align-items: center !important;
    min-width: 0 !important;
    width: 100% !important;
}

#screen-wallet #wdAmount {
    flex: 1 1 auto !important;
    min-width: 0 !important;
}

#screen-wallet #wdUsd {
    margin-left: auto !important;
    white-space: nowrap !important;
    text-align: right !important;
    flex: 0 0 auto !important;
}

#screen-wallet .wdAmount .buy.mini {
    grid-column: 3 / 4 !important;
    align-self: center;
    height: var(--wallet-field-h, 56px);
}
