/* Basic Reset & Body */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Cairo', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    position: relative;
    overflow-x: hidden;
}

/* Animated background particles */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(120, 119, 198, 0.2) 0%, transparent 50%);
    animation: float 20s ease-in-out infinite;
    pointer-events: none;
    z-index: -1;
}

@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    33% { transform: translateY(-20px) rotate(1deg); }
    66% { transform: translateY(10px) rotate(-1deg); }
}

/* Game Container */
.game-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(255, 255, 255, 0.2);
    text-align: center;
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    color: #333;
    position: relative;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.game-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57);
    border-radius: 22px;
    z-index: -1;
    animation: borderGlow 3s ease-in-out infinite alternate;
}

@keyframes borderGlow {
    0% { opacity: 0.5; }
    100% { opacity: 0.8; }
}

h1 {
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Card Display */
.card-container {
    width: 100%;
    min-height: 350px;
    position: relative;
    border-radius: 15px;
    overflow: hidden;
}

.card-flipper {
    width: 100%;
    height: 490px;
    position: relative;
    transform-style: preserve-3d;
    perspective: 1000px;
    transition: transform 0.8s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: none;
}

.card-flipper.is-flipped {
    transform: rotateY(180deg);
}

/* Card Faces */
.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0; /* Ensure both faces start at the top */
    left: 0; /* Ensure both faces start at the left */
    backface-visibility: hidden;
    border-radius: 15px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 1.5rem;
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        0 10px 30px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 2px solid rgba(255, 255, 255, 0.8);
    overflow: hidden;
    z-index: 1; /* Ensure stacking context */
}

.card-front {
    transform: rotateY(0deg);
    z-index: 2; /* Front face is above by default */
}

.card-back {
    transform: rotateY(180deg);
    z-index: 1;
}

/* When flipped, the .card-flipper rotates, showing the back */
.card-flipper.is-flipped {
    transform: rotateY(180deg);
}

/* Word List Styling */
.card-words-list {
    width: 100%;
    padding: 0 1rem;
    text-align: start;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    flex: 1;
}

html[dir="ltr"] .card-words-list {
    text-align: left;
}

.card-word-item {
    font-size: 1.2rem;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    margin-bottom: 0.3rem;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    position: relative;
    overflow: hidden;
    border: 2px solid transparent;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Active color state */
.card-word-item.active {
    transform: scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: rgba(255, 255, 255, 0.8);
}

/* Inactive/dimmed state */
.card-word-item.inactive {
    opacity: 0.3;
    transform: scale(0.95);
    filter: grayscale(0.7);
}

/* Color coding with enhanced gradients */
.card-word-item[data-color="yellow"] {
    background: linear-gradient(135deg, #ffd93d 0%, #ff9800 100%);
    color: #333;
}

.card-word-item[data-color="blue"] {
    background: linear-gradient(135deg, #4fc3f7 0%, #2196f3 100%);
    color: #fff;
}

.card-word-item[data-color="orange"] {
    background: linear-gradient(135deg, #ffb74d 0%, #ff5722 100%);
    color: #fff;
}

.card-word-item[data-color="red"] {
    background: linear-gradient(135deg, #ef5350 0%, #c62828 100%);
    color: #fff;
}

.card-word-item[data-color="green"] {
    background: linear-gradient(135deg, #66bb6a 0%, #2e7d32 100%);
    color: #fff;
}

.card-word-item span:first-child {
    display: inline-block;
    color: inherit;
    opacity: 0.9;
    margin-right: 8px;
    font-weight: bold;
}

html[dir="ltr"] .card-word-item span:first-child {
    margin-right: 0;
    margin-left: 8px;
}

.card-word-item .word-text {
    font-weight: bold;
}

/* Placeholder */
#card-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #6c757d;
    font-size: 1.2rem;
    display: block;
    width: 100%;
    text-align: center;
    font-weight: 600;
}

/* Flip Corners */
.flip-corner {
    position: absolute;
    width: 50px;
    height: 50px;
    cursor: pointer;
    z-index: 10;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flip-corner:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.top-right::before {
    content: '🔄';
    font-size: 1.5rem;
    transition: transform 0.3s ease;
}

.flip-corner:hover::before {
    transform: rotate(180deg);
}

.flip-corner.top-left { top: 10px; left: 10px; }
.flip-corner.top-right { top: 10px; right: 10px; }
.flip-corner.bottom-left { bottom: 10px; left: 10px; }
.flip-corner.bottom-right { bottom: 10px; right: 10px; }

/* Timer */
.timer {
    font-size: 3rem;
    font-weight: bold;
    background: linear-gradient(135deg, #4caf50, #8bc34a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 1rem;
    border-radius: 15px;
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* Dice Area */
.dice-area {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.dice {
    width: 60px;
    height: 60px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.2rem;
    font-weight: bold;
    background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
    color: #333;
    box-shadow: 
        0 8px 20px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
}

.dice:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.15);
}

.challenge-dice-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
}

.challenge-dice-container.hidden {
    display: none;
}

.challenge-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #666;
}

.challenge-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #667eea;
}

.challenge-text {
    margin-top: 1rem;
    font-size: 1rem;
    color: #555;
    min-height: 1.5em;
    font-style: italic;
    font-weight: 600;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}


.selected-color-indicator {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 25px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* Buttons */
.controls, .settings-area {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-family: inherit;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);
}

.btn:active {
    transform: translateY(-1px);
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    box-shadow: 0 8px 20px rgba(108, 117, 125, 0.3);
}

.btn-secondary:hover {
    box-shadow: 0 12px 30px rgba(108, 117, 125, 0.4);
}

.btn:disabled {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 10px rgba(108, 117, 125, 0.2);
}

.btn:disabled:hover {
    transform: none;
    box-shadow: 0 4px 10px rgba(108, 117, 125, 0.2);
}

/* Language Switcher */
#language-switcher {
    padding: 0.8rem 1.2rem;
    font-family: inherit;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    color: #333;
    font-weight: 600;
    transition: all 0.3s ease;
}

#language-switcher:hover {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.2);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
    margin: 5% auto;
    padding: 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 700px;
    position: relative;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.modal-content h3,
.modal-content h4,
.modal-content h5,
.modal-content h6 {
    margin-bottom: 1rem;
    color: #333;
    font-weight: 600;
}

.modal-section {
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    border: 2px solid rgba(102, 126, 234, 0.1);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
}

.add-category-section {
    background: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.2);
}

.category-section {
    background: rgba(33, 150, 243, 0.1);
    border-color: rgba(33, 150, 243, 0.2);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.category-header h5 {
    margin: 0;
    font-size: 1.2em;
    font-weight: 600;
    flex: 1;
}

.category-actions,
.word-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.category-actions button,
.word-actions button {
    padding: 0.5rem 1rem;
    font-size: 0.9em;
    cursor: pointer;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    transition: all 0.3s ease;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.category-actions button:hover,
.word-actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.danger-btn {
    background: linear-gradient(135deg, #ef5350 0%, #c62828 100%) !important;
    color: white !important;
}

.danger-btn:hover {
    background: linear-gradient(135deg, #c62828 0%, #b71c1c 100%) !important;
    box-shadow: 0 4px 15px rgba(239, 83, 80, 0.3) !important;
}

.word-list {
    list-style: none;
    padding: 0;
    color: darkcyan;
    margin: 1rem 0;
}

.word-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;
    gap: 1rem;
}

.word-item > span {
    flex: 1;
    font-weight: 500;
}

.add-word-section {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(76, 175, 80, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(76, 175, 80, 0.2);
}

.add-word-section details summary {
    cursor: pointer;
    font-weight: 600;
    color: #2e7d32;
    padding: 0.5rem;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.add-word-section details summary:hover {
    background-color: rgba(76, 175, 80, 0.1);
}

.language-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.language-inputs label {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    display: block;
}

.language-inputs input,
.modal-section input,
.modal-section select {
    width: 100%;
    padding: 0.8rem;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.language-inputs input:focus,
.modal-section input:focus,
.modal-section select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.modal-section form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-section form button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    align-self: flex-start;
}

.modal-section form button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.edit-category-form-container,
.edit-word-form-container {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    border: 2px solid rgba(102, 126, 234, 0.2);
}

.close-btn {
    color: #aaa;
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

html[dir="rtl"] .close-btn {
    right: auto;
    left: 20px;
}

.close-btn:hover {
    color: #333;
    transform: scale(1.1);
}

/* Responsive Design */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .game-container {
        padding: 1.5rem;
        gap: 1rem;
        margin: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    .card-container {
        min-height: 300px;
    }

    .timer {
        font-size: 2.5rem;
    }

    .dice {
        width: 50px;
        height: 50px;
        font-size: 1.8rem;
    }

    .btn {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }

    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 1.5rem;
    }

    .dice-area {
        gap: 1rem;
        padding: 1rem;
    }

    .category-header,
    .word-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .category-actions,
    .word-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .card-flipper {
        height: 370px;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 1rem;
    }

    .card-word-item {
        font-size: 1rem;
        padding: 0.6rem 0.8rem;
    }

    .flip-corner {
        width: 40px;
        height: 40px;
    }

    .controls, .settings-area {
        gap: 0.5rem;
    }

    .btn {
        padding: 0.7rem 1.2rem;
        font-size: 0.9rem;
    }

    .language-inputs {
        grid-template-columns: 1fr;
    }
}