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

/* ── User menu overrides ── */
#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, .3) !important;
    color: var(--cyan) !important;
    font-family: 'Courier New', monospace !important;
    font-size: 12px !important;
    padding: 5px 12px !important;
    border-radius: 4px !important;
}

.user-menu-button {
    background: transparent !important;
    border: 1px solid rgba(0, 255, 213, .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, .15) !important;
    color: var(--cyan) !important;
    border: 1px solid rgba(0, 255, 213, .3) !important;
}

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

.user-menu-header {
    border-bottom-color: rgba(0, 255, 213, .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, .06) !important;
    color: var(--cyan) !important;
}

.user-menu-divider {
    border-top-color: rgba(0, 255, 213, .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);
}

body {
    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: 'Courier New', Courier, monospace;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ═══════════════════════════════════════
   Layout
   ═══════════════════════════════════════ */
.lab-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.lab-container.chapter-active .sidebar {
    display: none;
}

.lab-container.chapter-active .content {
    padding: 0;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: linear-gradient(180deg, var(--panel), var(--bg-dark));
    border-right: 1px solid var(--border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
}

.sidebar-back-btn {
    color: var(--text-muted);
    text-decoration: none;
    font-size: .85rem;
    transition: color .2s;
}

.sidebar-back-btn:hover {
    color: var(--cyan);
}

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

.subtitle {
    color: var(--text-muted);
    font-size: .85rem;
}

.progress-section h3 {
    font-size: .9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, .06);
    border-radius: 4px;
    overflow: hidden;
}

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

.progress-text {
    font-size: .8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.stats-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat {
    display: flex;
    justify-content: space-between;
}

.stat-label {
    color: var(--text-muted);
    font-size: .85rem;
}

.stat-value {
    color: var(--cyan);
    font-size: .85rem;
}

/* ── Content area ── */
.content {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

/* ═══════════════════════════════════════
   Chapter select grid
   ═══════════════════════════════════════ */
.chapter-select h2 {
    font-size: 1.4rem;
    color: var(--cyan);
    margin-bottom: 20px;
}

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

/* Section headers in the chapter grid */
.section-header {
    grid-column: 1 / -1;
    font-size: .85rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--cyan);
    padding: 18px 0 4px;
    border-bottom: 1px solid var(--border);
    margin-top: 8px;
}

.section-header:first-child {
    margin-top: 0;
    padding-top: 0;
}

.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: 8px;
    padding: 20px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all .3s ease;
}

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

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

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

.chapter-card.completed {
    border-color: var(--accent);
}

.chapter-card.completed::after {
    content: '✓';
    position: absolute;
    top: 12px;
    right: 14px;
    color: var(--accent);
    font-size: 1.2rem;
}

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

.chapter-number {
    font-size: .75rem;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.chapter-card h3 {
    font-size: 1rem;
    color: var(--text-light);
    margin-bottom: 6px;
}

.chapter-card p {
    font-size: .82rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.chapter-meta-card {
    margin-top: 10px;
}

.badge {
    font-size: .7rem;
    padding: 3px 8px;
    border-radius: 4px;
}

.badge.difficulty {
    background: rgba(0, 255, 213, .1);
    color: var(--cyan);
}

/* ═══════════════════════════════════════
   Active chapter layout
   ═══════════════════════════════════════ */
.active-chapter {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.initially-hidden {
    display: none;
}

.chapter-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: rgba(10, 14, 39, .95);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chapter-header h2 {
    font-size: 1.1rem;
    color: var(--cyan);
}

.back-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: .82rem;
    transition: all .2s;
}

.back-btn:hover {
    border-color: var(--cyan);
    color: var(--cyan);
}

.difficulty {
    font-size: .75rem;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(0, 255, 213, .1);
    color: var(--cyan);
}

.chapter-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left pane — explanation + challenge */
.chapter-left {
    width: 45%;
    padding: 24px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}

/* Text-only chapters: left pane goes full width */
.chapter-body.text-only .chapter-left {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    border-right: none;
}

.explanation {
    margin-bottom: 24px;
    line-height: 1.65;
}

.explanation h3 {
    color: var(--cyan);
    margin: 20px 0 10px;
    font-size: 1rem;
}

.explanation p {
    color: var(--text-muted);
    margin-bottom: 12px;
    font-size: .88rem;
}

.explanation ul,
.explanation ol {
    color: var(--text-muted);
    margin: 0 0 12px 20px;
    font-size: .88rem;
}

.explanation li {
    margin-bottom: 6px;
}

.explanation code {
    background: rgba(0, 255, 213, .08);
    color: var(--cyan);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: .84rem;
}

.explanation pre {
    background: rgba(0, 0, 0, .3);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px 16px;
    font-size: .82rem;
    line-height: 1.5;
    overflow-x: auto;
    margin: 10px 0 14px;
    color: var(--text-light);
}

/* Comparison tables (TCP vs UDP etc.) */
.explanation .net-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0 16px;
    font-size: .82rem;
}

.explanation .net-table th,
.explanation .net-table td {
    border: 1px solid var(--border);
    padding: 8px 10px;
    text-align: left;
}

.explanation .net-table th {
    background: rgba(0, 255, 213, .06);
    color: var(--cyan);
    font-weight: bold;
}

.explanation .net-table td {
    color: var(--text-muted);
}

.explanation .info-box {
    background: rgba(0, 255, 213, .04);
    border-left: 3px solid var(--cyan);
    padding: 12px 16px;
    border-radius: 0 6px 6px 0;
    margin: 14px 0;
    font-size: .85rem;
    color: var(--text-muted);
}

.explanation .info-box.info-box-center {
    text-align: center;
    border-left: none;
    border: 1px solid rgba(0, 255, 213, .2);
    border-radius: 6px;
}

.explanation .osi-layer-box {
    background: rgba(255, 255, 255, .02);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
    margin: 8px 0;
    transition: all .4s ease;
    max-height: 200px;
    opacity: 1;
    overflow: hidden;
}

.explanation .osi-layer-box.osi-pending {
    max-height: 0;
    opacity: 0;
    padding: 0 16px;
    margin: 0;
    border-color: transparent;
}

.explanation .osi-layer-box.osi-active {
    background: rgba(0, 255, 213, .06);
    border-color: var(--cyan);
    box-shadow: 0 0 16px rgba(0, 255, 213, .12);
}

.explanation .osi-layer-box strong {
    color: var(--cyan);
}

.explanation .osi-layer-box .layer-num {
    display: inline-block;
    width: 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    background: rgba(0, 255, 213, .12);
    border-radius: 50%;
    font-size: .75rem;
    color: var(--cyan);
    margin-right: 8px;
}

/* Pane footer — action button below canvas */
.pane-footer {
    display: flex;
    justify-content: center;
    padding: 10px 16px;
    background: rgba(10, 14, 39, .95);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* Right pane — interactive */
.chapter-right {
    width: 55%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.interactive-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-darker);
}

.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(10, 14, 39, .95);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.pane-title {
    font-size: .82rem;
    color: var(--text-muted);
}

.reset-btn {
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: .75rem;
    transition: all .2s;
}

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

/* OSI canvas */
#osiCanvas {
    width: 100%;
    height: auto;
    background: var(--bg-darker);
    display: block;
}

/* Packet game area */
#gameArea {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-darker);
    padding: 12px;
    overflow-y: auto;
}

#stickmanCanvas {
    width: 100%;
    max-height: 180px;
    display: block;
}

.dialogue-box {
    background: rgba(0, 255, 213, .04);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
    margin: 8px 0;
    min-height: 48px;
    position: relative;
}

.dialogue-box p {
    color: var(--text-light);
    font-size: .88rem;
    line-height: 1.5;
}

.dialogue-box::before {
    content: '△';
    position: absolute;
    top: -14px;
    left: 28px;
    color: rgba(0, 255, 213, .3);
    font-size: .9rem;
}

.game-interaction {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.game-input {
    background: rgba(0, 0, 0, .35);
    border: 1px solid var(--border);
    color: var(--text-light);
    font-family: 'Courier New', monospace;
    font-size: .88rem;
    padding: 10px 14px;
    border-radius: 4px;
    outline: none;
    transition: border-color .2s;
}

.game-input:focus {
    border-color: var(--cyan);
}

.game-input::placeholder {
    color: rgba(255, 255, 255, .25);
}

.game-btn {
    align-self: flex-end;
    background: rgba(0, 255, 213, .08);
    border: 1px solid rgba(0, 255, 213, .3);
    color: var(--cyan);
    font-family: 'Courier New', monospace;
    font-size: .85rem;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: all .2s;
}

.game-btn:hover {
    background: rgba(0, 255, 213, .15);
    border-color: var(--cyan);
}

.game-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.layer-choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.layer-choice {
    background: rgba(255, 255, 255, .02);
    border: 1px solid var(--border);
    color: var(--text-light);
    font-family: 'Courier New', monospace;
    font-size: .84rem;
    padding: 10px 14px;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    transition: all .2s;
}

.layer-choice:hover {
    border-color: var(--cyan);
    background: rgba(0, 255, 213, .04);
}

.layer-choice.correct {
    border-color: var(--success);
    background: rgba(0, 255, 136, .08);
    color: var(--success);
}

.layer-choice.wrong {
    border-color: var(--danger);
    background: rgba(255, 68, 68, .08);
    color: var(--danger);
}

.layer-choice:disabled {
    cursor: default;
    opacity: .7;
}

.packet-display {
    background: rgba(0, 0, 0, .3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    margin: 6px 0;
    font-size: .82rem;
    line-height: 1.5;
}

.packet-display .layer-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: .78rem;
    margin: 2px 4px 2px 0;
}

/* Challenge section */
.challenge-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.challenge-section h3 {
    color: var(--cyan);
    font-size: 1rem;
    margin-bottom: 10px;
}

.step-progress {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.step-label {
    font-size: .78rem;
    color: var(--text-muted);
    margin-right: 4px;
}

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

.step-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .65rem;
    color: var(--text-muted);
}

.step-dot.active {
    border-color: var(--cyan);
    color: var(--cyan);
    background: rgba(0, 255, 213, .1);
}

.step-dot.completed {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(0, 255, 136, .1);
}

#challengeDescription {
    color: var(--text-muted);
    font-size: .88rem;
    margin-bottom: 10px;
    line-height: 1.5;
}

.challenge-hint {
    background: rgba(255, 170, 0, .06);
    border-left: 3px solid var(--warning);
    padding: 10px 14px;
    border-radius: 0 6px 6px 0;
    font-size: .84rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.challenge-status {
    font-size: .85rem;
    min-height: 24px;
}

.challenge-status.success {
    color: var(--success);
}

.challenge-status.step-success {
    color: var(--cyan);
}

/* Chapter nav */
.chapter-nav {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.btn {
    padding: 8px 18px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: .85rem;
    transition: all .2s;
}

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

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

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

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

.btn-secondary:hover {
    border-color: var(--cyan);
    color: var(--cyan);
}

/* ── Bottom bar ── */
.bottom-bar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 24px;
    background: linear-gradient(180deg, var(--panel), var(--bg-dark));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.bottom-bar-title {
    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;
    font-size: .85rem;
}

.bottom-bar-subtitle {
    color: var(--text-muted);
    font-size: .75rem;
    margin-left: 8px;
}

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

.bottom-bar-progress .progress-bar {
    flex: 1;
    height: 6px;
}

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

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

/* ═══════════════════════════════════════
   Completion modal
   ═══════════════════════════════════════ */
.completion-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

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

.completion-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.completion-content h2 {
    color: var(--cyan);
    margin-bottom: 10px;
}

.completion-message {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: .9rem;
}

.completion-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-bottom: 20px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-item .stat-label {
    font-size: .75rem;
    color: var(--text-muted);
}

.stat-item .stat-value {
    font-size: 1.1rem;
    color: var(--cyan);
}

.completion-subtitle {
    color: var(--text-muted);
    font-size: .82rem;
    margin-bottom: 20px;
}

.completion-btn {
    background: linear-gradient(135deg, var(--cyan), var(--purple));
    color: white;
    border: none;
    padding: 10px 28px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: .9rem;
    transition: all .2s;
}

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

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

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

::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 213, .2);
    border-radius: 3px;
}

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

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

    .sidebar {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 16px;
        gap: 12px;
    }

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

    .chapter-left,
    .chapter-right {
        width: 100%;
    }

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

@media (max-width: 600px) {
    .chapter-header {
        padding: 8px 12px;
        gap: 8px;
    }

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

    .chapter-left {
        padding: 16px;
    }

    .explanation {
        font-size: 0.85rem;
    }

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

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

    .sidebar {
        padding: 12px;
        gap: 8px;
    }

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