        @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700&family=Poppins:wght@300;400;500;600;700&display=swap');

        :root {
            --primary: #1a4731;
            --primary-light: #2a5741;
            --secondary: #2d6a4f;
            --accent: #40916c;
            --gold: #d4a373;
            --cream: #faf6f1;
            --dark: #1b4332;
            --background: linear-gradient(135deg, #f8fffe 0%, #f1f5f3 50%, #eef3f1 100%);
            --text-color: #1f2937;
            --text-light: #f1faee;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Poppins', sans-serif;
            background: var(--background);
            color: var(--text-color);
            line-height: 1.6;
            min-height: 100vh;
        }

        body[dir="rtl"] {
            font-family: 'Tajawal', sans-serif;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 2rem 1.5rem;
        }

        .header {
            text-align: center;
            margin-bottom: 2rem;
        }

        .logo {
            font-size: 2.5rem;
            font-weight: 700;
            color: var(--primary);
            margin-bottom: 0.5rem;
        }

        .subtitle {
            color: var(--secondary);
            font-size: 1.1rem;
        }

        .language-selector {
            display: flex;
            justify-content: center;
            gap: 1rem;
            margin: 2rem 0;
            flex-wrap: wrap;
        }

        .lang-btn {
            background-color: white;
            color: var(--primary);
            border: 2px solid var(--accent);
            padding: 0.75rem 1.5rem;
            border-radius: 50px;
            cursor: pointer;
            font-weight: 600;
            font-size: 1rem;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
        }

        .lang-btn:hover, .lang-btn.active {
            background-color: var(--accent);
            color: var(--text-light);
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
        }

        .search-box {
            background: white;
            padding: 1.5rem;
            border-radius: 15px;
            margin-bottom: 2rem;
            box-shadow: 0 4px 12px rgba(0,0,0,0.05);
        }

        .search-input {
            width: 100%;
            padding: 0.75rem 1rem;
            border: 2px solid var(--accent);
            border-radius: 10px;
            font-size: 1rem;
            font-family: inherit;
        }

        .story-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 1.5rem;
            margin-bottom: 2rem;
        }

        .story-card-mini {
            background: white;
            padding: 1.5rem;
            border-radius: 15px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.05);
            cursor: pointer;
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }

        .story-card-mini:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0,0,0,0.1);
            border-color: var(--accent);
        }

        .story-card-mini h3 {
            color: var(--primary);
            margin-bottom: 0.5rem;
            font-size: 1.2rem;
        }

        .story-card-mini .preview {
            color: #666;
            font-size: 0.9rem;
            line-height: 1.4;
        }

        .story-detail {
            display: none;
            background: white;
            padding: 2.5rem;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.07);
            margin-bottom: 2rem;
        }

        .story-detail.active {
            display: block;
            animation: fadeIn 0.5s;
        }

        .story-header {
            border-bottom: 2px solid #e0e0e0;
            padding-bottom: 1.5rem;
            margin-bottom: 2rem;
        }

        .story-header h2 {
            color: var(--dark);
            font-size: 2rem;
            margin-bottom: 1rem;
        }

        .back-btn {
            background: var(--primary);
            color: white;
            border: none;
            padding: 0.75rem 1.5rem;
            border-radius: 10px;
            cursor: pointer;
            font-weight: 600;
            margin-bottom: 1rem;
            transition: all 0.3s ease;
        }

        .back-btn:hover {
            background: var(--primary-light);
            transform: translateY(-2px);
        }

        .story-content {
            margin-bottom: 2rem;
        }

        .story-paragraph {
            font-size: 1.15rem;
            line-height: 2;
            margin-bottom: 1.5rem;
        }

.word {
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 3px;
    transition: all 0.2s ease;
    display: inline-block;
    border-bottom: 2px dotted var(--accent);
    padding-bottom: 0; 
}

.word:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.05);
    border-bottom-color: transparent;
}

        .translation-popup {
            position: fixed;
            background: white;
            border: 3px solid var(--accent);
            border-radius: 12px;
            padding: 1.25rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            z-index: 1000;
            max-width: 320px;
            display: none;
        }

        .translation-popup.show {
            display: block;
            animation: popIn 0.3s ease;
        }

        .translation-popup .original {
            font-weight: 700;
            color: var(--primary);
            margin-bottom: 0.75rem;
            font-size: 1.2rem;
            border-bottom: 2px solid var(--cream);
            padding-bottom: 0.5rem;
        }

        .translation-popup .translations {
            display: flex;
            flex-direction: column;
            gap: 0.6rem;
        }

        .translation-item {
            padding: 0.6rem;
            background: var(--cream);
            border-radius: 8px;
            font-size: 1rem;
            border-left: 3px solid var(--accent);
        }

        .translation-item .lang-label {
            font-weight: 700;
            color: var(--secondary);
            margin-right: 0.5rem;
            text-transform: uppercase;
            font-size: 0.85rem;
        }

        .exercises-section {
            margin-top: 3rem;
            border-top: 2px solid #e0e0e0;
            padding-top: 2rem;
        }

        .exercises-section h3 {
            font-size: 1.8rem;
            color: var(--secondary);
            margin-bottom: 1.5rem;
        }

        .exercise {
            background: var(--cream);
            padding: 1.5rem;
            border-radius: 12px;
            margin-bottom: 1.5rem;
            border-left: 5px solid var(--gold);
        }

        .exercise-question {
            font-weight: 600;
            margin-bottom: 1rem;
            font-size: 1.15rem;
            color: var(--dark);
        }

        .exercise-options {
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
        }

        .option-btn {
            padding: 0.85rem 1rem;
            border: 2px solid var(--accent);
            background: white;
            color: var(--text-color);
            border-radius: 10px;
            cursor: pointer;
            text-align: left;
            transition: all 0.3s ease;
            font-family: inherit;
            font-size: 1rem;
        }

        .option-btn:hover:not(.correct):not(.incorrect):not(:disabled) {
            background: var(--accent);
            color: white;
            transform: translateX(8px);
        }

        .option-btn.correct {
            background: #90be6d;
            color: white;
            border-color: #90be6d;
        }

        .option-btn.incorrect {
            background: #ef476f;
            color: white;
            border-color: #ef476f;
        }

        .exercise-feedback {
            margin-top: 1rem;
            padding: 1rem;
            border-radius: 8px;
            display: none;
            font-weight: 600;
            font-size: 1rem;
        }

        .exercise-feedback.show {
            display: block;
            animation: slideDown 0.4s ease;
        }

        .exercise-feedback.correct {
            background: #d8f3dc;
            color: #1b4332;
        }

        .exercise-feedback.incorrect {
            background: #ffc9d4;
            color: #6d1b31;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes popIn {
            from { opacity: 0; transform: scale(0.8); }
            to { opacity: 1; transform: scale(1); }
        }

        @keyframes slideDown {
            from { opacity: 0; transform: translateY(-15px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @media (max-width: 768px) {
            .container {
                padding: 1rem;
            }
            
            .logo {
                font-size: 2rem;
            }
            
            .story-grid {
                grid-template-columns: 1fr;
            }

            .story-detail {
                padding: 1.5rem;
            }

            .story-paragraph {
                font-size: 1.05rem;
            }

            .translation-popup {
                max-width: calc(100vw - 40px);
                left: 20px !important;
                right: 20px;
            }

            .lang-btn {
                padding: 0.6rem 1.2rem;
                font-size: 0.9rem;
            }
        }

        body.dark-theme {
            background: #1a2026;
            color: #e0e0e0;
        }
        
        body.dark-theme .story-card-mini,
        body.dark-theme .story-detail,
        body.dark-theme .search-box {
            background-color: #2a2f35;
        }
        
        body.dark-theme .logo,
        body.dark-theme h2, 
        body.dark-theme h3 {
            color: #90be6d;
        }
        
        body.dark-theme .subtitle {
            color: #9fc49f;
        }
        
        body.dark-theme .lang-btn {
            background-color: #2a2f35;
            color: #d8e2dc;
        }
        
        body.dark-theme .lang-btn.active,
        body.dark-theme .lang-btn:hover {
            background-color: #40916c;
        }
        
        body.dark-theme .exercise {
            background-color: #2d3339;
        }

        body.dark-theme .option-btn {
            background-color: #3a3f45;
            color: #e0e0e0;
        }

        body.dark-theme .translation-popup {
            background-color: #2a2f35;
            color: #e0e0e0;
        }

        body.dark-theme .translation-item {
            background-color: #3a3f45;
        }
        
        body.dark-theme .search-input {
            background-color: #2a2f35;
            color: #e0e0e0;
        }

        body.dark-theme .preview {
            color: #aaa;
        }
       

.close-popup-btn {
    position: absolute;
    top: 5px;
    right: 10px;
    background: transparent;
    border: none;
    font-size: 1.6rem; 
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    padding: 5px;
    line-height: 1; 
    transition: color 0.2s ease;
}

.close-popup-btn:hover {
    color: #333;
}

body.dark-theme .close-popup-btn {
    color: #888;
}

body.dark-theme .close-popup-btn:hover {
    color: #eee;
}

.instruction-banner {
    background-color: var(--cream);
    border: 2px solid var(--gold);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideDown 0.5s ease;
}

.instruction-banner p {
    margin: 0;
    font-weight: 500;
    color: var(--dark);
}

.instruction-banner .close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gold);
    cursor: pointer;
}

body.dark-theme .instruction-banner {
    background-color: #2d3339;
    border-color: #d4a373;
}

body.dark-theme .instruction-banner p {
    color: var(--text-light);
}

.floating-action-group {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column; 
    gap: 12px; 
}

.dark-mode-toggle {
    position: relative; 
    z-index: 101; 
    background-color: var(--primary);
    border: none;
    border-radius: 50%; 
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    overflow: hidden;
}

.dark-mode-toggle:hover {
    background-color: var(--primary-light);
    transform: scale(1.05);
}

.dark-mode-toggle svg {
    position: absolute;
    transition: transform 0.4s ease, opacity 0.4s ease;
    color: white;
}
.moon-icon { transform: translateY(0); opacity: 1; }
.sun-icon { transform: translateY(100%); opacity: 0; }
body.dark-theme .moon-icon { transform: translateY(-100%); opacity: 0; }
body.dark-theme .sun-icon { transform: translateY(0); opacity: 1; }

.floating-home-btn {
    position: relative; 
    z-index: 101;
    width: 50px;
    height: 50px;
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: all 0.3s ease;
}

.floating-home-btn:hover {
    opacity: 1;
    transform: scale(1.1);
    background-color: var(--primary-light);
}

@media (max-width: 768px) {
    .floating-action-group {
        bottom: 15px;
        left: 15px;
        gap: 10px;
    }
    .floating-home-btn, .dark-mode-toggle {
        width: 45px;
        height: 45px;
    }
}

.exercise-sentence {
  margin: 10px 0;
  font-size: 1.1em;
  line-height: 1.8;
}

.fill-in-blank-input {
  border: none;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  color: inherit; 
  font-family: inherit; 
  font-size: 1em; 
  text-align: center;
  width: 150px;
  margin: 0 5px;
  padding-bottom: 2px;
  transition: border-color 0.3s ease;
}

.fill-in-blank-input:focus {
  outline: none;
  border-bottom-color: var(--gold);
}

.fill-in-blank-input.correct {
  border-color: #90be6d; 
  color: #90be6d;
  font-weight: bold;
}

.fill-in-blank-input.incorrect {
  border-color: #ef476f; 
  color: #ef476f;
}


.check-btn {
  background: var(--secondary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  margin-top: 1rem;
  transition: all 0.3s ease;
}

.check-btn:hover:not(:disabled) {
  background: var(--accent);
  transform: translateY(-2px);
}

.check-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

body.dark-theme .check-btn:disabled {
    background-color: #555;
}


.scramble-answer-container, .scramble-options-container {
  border: 2px dashed var(--accent);
  min-height: 60px;
  padding: 10px;
  margin: 10px 0;
  border-radius: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  transition: border-color 0.3s ease;
}

.scramble-answer-container.correct {
  border-color: #90be6d;
  border-style: solid;
}

.scramble-answer-container.incorrect {
  border-color: #ef476f;
  border-style: solid;
}

.scramble-word-btn {
  padding: 6px 12px;
  border: 1px solid #ddd;
  background-color: white;
  color: var(--text-color);
  cursor: grab;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  transition: all 0.2s ease;
}

.scramble-word-btn:active {
    cursor: grabbing;
    transform: scale(0.95);
    box-shadow: none;
}

body.dark-theme .scramble-word-btn {
    background-color: #3a3f45;
    border-color: #555;
    color: #e0e0e0;
}

body.dark-theme .scramble-answer-container, 
body.dark-theme .scramble-options-container {
    border-color: var(--accent);
}

body.dark-theme .word {
    border-bottom-color: #58c495; 
}


body.dark-theme .word:hover {
    background: var(--accent); 
    color: white;
}
