:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --bg: #f1f5f9;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #3b82f6;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --editor-bg: #1e1e2e;
    --editor-text: #cdd6f4;
    --success: #10b981;
    --warning: #f59e0b;
    --hint-bg: #fefce8;
    --hint-border: #fde047;
    --solution-bg: #f0fdf4;
    --solution-border: #86efac;
    --key-color: #eab308;
    --fk-color: #8b5cf6;
    --radius: 10px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: 1fr auto;
    height: 100vh;
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h1 {
    font-size: 20px;
    color: #f8fafc;
    margin-bottom: 4px;
}

.sidebar-header p {
    font-size: 13px;
    color: var(--sidebar-text);
}

.nav-section {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #64748b;
    padding: 0 20px;
    margin-bottom: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255,255,255,0.05);
    color: #f8fafc;
}

.nav-item.active {
    background: rgba(59,130,246,0.15);
    color: #60a5fa;
    border-left-color: var(--sidebar-active);
}

.nav-item .chapter-num {
    background: rgba(255,255,255,0.1);
    color: #94a3b8;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    margin-right: 12px;
    flex-shrink: 0;
}

.nav-item.active .chapter-num {
    background: var(--sidebar-active);
    color: #fff;
}

.nav-item.completed .chapter-num {
    background: var(--success);
    color: #fff;
}

/* Schema in sidebar */
.schema-section {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0;
}

.schema-table {
    padding: 6px 20px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.schema-table:hover { background: rgba(255,255,255,0.05); }

.schema-table-name {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    color: #93c5fd;
    font-family: 'Consolas', 'Cascadia Code', monospace;
    font-weight: 600;
    font-size: 13px;
}

.schema-table-name .arrow {
    font-size: 10px;
    transition: transform 0.2s;
    color: #64748b;
}

.schema-table.open .arrow { transform: rotate(90deg); }

.schema-columns {
    display: none;
    padding: 4px 0 8px 18px;
}

.schema-table.open .schema-columns { display: block; }

.schema-col {
    font-family: 'Consolas', 'Cascadia Code', monospace;
    font-size: 12px;
    padding: 2px 0;
    color: #94a3b8;
}

.schema-col .pk {
    color: var(--key-color);
    font-weight: bold;
}

.schema-col .fk {
    color: var(--fk-color);
    font-style: italic;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    overflow-y: auto;
    padding: 32px 40px;
    scroll-behavior: smooth;
}

.chapter {
    display: none;
    max-width: 860px;
    animation: fadeIn 0.3s ease;
}

.chapter.active { display: block; }

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

.chapter-header {
    margin-bottom: 32px;
}

.chapter-header .chapter-label {
    font-size: 13px;
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.chapter-header h2 {
    font-size: 28px;
    color: var(--text);
    font-weight: 700;
}

.chapter-header p {
    font-size: 16px;
    color: var(--text-light);
    margin-top: 8px;
    line-height: 1.6;
}

.lesson-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.lesson-card h3 {
    font-size: 18px;
    margin-bottom: 12px;
    color: var(--text);
}

.lesson-card p, .lesson-card li {
    font-size: 15px;
    line-height: 1.7;
    color: #475569;
}

.lesson-card ul {
    margin: 12px 0;
    padding-left: 24px;
}

.lesson-card li { margin-bottom: 6px; }

.syntax-box {
    background: var(--editor-bg);
    color: var(--editor-text);
    padding: 16px 20px;
    border-radius: 8px;
    font-family: 'Consolas', 'Cascadia Code', monospace;
    font-size: 14px;
    margin: 16px 0;
    line-height: 1.6;
    overflow-x: auto;
}

.syntax-box .keyword { color: #cba6f7; font-weight: 600; }
.syntax-box .table-name { color: #89b4fa; }
.syntax-box .column-name { color: #a6e3a1; }
.syntax-box .string-val { color: #f9e2af; }
.syntax-box .number-val { color: #fab387; }
.syntax-box .comment { color: #6c7086; font-style: italic; }

/* Clickable example queries */
.example-query {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 14px 18px;
    margin: 12px 0;
    font-family: 'Consolas', 'Cascadia Code', monospace;
    font-size: 14px;
    color: #e2e8f0;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    line-height: 1.5;
}

.example-query:hover {
    border-color: var(--primary);
    background: #1e2d45;
    transform: translateX(3px);
}

.example-query::after {
    content: 'Ausprobieren \25B6';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--primary-light);
    font-family: 'Segoe UI', sans-serif;
    opacity: 0;
    transition: opacity 0.2s;
}

.example-query:hover::after { opacity: 1; }

/* Exercises */
.exercise {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    padding: 14px 20px;
    margin-bottom: 10px;
    transition: all 0.2s;
}

.exercise.completed {
    border-left-color: var(--success);
    background: #f0fdf4;
}

.exercise.completed .exercise-text {
    color: var(--text-light);
}

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

.exercise-check {
    width: 20px;
    height: 20px;
    accent-color: var(--success);
    cursor: pointer;
    flex-shrink: 0;
}

/* Exercises with input fields: checkbox is display-only */
.exercise:has(.exercise-input) .exercise-check {
    pointer-events: none;
    cursor: default;
}

.exercise-text {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    flex: 1;
}

.exercise-stars {
    color: #f59e0b;
    font-size: 16px;
    letter-spacing: 2px;
    flex-shrink: 0;
}

/* Exercise input field */
.exercise-input-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    align-items: stretch;
}

.exercise-input {
    flex: 1;
    background: var(--editor-bg);
    color: var(--editor-text);
    border: 2px solid #313244;
    border-radius: 6px;
    padding: 8px 12px;
    font-family: 'Consolas', 'Cascadia Code', monospace;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.exercise-input:focus {
    border-color: var(--primary);
}

.exercise-input.correct {
    border-color: var(--success);
    background: #0f2922;
}

.exercise-input.wrong {
    border-color: #ef4444;
    animation: shake 0.3s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.btn-check-answer {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.btn-check-answer:hover {
    background: var(--primary-dark);
}

.btn-run-exercise {
    background: transparent;
    color: var(--primary-light);
    border: 1px solid var(--primary);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.btn-run-exercise:hover {
    background: rgba(59,130,246,0.1);
}

.exercise.completed .exercise-input {
    border-color: var(--success);
    background: #0f2922;
}

.exercise-feedback {
    font-size: 12px;
    color: #ef4444;
    padding: 4px 2px 0;
    min-height: 18px;
}

.chapter-progress {
    display: inline-block;
    background: #e2e8f0;
    color: var(--text-light);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 12px;
    margin-left: 12px;
}

/* Info box */
.info-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 14px 18px;
    margin: 16px 0;
    font-size: 14px;
    color: #1e40af;
    line-height: 1.6;
}

.info-box strong { color: #1e3a8a; }

.warning-box {
    background: #fefce8;
    border: 1px solid #fde047;
    border-radius: 8px;
    padding: 14px 18px;
    margin: 16px 0;
    font-size: 14px;
    color: #854d0e;
    line-height: 1.6;
}

/* ===== SQL EDITOR (bottom panel) ===== */
.editor-panel {
    grid-column: 2;
    background: var(--editor-bg);
    border-top: 2px solid var(--primary);
    display: flex;
    flex-direction: column;
    min-height: 200px;
    max-height: 45vh;
    resize: vertical;
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #181825;
    border-bottom: 1px solid #313244;
}

.editor-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.editor-label {
    color: #a6adc8;
    font-size: 13px;
    font-weight: 600;
}

.btn-run {
    background: var(--success);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-run:hover { background: #059669; transform: translateY(-1px); }

.btn-clear {
    background: transparent;
    color: #a6adc8;
    border: 1px solid #313244;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.btn-clear:hover { background: #313244; color: #cdd6f4; }

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

#sql-form {
    flex: 1;
    display: flex;
}

#sql-input {
    flex: 1;
    width: 100%;
    background: var(--editor-bg);
    color: var(--editor-text);
    border: none;
    padding: 14px 18px;
    font-family: 'Consolas', 'Cascadia Code', monospace;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
}

#sql-input::placeholder { color: #585b70; }


.keyboard-hint {
    font-size: 11px;
    color: #585b70;
    display: flex;
    align-items: center;
    gap: 4px;
}

kbd {
    background: #313244;
    color: #cdd6f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-family: inherit;
    border: 1px solid #45475a;
}

/* ===== WELCOME / SCHEMA PAGE ===== */
.schema-overview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 20px 0;
}

.schema-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}

.schema-card h4 {
    font-family: 'Consolas', monospace;
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 15px;
}

.schema-card .col-list {
    font-size: 13px;
    color: var(--text-light);
    font-family: 'Consolas', monospace;
}

.schema-card .col-list .pk { color: var(--key-color); font-weight: bold; }
.schema-card .col-list .fk { color: var(--fk-color); }

.er-relations {
    margin: 20px 0;
}

.er-relation {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 14px;
}

.er-relation .rel-from, .er-relation .rel-to {
    font-family: 'Consolas', monospace;
    font-weight: 600;
    color: var(--primary);
}

.er-relation .rel-arrow {
    color: var(--text-light);
    font-size: 18px;
}

.er-relation .rel-desc {
    color: var(--text-light);
    font-size: 13px;
}

/* Responsive */
@media (max-width: 900px) {
    body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    .sidebar {
        grid-row: 1;
        flex-direction: row;
        overflow-x: auto;
        max-height: 60px;
    }
    .nav-section, .schema-section, .sidebar-header p { display: none; }
    .sidebar-header { padding: 12px 16px; }
    .editor-panel { grid-column: 1; }
    .editor-body { flex-direction: column; }
}
