/* ===== CSS Variables ===== */
:root {
    --bg: #1a1a2e;
    --bg-card: #16213e;
    --bg-editor: #0f1629;
    --bg-hover: #1f2b47;
    --accent: #7c83ff;
    --accent-dim: #5a60cc;
    --accent-glow: rgba(124, 131, 255, 0.15);
    --text: #e0e0e0;
    --text-dim: #8892a4;
    --text-bright: #ffffff;
    --success: #4caf50;
    --success-bg: rgba(76, 175, 80, 0.12);
    --error: #ff5252;
    --error-bg: rgba(255, 82, 82, 0.12);
    --warning: #ffab40;
    --border: #2a3a5c;
    --sidebar-width: 260px;
    --header-height: 56px;
    --radius: 8px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* ===== Header ===== */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    z-index: 100;
}

#app-header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-bright);
    white-space: nowrap;
}

#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

#sidebar-toggle:hover {
    background: var(--bg-hover);
}

#header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Progress bar */
#progress-bar-container {
    width: 200px;
    height: 24px;
    background: var(--bg);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
}

#progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-dim));
    border-radius: 12px;
    transition: width 0.5s ease;
    width: 0%;
}

#progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-bright);
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

#reset-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition);
}

#reset-btn:hover {
    border-color: var(--error);
    color: var(--error);
}

/* ===== Layout ===== */
#app-container {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

/* ===== Sidebar ===== */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 12px 0;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
}

#lesson-list {
    list-style: none;
}

#lesson-list li {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    transition: var(--transition);
    border-left: 3px solid transparent;
    color: var(--text-dim);
}

#lesson-list li:hover {
    background: var(--bg-hover);
    color: var(--text);
}

#lesson-list li.active {
    background: var(--accent-glow);
    border-left-color: var(--accent);
    color: var(--text-bright);
}

#lesson-list li.completed .lesson-status {
    color: var(--success);
}

#lesson-list li.current .lesson-status {
    color: var(--accent);
}

.lesson-status {
    font-size: 0.9rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.lesson-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lesson-score {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

/* ===== Main Content ===== */
#main-content {
    flex: 1;
    padding: 24px 32px;
    max-width: 900px;
    overflow-y: auto;
}

/* ===== Welcome Screen ===== */
#welcome-screen {
    text-align: center;
    padding-top: 40px;
}

#welcome-screen h2 {
    font-size: 2rem;
    color: var(--text-bright);
    margin-bottom: 12px;
}

#welcome-screen > p {
    color: var(--text-dim);
    font-size: 1.05rem;
    margin-bottom: 40px;
}

#welcome-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.feature-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
}

.feature-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.feature-card h3 {
    color: var(--text-bright);
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.feature-card p {
    color: var(--text-dim);
    font-size: 0.82rem;
    line-height: 1.5;
}

/* ===== Lesson View ===== */
#lesson-header {
    margin-bottom: 20px;
}

#lesson-number {
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#lesson-title {
    font-size: 1.6rem;
    color: var(--text-bright);
    margin: 4px 0;
}

#lesson-theme {
    font-size: 0.82rem;
    color: var(--text-dim);
}

/* ===== Tabs ===== */
#lesson-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.tab {
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 10px 18px;
    font-size: 0.88rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== Tutorial Content ===== */
#tutorial-content {
    line-height: 1.7;
    font-size: 0.95rem;
}

#tutorial-content h3 {
    color: var(--text-bright);
    font-size: 1.15rem;
    margin: 24px 0 10px;
}

#tutorial-content h3:first-child {
    margin-top: 0;
}

#tutorial-content p {
    margin-bottom: 12px;
}

#tutorial-content code {
    background: var(--bg-editor);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.88em;
}

#tutorial-content pre {
    background: var(--bg-editor);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
}

#tutorial-content pre code {
    background: none;
    padding: 0;
    color: var(--text);
}

#tutorial-content .keyword {
    color: var(--accent);
    font-weight: 600;
}

#tutorial-content .sql-example {
    background: var(--bg-editor);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 16px;
    margin: 16px 0;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
}

#tutorial-content .note {
    background: var(--accent-glow);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 16px 0;
    font-size: 0.88rem;
}

#tutorial-next {
    margin-top: 24px;
}

/* ===== SQL Editor ===== */
.editor-container {
    margin-bottom: 16px;
}

.editor-container label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 500;
}

.sql-editor {
    width: 100%;
    min-height: 100px;
    background: var(--bg-editor);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition);
}

.sql-editor:focus {
    border-color: var(--accent);
}

.sql-editor::placeholder {
    color: var(--text-dim);
    opacity: 0.5;
}

.editor-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* ===== Buttons ===== */
.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 22px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--accent-dim);
    transform: translateY(-1px);
}

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

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 22px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-dim);
}

/* ===== Results Area ===== */
.results-area {
    background: var(--bg-editor);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    min-height: 60px;
    overflow-x: auto;
}

.results-placeholder {
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.85rem;
}

.results-error {
    color: var(--error);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    white-space: pre-wrap;
}

.results-info {
    color: var(--success);
    font-size: 0.85rem;
}

/* Results table */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    font-family: var(--font-mono);
}

.results-table th {
    background: var(--bg-card);
    color: var(--accent);
    font-weight: 600;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.results-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

.results-count {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 8px;
}

/* ===== Sandbox ===== */
#sandbox-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

#sandbox-info p {
    flex: 1;
    font-size: 0.88rem;
    color: var(--text-dim);
    min-width: 200px;
}

#schema-display {
    margin-bottom: 16px;
}

#schema-display pre {
    background: var(--bg-editor);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.5;
    overflow-x: auto;
    color: var(--text-dim);
}

/* ===== Exercises ===== */
#exercises-progress {
    font-size: 0.88rem;
    color: var(--text-dim);
    margin-bottom: 20px;
    padding: 10px 14px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.exercise-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    transition: border-color var(--transition);
}

.exercise-card.completed {
    border-color: var(--success);
}

.exercise-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.exercise-num {
    background: var(--accent);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.exercise-card.completed .exercise-num {
    background: var(--success);
}

.exercise-instruction {
    font-size: 0.92rem;
    line-height: 1.5;
}

.exercise-hint {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-top: 6px;
    display: none;
}

.exercise-hint.visible {
    display: block;
}

.hint-toggle {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.82rem;
    padding: 0;
    margin-top: 6px;
}

.hint-toggle:hover {
    text-decoration: underline;
}

.exercise-editor {
    min-height: 70px;
}

.exercise-feedback {
    margin-top: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    display: none;
}

.exercise-feedback.correct {
    display: block;
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success);
}

.exercise-feedback.incorrect {
    display: block;
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error);
}

.exercise-results {
    margin-top: 10px;
}

/* ===== Test ===== */
#test-intro {
    text-align: center;
    padding: 40px 0;
}

#test-intro h3 {
    font-size: 1.3rem;
    color: var(--text-bright);
    margin-bottom: 10px;
}

#test-intro p {
    color: var(--text-dim);
    margin-bottom: 20px;
}

#test-best-score {
    font-size: 0.92rem;
    color: var(--warning);
    margin-bottom: 20px;
}

#test-progress-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-dim);
}

/* Test question types */
.test-question {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}

.test-question-text {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 16px;
    color: var(--text-bright);
}

.test-question-text code {
    background: var(--bg-editor);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.88em;
}

.test-question-text pre {
    background: var(--bg-editor);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin: 10px 0;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
    overflow-x: auto;
}

.test-mcq-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mcq-option {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: left;
    color: var(--text);
    transition: var(--transition);
}

.mcq-option:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.mcq-option.selected {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.test-submit-row {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
}

/* Test Results */
#test-results {
    text-align: center;
    padding: 20px 0;
}

#test-score-heading {
    font-size: 1.5rem;
    color: var(--text-bright);
    margin-bottom: 8px;
}

#test-score-detail {
    color: var(--text-dim);
    margin-bottom: 24px;
}

#test-review {
    text-align: left;
    margin-bottom: 24px;
}

.review-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
}

.review-item.correct {
    border-left: 3px solid var(--success);
}

.review-item.incorrect {
    border-left: 3px solid var(--error);
}

.review-question {
    font-size: 0.88rem;
    margin-bottom: 6px;
}

.review-answer {
    font-size: 0.82rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

#test-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ===== Lesson Navigation ===== */
#lesson-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* ===== Confirmation Dialog ===== */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
}

.dialog-box {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    min-width: 320px;
    max-width: 90vw;
    z-index: 201;
}

.dialog-box h3 {
    color: var(--text-bright);
    margin-bottom: 10px;
}

.dialog-box p {
    color: var(--text-dim);
    margin-bottom: 20px;
    font-size: 0.92rem;
    line-height: 1.5;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ===== Toast ===== */
#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--success);
    color: var(--success);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    z-index: 300;
    animation: toast-in 0.3s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Correct answer animation ===== */
@keyframes flash-green {
    0% { box-shadow: 0 0 0 0 rgba(76,175,80,0.4); }
    50% { box-shadow: 0 0 20px 4px rgba(76,175,80,0.2); }
    100% { box-shadow: 0 0 0 0 rgba(76,175,80,0); }
}

.flash-success {
    animation: flash-green 0.6s ease;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #sidebar-toggle {
        display: block;
    }

    #sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #main-content {
        padding: 16px;
    }

    #progress-bar-container {
        width: 120px;
    }

    #app-header h1 {
        font-size: 1rem;
    }

    #lesson-tabs {
        overflow-x: auto;
    }

    .tab {
        padding: 10px 12px;
        font-size: 0.82rem;
        white-space: nowrap;
    }

    #welcome-features {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    #welcome-features {
        grid-template-columns: 1fr;
    }

    .test-question {
        padding: 16px;
    }
}
