/* Sober and Formal Academic Color Palette CSS */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&family=Fira+Code:wght@400;500&display=swap');

:root {
    --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 50%, #e2e8f0 100%);
    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent-primary: #1e3a8a; /* Formal Deep Blue */
    --accent-glow: rgba(30, 58, 138, 0.15);
    --accent-success: #059669; /* Emerald Green */
    --accent-warning: #d97706; /* Amber */
    --accent-error: #dc2626; /* Rose Red */
    
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 4px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base resets & selection block */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    padding: 30px 20px;
    position: relative;
}

/* Blur overlay for screenshot / window blur protection */
#security-blur-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    text-align: center;
    padding: 30px;
}

#security-blur-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#security-blur-overlay h1 {
    font-family: 'Outfit', sans-serif;
    color: var(--accent-error);
    font-size: 2.2rem;
    margin-bottom: 15px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#security-blur-overlay p {
    font-size: 1.1rem;
    color: #e2e8f0;
    max-width: 500px;
    line-height: 1.6;
}

#security-blur-overlay .btn-resume {
    margin-top: 25px;
    padding: 12px 30px;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(30,58,138,0.3);
    transition: var(--transition);
}

#security-blur-overlay .btn-resume:hover {
    transform: scale(1.03);
    background: #1d4ed8;
}

/* Floating webcam preview circle for student */
#webcam-preview-container {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 3px solid var(--accent-primary);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    overflow: hidden;
    z-index: 99;
    display: none;
    background: #000000;
    transform: scaleX(-1); /* mirror view */
}

#webcam-preview-container.active {
    display: block;
    animation: scaleIn 0.3s ease;
}

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

#webcam-preview-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.webcam-status-indicator {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%) scaleX(-1); /* unmirror status text */
    background: rgba(15, 23, 42, 0.85);
    border-radius: 20px;
    padding: 3px 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

.status-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-success);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--accent-success);
    animation: breathing 1.5s infinite;
}

@keyframes breathing {
    0% { opacity: 0.3; }
    50% { opacity: 1; }
    100% { opacity: 0.3; }
}

.status-text {
    font-size: 0.62rem;
    font-weight: 700;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* App Wrapper */
.app-container {
    width: 100%;
    max-width: 800px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.02);
    padding: 40px;
    transition: var(--transition);
    position: relative;
    z-index: 10;
}

/* Headings */
h1, h2, h3, h4 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.header-logo {
    text-align: center;
    margin-bottom: 30px;
}

.header-logo h1 {
    font-size: 2.1rem;
    color: var(--accent-primary);
    margin-bottom: 8px;
    font-weight: 800;
}

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

/* Cards & Sections transition */
.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}

.form-control {
    width: 100%;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: #ffffff;
}

select.form-control option {
    background: #ffffff;
    color: var(--text-primary);
}

/* Primary Button */
.btn-primary {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 14px;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-md);
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-disabled {
    opacity: 0.45;
    pointer-events: none;
    cursor: not-allowed;
}

/* Quiz UI Components */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--card-border);
}

.quiz-progress-info {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
}

.quiz-part-tag {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(30, 58, 138, 0.08);
    border: 1px solid rgba(30, 58, 138, 0.2);
    color: var(--accent-primary);
    padding: 4px 10px;
    border-radius: 20px;
}

/* Progress bar container */
.progress-container {
    width: 100%;
    height: 5px;
    background: #e2e8f0;
    border-radius: 3px;
    margin-bottom: 30px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-primary);
    border-radius: 3px;
    transition: width 0.25s ease;
}

/* Question style */
.question-container h3 {
    font-size: 1.3rem;
    line-height: 1.45;
    margin-bottom: 20px;
    color: var(--text-primary);
}

/* Monospace Syntax Code Block */
.code-block {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 25px;
    overflow-x: auto;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.88rem;
    line-height: 1.5;
    color: #e2e8f0;
}

.code-keyword { color: #f43f5e; font-weight: 500; }
.code-type { color: #38bdf8; }
.code-string { color: #10b981; }
.code-comment { color: #64748b; font-style: italic; }
.code-fn { color: #fbbf24; }

/* Options layout */
.options-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 30px;
}

.option-item {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.option-item:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.option-item.selected {
    background: rgba(30, 58, 138, 0.04);
    border-color: var(--accent-primary);
}

.option-radio {
    display: none; /* Hide default radio */
}

.option-marker {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
    margin-right: 15px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-secondary);
    transition: var(--transition);
    background: #ffffff;
}

.option-item:hover .option-marker {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.option-item.selected .option-marker {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #ffffff;
}

.option-text {
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--text-primary);
}

/* Footer of Quiz Card */
.quiz-footer {
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.btn-secondary {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 12px 24px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-md);
    color: #475569;
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    border-color: #94a3b8;
    color: var(--text-primary);
    background: #f8fafc;
}

.btn-success {
    background: var(--accent-success);
}

.btn-success:hover {
    background: #047857;
}

/* Results / Info Card Styling */
.results-card {
    text-align: center;
}

.score-circle {
    position: relative;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(30, 58, 138, 0.05) 0%, rgba(255, 255, 255, 1) 100%);
    border: 3px solid var(--card-border);
    margin: 0 auto 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.score-value {
    font-family: 'Outfit', sans-serif;
    font-size: 2.8rem;
    font-weight: 800;
    color: var(--accent-success);
    line-height: 1.1;
}

.score-total {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.results-stats {
    background: #f8fafc;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-around;
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 5px;
    letter-spacing: 0.02em;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
}

.stat-value.ok {
    color: var(--accent-success);
}

.stat-value.warn {
    color: var(--accent-warning);
}

.stat-value.danger {
    color: var(--accent-error);
}

/* Warnings layout in-app */
.alert-banner {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: rgba(220, 38, 38, 0.05);
    border: 1px solid rgba(220, 38, 38, 0.15);
    border-radius: var(--radius-sm);
    color: var(--accent-error);
    margin-bottom: 20px;
    font-size: 0.88rem;
    line-height: 1.4;
}

.alert-banner svg {
    flex-shrink: 0;
    margin-right: 10px;
    width: 20px;
    height: 20px;
    fill: var(--accent-error);
}

/* Admin Tabs */
.admin-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 25px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 15px;
}

.tab-btn {
    padding: 10px 18px;
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
    background: #f8fafc;
}

.tab-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #ffffff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

/* Admin Dashboard View */
.admin-card {
    max-width: 1000px;
    margin: 20px auto;
    width: 100%;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.admin-stat-card {
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: left;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.02);
}

.admin-stat-card .value {
    font-size: 1.8rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    margin-top: 5px;
}

.table-wrapper {
    overflow-x: auto;
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    margin-bottom: 35px;
}

.table-admin {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.table-admin th {
    background: #f8fafc;
    padding: 14px 16px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--card-border);
}

.table-admin td {
    padding: 14px 16px;
    font-size: 0.9rem;
    border-bottom: 1px solid #f1f5f9;
}

.table-admin tr:hover {
    background: #f8fafc;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 4px;
}

.badge-success { background: rgba(5, 150, 105, 0.1); color: #047857; border: 1px solid rgba(5, 150, 105, 0.2); }
.badge-warning { background: rgba(217, 119, 6, 0.1); color: #b45309; border: 1px solid rgba(217, 119, 6, 0.2); }
.badge-danger { background: rgba(220, 38, 38, 0.1); color: #b91c1c; border: 1px solid rgba(220, 38, 38, 0.2); }

.btn-table {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.15);
    color: var(--accent-error);
    transition: var(--transition);
}

.btn-table:hover {
    background: var(--accent-error);
    color: white;
}

/* Details popup modal for Admin */
.modal-admin {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-admin.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content-admin {
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    width: 95%;
    max-width: 850px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 30px;
    box-shadow: 0 10px 45px rgba(0,0,0,0.15);
}

.modal-header-admin {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 10px;
}

.modal-close-admin {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close-admin:hover {
    color: var(--text-primary);
}

.detail-ans-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.detail-ans-item {
    padding: 20px;
    background: #f8fafc;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
}

.detail-ans-item.correct {
    border-left: 5px solid var(--accent-success);
}

.detail-ans-item.incorrect {
    border-left: 5px solid var(--accent-error);
}

/* Webcam capture images side-by-side grid inside details */
.webcam-captures-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 15px;
}

.webcam-capture-card {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
}

.webcam-capture-card span {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.webcam-capture-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid #cbd5e1;
    background: #000;
}

.no-webcam-capture {
    height: 120px;
    border-radius: var(--radius-sm);
    border: 1px dashed #cbd5e1;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    background: #ffffff;
}

/* Horizontal accuracy progress bar for stats per question */
.stat-bar-container {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 6px;
}

.stat-bar-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 4px;
}

/* QR display box */
.qr-container {
    display: flex;
    gap: 30px;
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--card-border);
    padding: 20px;
    border-radius: var(--radius-md);
    margin-top: 20px;
}

.qr-image-box {
    background: #ffffff;
    padding: 10px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 160px;
    height: 160px;
    flex-shrink: 0;
}

.qr-image-box img {
    width: 100%;
    height: 100%;
}

/* Animations and Responsive */
@media (max-width: 768px) {
    .app-container {
        padding: 20px;
    }
    
    .quiz-footer {
        flex-direction: column;
    }
    
    .btn-secondary, .btn-primary {
        width: 100%;
    }
    
    .header-logo h1 {
        font-size: 1.8rem;
    }
    
    .webcam-captures-grid {
        grid-template-columns: 1fr;
    }
    
    .qr-container {
        flex-direction: column;
        text-align: center;
    }
}
