/* ألوان النمط الليلي */
:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --primary-text: #ffffff;
    --secondary-text: #b3b3b3;
    --accent-color: #bb86fc;
    --button-bg: #3700b3;
    --button-hover: #6200ee;
    --button-text: #ffffff;
    --border-color: #2d2d2d;
    --progress-bg: #2d2d2d;
    --progress-fill: #bb86fc;
    --error-color: #cf6679;
    --success-color: #03dac6;
}

/* تنسيق عام للصفحة */
body {
    background-color: var(--bg-color);
    color: var(--primary-text);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 15px;
    line-height: 1.6;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

/* تنسيق الترويسة */
h1, h2, h3, h4 {
    color: var(--accent-color);
    text-align: center;
    margin-bottom: 20px;
    font-weight: bold;
    word-wrap: break-word;
}

h1 {
    font-size: 1.8rem;
    margin-top: 20px;
    text-shadow: 0 0 10px rgba(187, 134, 252, 0.3);
    padding: 0 10px;
}

/* القسم الرئيسي */
#quiz-info, #quiz-container, #already-taken {
    background-color: var(--card-bg);
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-width: 800px;
    margin: 0 auto 30px;
    padding: 25px;
    transition: all 0.3s ease;
    width: 100%;
}

/* شريط التقدم */
#progress-bar {
    background-color: var(--progress-bg);
    border-radius: 10px;
    height: 30px;
    line-height: 30px;
    margin: 20px auto;
    max-width: 800px;
    width: 100%;
    text-align: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#progress-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--progress-width, 0%);
    background-color: var(--progress-fill);
    transition: width 0.5s ease;
    z-index: 1;
}

#progress-bar span {
    position: relative;
    z-index: 2;
    font-weight: bold;
}

/* تنسيق الأسئلة */
#question {
    font-size: 1.3rem;
    margin-bottom: 25px;
    text-align: center;
    color: var(--primary-text);
    padding: 0 5px;
    word-wrap: break-word;
}

/* الأزرار */
button {
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    overflow-wrap: break-word;
    word-wrap: break-word;
    padding: 12px;
    width: 100%;
}

button:hover {
    background-color: var(--button-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

button:active {
    transform: translateY(0);
}

button:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* تنسيق جدول الإجابات */
#quiz-container table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 8px;
    table-layout: fixed;
}

#quiz-container td {
    padding: 0;
    width: 50%;
    vertical-align: top;
}

#quiz-container button {
    width: 100%;
    padding: 15px;
    font-size: 16px;
    height: 100%;
    text-align: center;
    min-height: 60px;
}

/* تنسيق النتيجة */
#result-container {
    text-align: center;
}

/* قاعدة عامة لجميع الصور التي تريد أن تكون دائرية */
#result-image, #previous-image {
    border-radius: 50%;
    border: 3px solid var(--accent-color);
    object-fit: cover;
    width: 200px;
    height: 200px;
    margin: 10px auto 20px;
    box-shadow: 0 0 15px rgba(187, 134, 252, 0.5);
    transition: all 0.3s ease;
    max-width: 100%;
    display: block;
    background-color: var(--card-bg); /* لون احتياطي قبل تحميل الصورة */
}

#result-image:hover, #previous-image:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(187, 134, 252, 0.7);
}

/* جعل الصور متجاوبة مع الشاشات الصغيرة */
@media (max-width: 768px) {
    #result-image, #previous-image {
        width: 150px;
        height: 150px;
    }
}

@media (max-width: 480px) {
    #result-image, #previous-image {
        width: 120px;
        height: 120px;
    }
}

#result-name, #previous-result {
    font-size: 1.8rem;
    color: var(--accent-color);
    margin-bottom: 10px;
    word-wrap: break-word;
    padding: 0 10px;
}

#result-description, #previous-description {
    line-height: 1.7;
    margin: 15px auto;
    max-width: 650px;
    color: var(--secondary-text);
    text-align: justify;
    padding: 0 10px;
    word-wrap: break-word;
}

/* جدول السمات */
#traits-table, #previous-traits-table {
    width: 90%;
    max-width: 500px;
    margin: 20px auto;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

#traits-table:hover, #previous-traits-table:hover {
    box-shadow: 0 6px 20px rgba(187, 134, 252, 0.4);
    transform: translateY(-2px);
}

/* تنسيق رؤوس الجدول */
#traits-table th, #previous-traits-table th {
    width: 50%;
    background-color: var(--button-bg);
    color: var(--button-text);
    padding: 12px 8px;
    font-weight: bold;
    text-align: center;
    position: relative;
    overflow: hidden;
    border: none;
}

#traits-table th:after, #previous-traits-table th:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent-color);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

#traits-table:hover th:after, #previous-traits-table:hover th:after {
    transform: scaleX(1);
}

/* تنسيق خلايا الجدول العامة */
#traits-table td, #previous-traits-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

#traits-table tr:last-child td, #previous-traits-table tr:last-child td {
    border-bottom: none;
}

#traits-table tr:hover td, #previous-traits-table tr:hover td {
    background-color: rgba(187, 134, 252, 0.1);
}

/* تنسيق خلايا السمات */
.trait-name {
    font-weight: 500;
    padding-right: 10px !important;
    text-align: right !important;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    font-size: 0.95rem;
    position: relative;
    transition: all 0.2s ease;
}

.trait-name:after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    height: 70%;
    width: 3px;
    background-color: var(--accent-color);
    opacity: 0;
    transform: translateY(-50%);
    transition: opacity 0.3s ease;
}

tr:hover .trait-name:after {
    opacity: 1;
}

/* تنسيق خلايا النجوم مع مؤثرات */
.trait-stars {
    text-align: center !important;
    white-space: nowrap;
    letter-spacing: 3px;
    color: var(--accent-color);
    font-size: 1.1rem;
    text-shadow: 0 0 5px rgba(187, 134, 252, 0.3);
    transition: all 0.3s ease;
}

tr:hover .trait-stars {
    letter-spacing: 4px;
    text-shadow: 0 0 8px rgba(187, 134, 252, 0.5);
}

/* مؤثرات النجوم المتحركة */
@keyframes starPulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

.trait-stars .star-filled {
    display: inline-block;
    animation: starPulse 2s infinite;
}

.trait-stars .star-filled:nth-child(1) { animation-delay: 0s; }
.trait-stars .star-filled:nth-child(2) { animation-delay: 0.3s; }
.trait-stars .star-filled:nth-child(3) { animation-delay: 0.6s; }
.trait-stars .star-filled:nth-child(4) { animation-delay: 0.9s; }
.trait-stars .star-filled:nth-child(5) { animation-delay: 1.2s; }

/* عند المرور فوق الصف، تظهر اسم السمة في الشاشات الصغيرة */
.trait-stars:before {
    content: attr(data-trait);
    display: none;
    font-size: 0.8rem;
    color: var(--secondary-text);
    opacity: 0.8;
    letter-spacing: normal;
    margin-bottom: 3px;
}

/* أزرار المشاركة الاجتماعية */
#social-share, #previous-social-share {
    margin: 20px 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

#social-share button, #previous-social-share button {
    margin: 0;
    padding: 10px 15px;
    font-size: 14px;
    border-radius: 25px;
    width: auto;
    flex: 0 1 auto;
    min-width: 100px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

/* أزرار مشاركة الشبكات الاجتماعية بألوانها المخصصة */
#social-share button:nth-child(1), #previous-social-share button:nth-child(1) {
    background-color: #1877f2; /* لون فيسبوك */
}

#social-share button:nth-child(1):hover, #previous-social-share button:nth-child(1):hover {
    background-color: #0e5aa7;
}

#social-share button:nth-child(2), #previous-social-share button:nth-child(2) {
    background-color: #1da1f2; /* لون تويتر */
}

#social-share button:nth-child(2):hover, #previous-social-share button:nth-child(2):hover {
    background-color: #0c85d0;
}

#social-share button:nth-child(3), #previous-social-share button:nth-child(3) {
    background-color: #25d366; /* لون واتساب */
}

#social-share button:nth-child(3):hover, #previous-social-share button:nth-child(3):hover {
    background-color: #1da851;
}

/* خط فاصل */
hr {
    border: 0;
    height: 1px;
    background-image: linear-gradient(to right, rgba(187, 134, 252, 0), rgba(187, 134, 252, 0.75), rgba(187, 134, 252, 0));
    margin: 25px 0;
}

/* خلفية مميزة لمنطقة البداية */
#quiz-start {
    text-align: center;
    padding: 10px;
    background-color: rgba(187, 134, 252, 0.1);
    border-radius: 10px;
    margin: 15px auto;
    width: 100%;
    max-width: 800px;
    animation: glowBg 3s infinite alternate;
}

@keyframes glowBg {
    0% { box-shadow: 0 0 5px rgba(187, 134, 252, 0.3); }
    100% { box-shadow: 0 0 15px rgba(187, 134, 252, 0.6); }
}

#quiz-start button {
    background-color: var(--button-bg);
    color: white;
    padding: 12px 25px;
    font-size: 18px;
    margin-top: 10px;
    border-radius: 25px;
    max-width: 250px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

#quiz-start button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
}

#quiz-start button i {
    transition: transform 0.3s ease;
}

#quiz-start button:hover i {
    transform: scale(1.2);
}

/* تصميم لقائمة الأسئلة */
#question-container {
    position: relative;
    padding-bottom: 10px;
}

/* تنسيق رسالة JavaScript */
noscript p {
    background-color: var(--error-color);
    color: white;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    margin: 15px auto;
    max-width: 90%;
    width: 100%;
}

/* تنسيق لتصحيح اتجاه اللغة العربية */
html[dir="rtl"] {
    text-align: right;
}

html[dir="rtl"] .trait-name {
    text-align: left !important;
    padding-left: 10px !important;
    padding-right: 0 !important;
}

html[dir="rtl"] .trait-name:after {
    right: auto;
    left: 0;
}

/* تحسين تجربة الاختبار على الأجهزة اللمسية */
@media (hover: none) {
    button:hover {
        transform: none;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }
}

/* انيميشن للنتيجة عند ظهورها */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

#result-container:not([hidden]), #already-taken:not([hidden]) {
    animation: fadeIn 0.8s ease-out;
}

/* تأثير اختيار الإجابة */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.answer-selected {
    animation: pulse 0.3s ease-in-out;
    background-color: var(--accent-color) !important;
}

/* تأثير عند تعذر تحميل الصورة */
#result-image.error, #previous-image.error {
    border-color: var(--error-color);
    box-shadow: 0 0 15px rgba(207, 102, 121, 0.5);
}

/* تصميم متجاوب للشاشات المتوسطة */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    #quiz-info, #quiz-container, #already-taken {
        padding: 15px;
    }
    
    #question {
        font-size: 1.2rem;
    }
    
    #result-name, #previous-result {
        font-size: 1.6rem;
    }
    
    #quiz-container table {
        border-spacing: 6px;
    }
    
    #traits-table, #previous-traits-table {
        width: 95%;
    }
}

/* تصميم متجاوب للشاشات الصغيرة */
@media (max-width: 576px) {
    body {
        padding: 5px;
    }
    
    h1 {
        font-size: 1.3rem;
    }
    
    #quiz-info, #quiz-container, #already-taken {
        padding: 12px;
        border-radius: 10px;
    }
    
    #question {
        font-size: 1.1rem;
    }
    
    #quiz-container table {
        border-spacing: 4px;
    }
    
    #quiz-container button {
        font-size: 15px;
        padding: 12px 8px;
    }
    
    #result-name, #previous-result {
        font-size: 1.5rem;
    }
    
    #traits-table, #previous-traits-table {
        width: 100%;
        font-size: 0.9rem;
    }
    
    #traits-table th, #traits-table td,
    #previous-traits-table th, #previous-traits-table td {
        padding: 8px 4px;
    }
    
    #social-share, #previous-social-share {
        flex-direction: column;
        align-items: center;
    }
    
    #social-share button, #previous-social-share button {
        width: 80%;
        margin: 4px 0;
        padding: 10px 5px;
        font-size: 12px;
    }
    
    .trait-stars {
        letter-spacing: 2px;
        font-size: 1rem;
    }
}

/* تصميم متجاوب للشاشات الصغيرة جداً */
@media (max-width: 360px) {
    body {
        padding: 2px;
    }
    
    h1 {
        font-size: 1.2rem;
    }
    
    #quiz-info, #quiz-container, #already-taken {
        padding: 10px 8px;
    }
    
    #question {
        font-size: 1rem;
        margin-bottom: 15px;
    }
    
    #quiz-container button {
        font-size: 14px;
        padding: 10px 5px;
    }
    
    #result-name, #previous-result {
        font-size: 1.3rem;
    }
    
    #result-description, #previous-description {
        font-size: 0.9rem;
    }
    
    #progress-bar {
        height: 25px;
        line-height: 25px;
        font-size: 0.8rem;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    #traits-table, #previous-traits-table {
        font-size: 0.8rem;
        border-radius: 8px;
    }
    
    #traits-table th:first-child, #previous-traits-table th:first-child,
    .trait-name {
        display: none;
    }
    
    #traits-table th:last-child, #previous-traits-table th:last-child {
        width: 100%;
    }
    
    #traits-table td:last-child, #previous-traits-table td:last-child {
        width: 100%;
    }
    
    .trait-stars:before {
        display: block;
        margin-bottom: 5px;
    }
    
    .trait-stars {
        letter-spacing: 1px;
        font-size: 0.9rem;
        padding: 8px 3px;
        text-align: center !important;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    tr:hover .trait-stars {
        letter-spacing: 2px;
    }
}

/* تحسينات الوضع المظلم للأنظمة التي تدعم تفضيلات الوضع المظلم */
@media (prefers-color-scheme: dark) {
    /* الألوان الأساسية موجودة بالفعل في النمط الليلي */
}

/* إضافات للوصول والاستخدام السهل */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}