:root {
    --bg-color: #05070a;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-bg-hover: rgba(255, 255, 255, 0.06);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-active: rgba(99, 102, 241, 0.4);
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.25);
    --primary-bg: rgba(99, 102, 241, 0.08);
    --accent: #f43f5e;
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.08);
    --text-main: #f1f5f9;
    --text-dim: #64748b;
    --text-bright: #f8fafc;
    --glass-blur: 20px;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-full: 100px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Outfit', 'Noto Sans Arabic', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow-x: hidden;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.background-blobs {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1; overflow: hidden;
    filter: blur(100px);
}

.blob {
    position: absolute; width: 40vw; height: 40vw;
    border-radius: 50%; opacity: 0.15;
    animation: blobMove 25s infinite alternate ease-in-out;
}
.blob-1 { background: var(--primary); top: -10%; left: -10%; }
.blob-2 { background: var(--accent); bottom: -10%; right: -10%; animation-delay: -7s; }
.blob-3 { background: #8b5cf6; top: 40%; left: 30%; animation-delay: -14s; }

@keyframes blobMove {
    0% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(5vw, 8vh) scale(1.1); }
    66% { transform: translate(-3vw, -5vh) scale(0.95); }
    100% { transform: translate(8vw, 3vh) scale(1.15); }
}

/* ====== FILTER VIEW ====== */
.app-container {
    max-width: 560px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.app-container.hidden { display: none; }

header {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeInDown 0.6s ease;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.3rem;
}

header p {
    color: var(--text-dim);
    font-size: 0.95rem;
}

.glass {
    background: var(--card-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.3);
}

.filters-card {
    padding: 1.75rem;
    animation: fadeInUp 0.5s ease;
    z-index: 1;
}

.filters-card.in-flow {
    position: relative;
}

.filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.reset-btn {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.9rem;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.reset-btn:hover {
    background: rgba(244, 63, 94, 0.1);
    border-color: rgba(244, 63, 94, 0.3);
    color: var(--accent);
}
.reset-btn.hidden { display: none; }

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
    min-height: 0;
    transition: all 0.3s ease;
}
.breadcrumb:empty { margin-bottom: 0; }

.breadcrumb-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--success);
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    animation: chipIn 0.25s ease;
}
.breadcrumb-item:hover { background: rgba(16, 185, 129, 0.18); }
.breadcrumb-label { color: var(--text-dim); font-weight: 400; }

@keyframes chipIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.current-step { animation: stepIn 0.3s ease; }
@keyframes stepIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

select {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    color: var(--text-main);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: all var(--transition);
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 1rem center;
}

select:focus {
    border-color: var(--primary);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

select option { background: #1a1c23; color: #fff; }

.fetch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    animation: stepIn 0.3s ease;
}
.fetch-controls.hidden { display: none; }
.fetch-left { display: flex; align-items: center; }

.available-count {
    color: var(--success);
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--success-bg);
    padding: 0.35rem 0.85rem;
    border-radius: var(--radius-full);
}

.fetch-right { display: flex; align-items: center; gap: 0.75rem; }
.count-label { color: var(--text-dim); font-size: 0.85rem; }

input[type="number"] {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.65rem;
    color: var(--text-main);
    width: 72px;
    text-align: center;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: all var(--transition);
    -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type="number"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.65rem 2rem;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 14px 0 var(--primary-glow);
    font-family: inherit;
}
.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px 0 var(--primary-glow);
}
.primary-btn:active { transform: scale(0.97); }

/* ====== QUIZ VIEW ====== */
.quiz-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}
.quiz-view.hidden { display: none; }

.quiz-container {
    max-width: 720px;
    width: 100%;
    animation: fadeInUp 0.4s ease;
}

.quiz-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.back-btn {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.quiz-counter {
    color: var(--text-dim);
    font-size: 0.9rem;
    font-weight: 600;
}

.quiz-progress {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    margin-bottom: 2rem;
    overflow: hidden;
}

.quiz-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.quiz-card {
    padding: 2.5rem;
    background: var(--card-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    animation: fadeInUp 0.4s ease;
}

.q-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.q-tag {
    background: var(--primary-bg);
    color: var(--primary-light);
    padding: 0.3rem 0.85rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.85rem;
}

.q-meta { color: var(--text-dim); font-size: 0.82rem; }

.q-text {
    font-size: 1.25rem;
    line-height: 2;
    margin-bottom: 2rem;
    color: var(--text-bright);
}

.answer-textarea {
    width: 100%;
    min-height: 180px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1.2rem;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1.05rem;
    line-height: 1.9;
    resize: vertical;
    outline: none;
    transition: all var(--transition);
    direction: rtl;
}

.answer-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.answer-textarea::placeholder { color: var(--text-dim); }

.answer-textarea.shake { animation: shake 0.4s ease; }

.image-upload-area {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.upload-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    width: fit-content;
}
.upload-label:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.image-preview-container {
    position: relative;
    display: inline-block;
    width: fit-content;
}

.image-preview {
    max-width: 200px;
    max-height: 150px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    display: block;
}

.remove-image-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all var(--transition);
}
.remove-image-btn:hover { background: #e11d48; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.quiz-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

.compare-btn {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.75rem 2.5rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-family: inherit;
    box-shadow: 0 4px 14px 0 var(--primary-glow);
}
.compare-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px 0 var(--primary-glow);
}
.compare-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.answer-btn-inline {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-dim);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.answer-btn-inline:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.model-answer {
    margin-top: 1.5rem;
    background: var(--success-bg);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: var(--radius-sm);
    padding: 1.5rem;
    color: #34d399;
    line-height: 2;
    font-size: 1rem;
    animation: slideUp 0.3s ease;
}
.model-answer.hidden { display: none; }

.quiz-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.65rem 1.5rem;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}
.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ====== RESULT OVERLAY ====== */
.compare-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(5, 7, 10, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    animation: fadeIn 0.2s ease;
}
.compare-overlay.hidden { display: none; }

.compare-overlay-inner {
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    animation: scaleIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.result-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.result-score-section {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.result-big-score {
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1;
}

.result-score-bar {
    flex: 1;
    height: 10px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 5px;
    overflow: hidden;
    min-width: 100px;
}

.result-score-fill {
    height: 100%;
    border-radius: 5px;
    transition: width 0.8s ease;
}

.result-rating-badge {
    padding: 0.5rem 1.5rem;
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: 1rem;
    border: 1px solid;
}

.result-notes {
    color: var(--text-bright);
    font-size: 1.05rem;
    line-height: 2;
}

.compare-text-raw {
    color: var(--text-bright);
    line-height: 2;
    font-size: 1rem;
}

.compare-error {
    background: rgba(244, 63, 94, 0.08);
    border: 1px solid rgba(244, 63, 94, 0.2);
    border-radius: var(--radius-sm);
    padding: 1.5rem;
    color: var(--accent);
    font-size: 0.95rem;
    text-align: center;
}

.compare-loading {
    display: flex;
    justify-content: center;
    padding: 4rem;
}

.spinner-small {
    width: 40px; height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ====== LOADER ====== */
.loader-overlay {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(5, 7, 10, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
}
.spinner-container {
    display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.spinner {
    width: 44px; height: 44px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.loader-text { color: var(--text-dim); font-size: 0.9rem; }
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

@media (max-width: 640px) {
    .app-container { padding: 1rem; }
    header h1 { font-size: 2rem; }
    .filters-card { padding: 1.25rem; }
    .fetch-controls {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    .fetch-right { justify-content: flex-end; }
    .quiz-card { padding: 1.5rem; }
    .q-text { font-size: 1.1rem; }
    .quiz-container { padding: 0; }
    .result-big-score { font-size: 2.5rem; }
    .compare-overlay { padding: 1rem; }
}

.katex-display { margin: 1em 0; overflow-x: auto; overflow-y: hidden; }

@media print {
    .background-blobs, .loader-overlay { display: none !important; }
    body { background: white; color: black; }
    .glass { background: white; border: 1px solid #ccc; box-shadow: none; }
}