/* Reset وتنسيق عام */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4a6baf;
    --secondary-color: #6c757d;
    --success-color: #4CAF50;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --info-color: #2196F3;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --border-radius: 12px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

body {
    font-family: 'Cairo', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    direction: rtl;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* الشاشات */
.screen {
    display: none;
    width: 100%;
    min-height: 80vh;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* شاشة البداية */
.start-container {
    padding: 40px;
    text-align: center;
}

.logo {
    margin-bottom: 40px;
}

.logo i {
    font-size: 4rem;
    color: var(--primary-color);
    margin-bottom: 20px;
}

.logo h1 {
    color: var(--dark-color);
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.start-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 40px 0;
}

.info-card {
    padding: 25px;
    background: var(--light-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
    border: 2px solid transparent;
}

.info-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
}

.info-card i {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.info-card h3 {
    color: var(--dark-color);
    margin-bottom: 10px;
}

.info-card p {
    color: var(--secondary-color);
    font-size: 0.9rem;
}

.difficulty-selector {
    background: var(--light-color);
    padding: 30px;
    border-radius: var(--border-radius);
    margin: 30px 0;
}

.difficulty-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.difficulty-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 50px;
    background: white;
    color: var(--secondary-color);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

.difficulty-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.difficulty-btn:hover:not(.active) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.start-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 40px;
}

/* الأزرار */
.btn-primary, .btn-secondary {
    padding: 15px 35px;
    border: none;
    border-radius: 50px;
    font-family: 'Cairo', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #3a56a0);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(74, 107, 175, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background: var(--light-color);
    transform: translateY(-3px);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--light-color);
    color: var(--secondary-color);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

/* شاشة الاختبار */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: var(--light-color);
    border-bottom: 1px solid #dee2e6;
}

.progress-container {
    flex: 1;
    max-width: 300px;
}

.progress-bar {
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), #3a56a0);
    width: 0%;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--secondary-color);
    display: flex;
    justify-content: space-between;
}

.quiz-controls {
    display: flex;
    gap: 10px;
}

.quiz-content {
    padding: 30px;
    min-height: 500px;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.difficulty-badge {
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.difficulty-badge.easy {
    background: #d4edda;
    color: #155724;
}

.difficulty-badge.medium {
    background: #fff3cd;
    color: #856404;
}

.difficulty-badge.hard {
    background: #f8d7da;
    color: #721c24;
}

.question-number {
    color: var(--secondary-color);
    font-weight: 600;
}

.question-text {
    font-size: 1.4rem;
    line-height: 1.6;
    color: var(--dark-color);
    margin-bottom: 30px;
    padding: 20px;
    background: var(--light-color);
    border-radius: var(--border-radius);
    border-right: 5px solid var(--primary-color);
}

.code-example {
    background: #282c34;
    color: #abb2bf;
    padding: 20px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    direction: ltr;
}

.code-example pre {
    margin: 0;
}

.code-example code {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.options-container {
    display: grid;
    gap: 15px;
    margin-bottom: 30px;
}

.option {
    padding: 20px;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    text-align: right;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 15px;
}

.option:hover {
    border-color: var(--primary-color);
    background: #f8f9fa;
}

.option.selected {
    border-color: var(--primary-color);
    background: rgba(74, 107, 175, 0.1);
}

.option.correct {
    border-color: var(--success-color);
    background: rgba(76, 175, 80, 0.1);
}

.option.wrong {
    border-color: var(--danger-color);
    background: rgba(244, 67, 54, 0.1);
}

.option-number {
    width: 35px;
    height: 35px;
    background: var(--light-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--secondary-color);
}

.option.selected .option-number {
    background: var(--primary-color);
    color: white;
}

/* مطابقة */
.matching-container {
    margin-bottom: 30px;
}

.matching-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    min-height: 300px;
}

.items-column, .descriptions-column {
    background: var(--light-color);
    border-radius: var(--border-radius);
    padding: 20px;
}

.matching-item {
    padding: 15px;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    cursor: move;
    touch-action: none;
    user-select: none;
    transition: var(--transition);
    text-align: center;
    font-weight: 600;
}

.matching-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.matching-item.dragging {
    opacity: 0.7;
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    z-index: 1000;
}

.drop-zone {
    min-height: 60px;
    border: 2px dashed #dee2e6;
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--secondary-color);
    transition: var(--transition);
}

.drop-zone.active {
    border-color: var(--primary-color);
    background: rgba(74, 107, 175, 0.05);
}

.matched-pair {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: var(--border-radius);
    margin-bottom: 10px;
}

.matched-pair.correct {
    border-color: var(--success-color);
    background: rgba(76, 175, 80, 0.1);
}

.matched-pair.incorrect {
    border-color: var(--danger-color);
    background: rgba(244, 67, 54, 0.1);
}

.quiz-actions {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-top: 30px;
}

.feedback-container, .learning-container {
    display: none;
    animation: fadeIn 0.3s ease;
}

.feedback-container.active, .learning-container.active {
    display: block;
}

.feedback-content {
    padding: 30px;
    background: var(--light-color);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    border-right: 5px solid var(--info-color);
}

.feedback-content.correct {
    border-right-color: var(--success-color);
}

.feedback-content.incorrect {
    border-right-color: var(--danger-color);
}

/* المحتوى التعليمي */
.learning-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.learning-content {
    background: white;
    border-radius: var(--border-radius);
    padding: 30px;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.learning-content h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.learning-content ul {
    margin: 15px 0;
    padding-right: 20px;
}

.learning-content li {
    margin-bottom: 10px;
    padding-right: 10px;
}

.diagram-container {
    text-align: center;
    margin: 25px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.learning-diagram {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.diagram-caption {
    font-style: italic;
    color: #666;
    font-size: 0.9em;
    margin-top: 10px;
}

.comparison-diagram {
    display: flex;
    gap: 20px;
    margin: 25px 0;
    flex-wrap: wrap;
}

.diagram-column {
    flex: 1;
    min-width: 300px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.concepts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 25px 0;
}

.concept-card {
    padding: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border: 1px solid #e9ecef;
}

.concept-diagram {
    width: 100%;
    height: 150px;
    object-fit: contain;
    margin-bottom: 15px;
}

.example-table, .differences-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 0.9rem;
}

.example-table th, .differences-table th {
    background: var(--primary-color);
    color: white;
    padding: 12px;
    text-align: right;
}

.example-table td, .differences-table td {
    padding: 10px;
    border: 1px solid #dee2e6;
    text-align: right;
}

.example-table tr:nth-child(even), .differences-table tr:nth-child(even) {
    background: #f8f9fa;
}

.programming-patterns {
    display: grid;
    gap: 25px;
}

.pattern-section {
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    border-right: 4px solid var(--primary-color);
}

.pattern-section h4 {
    color: var(--dark-color);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.pattern-diagram {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    margin: 15px 0;
}

.inheritance-comparison {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 30px;
    margin: 25px 0;
}

.comparison-side {
    padding: 25px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #dee2e6;
}

.key-differences {
    margin-top: 30px;
}

/* شاشة النتائج */
.results-container {
    padding: 40px;
}

.results-header {
    text-align: center;
    margin-bottom: 40px;
}

.results-header i {
    font-size: 4rem;
    color: #FFD700;
    margin-bottom: 20px;
}

.results-header h1 {
    color: var(--dark-color);
    font-size: 2.5rem;
}

.score-display {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 40px;
    margin-bottom: 40px;
    align-items: center;
}

@media (max-width: 768px) {
    .score-display {
        grid-template-columns: 1fr;
    }
}

.score-circle {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 0 auto;
}

.score-circle-fill {
    stroke-dasharray: 565;
    stroke-dashoffset: 565;
    transition: stroke-dashoffset 1s ease;
}

.score-percent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: bold;
    color: var(--dark-color);
}

.score-details h2 {
    color: var(--dark-color);
    margin-bottom: 25px;
    font-size: 1.8rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background: var(--light-color);
    border-radius: var(--border-radius);
}

.stat-item i {
    font-size: 2rem;
    color: var(--primary-color);
}

.stat-item .correct i {
    color: var(--success-color);
}

.stat-item .wrong i {
    color: var(--danger-color);
}

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--dark-color);
}

.difficulty-breakdown {
    background: var(--light-color);
    padding: 30px;
    border-radius: var(--border-radius);
    margin-bottom: 40px;
}

.difficulty-breakdown h3 {
    color: var(--dark-color);
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.breakdown-bars {
    display: grid;
    gap: 20px;
}

.bar-container {
    display: grid;
    grid-template-columns: 80px 1fr 60px;
    gap: 15px;
    align-items: center;
}

.bar-label {
    font-weight: 600;
    color: var(--dark-color);
}

.bar-bg {
    height: 25px;
    background: #e9ecef;
    border-radius: 12px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 12px;
    transition: width 1s ease;
}

.easy-fill {
    background: linear-gradient(90deg, #4CAF50, #2E7D32);
}

.medium-fill {
    background: linear-gradient(90deg, #FF9800, #EF6C00);
}

.hard-fill {
    background: linear-gradient(90deg, #F44336, #C62828);
}

.bar-value {
    text-align: left;
    font-weight: bold;
    color: var(--dark-color);
}

.results-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

/* شاشة الإحصائيات */
.stats-container {
    padding: 30px;
    height: 80vh;
    overflow-y: auto;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.stats-header i {
    font-size: 3rem;
    color: var(--primary-color);
}

.stats-header h1 {
    color: var(--dark-color);
    font-size: 2rem;
}

.stats-content {
    display: grid;
    gap: 30px;
}

.overall-stats h3, .progress-history h3, .weak-areas h3 {
    color: var(--dark-color);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.overall-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.overall-stat {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 25px;
    background: var(--light-color);
    border-radius: var(--border-radius);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.correct {
    background: rgba(76, 175, 80, 0.2);
    color: var(--success-color);
}

.stat-icon.wrong {
    background: rgba(244, 67, 54, 0.2);
    color: var(--danger-color);
}

.stat-icon.attempts {
    background: rgba(33, 150, 243, 0.2);
    color: var(--info-color);
}

.stat-icon.avg {
    background: rgba(255, 152, 0, 0.2);
    color: var(--warning-color);
}

.stat-info h4 {
    color: var(--secondary-color);
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.stat-info p {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--dark-color);
}

.progress-history {
    background: white;
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

#progress-chart {
    width: 100% !important;
    height: 300px !important;
}

.weak-areas {
    background: white;
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.areas-list {
    display: grid;
    gap: 15px;
}

.area-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--light-color);
    border-radius: var(--border-radius);
    border-right: 4px solid var(--danger-color);
}

.area-name {
    font-weight: 600;
    color: var(--dark-color);
}

.area-score {
    font-weight: bold;
    color: var(--danger-color);
}

/* نافذة التلميح */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 500px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--warning-color), #e68a00);
    color: white;
}

.modal-header h3 {
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-modal {
    background: none;
    border: none;
    color: white;
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 30px;
}

.modal-body p {
    font-size: 1.2rem;
    line-height: 1.6;
    color: var(--dark-color);
}

.modal-footer {
    padding: 20px;
    background: var(--light-color);
    display: flex;
    justify-content: flex-end;
}

/* إشعارات */
.notification {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    max-width: 400px;
    margin: 0 auto;
    padding: 15px 20px;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    transform: translateY(-100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 3000;
    display: flex;
    align-items: center;
    gap: 15px;
}

.notification.show {
    transform: translateY(0);
    opacity: 1;
}

.notification.success {
    border-right: 5px solid var(--success-color);
}

.notification.error {
    border-right: 5px solid var(--danger-color);
}

.notification.info {
    border-right: 5px solid var(--info-color);
}

/* تأثيرات خاصة للمس */
@media (hover: none) and (pointer: coarse) {
    .option, .matching-item {
        min-height: 44px;
        min-width: 44px;
    }
    
    .btn-primary, .btn-secondary {
        padding: 20px 40px;
        font-size: 1.2rem;
    }
    
    .icon-btn {
        width: 50px;
        height: 50px;
    }
    
    .matching-item {
        font-size: 1.1rem;
        padding: 20px;
    }
}

/* دعم اللمس المتعدد */
.matching-item.multi-touch {
    transition: transform 0.2s, opacity 0.2s;
}

.matching-item.active-touch {
    z-index: 1000;
    transform: scale(1.15);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

/* التكبير بالضغط */
.diagram-container.zoomable {
    overflow: hidden;
    cursor: zoom-in;
}

.diagram-container.zoomable.zoomed {
    cursor: zoom-out;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.diagram-container.zoomed .learning-diagram {
    max-width: 90%;
    max-height: 90vh;
    cursor: zoom-out;
}

/* تحسينات للأجهزة الصغيرة */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
    }
    
    .start-container, .quiz-content, .results-container {
        padding: 20px;
    }
    
    .logo h1 {
        font-size: 1.8rem;
    }
    
    .question-text {
        font-size: 1.2rem;
        padding: 15px;
    }
    
    .matching-area {
        grid-template-columns: 1fr;
    }
    
    .quiz-actions {
        flex-direction: column;
    }
    
    .learning-content {
        padding: 20px;
        max-height: 85vh;
    }
    
    .inheritance-comparison {
        grid-template-columns: 1fr;
    }
    
    .comparison-side {
        min-width: 100%;
    }
}

@media (max-width: 480px) {
    .start-info {
        grid-template-columns: 1fr;
    }
    
    .difficulty-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    
    .difficulty-btn {
        width: 100%;
    }
    
    .stats-grid, .overall-grid {
        grid-template-columns: 1fr;
    }
}