@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@700;800;900&display=swap');

:root {
    --blue:    #3944f7;
    --blue-h:  #222bcc;
    --green:   #3ce070;
    --green-h: #2cbc5c;
    --cyan:    #40c4ff;
    --modal:   #1f2226;
    --muted:   #9ca3af;
    --border:  rgba(255,255,255,0.06);
    --bounce:  cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --ease:    cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after {
    margin: 0; padding: 0;
    box-sizing: border-box;
    font-family: 'Nunito', sans-serif;
    user-select: none;
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.phone {
    width: 390px;
    height: 844px;
    max-height: 100vh;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% 0%,  #1a1550 0%,  transparent 58%),
        radial-gradient(ellipse at 10% 100%,#0e1a3a 0%,  transparent 50%),
        radial-gradient(ellipse at 90% 100%,#0e1a3a 0%,  transparent 50%),
        #06080f;
}

/* ─── CHARACTER ZONE ───────────────────── */
.char-zone {
    position: absolute;
    left: 0; right: 0;
    top: 56px;
    bottom: 170px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    z-index: 5;
    pointer-events: none;
    overflow: hidden;
}

/* ─── 3D AVATAR SYSTEM ─────────────────── */
.char-render-box {
    position: relative;
    width: 410px;
    height: 480px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.ground-shadow {
    position: absolute;
    bottom: -5px;
    width: 240px;
    height: 30px;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    animation: shadow-breathe 3.5s ease-in-out infinite;
}

.float-wrapper {
    position: absolute;
    bottom: -45px; /* Pulls the image down onto the shadow to ignore empty PNG padding */
    width: 100%;
    height: 100%;
    animation: avatar-float 3.5s ease-in-out infinite;
}

/* Base style for the avatar images */
.real-avatar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: transparent;
    filter: drop-shadow(0 12px 30px rgba(0,0,0,0.55));
    opacity: 0;
    transition: opacity 0.7s ease; /* Fade duration */
}

/* Active crossfade image */
.real-avatar.is-active {
    opacity: 1;
    z-index: 2;
}

/* ─── CHARACTER ANIMATIONS ─────────────── */

@keyframes shadow-breathe {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(0.85); opacity: 0.55; }
}

@keyframes avatar-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-16px); }
}

/* Celebrate bounce applied triggered via JS */
.float-wrapper.is-celebrating {
    animation: celebrate 0.6s var(--bounce);
}

@keyframes celebrate {
    0%   { transform: translateY(0)    scale(1); }
    25%  { transform: translateY(-28px) scale(1.06); }
    50%  { transform: translateY(0)    scale(1); }
    75%  { transform: translateY(-14px)  scale(1.03); }
    100% { transform: translateY(0)    scale(1); }
}

/* ─── LOADING SPINNER ──────────────────── */
.avatar-loading {
    position: absolute;
    bottom: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ─── GIFT BUTTON ──────────────────────── */
.gift-btn {
    position: absolute;
    bottom: 56px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 13px 28px;
    background: var(--green);
    color: #000;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.5px;
    cursor: pointer;
    z-index: 30;
    box-shadow: none;
    transition: background .15s, transform .1s;
    pointer-events: all;
    white-space: nowrap;
}
.gift-btn:hover  { background: var(--green); }
.gift-btn:active { transform: translateX(-50%) scale(0.97); }
body.modal-open .gift-btn { opacity: 0; pointer-events: none; }

/* ─── HOTKEY HINT ──────────────────────── */
.hotkey-hint {
    position: absolute;
    bottom: 24px; right: 10px;
    font-size: 9px;
    font-weight: 700;
    color: rgba(255,255,255,0.16);
    z-index: 5;
}
kbd {
    display: inline-block;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 3px;
    padding: 1px 4px;
    font: inherit;
}

/* ─── MODAL OVERLAY (absolute in phone) ── */
.modal-overlay {
    position: absolute; inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s var(--ease);
}
.modal-overlay.is-open {
    opacity: 1; pointer-events: all;
}

/* ─── SELECTOR PANEL ───────────────────── */
#modal-selector {
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
}
.selector-panel {
    width: 320px;
    display: flex; flex-direction: column; align-items: center;
    transform: translateY(18px) scale(0.96);
    transition: transform .3s var(--bounce);
}
.modal-overlay.is-open .selector-panel { transform: translateY(0) scale(1); }

.user-input-row {
    width: 100%;
    background: var(--modal); border: 1px solid var(--border); border-radius: 12px;
    padding: 12px 14px;
    display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
    box-shadow: 0 20px 48px rgba(0,0,0,0.6);
}
.avatar-icon {
    width: 26px; height: 26px; border-radius: 50%;
    background: #2d2f31; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.user-input {
    flex: 1; background: transparent; border: none; color: #fff;
    font-size: 14px; font-weight: 700; outline: none; caret-color: var(--green);
}
.user-input::placeholder { color: var(--muted); font-weight: 600; }
.close-x {
    cursor: pointer; color: var(--muted); font-size: 15px; flex-shrink: 0;
    transition: color .15s; pointer-events: all;
}
.close-x:hover { color: #fff; }

.sel-amount { font-size: 26px; font-weight: 900; letter-spacing: -0.5px; margin-bottom: 4px; }
.sel-sublabel {
    font-size: 11px; font-weight: 800; color: var(--muted); text-align: center;
    text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; line-height: 1.6;
}
.at-user { display: block; opacity: 0.55; }

.btn-confirm {
    width: 100%; padding: 13px; background: var(--green); color: #000;
    border: none; border-radius: 8px; font-size: 14px; font-weight: 900;
    letter-spacing: 1px; cursor: pointer; margin-bottom: 14px;
    transition: background .15s, transform .1s;
}
.btn-confirm:hover  { background: var(--green-h); }
.btn-confirm:active { transform: scale(0.98); }

.package-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.pkg-card {
    background: rgba(31,34,38,0.96); border: 2px solid var(--border);
    border-radius: 10px; padding: 16px 8px 12px;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    cursor: pointer; transition: background .15s, border-color .15s, transform .1s;
    pointer-events: all;
}
.pkg-card:hover  { background: rgba(40,44,50,1); }
.pkg-card:active { transform: scale(0.97); }
.pkg-card.is-active { border-color: var(--green); background: rgba(60,224,112,0.08); }
.pkg-card.is-active span { color: #fff; }
.pkg-card span { font-size: 11px; font-weight: 800; color: var(--muted); text-align: center; }
.rbx-ico { width: 32px; height: 32px; }

/* ─── BUY PANEL ────────────────────────── */
#modal-buy { background: transparent; }
.buy-panel {
    width: 340px; background: var(--modal); border: 1px solid var(--border);
    border-radius: 14px; overflow: hidden;
    box-shadow: 0 36px 80px rgba(0,0,0,0.74), inset 0 1px 0 rgba(255,255,255,0.04);
    transform: scale(0.92); transition: transform .32s var(--bounce);
}
.modal-overlay.is-open .buy-panel { transform: scale(1); }

.buy-header {
    padding: 18px 20px; display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border);
}
.buy-title { font-size: 16px; font-weight: 800; }
.buy-header-right { display: flex; align-items: center; gap: 14px; }
.balance-chip {
    display: flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 800; color: var(--muted);
}

.buy-body { padding: 20px; display: flex; align-items: center; gap: 16px; }
.buy-icon-box {
    width: 66px; height: 66px; background: rgba(255,255,255,0.04);
    border: 1px solid var(--border); border-radius: 10px;
    display: flex; justify-content: center; align-items: center; flex-shrink: 0;
}
.buy-details { display: flex; flex-direction: column; gap: 7px; }
.buy-item-name { font-size: 14px; font-weight: 800; line-height: 1.4; }
.buy-price-row {
    display: flex; align-items: center; gap: 5px;
    font-size: 13px; font-weight: 800; color: var(--muted);
}

.buy-footer { padding: 0 20px 20px; }
.btn-buy {
    width: 100%; padding: 14px; background: var(--blue); color: #fff;
    border: none; border-radius: 8px; font-size: 15px; font-weight: 900;
    cursor: pointer; transition: background .15s, transform .1s;
}
.btn-buy:hover  { background: var(--blue-h); }
.btn-buy:active { transform: scale(0.98); }

/* ─── LIVE CHAT FEED ───────────────────── */
.chat-feed {
    position: absolute;
    bottom: 120px;
    left: 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-start;
    gap: 8px;
    z-index: 150;
    pointer-events: none;
    width: 280px;
    max-height: 250px;
    overflow: hidden;
}

.chat-bubble {
    background: rgba(14, 16, 19, 0.7);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 20px;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slide-in-left 0.4s var(--bounce) forwards;
    opacity: 0;
    transform: translateX(-40px);
}
.chat-bubble.fade-out {
    animation: fade-out-chat 0.4s ease forwards;
}

.chat-icon {
    width: 24px; height: 24px; border-radius: 50%;
    background: #e0e0e0; display: flex; align-items: flex-end; justify-content: center;
    overflow: hidden; flex-shrink: 0;
}
.chat-text {
    font-size: 13px; color: #fff; font-weight: 500; text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.chat-text strong {
    font-weight: 800; color: var(--green);
}

@keyframes slide-in-left {
    to { opacity: 1; transform: translateX(0); }
}
@keyframes fade-out-chat {
    to { opacity: 0; transform: translateY(-10px); }
}

/* ─── HEADER ───────────────────────────── */
.app-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background:
        radial-gradient(ellipse at 50% 0%,  #1a1550 0%,  transparent 58%),
        radial-gradient(ellipse at 10% 100%,#0e1a3a 0%,  transparent 50%),
        radial-gradient(ellipse at 90% 100%,#0e1a3a 0%,  transparent 50%),
        #06080f;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    z-index: 40;
}

.header-title {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.5px;
    color: #fff;
}

.menu-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ─── MENU DROPDOWN ────────────────────── */
.menu-dropdown {
    position: absolute;
    top: 56px;
    right: 8px;
    background: var(--modal);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    z-index: 39;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px) scale(0.95);
    transition: opacity 0.2s, transform 0.2s;
    min-width: 160px;
    overflow: hidden;
}

.menu-dropdown.is-open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0) scale(1);
}

.menu-item {
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ─── LOGIN MODAL ──────────────────────── */
#modal-login {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.login-panel {
    width: 300px;
    background: var(--modal);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 36px 80px rgba(0, 0, 0, 0.8);
    overflow: hidden;
    transform: scale(0.92) translateY(-20px);
    transition: transform 0.3s var(--bounce);
    opacity: 0;
}

#modal-login.is-open .login-panel {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.login-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.login-header h2 {
    font-size: 24px;
    font-weight: 900;
    letter-spacing: -0.5px;
    margin: 0;
}

.login-close-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.login-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.login-body {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-form-group label {
    font-size: 12px;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.login-input {
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    outline: none;
    transition: background 0.15s, border-color 0.15s;
    caret-color: var(--green);
}

.login-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--green);
}

.login-input::placeholder {
    color: var(--muted);
}

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper .login-input {
    padding-right: 40px;
    width: 100%;
}

.password-toggle-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
    z-index: 2;
    pointer-events: all;
}

.password-toggle-btn:hover {
    color: #fff;
}

.password-toggle-btn svg {
    width: 18px;
    height: 18px;
}

.hidden {
    display: none !important;
}

.btn-login {
    padding: 14px;
    background: var(--green);
    color: #000;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    margin-top: 8px;
}

.btn-login:hover {
    background: var(--green-h);
}

.btn-login:active {
    transform: scale(0.98);
}

.btn-login:disabled {
    background: var(--muted);
    cursor: not-allowed;
    opacity: 0.6;
}

.login-error {
    font-size: 12px;
    color: #ff6b6b;
    font-weight: 600;
    text-align: center;
    min-height: 16px;
}

/* Adjust char-zone top to account for header */
.app-header + .char-zone {
    top: 56px;
}
