
:root {
    --bg: #101123;
    --surface: #16193a;
    --primary: #1e254f;
    --border-color: #2a2f59;
    --text-primary: #ffffff;
    --text-secondary: #a9b3d5;
    --pixel-color: #39d353;
    --glow-color: rgba(57, 211, 83, 0.7);
    --gold: #ffd700;
    --silver: #c0c0c0;
    --bronze: #cd7f32;

    --screen-height: 100vh;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
}

body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text-primary);
    font-family: Vazirmatn, system-ui, sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.main-container {
    display: flex;
    height: var(--screen-height);
    padding: 1rem;
    justify-content: center;
    align-items: center;
}

.game-column {
    width: 100%;
    height: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
}

header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

header h1 {
    font-family: 'Lalezar', cursive;
    font-size: clamp(24px, 5vw, 32px);
    margin: 0;
    text-align: center;
    color: var(--text-primary);
    text-shadow: 0 0 10px var(--glow-color);
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 10px;
}

.stats {
    display: flex;
    gap: 12px;
    font-size: clamp(14px, 3vw, 16px);
}

.stats span {
    background: var(--primary);
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 500;
}

#score {
    color: var(--gold);
    font-weight: bold;
    transition: transform 0.2s ease;
}

#score.popped {
    transform: scale(1.2);
}

.stage-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    min-height: 0;
}

.stage {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: 100%;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    border-radius: 10px;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.controls {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.btn {
    width: 100%;
    background-image: linear-gradient(to top, #26a241, #39d353);
    color: var(--bg);
    border: none;
    padding: 14px 20px;
    border-radius: 12px;
    cursor: pointer;
    user-select: none;
    font-size: 1.1rem;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    box-shadow: 0 4px 0 #1b7931, 0 6px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.1s ease-out;
    font-family: Vazirmatn, system-ui, sans-serif;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #1b7931, 0 8px 12px rgba(0, 0, 0, 0.3);
}

.btn:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #1b7931, 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn:disabled {
    background: #555;
    box-shadow: 0 4px 0 #333;
    cursor: not-allowed;
    opacity: 0.7;
}

.btn.icon-btn {
    width: auto;
    background: var(--primary);
    box-shadow: none;
    font-size: 1.5rem;
    padding: 6px 12px;
}

.btn.btn-secondary {
    background-image: linear-gradient(to top, #4a4e69, #6b7091);
    box-shadow: 0 4px 0 #3b3f55;
}


.overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 10vh 1rem;
    background: rgba(16, 17, 35, 0.7);
    backdrop-filter: blur(8px);
    z-index: 10;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    padding: 24px;
    border-radius: 16px;
    text-align: center;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: fadeIn .3s ease-out;
    position: relative;
    /* اصلاح اصلی برای فشردگی */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem; /* فاصله بین تمام آیتم‌های داخل کارت */
}

.card h2, .card p {
    margin: 0;
}

/* حذف مارجین‌های پیش‌فرض */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}


#name-input {
    background-color: var(--primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-size: 1rem;
    font-family: Vazirmatn, system-ui, sans-serif;
    text-align: center;
    transition: all 0.2s ease;
}

#name-input:focus {
    outline: none;
    border-color: var(--pixel-color);
    box-shadow: 0 0 10px var(--glow-color);
}

#name-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.prompt-buttons {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.prompt-buttons .btn {
    flex-grow: 1; /* هر دو دکمه عرض یکسانی می‌گیرند */
}

/* ============================================== */

.close-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

/* Leaderboard Modal */
.leaderboard-card {
    gap: 1rem;
}

#leaderboard {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 60vh;
    overflow-y: auto;
    width: 100%;
}

#leaderboard li {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    background: var(--primary);
}

#leaderboard li.is-player {
    border: 2px solid var(--gold);
}

#leaderboard .rank-1, #leaderboard .rank-2, #leaderboard .rank-3 {
    font-weight: bold;
}

#leaderboard .rank-1 {
    background: linear-gradient(45deg, var(--gold), #b89b00);
    color: #222;
}

#leaderboard .rank-2 {
    background: linear-gradient(45deg, var(--silver), #a0a0a0);
    color: #222;
}

#leaderboard .rank-3 {
    background: linear-gradient(45deg, var(--bronze), #a05a2c);
    color: var(--text-primary);
}

#leaderboard li .rank {
    margin-left: 1rem;
}

#leaderboard li .name {
    flex-grow: 1;
    text-align: right;
}

#leaderboard li .score {
    font-weight: bold;
    margin-right: 1rem;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}

.toast-item {
    background: rgba(30, 37, 79, 0.9);
    border: 1px solid #333a77;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #fff;
    animation: slideInUp .3s ease-out, fadeOutToast .5s ease-in 4.5s forwards;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOutToast {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Mobile Layout */
@media (max-width: 480px) {
    header h1 {
        margin-bottom: 10px;
    }

    .header-actions {
        flex-direction: column-reverse;
        align-items: stretch;
        text-align: center;
    }

    .stats {
        justify-content: space-around;
    }

    .btn {
        padding: 12px;
        font-size: 1rem;
    }
}