:root {
    --bg: #F6F7FB;
    --surface: #FFFFFF;
    --border: #E2E5EE;
    --text: #1E2433;
    --muted: #5E677A;
    --accent: #5B3FE0;
    --accent-soft: #EEEAFF;
    --success: #15803D;
    --success-soft: #E8F7EE;
    --warn: #A15C07;
    --warn-soft: #FFF5E0;
    --error: #B42318;
    --error-soft: #FDECEA;
    --code-bg: #0F172A;
    --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: Inter, system-ui, sans-serif; font-size: 16px; line-height: 1.55; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button { font: inherit; }
kbd { font-family: "JetBrains Mono", monospace; font-size: 12px; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.loading-inline { padding: 40px 0; color: var(--muted); }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 0 24px; height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; font-family: "JetBrains Mono", monospace; font-size: 14px; }
.topnav { display: flex; gap: 4px; }
.topnav a { padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.topnav a:hover { background: var(--bg); color: var(--text); }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }

.page { max-width: 1100px; margin: 0 auto; padding: 32px 24px 48px; }
.page.wide { max-width: 1400px; }
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 28px; margin-bottom: 4px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px; border-top: 1px solid var(--border); }

/* Home */
.intro { padding: 24px 0 32px; }
.intro h1 { font-size: clamp(28px, 4vw, 40px); max-width: 760px; }
.lead { font-size: 18px; color: var(--muted); max-width: 680px; margin-top: 12px; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.tool-card { display: flex; flex-direction: column; gap: 10px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s, box-shadow .15s; }
a.tool-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(30, 36, 51, 0.08); }
.tool-card h2 { font-size: 22px; }
.tool-card p { margin: 0; color: var(--muted); }
.tool-badge { align-self: flex-start; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tool-link { margin-top: auto; font-weight: 600; color: var(--accent); }
.tool-soon { margin-top: auto; font-size: 14px; color: var(--muted); }
.tool-card.soon { opacity: .75; }

/* Topic tabs */
.topic-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.tab { padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500; min-height: 40px; }
.tab:hover { border-color: var(--accent); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab-count { font-size: 12px; opacity: .75; margin-left: 4px; }
.tab-num { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--bg); color: var(--muted); font-size: 11px; font-weight: 700; margin-right: 4px; }
.tab.active .tab-num { background: rgba(255,255,255,.25); color: #fff; }

/* Section tabs */
.section-tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 24px; }
.stab { background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: 10px 16px; min-height: 44px; font-weight: 600; font-size: 15px; color: var(--muted); cursor: pointer; }
.stab:hover { color: var(--text); }
.stab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Lesson */
.lesson { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 32px; display: flex; flex-direction: column; gap: 14px; }
.lesson-h { font-size: 22px; margin-top: 10px; }
.lesson-h:first-child { margin-top: 0; }
.lesson-p { margin: 0; font-size: 17px; line-height: 1.65; max-width: 78ch; }
.lesson code, .example-expl code, .note-important code { font-family: "JetBrains Mono", monospace; font-size: .9em; background: #F1F3F9; padding: 1px 6px; border-radius: 5px; }
pre code, .lesson pre code { background: none; padding: 0; border-radius: 0; color: inherit; font-size: inherit; }
.note-label { display: block; font-weight: 800; font-size: 14px; margin-bottom: 6px; }
.note-write { background: #FFF8DB; border: 1px solid #F3DE8A; border-radius: 10px; padding: 14px 18px; color: #3B3000; line-height: 1.7; }
.note-write .note-label { color: #7F6000; }
.note-write code { background: #FFFBEA; }
.note-important { background: var(--accent-soft); border: 1px solid #D7CEFF; border-radius: 10px; padding: 14px 18px; }
.note-important .note-label { color: var(--accent); }
.note-important ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.note-mistake { background: var(--warn-soft); border: 1px solid #F5D9A8; border-radius: 10px; padding: 14px 18px; }
.note-mistake .note-label { color: var(--warn); }
.note-mistake p { margin: 8px 0 0; }
.mistake-grid, .compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mistake-grid span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.mistake-grid .wrong span { color: var(--error); }
.mistake-grid .right span { color: var(--success); }
.mistake-grid pre, .compare-grid pre, .syntax pre, .example-code { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--code-bg); color: #E2E8F0; font-family: "JetBrains Mono", monospace; font-size: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.mistake-grid .wrong pre { box-shadow: inset 0 0 0 2px #F87171; }
.mistake-grid .right pre { box-shadow: inset 0 0 0 2px #4ADE80; }
.syntax-label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.next-row { display: flex; justify-content: flex-end; margin-top: 20px; }

/* Examples */
.example { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.example-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.example-head h3 { font-size: 18px; }
.example-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.example-expl { margin: 0; color: var(--muted); }
.small-btn { min-height: 38px; padding: 0 12px; font-size: 13.5px; }
.console { background: var(--surface); border: 2px dashed #C7BCFF; border-radius: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

/* Quiz */
.quiz { display: flex; flex-direction: column; gap: 14px; }
.quiz-q { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.quiz-question { font-weight: 700; font-size: 17px; margin: 0 0 12px; }
.quiz-options { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-opt { min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text); font-size: 15px; cursor: pointer; text-align: left; }
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.right { border-color: var(--success); background: var(--success-soft); color: var(--success); font-weight: 600; }
.quiz-opt.wrong { border-color: var(--error); background: var(--error-soft); color: var(--error); }
.quiz-fb { margin: 10px 0 0; font-size: 15px; }
.quiz-fb.ok { color: var(--success); }
.quiz-fb.no { color: var(--warn); }
.quiz-score { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 18px; background: var(--accent-soft); border-radius: 12px; padding: 14px 20px; }

/* Layout */
.sql-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.sidebar { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.panel-title { font-size: 15px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 6px; }

.exercise-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.exercise { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 10px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--text); cursor: pointer; font-size: 14px; }
.exercise:hover { background: var(--bg); }
.exercise.active { border-color: var(--accent); background: var(--accent-soft); }
.ex-num { flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); font-size: 12px; font-weight: 600; }
.exercise.solved .ex-num { background: var(--success); border-color: var(--success); color: #fff; }

.schema-table { border-top: 1px solid var(--border); padding: 10px 0 4px; }
.schema-name { background: none; border: 0; padding: 0; font-family: "JetBrains Mono", monospace; font-weight: 700; font-size: 14px; color: var(--accent); cursor: pointer; }
.schema-name:hover { text-decoration: underline; }
.schema-table ul { list-style: none; margin: 6px 0 0; padding: 0; }
.schema-table li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-family: "JetBrains Mono", monospace; font-size: 12.5px; padding: 2px 0; }
.col-type { color: var(--muted); }
.key { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 4px; }
.key.pk { background: #FEF3C7; color: #8A5300; }
.key.fk { background: #E0ECFF; color: #1D4ED8; }

/* Workspace */
.workspace { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.task-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.task-label { font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.task-prompt { font-size: 18px; font-weight: 500; margin: 0 0 12px; }
.task-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { margin: 12px 0 0; padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: #5C3A06; }
.solution { margin: 12px 0 0; padding: 12px 14px; border-radius: 8px; background: var(--code-bg); color: #E2E8F0; font-family: "JetBrains Mono", monospace; font-size: 14px; white-space: pre-wrap; }

.editor-label { font-weight: 600; font-size: 14px; }
.editor { width: 100%; resize: vertical; min-height: 150px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid #1E293B; background: var(--code-bg); color: #E2E8F0; caret-color: #A99BFF; font-family: "JetBrains Mono", monospace; font-size: 15px; line-height: 1.6; tab-size: 4; }
.editor:focus { outline: 3px solid #C7BCFF; outline-offset: 1px; }
.editor::placeholder { color: #64748B; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.push-right { margin-left: auto; }
.btn { min-height: 42px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #4A2FCC; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover:not(:disabled) { background: #116330; }
.btn.ghost { background: var(--surface); }

.alert { padding: 12px 16px; border-radius: 8px; font-size: 15px; }
.alert.success { background: var(--success-soft); color: var(--success); border: 1px solid #BBE5C8; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #F5D9A8; }
.alert.error { background: var(--error-soft); color: var(--error); border: 1px solid #F5C2BC; font-family: "JetBrains Mono", monospace; font-size: 14px; }
.alert.info { background: var(--accent-soft); color: var(--accent); border: 1px solid #D7CEFF; }

.result-wrap { overflow: auto; max-height: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.result { width: 100%; border-collapse: collapse; font-size: 14px; }
.result th { position: sticky; top: 0; background: #F1F3F9; text-align: left; font-family: "JetBrains Mono", monospace; font-size: 13px; padding: 9px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.result td { padding: 8px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.result tbody tr:nth-child(even) { background: #FAFBFD; }
.result td.null { color: var(--muted); font-style: italic; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 12px 20px; background: var(--error); color: #fff; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

@media (max-width: 900px) {
    .sql-layout { grid-template-columns: 1fr; }
    .sidebar { position: static; max-height: none; }
    .mistake-grid, .compare-grid { grid-template-columns: 1fr; }
    .lesson { padding: 20px; }
    .push-right { margin-left: 0; }
}
