/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --text: #1d1d1f;
    --text2: #6e6e73;
    --primary: #4F46E5;
    --primary-light: #E0E7FF;
    --success: #10B981;
    --success-light: #D1FAE5;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --border: #e5e5ea;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== LAYOUT ===== */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== HEADER ===== */
.header {
    text-align: center;
    padding: 40px 20px 20px;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header p {
    color: var(--text2);
    margin-top: 4px;
    font-size: 0.95rem;
}

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

/* ===== WELCOME SCREEN ===== */
#welcome {
    text-align: center;
    padding: 60px 20px;
}

#welcome h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

#welcome .info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin: 30px 0;
    text-align: left;
}

#welcome .info-item {
    background: var(--bg);
    border-radius: 8px;
    padding: 14px;
    font-size: 0.9rem;
}

#welcome .info-item .icon {
    font-size: 1.3rem;
    margin-bottom: 4px;
    display: block;
}

#welcome .info-item .label {
    color: var(--text2);
    font-size: 0.8rem;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font);
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #4338CA; }

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-sm { padding: 8px 16px; font-size: 0.85rem; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== PROGRESS BAR ===== */
.progress-container {
    margin-bottom: 24px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.progress-subject {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-steps {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.progress-step {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    transition: background 0.3s ease;
}

.progress-step.done { background: var(--success); }
.progress-step.current { background: var(--primary); }
.progress-step.wrong { background: var(--danger); }

/* ===== TIMER ===== */
.timer {
    display: flex;
    align-items: center;
    gap: 6px;
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
    color: var(--text2);
}

.timer.warning { color: var(--warning); }
.timer.danger { color: var(--danger); font-weight: 600; }

/* ===== DIFFICULTY BADGE ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-easy { background: var(--success-light); color: #065F46; }
.badge-medium { background: var(--warning-light); color: #92400E; }
.badge-hard { background: var(--danger-light); color: #991B1B; }

/* ===== QUESTION ===== */
.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.question-number {
    font-size: 0.85rem;
    color: var(--text2);
}

.question-text {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 24px;
    line-height: 1.5;
}

/* ===== OPTIONS ===== */
.options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--bg);
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.95rem;
}

.option:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.option.correct {
    border-color: var(--success);
    background: var(--success-light);
}

.option.wrong {
    border-color: var(--danger);
    background: var(--danger-light);
}

.option-letter {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface);
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

.option.selected .option-letter {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.option.correct .option-letter {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.option.wrong .option-letter {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

/* ===== QUESTION NAV ===== */
.question-nav {
    display: flex;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ===== SUBJECTS OVERVIEW ===== */
.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin: 20px 0;
}

.subject-card {
    background: var(--bg);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    border: 2px solid transparent;
    transition: all 0.15s ease;
}

.subject-card.completed {
    border-color: var(--success);
    background: var(--success-light);
}

.subject-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.subject-card .icon { font-size: 1.8rem; margin-bottom: 6px; display: block; }
.subject-card .name { font-weight: 600; font-size: 0.9rem; }
.subject-card .score { font-size: 0.8rem; color: var(--text2); margin-top: 4px; }

/* ===== CODE EDITOR SECTION ===== */
.code-section {
    margin-top: 16px;
}

.code-section h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.code-description {
    background: var(--bg);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    white-space: pre-wrap;
    line-height: 1.6;
}

.editor-container {
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 12px;
}

#editor {
    height: 320px;
    width: 100%;
}

.console-output {
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 8px;
    padding: 14px;
    font-family: var(--mono);
    font-size: 0.85rem;
    min-height: 80px;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
    white-space: pre-wrap;
    word-break: break-all;
}

.console-output .error { color: #f44747; }
.console-output .success { color: #4ec9b0; }
.console-output .info { color: #569cd6; }

.test-results {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.test-result {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: var(--mono);
}

.test-result.pass { background: var(--success-light); }
.test-result.fail { background: var(--danger-light); }

.code-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ===== RESULTS ===== */
#results {
    text-align: center;
}

#results h2 {
    font-size: 1.6rem;
    margin-bottom: 8px;
}

.score-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 24px auto;
    font-size: 2.2rem;
    font-weight: 700;
    border: 6px solid var(--primary);
}

.score-circle small {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text2);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin: 24px 0;
    text-align: left;
}

.result-item {
    background: var(--bg);
    border-radius: 10px;
    padding: 16px;
}

.result-item .subject-name {
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.result-item .result-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.result-item .result-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.result-item .score-text {
    font-size: 0.85rem;
    color: var(--text2);
    margin-top: 4px;
}

/* ===== MONITORING ALERT (subtle) ===== */
.monitor-alert {
    position: fixed;
    top: 16px;
    right: 16px;
    background: var(--danger);
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.monitor-alert.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ===== LOADING ===== */
.loader {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SCREEN SECTIONS ===== */
.screen { display: none; }
.screen.active { display: block; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
    .container { padding: 12px; }
    .header h1 { font-size: 1.4rem; }
    .card { padding: 20px; }
    #welcome .info-grid { grid-template-columns: 1fr 1fr; }
    .subjects-grid { grid-template-columns: repeat(2, 1fr); }
    .results-grid { grid-template-columns: 1fr; }
    .question-text { font-size: 1rem; }
    #editor { height: 250px; }
}

/* ===== ADMIN STYLES ===== */
.admin-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.admin-header h1 { font-size: 1.2rem; }

.admin-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.admin-login {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    gap: 16px;
}

.admin-login h2 { font-size: 1.4rem; }

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

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--text2);
    margin-top: 4px;
}

.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
}

.chart-card h3 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.chart-card canvas {
    max-height: 300px;
}

.students-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.students-table th,
.students-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.students-table th {
    font-weight: 600;
    color: var(--text2);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.students-table tr:hover td {
    background: var(--bg);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--text2); }
.status-dot.alert { background: var(--danger); animation: pulse 1.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.alert-badge {
    background: var(--danger-light);
    color: #991B1B;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.correlation-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.correlation-item {
    background: var(--bg);
    border-radius: 8px;
    padding: 14px;
}

.correlation-item .label {
    font-size: 0.8rem;
    color: var(--text2);
    margin-bottom: 4px;
}

.correlation-item .value {
    font-size: 1.3rem;
    font-weight: 700;
}

.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.tab {
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text2);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s ease;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: var(--font);
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.student-detail {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    margin-top: 16px;
}

.student-detail h3 { margin-bottom: 16px; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.detail-item {
    background: var(--bg);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}

.detail-item .d-value {
    font-size: 1.4rem;
    font-weight: 700;
}

.detail-item .d-label {
    font-size: 0.75rem;
    color: var(--text2);
    margin-top: 2px;
}

.timeline {
    margin-top: 16px;
}

.timeline-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.timeline-item .time {
    color: var(--text2);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    min-width: 60px;
}

@media (max-width: 800px) {
    .chart-grid { grid-template-columns: 1fr; }
    .admin-container { padding: 12px; }
    .students-table { font-size: 0.78rem; }
}
