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

/* User menu — top right of lab */
#user-menu {
    position: fixed !important;
    top: 10px !important;
    right: 14px !important;
    z-index: 10000 !important;
}

.user-menu-signin-btn {
    background: transparent !important;
    border: 1px solid rgba(0, 255, 213, 0.3) !important;
    color: var(--cyan) !important;
    font-family: 'Courier New', monospace !important;
    font-size: 12px !important;
    padding: 5px 12px !important;
    border-radius: 4px !important;
    box-shadow: none !important;
}

.user-menu-button {
    background: transparent !important;
    border: 1px solid rgba(0, 255, 213, 0.25) !important;
    color: var(--cyan) !important;
    font-family: 'Courier New', monospace !important;
    font-size: 12px !important;
    padding: 5px 10px !important;
    border-radius: 4px !important;
    gap: 5px !important;
}

.user-menu-avatar {
    width: 22px !important;
    height: 22px !important;
    font-size: 11px !important;
    background: rgba(0, 255, 213, 0.15) !important;
    color: var(--cyan) !important;
    border: 1px solid rgba(0, 255, 213, 0.3) !important;
}

.user-menu-dropdown {
    background: rgba(5, 8, 18, 0.98) !important;
    border: 1px solid rgba(0, 255, 213, 0.2) !important;
    border-radius: 4px !important;
    font-family: 'Courier New', monospace !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6) !important;
}

.user-menu-header {
    border-bottom-color: rgba(0, 255, 213, 0.15) !important;
}

.user-menu-name {
    font-family: 'Courier New', monospace !important;
    font-size: 13px !important;
    color: var(--cyan) !important;
}

.user-menu-email {
    font-family: 'Courier New', monospace !important;
    font-size: 12px !important;
}

.user-menu-link {
    font-family: 'Courier New', monospace !important;
    font-size: 13px !important;
    color: var(--text-muted) !important;
}

.user-menu-link:hover {
    background: rgba(0, 255, 213, 0.06) !important;
    color: var(--cyan) !important;
}

.user-menu-divider {
    border-top-color: rgba(0, 255, 213, 0.15) !important;
}

.user-menu-logout {
    font-family: 'Courier New', monospace !important;
    font-size: 13px !important;
}

:root {
    --primary: #00d4ff;
    --primary-dark: #0099cc;
    --cyan: #00ffd5;
    --purple: #6a00ff;
    --accent: #00ff88;
    --bg: #03040a;
    --bg-dark: #0a0e27;
    --bg-darker: #050812;
    --panel: #071028;
    --text-primary: #e6f7ff;
    --text-light: #e0e0e0;
    --text-muted: #9fb3c6;
    --success: #00ff88;
    --warning: #ffaa00;
    --danger: #ff4444;
    --border: rgba(0, 255, 213, 0.15);
}

html,
body {
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 20% 10%, rgba(0, 255, 213, 0.03), transparent 15%),
        radial-gradient(circle at 80% 80%, rgba(106, 0, 255, 0.03), transparent 15%),
        var(--bg-darker);
    color: var(--text-primary);
    font-family: 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
}

.lab-container {
    display: flex;
    height: 100vh;
    gap: 0;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 280px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--bg-dark) 100%);
    border-right: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.lab-header h1 {
    font-size: 24px;
    background: linear-gradient(135deg, var(--cyan), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.lab-header .subtitle {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.progress-section h3,
.stats-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cyan), var(--accent));
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 12px;
    color: var(--text-muted);
}

.stats-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 18px;
    font-weight: bold;
    color: var(--cyan);
}

/* ===== MAIN CONTENT ===== */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chapter Select */
.chapter-select {
    padding: 40px;
    overflow-y: auto;
    flex: 1;
}

.chapter-select h2 {
    font-size: 28px;
    margin-bottom: 30px;
    color: var(--cyan);
}

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.chapter-card {
    background: linear-gradient(135deg, rgba(0, 255, 213, 0.05), rgba(106, 0, 255, 0.05));
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.chapter-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.chapter-card:hover {
    border-color: var(--cyan);
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0, 255, 213, 0.2);
}

.chapter-card:hover::before {
    left: 100%;
}

.chapter-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.chapter-number {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.chapter-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--cyan);
}

.chapter-card p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.chapter-meta-card {
    display: flex;
    gap: 8px;
    font-size: 11px;
}

.badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-muted);
}

.badge.difficulty {
    color: var(--warning);
    background: rgba(255, 170, 0, 0.2);
}

.chapter-card.completed::after {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: var(--accent);
    color: var(--bg-darker);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Hide sidebar when chapter is active */
.lab-container.chapter-active .sidebar {
    display: none;
}

/* Active Chapter — fills full viewport */
.active-chapter {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chapter-header {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 8px;
    transition: all 0.2s;
}

.back-btn:hover {
    transform: translateX(-4px);
}

.chapter-header h2 {
    flex: 1;
    font-size: 22px;
    color: var(--cyan);
}

.chapter-meta {
    display: flex;
    gap: 12px;
}

.difficulty,
.time-estimate {
    background: rgba(255, 255, 255, 0.05);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== TWO-COLUMN BODY ===== */
.chapter-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.chapter-left {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-width: 0;
}

.chapter-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    min-width: 0;
}

.chapter-right .terminal-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.chapter-right .terminal {
    flex: 1;
    height: auto;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border);
    overflow: hidden;
}

.chapter-right .terminal-header {
    border-radius: 0;
    border: none;
    border-bottom: none;
}

/* ===== BOTTOM BAR ===== */
.bottom-bar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 24px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--bg-dark) 100%);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    font-size: 13px;
}

.bottom-bar-title {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.bottom-bar-title strong {
    background: linear-gradient(135deg, var(--cyan), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.bottom-bar-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bottom-bar-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    max-width: 300px;
}

.bottom-bar-progress .progress-bar {
    flex: 1;
}

.bottom-bar-progress .progress-text {
    white-space: nowrap;
}

.bottom-bar-stats {
    color: var(--text-muted);
    white-space: nowrap;
}

.bottom-bar-stats strong {
    color: var(--cyan);
}

/* Explanation Section */
.explanation {
    background: rgba(255, 255, 255, 0.03);
    border-left: 4px solid var(--cyan);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
    line-height: 1.6;
}

.explanation h3 {
    color: var(--cyan);
    margin-bottom: 12px;
}

.explanation p {
    margin-bottom: 12px;
}

.explanation code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    color: var(--accent);
}

/* Terminal Section */
.terminal-section {
    margin-bottom: 30px;
}

.terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-dark);
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.reset-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    text-decoration: underline;
    transition: color 0.2s;
}

.reset-btn:hover {
    color: var(--accent);
}

.terminal {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    padding: 16px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    height: 250px;
    display: flex;
    flex-direction: column;
    color: var(--text-light);
}

.terminal-output {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.terminal-output-line {
    margin-bottom: 4px;
}

.output-command {
    color: var(--primary);
}

.output-success {
    color: var(--success);
}

.output-error {
    color: var(--danger);
}

.output-info {
    color: var(--text-muted);
}

.terminal-input-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.prompt {
    color: var(--text-muted);
    user-select: none;
}

.terminal-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--accent);
    font-family: inherit;
    font-size: inherit;
    outline: none;
}

.terminal-input::placeholder {
    color: var(--text-muted);
}

/* Challenge Section */
.challenge-section {
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.05), rgba(0, 255, 213, 0.05));
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.challenge-section h3 {
    color: var(--accent);
    margin-bottom: 12px;
}

#challengeDescription {
    margin-bottom: 12px;
    line-height: 1.6;
}

.challenge-hint {
    background: rgba(255, 170, 0, 0.1);
    border-left: 4px solid var(--warning);
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 12px;
    font-size: 13px;
}

.challenge-status {
    padding: 12px;
    border-radius: 4px;
    font-size: 13px;
    display: none;
}

.challenge-status.success {
    background: rgba(0, 255, 136, 0.15);
    color: var(--success);
    border: 1px solid var(--success);
    display: block;
}

.challenge-status.error {
    background: rgba(255, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid var(--danger);
    display: block;
}

.challenge-status.step-success {
    background: rgba(0, 255, 136, 0.1);
    color: var(--success);
    display: block;
    font-size: 13px;
}

/* Step Progress */
.step-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.step-label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.step-dots {
    display: flex;
    gap: 6px;
}

.step-dot {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.06);
    color: var(--muted);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.step-dot.active {
    background: rgba(0, 255, 136, 0.15);
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(0, 255, 136, 0.2);
}

.step-dot.completed {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, var(--cyan), var(--purple));
    color: var(--bg-darker);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 255, 213, 0.3);
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--cyan);
}

.chapter-nav {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}


/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 213, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 213, 0.4);
}

/* Responsive */
@media (max-width: 768px) {
    .lab-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        gap: 20px;
    }

    .chapter-select {
        padding: 20px;
    }

    .chapter-grid {
        grid-template-columns: 1fr;
    }

    .chapter-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .chapter-meta {
        width: 100%;
    }

    .chapter-body {
        flex-direction: column;
    }

    .chapter-right {
        border-left: none;
        border-top: 1px solid var(--border);
        min-height: 300px;
    }

    .bottom-bar {
        flex-wrap: wrap;
        gap: 10px;
    }
}

/* Completion Modal */
.completion-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.completion-content {
    background: linear-gradient(135deg, var(--bg-dark), var(--bg-darker));
    border: 2px solid var(--cyan);
    border-radius: 12px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 40px rgba(0, 255, 213, 0.2);
}

.completion-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.completion-content h2 {
    color: var(--cyan);
    font-size: 32px;
    margin-bottom: 15px;
}

.completion-message {
    color: var(--text-primary);
    font-size: 18px;
    margin-bottom: 30px;
}

.completion-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 30px;
    gap: 20px;
}

.stat-item {
    flex: 1;
    background: rgba(0, 255, 213, 0.08);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--cyan);
}

.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.stat-value {
    display: block;
    color: var(--cyan);
    font-size: 24px;
    font-weight: bold;
}

.completion-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 25px;
}

.completion-btn {
    background: linear-gradient(135deg, var(--cyan), var(--purple));
    color: white;
    border: none;
    padding: 12px 40px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.completion-btn:hover {
    box-shadow: 0 0 20px rgba(0, 255, 213, 0.4);
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .completion-content {
        padding: 30px 20px;
    }

    .completion-icon {
        font-size: 60px;
    }

    .completion-content h2 {
        font-size: 24px;
    }

    .completion-message {
        font-size: 16px;
    }

    .completion-stats {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .chapter-select {
        padding: 12px;
    }

    .chapter-header {
        padding: 8px 12px;
        gap: 8px;
    }

    .chapter-header h2 {
        font-size: 0.85rem;
    }

    .chapter-meta {
        font-size: 0.7rem;
    }

    .chapter-left {
        padding: 12px;
    }

    .question-text {
        font-size: 0.85rem;
    }

    .bottom-bar {
        padding: 6px 12px;
        gap: 6px;
    }

    .bottom-bar-title {
        display: none;
    }

    .chapter-right {
        min-height: 250px;
    }

    .completion-content {
        padding: 20px 14px;
    }

    .completion-content h2 {
        font-size: 20px;
    }

    .completion-message {
        font-size: 14px;
    }

    .completion-btn {
        padding: 10px 28px;
        font-size: 14px;
    }
}

/* ── CSP compliance classes ─── */

.initially-hidden {
    display: none;
}

.sidebar-back-btn {
    display: inline-block;
    margin-bottom: 20px;
    padding: 8px 16px;
    background: rgba(0, 255, 213, 0.1);
    border: 1px solid rgba(0, 255, 213, 0.3);
    color: var(--cyan);
    text-decoration: none;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}