/* === إعدادات الصفحة الأساسية === */
* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #222;
    touch-action: none;
    -webkit-font-smoothing: antialiased;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* === الشاشات (Layers) === */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    transition: opacity 0.3s;
}

/* === القائمة الرئيسية (Grid Layout الجديد) === */
#main-menu {
    background: rgba(0, 0, 0, 0.2);
    z-index: 100;
    display: block;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 30px 15px;
    text-align: center;
}

.menu-header {
    margin-bottom: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.menu-title {
    font-size: 40px;
    color: white;
    text-shadow: 4px 4px 0 #FF1493, -2px -2px 0 #87CEEB;
    font-weight: 900;
    margin-top: 15px;
    animation: bounceTitle 2s infinite ease-in-out;
}

.menu-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 5px solid white;
    background: #87CEEB;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    animation: floatAvatar 3s infinite ease-in-out;
}

/* خانة الاسم */
.player-input-box {
    margin-top: 15px;
    display: flex;
    gap: 8px;
    background: white;
    padding: 6px;
    border-radius: 50px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    transform: scale(1);
    transition: transform 0.2s;
}

.player-input-box:focus-within {
    transform: scale(1.05);
}

.player-input-box input {
    border: none;
    padding: 8px;
    border-radius: 20px;
    font-weight: bold;
    text-align: center;
    width: 140px;
    font-size: 16px;
    color: #333;
}

.player-input-box button {
    background: #FF1493;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 50px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 3px 0 #C71585;
    transition: transform 0.1s;
}

.player-input-box button:active {
    transform: translateY(3px);
    box-shadow: none;
}

/* شريط التحكم العلوي */
.top-menu-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.menu-coins {
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: bold;
    color: #333;
    font-size: 16px;
    border: 3px solid #FFD700;
    display: inline-block;
    min-width: 80px;
}

.menu-icon-btn {
    background: #FFF;
    border: 3px solid #87CEEB;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
    transition: transform 0.1s;
}

.menu-icon-btn:active {
    transform: translateY(3px);
    box-shadow: none;
}


/* === شبكة الألعاب (التصميم الجديد) === */
.games-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* عمودين متساويين */
    gap: 15px;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding-bottom: 80px;
}

/* البطاقة الأساسية (شكل مربع للألعاب) */
.game-card {
    background: rgba(255, 255, 255, 0.95);
    border: 4px solid white;
    border-radius: 25px;
    padding: 15px;

    /* ترتيب عمودي: أيقونة فوق، نص تحت */
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    gap: 10px;

    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.1);
    cursor: pointer;
    width: 100%;
    text-align: center;
    transition: transform 0.1s, background 0.2s;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* إصلاح أزرار الجوال */
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    z-index: 1;
    min-height: 140px;
    /* ارتفاع ثابت للبطاقات */
}

.game-card:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.game-card:hover {
    background: #fff;
}

.game-info {
    text-align: center;
    width: 100%;
    padding: 0;
}

.game-name {
    font-size: 16px;
    font-weight: 900;
    color: #333;
    margin-bottom: 5px;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.game-score {
    font-size: 12px;
    color: #666;
    background: #eee;
    padding: 4px 8px;
    border-radius: 10px;
    display: inline-block;
    font-weight: bold;
}

.game-icon {
    font-size: 35px;
    background: #FFEFF5;
    width: 65px;
    height: 65px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #FF69B4;
    margin: 0 auto;
}

/* === زر المتجر المميز (عريض) === */
.shop-main-btn {
    grid-column: 1 / -1;
    /* يأخذ كامل عرض الشبكة (عمودين) */
    flex-direction: row;
    /* يرجع للشكل الأفقي */
    justify-content: space-between;
    text-align: right;
    min-height: auto;
    /* ارتفاع تلقائي */
    padding: 15px 20px;

    border-color: #FFD700 !important;
    background: #FFFACD !important;
    box-shadow: 0 8px 0 #FFD700 !important;
    margin-bottom: 5px;
}

.shop-main-btn:active {
    box-shadow: 0 4px 0 #FFD700 !important;
    transform: translateY(4px);
}

.shop-main-btn .game-info {
    text-align: right;
    padding-right: 15px;
}

.shop-main-btn .game-name {
    font-size: 20px;
}

.shop-main-btn .game-icon {
    margin: 0;
}

/* إلغاء التوسيط للأيقونة */


/* === باقي التنسيقات (كما هي) === */
button {
    font-family: inherit;
    pointer-events: auto !important;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
    border: none;
    outline: none;
}

#ui-layer {
    position: fixed;
    top: 15px;
    left: 15px;
    right: 15px;
    display: none;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 150;
}

.hud-left {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.stat-box {
    background: rgba(0, 0, 0, 0.6);
    padding: 5px 12px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.7);
    color: white;
    font-weight: bold;
    font-size: 16px;
    text-shadow: 1px 1px 0 #000;
    display: flex;
    align-items: center;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.25);
    border: 2px solid white;
    color: white;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
    position: relative;
    z-index: 151;
}

.btn-icon:active {
    background: rgba(255, 255, 255, 0.5);
    transform: scale(0.9);
}

.overlay {
    display: none;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 60;
}

.modal-box {
    background: white;
    padding: 25px;
    border-radius: 25px;
    border: 5px solid #FF1493;
    text-align: center;
    width: 85%;
    max-width: 350px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#achievements-modal .modal-box,
#leaderboard-modal .modal-box {
    max-width: 500px;
    width: 90%;
}

.modal-box h2 {
    color: #d35400;
    margin: 0 0 10px;
    font-size: 28px;
}

.result-box {
    margin: 20px 0;
    font-size: 18px;
    line-height: 1.6;
}

.result-box span {
    font-weight: bold;
}

.action-btn {
    background: #FF1493;
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 18px;
    border-radius: 50px;
    margin-top: 10px;
    font-weight: bold;
    width: 100%;
    box-shadow: 0 4px 0 #C71585;
    cursor: pointer;
}

.action-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.action-btn.secondary {
    background: #87CEEB;
    box-shadow: 0 4px 0 #5F9EA0;
}

.big-btn {
    background: white;
    color: #FF1493;
    border: none;
    padding: 15px 40px;
    font-size: 24px;
    border-radius: 50px;
    font-weight: bold;
    cursor: pointer;
}

/* زر الموسيقى */
.music-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #FF1493;
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 14px;
    font-weight: bold;
    color: #FF1493;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.music-btn:hover {
    transform: scale(1.05);
    background: #fff;
}

.music-btn:active {
    transform: scale(0.95);
    background: #eee;
}

#speech-bubble {
    display: none;
    position: absolute;
    background: white;
    border: 3px solid #FF1493;
    border-radius: 20px;
    padding: 8px 15px;
    color: #333;
    font-weight: bold;
    font-size: 16px;
    text-align: center;
    z-index: 15;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
    pointer-events: none;
    transition: 0.1s;
}

#speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 20px;
    border-width: 10px 10px 0;
    border-style: solid;
    border-color: #FF1493 transparent;
    display: block;
    width: 0;
}

#rotate-msg {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #FF1493;
    z-index: 99999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-align: center;
}

@media screen and (orientation: portrait) {
    body.game-running #rotate-msg {
        display: flex !important;
    }

    body.game-running #main-menu {
        display: none !important;
    }
}

#go-new-record {
    display: none;
    color: #FFD700;
    font-weight: bold;
    margin-top: 10px;
    font-size: 20px;
    animation: pulse 1s infinite;
    text-shadow: 0 0 5px orange;
}

.achievement-popup {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 15px 25px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 3000;
    border: 2px solid #FFD700;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: slideDown 0.5s ease-out;
    pointer-events: none;
    transition: opacity 0.5s;
    min-width: 250px;
}

.leaderboard-tabs {
    display: flex;
    justify-content: center;
    gap: 5px;
    background: #f0f0f0;
    padding: 5px;
    border-radius: 15px;
    margin-bottom: 5px;
    flex-wrap: wrap;
}

.lb-tab {
    background: white;
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 5px 10px;
    font-size: 20px;
    cursor: pointer;
    flex: 1;
    min-width: 40px;
}

.lb-tab.active {
    background: #FF1493;
    color: white;
    border-color: #FF1493;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.tut-content p {
    margin-bottom: 10px;
    border-bottom: 1px dashed #eee;
    padding-bottom: 5px;
}

.tut-content strong {
    color: #00BFFF;
}

#tutorial-modal .modal-box {
    border: 5px solid #00BFFF;
}

/* === لوحة الإنجازات (Grid) === */
#achievements-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 15px;
    padding: 10px;
    width: 100%;
}

.ach-item {
    background: white;
    border: 3px solid #eee;
    border-radius: 20px;
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    transition: transform 0.2s;
    position: relative;
    box-shadow: 0 4px 0 #ddd;
}

.ach-item.locked {
    filter: grayscale(1);
    opacity: 0.8;
    background: #f9f9f9;
}

.ach-item.unlocked {
    border-color: #FFD700;
    background: linear-gradient(to bottom right, #ffffe0, #ffffff);
    box-shadow: 0 4px 0 #FFD700;
}

.ach-item.unlocked:active {
    transform: translateY(4px);
    box-shadow: none;
}

.ach-icon {
    font-size: 35px;
    background: rgba(0, 0, 0, 0.03);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ach-info {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ach-title {
    font-weight: bold;
    font-size: 14px;
    color: #333;
    line-height: 1.2;
}

.ach-desc {
    font-size: 11px;
    color: #777;
    line-height: 1.2;
    height: 26px;
    overflow: hidden;
}

.ach-reward {
    font-weight: bold;
    font-size: 12px;
    color: #fff;
    background: #FF1493;
    padding: 4px 10px;
    border-radius: 12px;
    margin-top: auto;
}

.ach-item.locked .ach-reward {
    background: #ccc;
    color: #666;
}

/* === المتجر === */
#shop-screen {
    background: #f4f4f4 !important;
    overflow: hidden;
    z-index: 200;
    display: none;
    flex-direction: column;
}

.shop-header {
    width: 100%;
    padding: 15px;
    background: #FF69B4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.shop-title {
    font-size: 24px;
    color: white;
    font-weight: bold;
}

.shop-content {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.shop-preview {
    background: #87CEEB;
    border-radius: 50%;
    border: 4px solid white;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    margin-bottom: 15px;
    flex-shrink: 0;
    width: 110px;
    height: 110px;
    max-width: 25vw;
    max-height: 25vw;
}

#shop-grid {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    padding-bottom: 50px;
    gap: 15px;
}

.shop-section-title {
    font-size: 20px;
    font-weight: bold;
    color: #FF1493;
    background: rgba(255, 255, 255, 0.8);
    padding: 8px 15px;
    border-radius: 10px;
    margin-top: 10px;
    border-right: 5px solid #FFD700;
    text-align: right;
}

.shop-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    width: 100%;
}

.shop-card {
    background: white;
    border-radius: 15px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
    border: 2px solid #eee;
    transition: transform 0.1s;
}

.shop-card:active {
    transform: scale(0.98);
}

.shop-card.equipped {
    border-color: #4CAF50;
    background: #E8F5E9;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
}

.shop-icon {
    font-size: 35px;
    margin-bottom: 5px;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.shop-name {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 8px;
    color: #333;
    text-align: center;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shop-btn {
    border: none;
    padding: 6px 12px;
    border-radius: 20px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    font-size: 13px;
}

.btn-buy {
    background: #FF1493;
    box-shadow: 0 3px 0 #C71585;
}

.btn-own {
    background: #2196F3;
    box-shadow: 0 3px 0 #1976D2;
}

.btn-equipped {
    background: #4CAF50;
    box-shadow: none;
    cursor: default;
}

.btn-locked {
    background: #ccc;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-buy:active,
.btn-own:active {
    transform: translateY(3px);
    box-shadow: none;
}

@keyframes bounceTitle {

    0%,
    100% {
        transform: translateY(0) rotate(-2deg);
    }

    50% {
        transform: translateY(-10px) rotate(2deg);
    }
}

@keyframes floatAvatar {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes slideDown {
    from {
        top: -100px;
    }

    to {
        top: 20px;
    }
}

/* === تنسيقات شاشة المقدمة (Intro) === */
.intro-title {
    font-size: 60px;
    color: white;
    text-shadow: 4px 4px 0px #FF69B4, -2px -2px 0 #00BFFF;
    margin-bottom: 20px;
    animation: popIn 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.intro-avatar {
    width: 150px;
    height: 150px;
    padding-left: 0;
    padding-right: 0;
    margin-left: auto;
    margin-right: auto;
    display: block;
    border-radius: 50%;
    border: 8px solid white;
    background: #87CEEB;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.6);
    animation: floatAvatar 3s infinite ease-in-out;
}

/* زر البدء النابض */
.start-btn-anim {
    background: #FFD700 !important;
    color: #333 !important;
    font-size: 28px !important;
    padding: 15px 50px !important;
    border: 5px solid white !important;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3) !important;
    animation: pulseBtn 1.5s infinite;
    margin-top: 30px;
}

@keyframes pulseBtn {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.7);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 15px rgba(255, 215, 0, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
    }
}