/* --- [1] الهيكل العام والشاشات (Layout & View Switching) --- */

#app-container {
    display: flex;
    flex-direction: column; /* جعل الترتيب عمودياً لضمان الامتداد السليم */
    justify-content: flex-start;
    align-items: center;
    min-height: 100vh;
    padding: 0;
    width: 100%;
    overflow-x: hidden; /* منع التمرير العرضي */
}

.content-wrapper {
    max-width: 1200px; 
    margin: 0 auto;
    position: relative; 
    padding: 0;
    width: 100%; 
    height: 100%;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.screen {
    display: none; 
    width: 100%;
    flex-grow: 1;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    
    /* [إصلاح جذري] إزالة الحشو الثابت والاعتماد على المرونة */
    padding-top: 10px !important; 
    margin-top: 0;
    
    background-color: transparent;
    border: none;
    
    animation: pixel-fade-in 0.3s forwards;
}

@keyframes pixel-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

#app-container[data-view="home"] #screen-home { 
    display: flex; 
}
#app-container[data-view="game"] #screen-game { 
    display: flex; 
}

/* إخفاء الهيدر القديم عند التبديل */
#app-container[data-view="game"] .screen-header {
    display: none;
}


/* --- [2] هيكل شاشة البداية (Screen Home Layout) --- */

#screen-home {
    gap: 20px;
    justify-content: flex-start;
}

/* --- [3] تنسيق الصناديق والهيدر (Box Styles) --- */
.screen-header {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    margin-bottom: 10px;
    text-align: center;
    
    /* [إصلاح] إزالة الوضع المطلق ليأخذ مساحته الطبيعية */
    position: relative; 
    top: auto;
    left: auto;
    transform: none;
}

.game-logo {
    image-rendering: pixelated;
    margin-bottom: 10px;
}
.game-logo.large {
    width: 100%;
    max-width: 300px; /* حد أقصى للعرض */
    height: auto;
    display: block;
}
.game-logo.small {
    width: 48px; 
    height: 48px;
    margin-bottom: 0;
    display: none; 
}

#screen-home .game-logo.large { display: block; }
#screen-home .game-logo.small { display: none; }
#screen-game .game-logo.large { display: none !important; } 
#screen-game .game-logo.small { display: block !important; }


.settings-box {
    background-color: #312d3f; 
    width: 100%;
    border: var(--border-width) solid #60347c; 
    box-shadow: inset 0 0 0 var(--border-width) var(--border-color-dark);
}
.settings-box-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr; 
    gap: 20px;
    width: 100%;
}

@media (min-width: 800px) {
    .settings-grid {
        grid-template-columns: repeat(3, 1fr); 
        align-items: flex-start;
    }
    .settings-grid-top {
        grid-template-columns: 1.2fr 0.6fr 1.2fr;
    }
    .settings-grid .settings-column-middle {
        align-items: center;
        justify-content: center;
        display: flex;
        height: 100%;
    }
}


/* --- [4] هيكل شاشة اللعب (Screen Game Layout) --- */
#screen-game {
    gap: 10px;
    padding-bottom: 20px;
    justify-content: flex-start;
}

#game-header {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.2); /* تمييز خفيف للهيدر */
    border-radius: 8px !important;
    
    /* [إصلاح] إزالة الوضع المطلق */
    position: relative; 
    top: auto;
    left: auto;
    transform: none;
    z-index: 5;
    border-bottom: none;
}

#game-title-info {
    text-align: center;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 15px;
    width: 100%;
    flex-wrap: wrap;
}

#game-controls-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

#player-turn-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    width: 100%;
    max-width: 600px;
    align-items: stretch;
}
#timer-display {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-width: 100px;
}

/* --- [5] هيكل لوحة اللعب (Game Board) --- */
#game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    
    /* [مهم] هذا هو لون الخطوط الفاصلة (الشبكة) */
    gap: 10px; 
    background-color: var(--border-color-light); /* لون الخط الفاصل */
    
    width: 100%;
    max-width: 450px;
    aspect-ratio: 1 / 1;
    margin: 10px auto;
    position: relative;
    
    /* حدود خارجية للوحة */
    border: var(--border-width) solid var(--border-color-dark);
    padding: 10px; /* إطار خارجي */
}

.board-cell {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    
    /* [مهم] لون الخانات (يجب أن يختلف عن لون الخلفية لتظهر الشبكة) */
    background-color: #261b36; 
    
    cursor: pointer;
    position: relative;
    image-rendering: pixelated;
    text-align: center;
    overflow: hidden;
    
    /* حدود داخلية (اختياري) لتعزيز المظهر */
    box-shadow: inset 2px 2px 0px rgba(255,255,255,0.05), inset -2px -2px 0px rgba(0,0,0,0.2);
}

/* --- [6] تعديلات الاستجابة (Responsive) --- */

/* للشاشات المتوسطة والصغيرة */
@media (max-width: 800px) {
    #game-header {
        width: 100%;
    }
    
    #game-board {
        max-width: 100%; /* استغلال كامل العرض المتاح */
        gap: 5px; /* تقليل سمك الشبكة قليلاً */
        padding: 5px;
    }
}

/* للموبايل فقط */
@media (max-width: 600px) {
    .screen {
        padding: 10px;
    }
    
    #game-title-info {
        gap: 5px;
    }
    
    .score-tag {
        font-size: 0.8rem;
        padding: 5px 8px;
    }

    #player-turn-bar {
        grid-template-columns: 1fr; /* ترتيب العناصر فوق بعضها */
        gap: 5px;
    }
    #timer-display {
        order: -1; /* رفع المؤقت للأعلى */
        flex-direction: row;
        gap: 10px;
        padding: 5px;
        width: 100%;
    }
    .player-tag {
        flex-direction: row;
        justify-content: space-between;
        padding: 5px 10px;
    }
    
    /* تصغير اللوجو في البداية */
    .game-logo.large {
        max-width: 200px;
    }
    
    /* إخفاء اللوجو الصغير في اللعب لتوفير المساحة */
    .game-logo.small {
        display: none !important;
    }
}
