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

:root {
    --font-primary: 'Cairo', sans-serif;
    --color-dark-bg: #1a1a2e;
    --color-light-bg: #f0f0f0;
    --color-text-dark: #ffffff;
    --color-purple: #8e44ad;
    --color-red: #c0392b;
    --color-grey: #bdc3c7;
    --color-yellow: #f1c40f;
    --hex-width: 90px;
    --hex-height: 104px; 
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-primary); margin: 0; padding: 0; overflow: hidden;
    background-color: var(--color-dark-bg); 
    background-image: url('assets/images/background.dark.png');
    background-size: cover; background-position: center;
    /* استخدام dvh للجوال لحل مشكلة شريط المتصفح */
    height: 100vh; 
    height: 100dvh; 
    width: 100vw; user-select: none;
    color: white;
    /* حماية من النوتش */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* ================= 1. الشاشات ================= */
.screen {
    position: absolute; top: 0; left: 0; width: 100%; 
    height: 100%; height: 100dvh; /* مهم جداً للجوال */
    display: none !important; z-index: 10;
    background-color: var(--color-dark-bg);
    background-image: url('assets/images/background.dark.png');
    background-size: cover;
}
.screen.active { display: flex !important; flex-direction: column; align-items: center; z-index: 20; }

/* ================= 2. الدخول ================= */
#security-screen { z-index: 99999 !important; justify-content: center; }
.login-container {
    display: flex; flex-direction: column; align-items: center; padding: 40px;
    background: rgba(0, 0, 0, 0.9); border: 2px solid var(--color-yellow);
    border-radius: 30px; box-shadow: 0 0 50px rgba(0,0,0,0.8); width: 90%; max-width: 400px;
}
.login-logo { width: 150px; margin-bottom: 20px; }
.login-container input {
    font-family: var(--font-primary); padding: 12px; margin-bottom: 20px;
    background: #333; border: 1px solid #555; color: white;
    text-align: center; font-size: 1.2rem; width: 100%; border-radius: 10px;
}
.login-container button {
    font-size: 1.2rem; font-weight: bold; padding: 12px; border: none; border-radius: 50px;
    background: var(--color-yellow); color: #000; cursor: pointer; width: 100%;
}
#login-error-message { color: red; margin-top: 15px; font-weight: bold; }

/* ================= 3. القائمة ================= */
.main-menu-wrapper {
    width: 95%; max-width: 1000px; margin: auto; padding: 20px;
    background: rgba(0, 0, 0, 0.85); border-radius: 20px;
    border: 1px solid #444; display: flex; flex-direction: column; align-items: center;
    max-height: 90dvh; overflow-y: auto; position: relative;
}
.menu-logo { width: 140px; margin-bottom: 10px; }

.sound-icon-btn {
    position: absolute; top: 20px; right: 20px;
    background: rgba(255,255,255,0.1); border: 1px solid #555; 
    width: 40px; height: 40px; border-radius: 50%; cursor: pointer; 
    display: flex; align-items: center; justify-content: center; z-index: 200;
}

.mode-switcher { display: flex; gap: 20px; margin-bottom: 15px; z-index: 50; }
.mode-tab { background: none; border: none; color: #777; font-size: 1.4rem; font-family: var(--font-primary); font-weight: bold; cursor: pointer; }
.mode-tab.active { color: white; border-bottom: 3px solid var(--color-yellow); transform: scale(1.1); }
.mode-divider { color: #444; font-size: 1.5rem; }

.vs-arena {
    display: flex; width: 100%; justify-content: space-between; 
    background: rgba(255,255,255,0.03); border-radius: 15px; padding: 20px; 
    position: relative; margin-bottom: 20px; border: 1px solid #333;
}
.team-column { flex: 1; text-align: center; z-index: 100; }
.column-title { font-size: 1.3rem; font-weight: 900; margin-bottom: 15px; }
.red-side .column-title { color: var(--color-red); }
.purple-side .column-title { color: var(--color-purple); }
.vs-divider { 
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); 
    font-size: 3rem; font-weight: 900; color: rgba(255,255,255,0.1); z-index: 0; pointer-events: none;
}

.input-group input, .member-input {
    background: rgba(255, 255, 255, 0.15); border: 1px solid #666; border-radius: 8px;
    color: white; font-family: var(--font-primary); font-size: 1.1rem; padding: 10px;
    text-align: center; width: 90%; margin: 5px auto; display: block;
    position: relative; z-index: 5000 !important; pointer-events: auto !important;
}
.roster-list { display: flex; flex-direction: column; gap: 5px; width: 100%; align-items: center; margin-bottom: 10px; }
.add-roster-btn {
    background: #444; color: white; border: 1px solid #666; padding: 8px 20px; 
    border-radius: 10px; cursor: pointer; font-family: var(--font-primary); font-size: 0.9rem;
    position: relative; z-index: 5000 !important; margin-top: 10px; display: inline-block;
}

.bottom-settings-bar { 
    display: flex; gap: 15px; margin: 10px 0; background: rgba(255,255,255,0.05); 
    padding: 15px; border-radius: 15px; flex-wrap: wrap; justify-content: center;
}
.setting-group-row { display: flex; align-items: center; gap: 10px; }
.pill-btn { 
    background: transparent; border: 1px solid #555; color: #aaa; 
    padding: 6px 15px; border-radius: 15px; cursor: pointer; font-family: var(--font-primary);
}
.pill-btn.active { background: white; color: black; font-weight: bold; border-color: white; }

.launch-button {
    font-size: 1.5rem; font-weight: 900; color: white; margin-top: 15px;
    background: linear-gradient(90deg, var(--color-purple), var(--color-red));
    border: none; padding: 15px 80px; border-radius: 50px; cursor: pointer; 
}
.text-link { background: none; border: none; color: var(--color-yellow); text-decoration: underline; margin-top: 15px; cursor: pointer; }

/* ================= 4. اللعب (Desktop) ================= */
#game-screen { flex-direction: row; justify-content: space-between; overflow: hidden; }

.side-panel {
    width: 220px; height: 100%; background: rgba(0,0,0,0.85);
    display: flex; flex-direction: column; border: 1px solid #333; z-index: 30;
}
.right-panel { order: 3; border-left: 5px solid var(--color-red); }
.left-panel { order: 1; border-right: 5px solid var(--color-purple); }
.center-game-area { order: 2; flex: 1; display: flex; flex-direction: column; align-items: center; }

.active-turn-red { box-shadow: inset -10px 0 30px rgba(192, 57, 43, 0.4); }
.active-turn-purple { box-shadow: inset 10px 0 30px rgba(142, 68, 173, 0.4); }

.panel-header { padding: 15px; display: flex; justify-content: space-between; align-items: center; color: white; border-bottom: 1px solid #444; font-weight: bold; }
.turn-indicator-dot { width: 10px; height: 10px; background: #333; border-radius: 50%; }
.active-turn-red .turn-indicator-dot { background: var(--color-red); box-shadow: 0 0 10px red; }
.active-turn-purple .turn-indicator-dot { background: var(--color-purple); box-shadow: 0 0 10px purple; }

.team-info-box { text-align: center; width: 100%; }
.main-name { display: block; font-size: 1.3rem; font-weight: bold; }
.sub-name { display: block; font-size: 0.9rem; color: var(--color-yellow); margin-top: 3px; font-weight: normal; }

.roster-vertical-list { flex: 1; padding: 10px; overflow-y: auto; }
.roster-item { padding: 8px; color: #ddd; text-align: center; border-bottom: 1px solid #333; font-size: 0.9rem; }

.game-header-minimal { margin-top: 10px; z-index: 30; }
.game-logo-small { width: 100px; }

#game-board-container { 
    flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 10; margin-top: 80px; 
}
.hex-row { display: flex; margin-top: -35px; }
.hex-row:nth-child(even) { margin-left: 80px; }

.hex-cell { 
    position: relative; width: 90px; height: 104px; margin: 0 -4px; cursor: pointer; transition: 0.1s;
    background-size: contain; background-repeat: no-repeat; background-position: center;
}
.hex-cell:hover { transform: scale(1.1); z-index: 100; filter: brightness(1.2); }
.hex-cell-default { background-image: url('assets/images/hex.cell.default.png'); }
.hex-cell-red { background-image: url('assets/images/hex.red.png'); }
.hex-cell-purple { background-image: url('assets/images/hex.purple.png'); }
.hex-cell-red-owned { background-image: url('assets/images/hex.red.png') !important; filter: brightness(1.1); }
.hex-cell-purple-owned { background-image: url('assets/images/hex.purple.png') !important; filter: brightness(1.1); }
.hex-letter { 
    font-size: 2rem; font-weight: bold; position: absolute; top: 50%; left: 50%; 
    transform: translate(-50%,-50%); color: #1a1a2e; pointer-events: none; 
}
.hex-cell-red-owned .hex-letter, .hex-cell-purple-owned .hex-letter { color: white !important; }
.winning-path-cell { filter: brightness(1.5) drop-shadow(0 0 15px gold) !important; z-index: 50; }
.hex-cell-transparent { opacity: 0; pointer-events: none; }

.game-controls { position: absolute; bottom: 20px; display: flex; gap: 10px; z-index: 40; }
.game-controls button { background: rgba(255,255,255,0.1); border: 1px solid #555; color: white; padding: 8px 20px; border-radius: 20px; cursor: pointer; font-family: var(--font-primary); }

/* ================= 5. النوافذ ================= */
#question-modal-overlay, #round-win-overlay, #instructions-modal-overlay, .modal-overlay-small {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; height: 100dvh;
    background: rgba(0,0,0,0.95); display: flex; align-items: center; justify-content: center; z-index: 5000;
}
.modal-content { background: #f8f9fa; color: #111; padding: 30px; border-radius: 20px; width: 90%; max-width: 650px; text-align: center; }
.modal-content-small { background: #f8f9fa; color: #111; padding: 25px; border-radius: 15px; width: 320px; text-align: center; }
.modal-buttons { display: flex; justify-content: center; gap: 15px; margin-top: 20px; }
.danger-btn { background: var(--color-red); color: white; border: none; padding: 10px 25px; border-radius: 8px; }
.safe-btn { background: #ccc; color: black; border: none; padding: 10px 25px; border-radius: 8px; }

#question-char-display { font-size: 3.5rem; font-weight: 900; color: var(--color-purple); margin: 0; }
#question-text { font-size: 1.5rem; margin: 20px 0; color: #333; line-height: 1.5; }

#show-answer-button {
    width: 220px; height: 60px; cursor: pointer; border: none; background: transparent;
    background-image: url('assets/images/ui.button.show.answer.png'); background-size: 100% 100%;
    font-size: 1.2rem; color: white; font-weight: bold; font-family: var(--font-primary);
}
#answer-reveal-section { border-top: 1px solid #ccc; margin-top: 15px; padding-top: 15px; width: 100%; }
#answer-text { font-size: 1.6rem; color: var(--color-purple); font-weight: bold; margin-bottom: 20px; }

.team-choice-buttons { display: flex; justify-content: center; gap: 15px; width: 100%; flex-wrap: wrap; }
.team-choice-buttons button, #turn-correct-button {
    width: 170px; height: 60px; margin: 5px; cursor: pointer; border: none; background-color: transparent;
    background-size: 100% 100%; background-repeat: no-repeat;
    position: relative; z-index: 10000; color: white; font-family: var(--font-primary); font-size: 1.1rem; font-weight: bold;
}
#team-red-win-button { background-image: url('assets/images/ui.red.team.png'); }
#team-purple-win-button { background-image: url('assets/images/ui.purple.team.png'); }
#turn-correct-button { background-image: url('assets/images/ui.button.correct.answer.png'); }
#turn-wrong-button, #competitive-skip-button, #early-skip-button { 
    background-image: url('assets/images/ui.button.skip.png') !important; 
    filter: none !important; 
}

/* Win Buttons */
.win-buttons-container { display: flex; gap: 20px; justify-content: center; margin-top: 30px; width: 100%; }
.action-btn { background: var(--color-yellow); color: #1a1a2e; border: none; padding: 15px 40px; border-radius: 50px; font-weight: bold; cursor: pointer; }
.secondary-btn { background: transparent; color: white; border: 2px solid white; padding: 15px 40px; border-radius: 50px; font-weight: bold; cursor: pointer; }

#confetti-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 99999; }

/* ================= 6. إصلاحات الجوال (Mobile) ================= */
@media (max-width: 768px) {
    #game-screen { flex-direction: column; }
    
    .side-panel { 
        width: 100%; 
        height: 70px; /* تقليل الارتفاع في الجوال */
        flex-direction: row; 
        padding: 0 10px; 
        border: none; 
        justify-content: space-between;
    }
    
    .panel-header {
        width: 100%;
        padding: 5px;
        flex-direction: row;
        justify-content: space-between;
        border: none;
    }
    
    /* إخفاء قائمة الأسماء العمودية أثناء اللعب لتوفير مساحة */
    .roster-vertical-list { display: none; }

    .right-panel { order: 1; border-bottom: 3px solid var(--color-red); border-left: none; }
    .left-panel { order: 3; border-top: 3px solid var(--color-purple); border-right: none; margin-bottom: env(safe-area-inset-bottom); }
    
    .center-game-area { 
        order: 2; 
        height: auto; 
        flex: 1; 
        display: flex;
        justify-content: center;
    }

    #game-board-container { 
        margin-top: 0; 
        transform-origin: center center;
    }
    
    .game-logo-small { width: 60px; margin-top: 5px; display: none; /* إخفاء الشعار في الجوال لتوفير مساحة */ }
    
    .game-controls { 
        bottom: 10px; 
        right: 10px; 
        left: auto;
    }
