@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

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

body {
    background: #0a0e1a;
    overflow-x: hidden;
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    color: #fff;
    direction: ltr;
    min-height: 100vh;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ══ LOGIN ══ */
#login-screen { justify-content: center; align-items: center; background: #0a0e1a; }

.ring-wrapper { position: relative; display: flex; justify-content: center; align-items: center; }
.ring-wrapper::before {
    content: ''; position: absolute; width: 420px; height: 420px; border-radius: 50%;
    border: 2px solid rgba(0,180,200,0.25);
    box-shadow: 0 0 60px rgba(0,180,200,0.08), inset 0 0 60px rgba(0,180,200,0.05);
    animation: ringPulse 4s ease-in-out infinite;
}
.ring-wrapper::after {
    content: ''; position: absolute; width: 380px; height: 380px; border-radius: 50%;
    border: 1px solid rgba(0,180,200,0.12);
}
@keyframes ringPulse { 0%,100%{transform:scale(1);opacity:.7} 50%{transform:scale(1.03);opacity:1} }

.login-card {
    position: relative; z-index: 2; background: rgba(15,20,35,0.92);
    border: 1px solid rgba(255,255,255,0.06); border-radius: 16px;
    padding: 40px 36px 32px; width: 380px; backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.logo {
    width: 56px; height: 56px; margin: 0 auto 20px;
    background: linear-gradient(135deg,#e8531e,#f47b20); border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(232,83,30,0.35);
}
.logo svg { width: 28px; height: 28px; fill: #fff; }
.login-card h1 { text-align: center; font-size: 1.3em; font-weight: 700; margin-bottom: 4px; }
.login-card h1 span { color: #f47b20; }
.login-card .subtitle { text-align: center; font-size: 0.8em; color: #5a6178; margin-bottom: 28px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.78em; color: #6b7280; margin-bottom: 6px; }
.input-wrapper { position: relative; display: flex; align-items: center; }
.input-wrapper .icon { position: absolute; left: 14px; width: 16px; height: 16px; fill: #4a5068; pointer-events: none; }
.input-wrapper input {
    width: 100%; padding: 12px 14px 12px 42px;
    background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px; color: #fff; font-family: 'Cairo',sans-serif; font-size: 0.9em;
    outline: none; transition: border-color 0.2s, box-shadow 0.2s; direction: rtl;
}
.input-wrapper input::placeholder { color: #3d4358; }
.input-wrapper input:focus { border-color: rgba(244,123,32,0.5); box-shadow: 0 0 0 3px rgba(244,123,32,0.1); }

.login-btn {
    width: 100%; padding: 13px; margin-top: 8px;
    background: linear-gradient(135deg,#e8531e,#f47b20); color: #fff; border: none;
    border-radius: 10px; font-family: 'Cairo',sans-serif; font-size: 0.95em; font-weight: 600;
    cursor: pointer; transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(232,83,30,0.3);
}
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 25px rgba(232,83,30,0.45); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.login-footer { text-align: center; margin-top: 18px; font-size: 0.75em; }
.login-footer a { color: #6b7280; text-decoration: none; }
.login-footer a:hover { color: #f47b20; }

.msg { display: none; text-align: center; font-size: 0.8em; margin-top: 10px; padding: 8px; border-radius: 8px; }
.msg.show { display: block; }
.error-msg { color: #ef4444; background: rgba(239,68,68,0.08); }
.success-msg { color: #22c55e; background: rgba(34,197,94,0.08); }

.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
    border-radius: 50%; animation: spin 0.6s linear infinite;
    margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══ DASHBOARD ══ */
#dashboard-screen { background: #0a0e1a; }

.dash-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 32px; background: rgba(15,20,35,0.8);
    border-bottom: 1px solid rgba(255,255,255,0.05); flex-shrink: 0;
}
.header-right { display: flex; align-items: center; gap: 14px; }
.logo-sm {
    width: 40px; height: 40px; background: linear-gradient(135deg,#e8531e,#f47b20);
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
}
.logo-sm svg { width: 20px; height: 20px; fill: #fff; }
.header-titles h2 { font-size: 1.1em; font-weight: 700; }
.header-titles .header-sub { font-size: 0.72em; color: #5a6178; }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-user { font-size: 0.85em; color: #9ca3af; }
.btn-icon {
    background: none; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px;
    padding: 6px 10px; cursor: pointer; color: #9ca3af; transition: all 0.2s;
}
.btn-icon:hover { color: #ef4444; border-color: rgba(239,68,68,0.3); }

.dash-tabs {
    display: flex; gap: 4px; padding: 12px 32px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05); flex-shrink: 0;
}
.tab {
    padding: 10px 24px; background: none; border: none; color: #5a6178;
    font-family: 'Cairo',sans-serif; font-size: 0.88em; cursor: pointer;
    border-bottom: 2px solid transparent; transition: all 0.2s;
}
.tab:hover { color: #9ca3af; }
.tab.active { color: #f47b20; border-bottom-color: #f47b20; }

.tab-content { display: none; flex: 1; padding: 24px 32px; overflow-y: auto; }
.tab-content.active { display: block; }

.loading { text-align: center; padding: 40px; color: #5a6178; }

/* Quiz Cards Grid */
.quizzes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.quiz-card {
    background: rgba(15,20,35,0.8); border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px; padding: 24px; transition: border-color 0.2s; cursor: pointer;
}
.quiz-card:hover { border-color: rgba(244,123,32,0.3); }
.quiz-card.locked { opacity: 0.5; cursor: not-allowed; }
.quiz-card.locked:hover { border-color: rgba(255,255,255,0.05); }
.quiz-card.passed { border-color: rgba(34,197,94,0.3); }

.quiz-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.quiz-card-title { font-size: 1.05em; font-weight: 700; }
.quiz-card-badge {
    font-size: 0.7em; padding: 3px 10px; border-radius: 20px; font-weight: 600;
}
.badge-1 { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge-2 { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-3 { background: rgba(244,123,32,0.15); color: #f47b20; }
.badge-4 { background: rgba(139,92,246,0.15); color: #a78bfa; }
.badge-5 { background: rgba(239,68,68,0.15); color: #ef4444; }

.quiz-card-desc { font-size: 0.82em; color: #5a6178; margin-bottom: 16px; line-height: 1.5; }
.quiz-card-meta { display: flex; gap: 16px; font-size: 0.75em; color: #4a5068; }
.quiz-card-meta span { display: flex; align-items: center; gap: 4px; }
.quiz-card-score { margin-top: 12px; font-size: 0.82em; }
.quiz-card-score .passed { color: #4ade80; }
.quiz-card-score .failed { color: #ef4444; }

.lock-icon { display: inline-block; margin-left: 6px; }

/* Scores Table */
.scores-table { width: 100%; border-collapse: collapse; }
.scores-table th {
    text-align: right; padding: 12px 16px; font-size: 0.78em; color: #5a6178;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.scores-table td {
    padding: 12px 16px; font-size: 0.88em;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.scores-table tr:hover td { background: rgba(255,255,255,0.02); }

/* Leaderboard */
.lb-row {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 20px; background: rgba(15,20,35,0.8);
    border: 1px solid rgba(255,255,255,0.05); border-radius: 12px;
    margin-bottom: 8px;
}
.lb-rank {
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9em;
    background: rgba(255,255,255,0.04);
}
.lb-rank.top-1 { background: rgba(244,123,32,0.2); color: #f47b20; }
.lb-rank.top-2 { background: rgba(139,92,246,0.2); color: #a78bfa; }
.lb-rank.top-3 { background: rgba(59,130,246,0.2); color: #60a5fa; }
.lb-name { flex: 1; font-weight: 600; }
.lb-stats { display: flex; gap: 24px; font-size: 0.82em; color: #5a6178; }

/* ══ QUIZ TAKING ══ */
#quiz-screen { background: #0a0e1a; }

.quiz-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 32px; background: rgba(15,20,35,0.9);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.quiz-info h2 { font-size: 1.1em; font-weight: 700; }
.quiz-meta { display: flex; gap: 20px; font-size: 0.82em; color: #5a6178; margin-top: 4px; }
.quiz-timer { color: #f47b20; font-weight: 600; font-variant-numeric: tabular-nums; }

.quiz-body { flex: 1; display: flex; justify-content: center; padding: 32px; overflow-y: auto; }

.question-card {
    background: rgba(15,20,35,0.8); border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px; padding: 32px; width: 100%; max-width: 720px;
}
.question-prompt { font-size: 1.05em; line-height: 1.7; margin-bottom: 20px; }

.code-snippet {
    background: rgba(0,0,0,0.3) !important; border-radius: 10px; padding: 20px !important;
    margin-bottom: 20px; direction: ltr; text-align: left;
    font-family: 'JetBrains Mono','Fira Code',monospace; font-size: 0.85em;
    line-height: 1.7; overflow-x: auto; border: 1px solid rgba(255,255,255,0.06);
}

.options-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
    width: 100%; padding: 14px 20px; background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08); border-radius: 10px;
    color: #e2e8f0; font-family: 'Cairo',sans-serif; font-size: 0.92em;
    cursor: pointer; text-align: right; transition: all 0.2s; direction: ltr;
}
.option-btn:hover { border-color: rgba(244,123,32,0.4); background: rgba(244,123,32,0.05); }
.option-btn.selected { border-color: #f47b20; background: rgba(244,123,32,0.1); color: #fff; }

.question-input input {
    width: 100%; padding: 14px 20px; background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08); border-radius: 10px;
    color: #fff; font-family: 'JetBrains Mono',monospace; font-size: 0.9em;
    outline: none; transition: all 0.2s;
}
.question-input input:focus { border-color: rgba(244,123,32,0.5); }

.quiz-footer {
    padding: 16px 32px; background: rgba(15,20,35,0.9);
    border-top: 1px solid rgba(255,255,255,0.05);
    display: flex; justify-content: flex-end; gap: 12px;
}

.btn-primary {
    padding: 12px 32px; background: linear-gradient(135deg,#e8531e,#f47b20);
    color: #fff; border: none; border-radius: 10px; font-family: 'Cairo',sans-serif;
    font-size: 0.92em; font-weight: 600; cursor: pointer;
    box-shadow: 0 4px 15px rgba(232,83,30,0.3); transition: all 0.15s;
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-outline {
    padding: 10px 24px; background: none; color: #9ca3af;
    border: 1px solid rgba(255,255,255,0.1); border-radius: 10px;
    font-family: 'Cairo',sans-serif; font-size: 0.85em; cursor: pointer; transition: all 0.2s;
}
.btn-outline:hover { color: #ef4444; border-color: rgba(239,68,68,0.3); }

/* ══ RESULTS ══ */
#results-screen { justify-content: center; align-items: center; background: #0a0e1a; }

.results-card {
    background: rgba(15,20,35,0.9); border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px; padding: 48px; text-align: center; max-width: 420px; width: 100%;
}
.results-icon { margin-bottom: 20px; }
.results-icon.pass { color: #4ade80; }
.results-icon.fail { color: #ef4444; }
.results-card h2 { font-size: 1.2em; margin-bottom: 24px; }

.score-big { font-size: 3.5em; font-weight: 700; color: #f47b20; }
.results-details { margin: 24px 0; }
.detail-row {
    display: flex; justify-content: space-between; padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04); font-size: 0.9em;
}
.detail-row span:first-child { color: #5a6178; }

/* ══ CODING CHALLENGE SCREEN ══ */
#challenge-screen { background: #0a0e1a; }
#challenge-results-screen { justify-content: center; align-items: center; background: #0a0e1a; }

.challenge-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 24px; background: rgba(15,20,35,0.9);
    border-bottom: 1px solid rgba(255,255,255,0.05); flex-shrink: 0;
}
.challenge-info { display: flex; align-items: center; gap: 16px; }
.challenge-info h2 { font-size: 1em; font-weight: 700; }
.challenge-level {
    font-size: 0.72em; padding: 3px 12px; border-radius: 20px;
    background: rgba(244,123,32,0.15); color: #f47b20; font-weight: 600;
}
.challenge-actions { display: flex; align-items: center; gap: 16px; }

.challenge-layout {
    flex: 1; display: flex; overflow: hidden; direction: ltr;
}

.challenge-sidebar {
    width: 400px; min-width: 350px; display: flex; flex-direction: column;
    border-left: 1px solid rgba(255,255,255,0.05); background: rgba(10,14,26,0.95);
    direction: ltr;
}

.challenge-tabs {
    display: flex; border-bottom: 1px solid rgba(255,255,255,0.05); flex-shrink: 0;
}
.ch-tab {
    flex: 1; padding: 10px; background: none; border: none; color: #5a6178;
    font-family: 'Cairo',sans-serif; font-size: 0.82em; cursor: pointer;
    border-bottom: 2px solid transparent;
}
.ch-tab.active { color: #f47b20; border-bottom-color: #f47b20; }
.ch-tab-content { display: none; flex: 1; overflow-y: auto; padding: 16px; }
.ch-tab-content.active { display: block; }

.challenge-desc {
    font-size: 0.88em; line-height: 1.8; color: #cbd5e1;
    white-space: pre-wrap;
}

/* Test Results */
.test-item {
    padding: 10px 14px; margin-bottom: 6px;
    background: rgba(255,255,255,0.03); border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.05); font-size: 0.82em;
}
.test-item.pass { border-color: rgba(34,197,94,0.3); }
.test-item.fail { border-color: rgba(239,68,68,0.3); }
.test-item .test-name { font-weight: 600; margin-bottom: 4px; }
.test-item .test-status { font-size: 0.85em; }
.test-item .test-status.pass { color: #4ade80; }
.test-item .test-status.fail { color: #ef4444; }
.test-item .test-detail { font-size: 0.8em; color: #5a6178; margin-top: 4px; font-family: monospace; direction: ltr; text-align: left; }

/* Console */
.console-panel {
    border-top: 1px solid rgba(255,255,255,0.05); flex-shrink: 0;
    max-height: 180px; display: flex; flex-direction: column;
}
.console-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 14px; font-size: 0.78em; color: #5a6178;
    background: rgba(0,0,0,0.2);
}
.btn-small {
    background: none; border: none; color: #5a6178; cursor: pointer;
    font-family: 'Cairo',sans-serif; font-size: 0.9em;
}
.btn-small:hover { color: #f47b20; }
.console-output {
    flex: 1; overflow-y: auto; padding: 10px 14px;
    font-family: 'JetBrains Mono',monospace; font-size: 0.78em;
    color: #4ade80; background: rgba(0,0,0,0.3); line-height: 1.6;
    direction: ltr; text-align: left; margin: 0;
}

/* Editor */
.challenge-editor-wrap {
    flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.editor-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 16px; background: rgba(15,20,35,0.95);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.editor-lang {
    font-size: 0.75em; color: #f47b20; font-weight: 600;
    padding: 2px 10px; background: rgba(244,123,32,0.1); border-radius: 4px;
}
.editor-btns { display: flex; gap: 8px; }
.btn-run {
    padding: 7px 20px; background: rgba(34,197,94,0.15); color: #4ade80;
    border: 1px solid rgba(34,197,94,0.3); border-radius: 6px;
    font-family: 'Cairo',sans-serif; font-size: 0.82em; cursor: pointer;
    transition: all 0.2s;
}
.btn-run:hover { background: rgba(34,197,94,0.25); }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-submit-code {
    padding: 7px 20px; background: linear-gradient(135deg,#e8531e,#f47b20);
    color: #fff; border: none; border-radius: 6px;
    font-family: 'Cairo',sans-serif; font-size: 0.82em; font-weight: 600;
    cursor: pointer; transition: all 0.15s;
}
.btn-submit-code:hover { transform: translateY(-1px); }
.btn-submit-code:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

#monaco-editor { flex: 1; min-height: 0; }

/* Challenge Cards */
.challenges-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px,1fr)); gap: 16px; }
.challenge-card {
    background: rgba(15,20,35,0.8); border: 1px solid rgba(255,255,255,0.05);
    border-radius: 14px; padding: 24px; cursor: pointer; transition: border-color 0.2s;
}
.challenge-card:hover { border-color: rgba(244,123,32,0.3); }
.challenge-card.completed { border-color: rgba(34,197,94,0.3); }
.challenge-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.challenge-card-title { font-weight: 700; font-size: 0.95em; }
.challenge-card-desc { font-size: 0.8em; color: #5a6178; line-height: 1.5; }
.challenge-card-meta { margin-top: 12px; display: flex; gap: 12px; font-size: 0.75em; color: #4a5068; }

.challenge-nav-btns { display: flex; gap: 12px; margin-top: 20px; justify-content: center; }

/* ══ ANTI-CHEAT ══ */

/* Disable text selection on exam content */
.exam-active .question-prompt,
.exam-active .option-btn,
.exam-active .challenge-desc,
.exam-active .quiz-card-desc,
.exam-active .quiz-card-title {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* Screenshot deterrent — near-invisible pattern via mix-blend-mode */
.exam-active::after {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 99998;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 8px,
        rgba(255,255,255,0.004) 8px,
        rgba(255,255,255,0.004) 16px
    );
    mix-blend-mode: difference;
}

/* Watermark overlay */
.watermark-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 99997;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 80px;
    padding: 40px;
    transform: rotate(-25deg);
    user-select: none !important;
    -webkit-user-select: none !important;
}

.watermark-overlay span {
    font-size: 1.8em;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.025);
    white-space: nowrap;
    letter-spacing: 4px;
}

/* Disable printing */
@media print {
    body { display: none !important; }
}

/* ══ SCROLLBAR ══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
