:root {
    --primary-color: #6a1b9a;
    --primary-light: #9c4dcc;
    --primary-dark: #38006b;
    --secondary-color: #ff9800;
    --error-color: #f44336;
    --success-color: #4caf50;
    --warning-color: #ffc107;
    --text-color: #333;
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --timer-color: #ff5722;
    --special-letter: #28beca;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
}

.setup, .game, .winner {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 20px;
}

.setup-container, .winner-content {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    background: var(--card-bg);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

h1 {
    text-align: center;
    color: var(--primary-color);
    margin-top: 0;
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 12px 15px;
    font-size: 16px;
    border-radius: 8px;
    border: 2px solid #ddd;
    transition: border-color 0.3s;
}

input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--primary-color);
    outline: none;
}

.players-names {
    margin: 20px 0;
}

.players-names input {
    margin-bottom: 10px;
}

button {
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.current-player {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary-dark);
    margin: 15px 0;
    padding: 10px;
    background: rgba(106, 27, 154, 0.1);
    border-radius: 8px;
    text-align: center;
}

.last-word {
    color: var(--primary-light);
    cursor: pointer;
    text-decoration: underline;
    font-weight: bold;
}

.last-word:hover {
    color: var(--primary-dark);
}

.letters-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    max-width: 400px;
    width: 100%;
    transition: opacity 0.3s ease, filter 0.3s ease;
}

.letter {
    aspect-ratio: 1/1;
    background-color: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.letter:hover {
    transform: scale(1.05);
}

.special {
    background-color: var(--special-letter);
    color: white;
    border-color: var(--special-letter);
}

.input-area {
    width: 100%;
    max-width: 400px;
    margin: 20px 0;
}

.input-area input {
    width: 100%;
    margin-bottom: 10px;
}

.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.btn-skip {
    background-color: #ff9800;
    color: white;
    display: none;
}

.btn-skip.visible {
    display: block;
}

.blurred {
    opacity: 0.9;
    filter: blur(8px);
    pointer-events: none;
}

.timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 24px;
    color: var(--timer-color);
    cursor: pointer;
    padding: 12px 20px;
    border: 2px dashed var(--timer-color);
    border-radius: 12px;
    background: #fff3e0;
    transition: all 0.3s;
}

.timer:hover {
    background: #ffe0b2;
    transform: scale(1.02);
}

.timer-icon {
    font-size: 28px;
}

.timer-warning {
    color: #f44336 !important;
    animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.score-board {
    background: var(--card-bg);
    padding: 15px;
    border-radius: 10px;
    margin: 15px 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    text-align: center;
    font-size: 18px;
}

.score-board span {
    font-weight: bold;
    color: var(--primary-color);
}

.message {
    margin: 10px 0;
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-weight: bold;
}

.error-message {
    background-color: rgba(244, 67, 54, 0.1);
    color: var(--error-color);
    border-left: 4px solid var(--error-color);
}

.success-message {
    background-color: rgba(76, 175, 80, 0.1);
    color: var(--success-color);
    border-left: 4px solid var(--success-color);
}

.warning-message {
    background-color: rgba(255, 193, 7, 0.1);
    color: var(--warning-color);
    border-left: 4px solid var(--warning-color);
}

.flash-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 25px;
    border-radius: 8px;
    font-weight: bold;
    text-align: center;
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    animation: fadeInOut 3s forwards;
    opacity: 0;
    font-size: 18px;
    max-width: 90%;
    width: auto;
    white-space: nowrap;
}

.flash-error {
    background-color: #f44336;
    color: white;
}

.flash-warning {
    background-color: #ff9800;
    color: black;
}

.flash-success {
    background-color: #4caf50;
    color: white;
}

.flash-info {
    background-color: #2196F3;
    color: white;
}

@keyframes fadeInOut {
    0% { opacity: 0; top: 10px; }
    20% { opacity: 1; top: 20px; }
    80% { opacity: 1; top: 20px; }
    100% { opacity: 0; top: 10px; }
}

.instructions-toggle {
    margin: 20px 0;
    text-align: center;
}

.instructions {
    background-color: #f3e5f5;
    border: 2px solid var(--primary-color);
    padding: 20px;
    border-radius: 12px;
    margin-top: 20px;
    font-size: 16px;
    text-align: right;
    line-height: 1.8;
}

.instructions h3 {
    color: var(--primary-dark);
    margin-top: 0;
    text-align: center;
}

.instructions ul {
    padding-right: 20px;
    margin-bottom: 0;
}

.instructions li {
    margin-bottom: 10px;
}

.hidden {
    display: none;
}

.popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.popup.active {
    opacity: 1;
    pointer-events: all;
}

.popup-content {
    background: white;
    border-radius: 15px;
    padding: 25px;
    max-width: 90%;
    width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(20px);
    transition: transform 0.3s;
}

.popup.active .popup-content {
    transform: translateY(0);
}

.popup-words {
    margin: 20px 0;
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
}

.popup-words div {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.popup-words div:last-child {
    border-bottom: none;
}

.winner-content {
    text-align: center;
    position: relative;
    z-index: 10;
}

#winnerName {
    color: var(--primary-color);
    font-size: 42px;
    margin-bottom: 30px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

footer {
    text-align: center;
    padding: 15px;
    background: var(--primary-dark);
    color: white;
    font-size: 14px;
    margin-top: auto;
}

footer a {
    color: #ff9e80;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* التعديلات الجديدة للتحسينات المطلوبة */
.game {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 15px;
    overflow: hidden;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 15px;
    width: 100%;
}

.letters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.letter {
    aspect-ratio: 1;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-area {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 10px 0;
}

.game-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    margin-top: auto;
}

.timer {
    font-size: 18px;
    padding: 10px;
}

.score-board {
    font-size: 16px;
    padding: 10px;
    overflow-x: auto;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .letters-grid {
        grid-template-columns: repeat(6, 1fr);
        max-width: 600px;
    }
    
    .letter {
        font-size: 32px;
    }
    
    .game-main {
        gap: 20px;
    }
}

@media (max-width: 480px) {
    .letters-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .letter {
        font-size: 20px;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn-primary, .btn-skip {
        width: 100%;
    }
}