:root {
    --primary: #0d6efd;
    --primary-hover: #0b5ed7;
    --success: #198754;
    --danger: #dc3545;
    --dark: #212529;
    --gray: #6c757d;
    --bg: #f4f6f9;
    --border: #e2e8f0;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }

/* DYNAMIC FLEX BODY: Solves scroll issues and handles the navbar perfectly */
body { 
    background-color: var(--bg); 
    color: var(--dark); 
    font-size: 16px; 
    height: 100dvh; 
    overflow: hidden; 
    display: flex;
    flex-direction: column;
}

/* GLOBAL TOP NAVBAR */
.top-navbar {
    background-color: #0f172a;
    color: white;
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    flex-shrink: 0;
    z-index: 1000;
}
.top-navbar a { color: white; text-decoration: none; font-weight: bold; transition: 0.2s; display: flex; align-items: center; gap: 5px; }
.top-navbar a:hover { color: #fbbf24; }
.nav-title { color: #94a3b8; }

/* SCREEN MANAGEMENT */
.screen { display: none; width: 100%; flex: 1; }
#exam-screen.active { display: flex; flex-direction: column; overflow: hidden; }
#result-screen.active { display: block; overflow-y: auto; padding-bottom: 50px; }
.text-center { text-align: center; }

/* UTILITY COLORS */
.val-green { color: var(--success); font-weight: 700; }
.val-red { color: var(--danger); font-weight: 700; }
.val-blue { color: var(--primary); font-weight: 700; }
.mobile-only { display: none; }

/* HINDI HOVER TOOLTIP */
.hover-hint { position: relative; border-bottom: 2px dashed var(--primary); cursor: help; color: var(--primary); padding-bottom: 1px; font-weight: 600; display: inline-block; }
.hover-hint::after {
    content: attr(data-hint);
    position: absolute; bottom: calc(100% + 8px); left: -5px; 
    background: #1e293b; color: #fff; padding: 8px 14px; font-size: 13px;
    border-radius: 6px; white-space: normal; width: max-content; max-width: min(260px, calc(100vw - 40px)); 
    text-align: left; opacity: 0; visibility: hidden; transition: 0.2s ease; box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 9999; font-family: 'Noto Sans Devanagari', sans-serif; line-height: 1.4;
}
.hover-hint::before {
    content: ''; position: absolute; bottom: 100%; left: 15px; 
    border-width: 8px; border-style: solid; border-color: #1e293b transparent transparent transparent;
    opacity: 0; visibility: hidden; transition: 0.2s ease; z-index: 9999;
}
.hover-hint:hover::after, .hover-hint:hover::before,
.hover-hint:active::after, .hover-hint:active::before { opacity: 1; visibility: visible; }

/* SYSTEM HEADER */
.sys-header { background-color: var(--primary); color: white; padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: 600; box-shadow: 0 2px 5px rgba(0,0,0,0.1); z-index: 10; flex-shrink: 0; }
.mobile-palette-btn { display: none; background: rgba(255,255,255,0.2); border: 1px solid white; color: white; padding: 5px 10px; border-radius: 4px; font-weight: bold; cursor: pointer; font-size: 13px; }

/* CANDIDATE BAR */
.candidate-bar { background-color: white; border-bottom: 1px solid var(--border); padding: 8px 15px; display: flex; justify-content: space-between; align-items: center; font-size: 14px; flex-shrink: 0; }
.candidate-info { display: flex; align-items: center; gap: 10px; }
.avatar-placeholder { border-radius: 5px; width: 35px; height: 35px; display: flex; justify-content: center; align-items: center; font-size: 18px; background: #e9ecef; }
.c-name { font-weight: 700; font-size: 14px; }
.c-sys { color: var(--gray); font-size: 12px; }
.time-left { font-size: 18px; font-weight: 700; color: var(--danger); background: #ffe9e9; padding: 2px 8px; border-radius: 4px; }

/* MAIN EXAM LAYOUT */
.main-layout { flex: 1; display: flex; overflow: hidden; width: 100%; position: relative; }
.question-panel { flex: 1; background: white; padding: 25px; overflow-y: auto; border-right: 1px solid var(--border); }
.palette-panel { width: 320px; background: #f8f9fa; display: flex; flex-direction: column; flex-shrink: 0; transition: 0.3s ease; border-left: 1px solid var(--border); }

/* QUESTION STYLING */
.q-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 15px; }
.q-title { font-size: 20px; font-weight: 800; color: #1e293b; }
.q-marks { text-align: right; font-size: 13px; }
.mark-badge { background: #f1f3f5; padding: 4px 10px; border-radius: 20px; margin-top: 4px; border: 1px solid var(--border); font-weight: 600; display: inline-block; }
.q-body { font-size: 17px; margin-bottom: 20px; line-height: 1.6; color: #334155; }
.q-body ul { margin-left: 20px; margin-top: 8px; }
.options-body { display: flex; flex-direction: column; gap: 12px; }
.opt-label { display: flex; align-items: center; padding: 14px 16px; background: #ffffff; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; transition: all 0.2s ease; font-size: 15px; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.opt-label:hover { background: #f8fafc; border-color: var(--primary); }
.opt-label input { margin-right: 12px; transform: scale(1.3); cursor: pointer; accent-color: var(--primary); flex-shrink: 0; }

/* PALETTE GRID */
.p-header { background: #e2e8f0; padding: 12px 15px; font-weight: 700; text-align: center; border-bottom: 1px solid #cbd5e1; color: #475569; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.close-palette { background: none; border: none; font-size: 20px; color: var(--danger); cursor: pointer; }
.legend-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); font-size: 11px; background: white; font-weight: 600; flex-shrink: 0; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.p-grid { padding: 15px; display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 8px; overflow-y: auto; flex: 1; align-content: flex-start; }

/* STATUS BADGES */
.badge { width: 36px; height: 36px; display: flex; justify-content: center; align-items: center; font-size: 13px; font-weight: 700; cursor: pointer; color: white; border: 1px solid rgba(0,0,0,0.1); border-radius: 4px; transition: transform 0.1s; }
.badge:active { transform: scale(0.92); }
.not-vis { background-color: #fff; color: #475569; border-color: #cbd5e1; }
.not-ans { background-color: var(--danger); border-radius: 50% 50% 0 0; }
.ans { background-color: var(--success); border-radius: 50% 50% 0 0; }
.marked { background-color: #7c3aed; border-radius: 50%; }
.ans-marked { background-color: #7c3aed; border-radius: 50%; position: relative; }
.ans-marked::after { content: '✔'; position: absolute; bottom: -3px; right: -3px; width: 14px; height: 14px; background: var(--success); color: white; border-radius: 50%; font-size: 9px; display: flex; justify-content: center; align-items: center; border: 2px solid white; }

/* ACTION FOOTER */
.action-footer { background: #ffffff; display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-top: 1px solid var(--border); box-shadow: 0 -4px 10px rgba(0,0,0,0.03); z-index: 10; flex-shrink: 0; }
.footer-left, .footer-right { display: flex; gap: 10px; }
.btn { padding: 10px 18px; border: none; cursor: pointer; border-radius: 6px; font-size: 14px; font-weight: 600; transition: all 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: white; color: #475569; border: 1px solid #cbd5e1; }
.btn-outline:hover { background: #f1f5f9; }
.btn-success { background: var(--success); color: white; }

/* --- RESULT SCREEN UPGRADES --- */
.result-wrapper { max-width: 1200px; margin: 20px auto; padding: 0 15px; }
.card { background: white; padding: 20px; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.03); margin-bottom: 20px; border: 1px solid var(--border); }
.result-header { text-align: center; background: linear-gradient(135deg, #0d6efd, #3b82f6); color: white; border: none; padding: 25px; }
.final-score { font-size: 36px; font-weight: 800; margin: 10px 0; text-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.grade-badge { display: inline-block; padding: 6px 25px; background: #fbbf24; color: #78350f; font-size: 20px; font-weight: 800; border-radius: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }

/* AI Card */
.ai-card h2 { color: #1e293b; font-size: 18px; margin-bottom: 15px; border-bottom: 2px solid var(--border); padding-bottom: 10px; }
.ai-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.ai-box { padding: 15px; border-radius: 8px; font-size: 14px; line-height: 1.5; border-left: 5px solid; }
.ai-box.strength { background: #f0fdf4; border-color: var(--success); color: #166534; }
.ai-box.weakness { background: #fef2f2; border-color: var(--danger); color: #991b1b; }
.ai-box.remark { background: #eff6ff; border-color: var(--primary); color: #1e40af; }

/* Dashboard Cards */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 15px; margin-bottom: 20px; }
.dash-card { background: white; border-radius: 12px; padding: 18px; border: 1px solid var(--border); box-shadow: 0 4px 15px rgba(0,0,0,0.02); }
.dash-card h3 { font-size: 17px; color: #334155; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.stat-row:last-child { border-bottom: none; }
.stat-row span { color: #64748b; }

/* Charts */
.charts-row { display: flex; flex-wrap: wrap; gap: 15px; margin-bottom: 20px; }
.chart-container { flex: 1; min-width: 300px; display: flex; justify-content: center; align-items: center; padding: 15px; }

/* Accordion Breakdown */
.detailed-review h2 { margin-bottom: 15px; color: #1e293b; border-bottom: 2px solid var(--border); padding-bottom: 10px; font-size: 18px; }
.review-item { border: 1px solid var(--border); margin-bottom: 10px; border-radius: 8px; }
.review-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 15px; background: #f8fafc; cursor: pointer; transition: 0.2s; border-radius: 8px; }
.review-header:hover { background: #f1f5f9; }
.review-body.active ~ .review-header { border-radius: 8px 8px 0 0; }
.rq-title { font-weight: 700; font-size: 15px; color: #334155; max-width: 65%; }
.status-pill { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; color: white; display: inline-block; text-align: center; }
.status-pill.correct { background: var(--success); }
.status-pill.wrong { background: var(--danger); }
.status-pill.skipped { background: var(--gray); }
.review-body { display: none; padding: 15px; background: white; border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; }
.review-body.active { display: block; }
.ans-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.r-ans b { color: #64748b; font-size: 11px; text-transform: uppercase; display: block; margin-bottom: 4px; }
.r-ans span { font-size: 14px; font-weight: 600; color: #1e293b; }

/* =========================================
   MOBILE RESPONSIVENESS
========================================= */
#mobile-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 99; }

@media (max-width: 900px) {
    .hide-mobile { display: none !important; }
    .mobile-only { display: block; }
    
    .mobile-palette-btn { display: block; }
    .sys-header { padding: 8px 12px; font-size: 15px; }
    .candidate-bar { padding: 8px 12px; }
    .time-left { font-size: 15px; }
    
    .question-panel { padding: 15px 12px; border-right: none; }
    .q-title { font-size: 18px; margin-bottom: 2px; }
    .q-header { padding-bottom: 8px; margin-bottom: 12px; }
    .q-body { font-size: 15px; margin-bottom: 12px; line-height: 1.5; }
    
    .options-body { gap: 8px; }
    .opt-label { padding: 10px 12px; font-size: 14px; }
    .opt-label input { transform: scale(1.2); margin-right: 10px; }

    .palette-panel {
        position: fixed; top: 0; right: -350px; 
        width: 85%; max-width: 320px; height: 100dvh;
        z-index: 100; box-shadow: -5px 0 15px rgba(0,0,0,0.2);
    }
    .palette-panel.open { right: 0; }
    #mobile-overlay.active { display: block; }

    .action-footer { padding: 8px; flex-direction: column; gap: 8px; }
    .footer-left, .footer-right { width: 100%; display: flex; gap: 8px; justify-content: space-between; }
    .btn { padding: 8px 6px; font-size: 13px; flex: 1; text-align: center; border-radius: 4px; }
    
    .prev-btn { display: none; }
    
    .result-wrapper { margin: 10px auto; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .ans-grid { grid-template-columns: 1fr; }
    .rq-title { max-width: 60%; font-size: 13px; }
}