/* ============ UpSkill — «ночная IDE» ============ */

:root {
  --bg: #0a0e14;
  --surface: #10161f;
  --surface-2: #161e2a;
  --surface-3: #1d2736;
  --border: #1f2a3a;
  --border-hi: #2c3b52;
  --text: #e8edf2;
  --muted: #8b98a8;
  --dim: #5c6b7d;
  --accent: #ffb454;
  --accent-dim: rgba(255, 180, 84, .12);
  --green: #c2d94c;
  --cyan: #39bae6;
  --red: #f07178;
  --mint: #95e6cb;
  /* Одна гарнитура на весь интерфейс: заголовки отличаются
     весом и трекингом, а не сменой шрифта — так спокойнее
     и читается лучше на длинных технических текстах */
  --font-display: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --radius: 14px;
  --sidebar-w: 300px;
}

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

/* Inter на крупных кеглях смотрится разреженным — поджимаем.
   Чем крупнее текст, тем плотнее трекинг */
h1, h2, h3, .hero p, .stat b {
  letter-spacing: -.015em;
}
h1 { letter-spacing: -.025em; }


html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  min-height: 100vh;
}

/* фоновая сетка как в блюпринте */
.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(57, 186, 230, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 186, 230, .035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 30%, transparent 75%);
}

.app { display: flex; position: relative; z-index: 1; }

/* ============ Sidebar ============ */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  position: sticky; top: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(16,22,31,.92), rgba(10,14,20,.96));
  backdrop-filter: blur(8px);
  padding: 26px 18px 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}

.logo {
  display: block; text-decoration: none; color: var(--text);
  font-family: var(--font-display); font-weight: 800; font-size: 22px;
  letter-spacing: -.02em;
  letter-spacing: -.5px; margin: 0 8px 4px;
}
.logo em { font-style: normal; color: var(--accent); }
.logo-sub {
  margin: 0 8px 22px; font-size: 12px; color: var(--dim);
  font-family: var(--font-mono);
}

.side-progress { margin: 0 8px 24px; }
.side-progress-bar {
  height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden;
}
.side-progress-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width .6s cubic-bezier(.22,1,.36,1);
}
.side-progress-label {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); margin-top: 7px;
  font-family: var(--font-mono);
}

.nav-title {
  font-family: var(--font-mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: 2px; color: var(--dim); margin: 18px 8px 10px;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; border-radius: 10px;
  text-decoration: none; color: var(--muted);
  transition: background .15s, color .15s;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--surface-2); color: var(--text);
  border-color: var(--border-hi);
}
.nav-item .dot {
  width: 10px; height: 10px; min-width: 10px; border-radius: 3px;
  background: var(--mod, var(--accent));
  box-shadow: 0 0 10px color-mix(in srgb, var(--mod, var(--accent)) 50%, transparent);
}
.nav-item .nav-name { flex: 1; font-size: 14px; font-weight: 500; }
.nav-item .nav-pct {
  font-family: var(--font-mono); font-size: 11px; color: var(--dim);
}
.nav-item.done .nav-pct { color: var(--green); }

/* ============ Main ============ */

.main {
  flex: 1; min-width: 0;
  padding: 44px clamp(20px, 4vw, 56px) 90px;
  max-width: 1120px;
  margin-inline: auto;   /* дашборд и справочник центрируются на широких экранах */
  animation: viewIn .45s cubic-bezier(.22,1,.36,1);
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.reveal { opacity: 0; animation: viewIn .5s cubic-bezier(.22,1,.36,1) forwards; }

/* ============ Dashboard ============ */

.hero { margin-bottom: 40px; position: relative; }
.hero-kicker {
  font-family: var(--font-mono); font-size: 13px; color: var(--accent);
  margin-bottom: 14px; letter-spacing: 1px;
}
.hero h1 {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(30px, 4.6vw, 52px); line-height: 1.12;
  letter-spacing: -1px; margin-bottom: 18px;
}
.hero h1 .hl {
  background: linear-gradient(90deg, var(--accent), var(--green));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--muted); max-width: 640px; font-size: 17px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 34px 0 44px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
}
.stat b {
  display: block; font-family: var(--font-display); font-size: 30px;
  font-weight: 700; color: var(--text); line-height: 1.2;
}
.stat b .of { font-size: 15px; color: var(--dim); font-weight: 500; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.a b { color: var(--accent); }
.stat.g b { color: var(--green); }
.stat.c b { color: var(--cyan); }

.section-title {
  font-family: var(--font-display); font-weight: 700; font-size: 22px;
  margin: 40px 0 18px; letter-spacing: -.4px;
}

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

.mod-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px;
  text-decoration: none; color: var(--text);
  transition: transform .2s cubic-bezier(.22,1,.36,1), border-color .2s, box-shadow .2s;
  display: flex; flex-direction: column; gap: 10px;
}
.mod-card::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--mod, var(--accent)); opacity: .85;
}
.mod-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--mod, var(--accent)) 45%, var(--border));
  box-shadow: 0 14px 40px -18px color-mix(in srgb, var(--mod, var(--accent)) 35%, transparent);
}
.mod-num {
  font-family: var(--font-mono); font-size: 11px; color: var(--dim);
  letter-spacing: 1px;
}
.mod-card h3 {
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  letter-spacing: -.3px; line-height: 1.3;
}
.mod-card p { font-size: 13.5px; color: var(--muted); flex: 1; }
.mod-meta {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--dim);
}
.mod-meta .bar {
  flex: 1; height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden;
}
.mod-meta .bar i {
  display: block; height: 100%;
  background: var(--mod, var(--accent));
  transition: width .5s ease;
}
.mod-card .badge-done {
  position: absolute; top: 16px; right: 16px;
  color: var(--green); font-family: var(--font-mono); font-size: 11px;
}

.continue-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--accent); color: #17110a;
  font-weight: 700; font-size: 15px; font-family: var(--font-body);
  padding: 13px 24px; border-radius: 12px; text-decoration: none;
  margin-top: 26px; border: none; cursor: pointer;
  transition: transform .15s, box-shadow .2s;
  box-shadow: 0 8px 30px -10px rgba(255, 180, 84, .5);
}
.continue-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 36px -10px rgba(255,180,84,.6); }

/* ============ Module page ============ */

.crumbs {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--dim);
  margin-bottom: 22px; display: flex; gap: 8px; flex-wrap: wrap;
}
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.mod-hero { margin-bottom: 34px; }
.mod-hero .tag {
  display: inline-block; font-family: var(--font-mono); font-size: 12px;
  color: var(--mod, var(--accent));
  border: 1px solid color-mix(in srgb, var(--mod, var(--accent)) 40%, transparent);
  background: color-mix(in srgb, var(--mod, var(--accent)) 10%, transparent);
  padding: 4px 12px; border-radius: 100px; margin-bottom: 16px;
}
.mod-hero h1 {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(26px, 3.6vw, 40px); letter-spacing: -.8px; margin-bottom: 12px;
}
.mod-hero p { color: var(--muted); max-width: 680px; }

.lesson-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 36px; }
.lesson-row {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 20px;
  text-decoration: none; color: var(--text);
  transition: border-color .15s, transform .15s;
}
.lesson-row:hover { border-color: var(--border-hi); transform: translateX(4px); }
.lesson-row .idx {
  font-family: var(--font-mono); font-size: 13px; color: var(--dim);
  width: 26px; min-width: 26px; text-align: center;
}
.lesson-row .name { flex: 1; font-weight: 500; font-size: 15px; }
.lesson-row .check {
  font-family: var(--font-mono); font-size: 12px; color: var(--dim);
}
.lesson-row.done .check { color: var(--green); }
.lesson-row.done .idx { color: var(--green); }

.lesson-row.quiz-row { border-style: dashed; border-color: color-mix(in srgb, var(--mod, var(--accent)) 45%, var(--border)); }
.lesson-row.quiz-row .idx { color: var(--mod, var(--accent)); }

/* видео */
.video-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.video-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; text-decoration: none; color: var(--text);
  transition: border-color .15s;
}
.video-card:hover { border-color: var(--red); }
.video-card .yt {
  color: var(--red); font-size: 18px; line-height: 1.3;
}
.video-card .vt { font-size: 13.5px; font-weight: 500; line-height: 1.45; }
.video-card .vc { font-size: 11.5px; color: var(--dim); font-family: var(--font-mono); margin-top: 3px; }

/* ============ Lesson ============ */

.lesson-body { max-width: 780px; }
.lesson-body h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(24px, 3vw, 32px); letter-spacing: -.6px;
  margin-bottom: 26px; line-height: 1.25;
}
.lesson-body h2 {
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  letter-spacing: -.3px; margin: 38px 0 14px;
  padding-top: 10px;
}
.lesson-body h3 { font-size: 17px; font-weight: 700; margin: 26px 0 10px; }
.lesson-body p { margin-bottom: 14px; color: #c7d0da; }
.lesson-body ul, .lesson-body ol { margin: 0 0 16px 22px; color: #c7d0da; }
.lesson-body li { margin-bottom: 7px; }
.lesson-body strong { color: var(--text); }
.lesson-body a { color: var(--cyan); }
.lesson-body table {
  width: 100%; border-collapse: collapse; margin: 6px 0 20px; font-size: 14px;
}
.lesson-body th, .lesson-body td {
  border: 1px solid var(--border); padding: 9px 13px; text-align: left;
}
.lesson-body th { background: var(--surface-2); font-weight: 600; }
.lesson-body td { color: #c7d0da; }

.lesson-body code:not(pre code) {
  font-family: var(--font-mono); font-size: .86em;
  background: var(--surface-3); border: 1px solid var(--border);
  padding: 1.5px 7px; border-radius: 6px; color: var(--mint);
  white-space: nowrap;
}

pre.code {
  background: #0d1320; border: 1px solid var(--border);
  border-radius: 12px; padding: 18px 20px; margin: 6px 0 20px;
  overflow-x: auto; position: relative;
  font-size: 13.5px; line-height: 1.7;
}
pre.code code { font-family: var(--font-mono); display: block; }
pre.code::after {
  content: attr(data-lang); position: absolute; top: 10px; right: 14px;
  font-family: var(--font-mono); font-size: 10px; color: var(--dim);
  text-transform: uppercase; letter-spacing: 1px;
}

/* подсветка */
.tk-kw { color: #ff8f40; }
.tk-str { color: #c2d94c; }
.tk-com { color: #5c6b7d; font-style: italic; }
.tk-num { color: #d4bfff; }
.tk-fn { color: #ffd580; }
.tk-type { color: #39bae6; }

/* коллауты */
.callout {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px 14px; margin: 20px 0;
  background: var(--surface); font-size: 14.5px;
}
.callout .co-title {
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  letter-spacing: 1.2px; text-transform: uppercase; margin-bottom: 8px;
}
.callout p:last-child { margin-bottom: 0; }
.callout ul { margin-bottom: 4px; }
.callout.when { border-color: rgba(194, 217, 76, .35); background: rgba(194, 217, 76, .05); }
.callout.when .co-title { color: var(--green); }
.callout.warn { border-color: rgba(240, 113, 120, .35); background: rgba(240, 113, 120, .05); }
.callout.warn .co-title { color: var(--red); }
.callout.tip { border-color: rgba(57, 186, 230, .35); background: rgba(57, 186, 230, .05); }
.callout.tip .co-title { color: var(--cyan); }
.callout.int { border-color: rgba(255, 180, 84, .4); background: rgba(255, 180, 84, .06); }
.callout.int .co-title { color: var(--accent); }

/* навигация урока */
.lesson-nav {
  display: flex; gap: 12px; margin-top: 44px; flex-wrap: wrap;
  border-top: 1px solid var(--border); padding-top: 26px;
}
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-body); font-weight: 600; font-size: 14px;
  padding: 11px 20px; border-radius: 10px; cursor: pointer;
  text-decoration: none; border: 1px solid var(--border-hi);
  background: var(--surface-2); color: var(--text);
  transition: border-color .15s, background .15s, transform .15s;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn.primary {
  background: var(--accent); color: #17110a; border-color: var(--accent);
}
.btn.primary:hover { box-shadow: 0 8px 24px -8px rgba(255,180,84,.5); }
.btn.done-btn.marked { border-color: var(--green); color: var(--green); background: rgba(194,217,76,.08); }
.btn:disabled { opacity: .4; cursor: default; pointer-events: none; }
.spacer { flex: 1; }

/* ============ Quiz ============ */

.quiz-wrap { max-width: 720px; }
.quiz-head { margin-bottom: 30px; }
.quiz-head h1 {
  font-family: var(--font-display); font-weight: 700; font-size: 28px;
  letter-spacing: -.5px; margin-bottom: 10px;
}
.quiz-progress {
  display: flex; gap: 6px; margin: 22px 0 30px;
}
.quiz-progress i {
  flex: 1; height: 5px; border-radius: 3px; background: var(--surface-3);
  transition: background .3s;
}
.quiz-progress i.past { background: var(--mod, var(--accent)); }
.quiz-progress i.cur { background: var(--text); }

.q-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  animation: viewIn .35s cubic-bezier(.22,1,.36,1);
}
.q-num { font-family: var(--font-mono); font-size: 12px; color: var(--dim); margin-bottom: 12px; }
.q-text { font-size: 17.5px; font-weight: 600; margin-bottom: 8px; line-height: 1.5; }
.q-text code { font-family: var(--font-mono); font-size: .85em; background: var(--surface-3); padding: 1px 6px; border-radius: 5px; color: var(--mint); }
.q-card pre.code { margin-top: 14px; }

.q-options { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.q-opt {
  text-align: left; font-family: var(--font-body); font-size: 14.5px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 10px;
  padding: 13px 17px; cursor: pointer; line-height: 1.5;
  transition: border-color .15s, background .15s, transform .1s;
}
.q-opt code { font-family: var(--font-mono); font-size: .85em; }
.q-opt:hover:not(:disabled) { border-color: var(--accent); transform: translateX(3px); }
.q-opt:disabled { cursor: default; }
.q-opt.correct { border-color: var(--green); background: rgba(194, 217, 76, .12); }
.q-opt.wrong { border-color: var(--red); background: rgba(240, 113, 120, .12); }
.q-opt.faded { opacity: .45; }

.q-explain {
  margin-top: 18px; padding: 15px 18px; border-radius: 10px;
  font-size: 14px; line-height: 1.6;
  border: 1px solid var(--border); background: var(--surface-2);
  animation: viewIn .3s ease;
}
.q-explain b { display: block; font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.q-explain.ok b { color: var(--green); }
.q-explain.bad b { color: var(--red); }

.q-next { margin-top: 20px; display: flex; justify-content: flex-end; }

/* результат квиза */
.quiz-result { text-align: center; padding: 30px 0 10px; }
.score-ring { position: relative; width: 168px; height: 168px; margin: 0 auto 24px; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring .ring-bg { stroke: var(--surface-3); }
.score-ring .ring-val {
  stroke: var(--mod, var(--accent)); stroke-linecap: round;
  transition: stroke-dashoffset 1s cubic-bezier(.22,1,.36,1);
}
.score-ring .score-label {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.score-ring .score-label b { font-family: var(--font-display); font-size: 34px; font-weight: 800; }
.score-ring .score-label span { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.quiz-result h2 { font-family: var(--font-display); font-size: 24px; margin-bottom: 10px; }
.quiz-result p { color: var(--muted); margin-bottom: 24px; }
.quiz-result .btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ============ Правая колонка урока ============ */

.lesson-rail { display: none; }

@media (min-width: 1240px) {
  /* урок занимает всю доступную ширину: ~62% контент / ~38% колонка ИИ.
     Сворачивание левого бара автоматически отдаёт место обеим колонкам */
  .main:has(.lesson-layout) { max-width: none; }
  .lesson-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(360px, 1fr);
    gap: clamp(32px, 3vw, 64px);
    align-items: start;
  }
  .lesson-layout .lesson-body,
  .lesson-layout .task-block { max-width: none; }
  .lesson-rail {
    display: block;
    position: sticky; top: 36px;
    max-height: calc(100vh - 72px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-hi) transparent;
    padding-bottom: 20px;
  }
}

.rail-title {
  font-family: var(--font-mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 2px; color: var(--dim);
  margin: 0 0 10px;
}
.rail-title:not(:first-child) { margin-top: 26px; }

/* сворачиваемые секции колонки */
.rail-sec { margin-bottom: 20px; }
.rail-sec summary.rail-title {
  margin: 0 0 10px; cursor: pointer; list-style: none;
  user-select: none; transition: color .15s;
}
.rail-sec summary.rail-title::-webkit-details-marker { display: none; }
.rail-sec summary.rail-title::before {
  content: '▸'; display: inline-block; margin-right: 7px;
  transition: transform .2s;
}
.rail-sec[open] summary.rail-title::before { transform: rotate(90deg); }
.rail-sec summary.rail-title:hover { color: var(--muted); }

.rail-toc a {
  display: block; text-decoration: none;
  font-size: 13px; line-height: 1.4; color: var(--muted);
  padding: 6px 12px; border-left: 2px solid var(--border);
  transition: color .15s, border-color .15s, background .15s;
}
.rail-toc a:hover { color: var(--text); }
.rail-toc a.active {
  color: var(--text);
  border-left-color: var(--mod, var(--accent));
  background: linear-gradient(90deg, color-mix(in srgb, var(--mod, var(--accent)) 8%, transparent), transparent);
}

.rail-terms { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.rail-terms .term { font-size: 12.5px; color: var(--muted); }
.rail-terms .term:hover { color: var(--text); }

.rail-next { display: flex; flex-direction: column; gap: 8px; }
.rail-next .btn { justify-content: center; font-size: 13px; padding: 9px 14px; }

/* чат ИИ, пристыкованный в правую колонку */
.rail-chat:not(:empty) { margin-bottom: 26px; }
.rail-chat .ai-panel { margin: 0; }
.rail-chat .ai-msgs {
  max-height: 52vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}
.rail-chat .ai-chip { font-size: 11.5px; padding: 4px 11px; }
.rail-chat .ai-form textarea { font-size: 13px; }

/* визуальная связь чата с блоком-источником */
.ai-source {
  outline: 1.5px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 3px;
  border-radius: 12px;
  box-shadow: 0 0 28px -8px rgba(255, 180, 84, .35);
}
.ai-src {
  display: flex; align-items: center; gap: 4px; width: 100%;
  background: var(--accent-dim); border: none;
  border-bottom: 1px solid var(--border);
  color: var(--accent); cursor: pointer; text-align: left;
  font-family: var(--font-mono); font-size: 11px;
  padding: 7px 14px;
}
.ai-src span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ai-src:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* подсказки в коде */
.code-hint {
  border-bottom: 1px dotted rgba(139, 152, 168, .45);
  cursor: help;
  transition: border-color .15s;
}
.code-hint:hover { border-bottom-color: var(--accent); }

/* ============ Термины и справочник ============ */

.term {
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 65%, transparent);
  cursor: help;
  transition: background .15s, border-color .15s;
  border-radius: 3px 3px 0 0;
}
.term:hover {
  background: var(--accent-dim);
  border-bottom-style: solid;
}

.term-tip {
  position: fixed; z-index: 100;
  max-width: 340px;
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  border-radius: 12px;
  padding: 12px 15px;
  font-size: 13.5px; line-height: 1.55; color: #d5dde6;
  box-shadow: 0 16px 48px -12px rgba(0, 0, 0, .7);
  opacity: 0; pointer-events: none;
  transform: translateY(4px);
  transition: opacity .15s, transform .15s;
}
.term-tip.show { opacity: 1; transform: none; }
.term-tip b {
  display: block; color: var(--accent);
  font-size: 12.5px; font-family: var(--font-mono);
  margin-bottom: 5px; letter-spacing: .3px;
}
.term-tip i {
  display: block; font-style: normal; color: var(--dim);
  font-size: 11px; margin-top: 7px; font-family: var(--font-mono);
}

.gloss-search {
  width: 100%; max-width: 520px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 12px;
  padding: 13px 18px; font-size: 15px; font-family: var(--font-body);
  outline: none; transition: border-color .15s;
}
.gloss-search:focus { border-color: var(--accent); }
.gloss-search::placeholder { color: var(--dim); }

.gloss-count {
  font-family: var(--font-mono); font-size: 12px; color: var(--dim);
  margin: 10px 2px 4px;
}

.gloss-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.gloss-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px;
}
.gloss-card:hover { border-color: var(--border-hi); }
.gloss-term {
  font-weight: 700; font-size: 15px; margin-bottom: 6px;
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.gloss-en {
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 400;
  color: var(--dim);
}
.gloss-def { font-size: 13.5px; color: var(--muted); line-height: 1.6; }

.glossary-nav { margin-bottom: 6px; border-style: dashed; border-color: var(--border); }

/* ============ Задание для самопроверки ============ */

.task-block {
  max-width: 780px;
  margin-top: 40px;
  border: 1px solid color-mix(in srgb, var(--mod, var(--accent)) 40%, var(--border));
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--mod, var(--accent)) 6%, var(--surface)), var(--surface));
  padding: 24px;
}
.task-head {
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--mod, var(--accent));
  margin-bottom: 12px;
}
.task-text { font-size: 15px; line-height: 1.65; color: #d5dde6; margin-bottom: 16px; }

.task-item + .task-item {
  margin-top: 26px; padding-top: 26px;
  border-top: 1px dashed var(--border-hi);
}
.task-num {
  font-family: var(--font-mono); font-size: 11px; color: var(--dim);
  letter-spacing: 1px; margin-bottom: 8px;
}

.task-answer {
  width: 100%; resize: vertical; min-height: 120px;
  background: #0d1320; color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 10px;
  padding: 12px 15px; font-family: var(--font-mono); font-size: 13px;
  line-height: 1.6; outline: none; tab-size: 2;
}
.task-answer:focus { border-color: var(--mod, var(--accent)); }
.task-answer::placeholder { color: var(--dim); font-family: var(--font-body); }

.task-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.task-solution { margin-top: 18px; }
.task-solution pre.code { margin-bottom: 12px; }
.task-note { font-size: 13.5px; color: var(--muted); line-height: 1.6; }

/* ============ ИИ-помощник (LM Studio) ============ */

.ai-bar {
  display: flex; justify-content: flex-end;
  margin: -14px 0 20px;
}
.ai-bar-callout { margin: 6px -6px -4px 0; }
.ai-ask {
  background: none; border: none; cursor: pointer;
  font-family: var(--font-mono); font-size: 11.5px;
  color: var(--dim); padding: 4px 6px; border-radius: 6px;
  transition: color .15s, background .15s;
}
.ai-ask:hover { color: var(--accent); background: var(--accent-dim); }

.ai-panel {
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--surface); border-radius: 12px;
  margin: -8px 0 24px; overflow: hidden;
  animation: viewIn .25s ease;
}
.ai-panel.hidden { display: none; }

.ai-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.ai-title { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.ai-status {
  flex: 1; font-family: var(--font-mono); font-size: 11px; color: var(--green);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ai-status.err { color: var(--red); }
.ai-gear, .ai-close {
  background: none; border: none; color: var(--dim); cursor: pointer;
  font-size: 14px; padding: 2px 6px; border-radius: 6px;
}
.ai-gear:hover, .ai-close:hover { color: var(--text); background: var(--surface-3); }

.ai-settings { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.ai-settings.hidden { display: none; }
.ai-settings label {
  display: block; font-family: var(--font-mono); font-size: 10.5px;
  color: var(--dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 1px;
}
.ai-settings input {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 8px;
  padding: 8px 12px; font-family: var(--font-mono); font-size: 12.5px; outline: none;
}
.ai-settings input:focus { border-color: var(--accent); }

.ai-chips {
  display: flex; flex-wrap: wrap; gap: 7px; padding: 12px 14px 4px;
}
.ai-chip {
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border-hi); border-radius: 100px;
  font-family: var(--font-body); font-size: 12px;
  padding: 5px 12px; cursor: pointer; transition: color .15s, border-color .15s;
}
.ai-chip:hover { color: var(--accent); border-color: var(--accent); }

.ai-msgs { padding: 6px 14px; display: flex; flex-direction: column; gap: 10px; }
.ai-msgs:empty { padding: 0; }
.ai-msg {
  font-size: 13.5px; line-height: 1.6; border-radius: 10px; padding: 9px 13px;
  max-width: 100%; overflow-wrap: break-word; white-space: pre-wrap;
}
.ai-msg.user {
  align-self: flex-end; background: var(--accent-dim);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--text); max-width: 85%;
}
.ai-msg.assistant {
  align-self: stretch; background: var(--surface-2);
  border: 1px solid var(--border); color: #cdd6e0;
}
.ai-msg.assistant code {
  font-family: var(--font-mono); font-size: .85em;
  background: var(--surface-3); padding: 1px 6px; border-radius: 5px; color: var(--mint);
}
.ai-code {
  display: block; background: #0d1320; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 13px; margin: 8px 0;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6;
  overflow-x: auto; white-space: pre; color: #d5dde6;
}
.ai-typing { color: var(--dim); font-style: italic; }

.ai-offline { white-space: normal; }
.ai-offline ol { margin: 8px 0 0 20px; }
.ai-offline li { margin-bottom: 4px; }
.ai-offline code { white-space: nowrap; }

.ai-form {
  display: flex; gap: 8px; padding: 10px 14px 14px; align-items: flex-end;
}
.ai-form textarea {
  flex: 1; resize: none; background: var(--bg); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 10px;
  padding: 9px 13px; font-family: var(--font-body); font-size: 13.5px;
  line-height: 1.5; outline: none;
}
.ai-form textarea:focus { border-color: var(--accent); }
.ai-form textarea::placeholder { color: var(--dim); }
.ai-send {
  background: var(--accent); color: #17110a; border: none;
  width: 38px; height: 38px; border-radius: 10px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform .15s;
}
.ai-send:hover { transform: translateY(-1px); }

/* ============ Mobile ============ */

.burger {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 60;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 10px;
  width: 42px; height: 42px; font-size: 17px; cursor: pointer;
}
.sidebar-overlay { display: none; }

/* складной сайдбар (десктоп) */
.side-collapse {
  position: absolute; top: 22px; right: 12px;
  background: none; border: 1px solid transparent; border-radius: 8px;
  color: var(--dim); font-size: 15px; line-height: 1;
  width: 28px; height: 28px; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.side-collapse:hover { color: var(--text); border-color: var(--border-hi); }

.sidebar-expand {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 60;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 10px;
  width: 42px; height: 42px; font-size: 17px; cursor: pointer;
  transition: border-color .15s;
}
.sidebar-expand:hover { border-color: var(--accent); }

@media (min-width: 901px) {
  /* margin-left у sticky-элемента Chrome игнорирует — сворачиваем шириной */
  .sidebar {
    transition: width .22s ease, min-width .22s ease, padding .22s ease;
    overflow-x: hidden;
  }
  body.sidebar-collapsed .sidebar {
    width: 0; min-width: 0;
    padding-left: 0; padding-right: 0;
    border-right-width: 0;
  }
  body.sidebar-collapsed .sidebar-expand { display: block; }
  /* отступ под плавающую кнопку ☰, чтобы не наезжала на контент */
  body.sidebar-collapsed .main { padding-left: 84px; }
}
@media (max-width: 900px) {
  .side-collapse { display: none; }   /* на мобиле есть бургер и оверлей */
}

@media (max-width: 900px) {
  .burger { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 55;
    transform: translateX(-105%); transition: transform .25s ease;
    box-shadow: 20px 0 60px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: none; }
  .sidebar-overlay.show {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(5, 8, 12, .6); backdrop-filter: blur(2px);
  }
  .main { padding-top: 72px; }
}

/* ============ Конструктор схемы БД ============ */

/* Инструменту нужна ширина: холст и панель свойств рядом */
.main:has(.dbd) { max-width: 1600px; }

.dbd {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  margin-top: 6px;
}

/* --- Верхняя панель --- */

.dbd-bar {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.dbd-bar-sep {
  width: 1px; height: 22px;
  background: var(--border-hi);
  margin: 0 2px;
}
.dbd-bar-name {
  flex: 1; min-width: 0;
  font-family: var(--font-mono); font-size: 12.5px;
  color: var(--dim);
  text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.dbd-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-body); font-weight: 600; font-size: 13px;
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border-hi);
  background: var(--surface-3); color: var(--text);
  transition: border-color .15s, background .15s, color .15s;
}
.dbd-btn:hover { border-color: var(--accent); }
.dbd-btn.primary { background: var(--accent); color: #17110a; border-color: var(--accent); }
.dbd-btn.primary:hover { box-shadow: 0 8px 22px -10px rgba(255, 180, 84, .6); }
.dbd-btn.icon { padding: 8px 12px; font-size: 15px; line-height: 1; }
.dbd-btn:disabled { opacity: .35; cursor: default; pointer-events: none; }

/* --- Раскладка: холст + панель --- */

.dbd-body {
  display: flex;
  min-height: 0;
  height: clamp(520px, calc(100vh - 260px), 900px);
}

/* --- Холст --- */

.dbd-canvas {
  position: relative;
  flex: 1; min-width: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;          /* жесты обрабатываем сами, иначе браузер скроллит страницу */
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(57, 186, 230, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 186, 230, .06) 1px, transparent 1px);
  background-size: 20px 20px;
}
.dbd-canvas:active { cursor: grabbing; }

.dbd-world {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.dbd-tables { position: absolute; left: 0; top: 0; }

/* SVG нулевого размера с overflow: visible — линии рисуются
   в мировых координатах и не обрезаются рамкой элемента */
.dbd-links {
  position: absolute; left: 0; top: 0;
  width: 1px; height: 1px;
  overflow: visible;
  pointer-events: none;
}
.dbd-link {
  fill: none;
  stroke: var(--border-hi);
  stroke-width: 1.8;
}
.dbd-link.cap { stroke-width: 1.8; }
.dbd-link.sel { stroke: var(--accent); stroke-width: 2.4; }
.dbd-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: stroke;
  cursor: pointer;
}

/* Линия, которую тянут от порта колонки */
.dbd-links.ghost { z-index: 5; }
.dbd-wire {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 5 4;
}
.dbd-wire-dot { fill: var(--accent); }

/* --- Карточка таблицы --- */

.dbd-table {
  position: absolute;
  width: 236px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 30px -18px rgba(0, 0, 0, .9);
  user-select: none;
}
.dbd-table.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dbd-table.dragging { opacity: .92; }

.dbd-th {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  cursor: move;
}
.dbd-th-name {
  flex: 1; min-width: 0;
  font-family: var(--font-mono); font-weight: 700; font-size: 13px;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dbd-th-n {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--dim);
}

.dbd-col {
  position: relative;
  display: flex; align-items: center; gap: 7px;
  /* Боковые отступы под порты связи, иначе точки лягут на бейдж и тип */
  padding: 4px 17px;
  border-bottom: 1px solid rgba(255, 255, 255, .03);
  font-family: var(--font-mono); font-size: 11.5px;
  line-height: 1.7;
}
.dbd-col:last-child { border-bottom: none; }
.dbd-col.empty { color: var(--dim); font-style: italic; }
.dbd-badge {
  width: 20px; flex: none;
  font-size: 9px; font-weight: 700; letter-spacing: .4px;
  color: var(--dim);
}
.dbd-badge.pk { color: var(--accent); }
.dbd-badge.fk { color: var(--cyan); }
.dbd-badge.uq { color: var(--mint); }
.dbd-cn {
  flex: 1; min-width: 0;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dbd-cn.nn { color: var(--text); }
.dbd-ct { color: var(--dim); font-size: 10.5px; flex: none; }

/* --- Прямые действия на карточке --- */

/* Порты для протягивания связи. Держим их внутри границ карточки:
   у .dbd-table стоит overflow: hidden ради скруглённых углов */
.dbd-port {
  position: absolute; top: 50%;
  width: 15px; height: 15px;
  transform: translateY(-50%);
  display: grid; place-items: center;
  opacity: 0;
  transition: opacity .12s ease;
  cursor: crosshair;
  z-index: 3;
}
.dbd-port.l { left: 0; }
.dbd-port.r { right: 0; }
.dbd-port::after {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  transition: transform .12s ease, background .12s ease;
}
.dbd-port:hover::after { background: var(--accent); transform: scale(1.25); }
.dbd-table:hover .dbd-port,
.dbd-table.sel .dbd-port,
.dbd-canvas.linking .dbd-port { opacity: 1; }

.dbd-canvas.linking { cursor: crosshair; }
.dbd-canvas.linking .dbd-table { cursor: crosshair; }

/* Куда упадёт связь, если отпустить сейчас */
.dbd-col.drop-ok {
  background: rgba(240, 179, 108, .16);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.dbd-table.drop-ok { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(240, 179, 108, .5); }

.dbd-col-x {
  position: absolute; right: 19px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  display: grid; place-items: center;
  background: var(--surface-3);
  border: none; border-radius: 4px;
  color: var(--dim); font-size: 9px;
  cursor: pointer;
  opacity: 0;
}
.dbd-col:hover .dbd-col-x { opacity: 1; }
.dbd-col-x:hover { color: var(--red); background: var(--surface-2); }

.dbd-th-acts {
  position: absolute; right: 6px; top: 50%;
  transform: translateY(-50%);
  display: flex; gap: 2px;
  opacity: 0; pointer-events: none;
  transition: opacity .12s ease;
}
.dbd-table:hover .dbd-th-acts,
.dbd-table.sel .dbd-th-acts { opacity: 1; pointer-events: auto; }
.dbd-table:hover .dbd-th-n,
.dbd-table.sel .dbd-th-n { opacity: 0; }

.dbd-th-b {
  width: 20px; height: 20px;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted); font-size: 12px; line-height: 1;
  cursor: pointer;
}
.dbd-th-b:hover { color: var(--accent); border-color: var(--accent); }
.dbd-th-b.danger:hover { color: var(--red); border-color: var(--red); }

/* Правка имени и типа прямо на карточке */
.dbd-inline {
  width: 100%; min-width: 70px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono); font-size: 11.5px;
  padding: 1px 4px;
  user-select: text;
}
.dbd-inline:focus { outline: none; }
.dbd-ct .dbd-inline { min-width: 96px; }
.dbd-th-name .dbd-inline { font-size: 12.5px; font-weight: 700; }
[data-edit] { cursor: text; }

.dbd-ti {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, .015);
  padding: 5px 10px 7px;
}
.dbd-ti-h {
  font-family: var(--font-mono); font-size: 9px;
  letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 2px;
}
.dbd-ix {
  display: flex; gap: 5px; align-items: baseline;
  font-family: var(--font-mono); font-size: 10.5px;
  line-height: 1.6;
}
.dbd-ix-n { color: var(--green); }
.dbd-ix-c { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dbd-ix-f {
  color: var(--cyan); font-size: 9px;
  border: 1px solid var(--border-hi); border-radius: 4px;
  padding: 0 3px;
}

/* --- Элементы поверх холста --- */

.dbd-empty {
  display: none;
  position: absolute; inset: 0;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center; padding: 20px;
  pointer-events: none;
}
.dbd-empty.show { display: flex; }
.dbd-empty b { font-size: 17px; color: var(--muted); }
.dbd-empty span { font-size: 13.5px; color: var(--dim); max-width: 340px; }

.dbd-zoom {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: 9px;
  overflow: hidden;
}
.dbd-zoom button {
  background: none; border: none; cursor: pointer;
  color: var(--muted);
  font-family: var(--font-mono); font-size: 12px;
  padding: 6px 10px; min-width: 34px;
}
.dbd-zoom button:hover { background: var(--surface-3); color: var(--text); }

.dbd-hint {
  position: absolute; right: 14px; top: 14px;
  width: min(360px, calc(100% - 28px));
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px 16px;
  box-shadow: 0 20px 50px -22px rgba(0, 0, 0, .95);
  z-index: 5;
}
.dbd-hint b { display: block; font-size: 14.5px; margin-bottom: 8px; }
.dbd-hint ul { margin: 0 0 12px; padding-left: 18px; }
.dbd-hint li { font-size: 13px; color: var(--muted); line-height: 1.55; margin-bottom: 5px; }

/* --- Боковая панель --- */

.dbd-side {
  width: 400px; min-width: 400px;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.dbd-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex: none;
}
.dbd-tab {
  flex: 1;
  background: none; border: none; cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-family: var(--font-body); font-weight: 600; font-size: 12.5px;
  padding: 10px 6px;
  transition: color .15s, border-color .15s;
}
.dbd-tab:hover { color: var(--text); }
.dbd-tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.dbd-tab-b {
  display: inline-block;
  margin-left: 5px; padding: 0 5px;
  border-radius: 100px;
  background: var(--red); color: #17110a;
  font-size: 10px; font-weight: 700;
}

.dbd-panel {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}
.dbd-sheet-close { display: none; }

.dbd-p-head {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.dbd-p-kind {
  flex: 1; min-width: 0;
  font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--accent);
}
.dbd-p-actions {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.dbd-copy-ok { font-size: 12px; color: var(--green); }

.dbd-sec {
  display: flex; align-items: center; gap: 10px;
  margin: 20px 0 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 13px;
  color: var(--text);
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.dbd-sec .dbd-mini { margin-left: auto; }
.dbd-dim { color: var(--dim); font-size: 12.5px; }
.dbd-note {
  font-size: 12px; line-height: 1.55; color: var(--muted);
  background: var(--surface-2);
  border-left: 2px solid var(--cyan);
  border-radius: 0 8px 8px 0;
  padding: 8px 10px;
  margin: 10px 0;
}
.dbd-ok {
  font-size: 13px; line-height: 1.6; color: var(--green);
  background: rgba(194, 217, 76, .07);
  border: 1px solid rgba(194, 217, 76, .25);
  border-radius: 10px;
  padding: 12px 14px;
}

/* --- Поля ввода --- */

.dbd-l {
  display: block;
  font-size: 11.5px; color: var(--muted);
  margin: 10px 0 4px;
}
.dbd-l.half { flex: 1; min-width: 0; margin-top: 0; }

.dbd-in {
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-mono); font-size: 12px;
  padding: 7px 9px;
  min-width: 0; flex: 1;
  width: 100%;
}
.dbd-in:focus { outline: none; border-color: var(--accent); }
.dbd-in.num { flex: none; width: 66px; }
.dbd-in.sel { font-family: var(--font-body); cursor: pointer; }
.dbd-in.sel.tiny { flex: none; width: auto; font-size: 11px; padding: 3px 6px; }
.dbd-in.wide { width: 100%; margin-top: 6px; }

.dbd-ced {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--surface-2);
}
.dbd-ixed {
  border: 1px solid var(--border);
  border-left: 2px solid var(--green);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--surface-2);
}
.dbd-ced-row {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.dbd-ced-row:last-child { margin-bottom: 0; }

.dbd-flags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.dbd-flag {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border-hi);
  border-radius: 7px;
  padding: 3px 7px;
  cursor: pointer;
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--dim);
  transition: color .15s, border-color .15s, background .15s;
}
.dbd-flag:hover { color: var(--text); }
.dbd-flag.on { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.dbd-flag input { accent-color: var(--accent); margin: 0; }

.dbd-mini {
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  border-radius: 7px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-body); font-size: 11.5px; font-weight: 600;
  padding: 5px 8px;
  flex: none;
  transition: color .15s, border-color .15s;
}
.dbd-mini:hover { color: var(--text); border-color: var(--accent); }
.dbd-mini.danger:hover { color: var(--red); border-color: var(--red); }
.dbd-mini:disabled { opacity: .3; cursor: default; pointer-events: none; }

.dbd-chips {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  margin-bottom: 6px;
}
.dbd-chips-l {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--dim); letter-spacing: .6px;
}
.dbd-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  border-radius: 100px;
  padding: 2px 4px 2px 8px;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text);
}
.dbd-chip b { color: var(--accent); font-size: 9.5px; }
.dbd-chip-b {
  background: none; border: none; cursor: pointer;
  color: var(--dim); font-size: 11px; line-height: 1;
  padding: 2px 3px;
}
.dbd-chip-b:hover { color: var(--red); }

/* --- Списки --- */

.dbd-list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  margin-bottom: 6px;
  cursor: pointer;
  color: var(--text);
  transition: border-color .15s;
}
.dbd-list-row:hover { border-color: var(--accent); }
.dbd-list-row.on { border-color: var(--accent); background: var(--accent-dim); }
.dbd-list-row b { font-family: var(--font-mono); font-size: 12.5px; font-weight: 700; }
.dbd-list-row span { font-size: 11.5px; color: var(--dim); flex: none; }

.dbd-rel-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.dbd-rel-row .dbd-list-row { margin-bottom: 0; }
.dbd-rel-open {
  flex: 1; min-width: 0; text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--muted);
  font-family: var(--font-mono); font-size: 11.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.dbd-rel-open:hover { border-color: var(--accent); color: var(--text); }
.dbd-rel-open b { color: var(--text); font-weight: 700; }
.dbd-rel-k { color: var(--cyan); margin-left: 6px; }

/* --- SQL --- */

.dbd-switch {
  display: flex;
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  overflow: hidden;
}
.dbd-switch button {
  background: var(--surface-2); border: none; cursor: pointer;
  color: var(--muted);
  font-family: var(--font-body); font-size: 11.5px; font-weight: 600;
  padding: 6px 11px;
}
.dbd-switch button.on { background: var(--accent); color: #17110a; }

.dbd-sql {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--font-mono); font-size: 11.5px; line-height: 1.65;
  color: #d5dde6;
  white-space: pre;
  tab-size: 2;
}

/* --- Проверка схемы --- */

.dbd-lint-sum { display: flex; gap: 6px; flex-wrap: wrap; }
.dbd-lint-sum .lv {
  font-family: var(--font-mono); font-size: 10px;
  border-radius: 100px; padding: 2px 8px;
  border: 1px solid var(--border-hi);
  color: var(--muted);
}
.dbd-lint-sum .lv.error { color: var(--red); border-color: rgba(240, 113, 120, .5); }
.dbd-lint-sum .lv.warn { color: var(--accent); border-color: rgba(255, 180, 84, .5); }

.dbd-issue {
  border: 1px solid var(--border);
  border-left: 3px solid var(--dim);
  border-radius: 0 10px 10px 0;
  background: var(--surface-2);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.dbd-issue.error { border-left-color: var(--red); }
.dbd-issue.warn { border-left-color: var(--accent); }
.dbd-issue.info { border-left-color: var(--cyan); }
.dbd-issue-h {
  display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap;
  margin-bottom: 5px;
}
.dbd-issue-h b { font-size: 13px; }
.dbd-issue-h code {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--cyan);
  background: var(--surface-3);
  border-radius: 5px; padding: 1px 5px;
}
.dbd-issue-lv {
  font-family: var(--font-mono); font-size: 9px;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--dim);
}
.dbd-issue.error .dbd-issue-lv { color: var(--red); }
.dbd-issue.warn .dbd-issue-lv { color: var(--accent); }
.dbd-issue p { font-size: 12.5px; line-height: 1.6; color: var(--muted); }

/* --- Пояснение под инструментом --- */

.dbd-about { margin-top: 26px; max-width: 760px; }
.dbd-about h2 { font-size: 17px; margin-bottom: 8px; }
.dbd-about p { font-size: 14px; line-height: 1.7; color: var(--muted); margin-bottom: 10px; }

/* --- Планшет: панель уже --- */

@media (max-width: 1180px) {
  .dbd-side { width: 340px; min-width: 340px; }
}

/* --- Телефон: панель превращается в шторку снизу --- */

@media (max-width: 900px) {
  .dbd { margin-inline: -16px; border-radius: 0; border-left: none; border-right: none; }
  .dbd-body { height: calc(100vh - 210px); min-height: 420px; }
  .dbd-bar { padding: 8px 10px; }
  .dbd-btn { min-height: 40px; }

  .dbd-side {
    position: absolute; left: 0; right: 0; bottom: 0;
    width: auto; min-width: 0;
    height: 68%;
    z-index: 20;
    border-left: none;
    border-top: 1px solid var(--border-hi);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -18px 50px -20px rgba(0, 0, 0, .95);
    transform: translateY(102%);
    transition: transform .25s ease;
  }
  .dbd.sheet-open .dbd-side { transform: none; }
  .dbd-body { position: relative; }

  .dbd-sheet-close {
    display: block;
    flex: none;
    width: 100%;
    background: var(--surface-2);
    border: none; border-top: 1px solid var(--border);
    color: var(--muted);
    font-family: var(--font-body); font-size: 13px; font-weight: 600;
    padding: 12px;
    cursor: pointer;
  }
  .dbd-table { width: 210px; }
  .dbd-hint { right: 8px; left: 8px; top: 8px; width: auto; }
  .dbd-in { font-size: 16px; }   /* iOS зумит страницу на полях мельче 16px */
  .dbd-in.sel.tiny { font-size: 13px; }
  /* Тач-цели: ниже 40px попадать пальцем неудобно */
  .dbd-flag, .dbd-mini { min-height: 40px; min-width: 40px; }
  .dbd-tab { min-height: 42px; }
  .dbd-list-row { min-height: 42px; }
  .dbd-rel-open { min-height: 40px; }
  .dbd-side button, .dbd-side select { min-height: 40px; }
  .dbd-zoom button { min-height: 40px; min-width: 42px; font-size: 13px; }

  /* На телефоне наведения нет — прямые действия показываем всегда */
  .dbd-port { opacity: 1; width: 22px; height: 22px; }
  .dbd-port::after { width: 11px; height: 11px; }
  .dbd-col-x { opacity: 1; width: 22px; height: 22px; right: 18px; }
  .dbd-th-acts { opacity: 1; pointer-events: auto; }
  .dbd-th-b { width: 26px; height: 26px; }
  .dbd-th-n { display: none; }
}

/* На узких экранах у .main отступ 12px, а не 16 — иначе конструктор,
   растянутый отрицательным margin, вылезает за вьюпорт */
@media (max-width: 400px) {
  .dbd { margin-inline: -12px; }
  .dbd-table { width: 190px; }
}

/* Контентный слой для поисковиков.
   Виден только когда JS не отработал: приложение удаляет блок
   при запуске. Оформление минимальное — его читают роботы
   и редкие посетители без JS. */
#seo-fallback {
  position: relative; z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 20px;
  color: var(--muted);
}
#seo-fallback h1 {
  color: var(--text); font-size: 30px;
  margin-bottom: 16px; letter-spacing: -.02em;
}
#seo-fallback h2 {
  color: var(--text); font-size: 20px;
  margin: 28px 0 12px;
}
#seo-fallback p { margin-bottom: 12px; }
#seo-fallback ul { margin: 0 0 16px 22px; }
#seo-fallback li { margin-bottom: 8px; }
#seo-fallback a { color: var(--cyan); }

/* ============ Футер и обратная связь ============ */

.site-footer {
  margin-top: 72px;
  padding-top: 36px;
  border-top: 1px solid var(--border);
}

.footer-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
  gap: 48px;
  align-items: start;
}

.footer-logo {
  font-family: var(--font-display);
  font-weight: 800; font-size: 20px;
  letter-spacing: -.02em;
  margin-bottom: 12px;
}
.footer-logo em { font-style: normal; color: var(--accent); }

.footer-about p { color: var(--muted); font-size: 14.5px; margin-bottom: 10px; max-width: 460px; }
.footer-note { color: var(--dim); font-size: 13.5px; }

.feedback-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.ff-title {
  font-weight: 700; font-size: 15px;
  margin-bottom: 14px;
}

.ff-topics { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.ff-topics label { cursor: pointer; }
.ff-topics input { position: absolute; opacity: 0; pointer-events: none; }
.ff-topics span {
  display: inline-block;
  padding: 6px 13px; border-radius: 100px;
  border: 1px solid var(--border-hi);
  color: var(--muted); font-size: 13px;
  transition: all .15s;
}
.ff-topics label:hover span { color: var(--text); border-color: var(--accent); }
.ff-topics input:checked + span {
  background: var(--accent); border-color: var(--accent);
  color: #12161d; font-weight: 600;
}
.ff-topics input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 2px; }

.ff-field { display: block; margin-bottom: 14px; }
.ff-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.ff-label em { font-style: normal; color: var(--dim); }

.ff-field textarea,
.ff-field input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-hi);
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit; font-size: 14.5px;
  line-height: 1.55;
  resize: vertical;
  transition: border-color .15s;
}
.ff-field textarea:focus,
.ff-field input[type="text"]:focus {
  outline: none; border-color: var(--accent);
}
.ff-field textarea::placeholder,
.ff-field input::placeholder { color: var(--dim); }

.ff-error { display: block; color: var(--red); font-size: 12.5px; margin-top: 5px; }
.ff-error:empty { display: none; }

/* Ловушка для ботов: убрана из потока, но остаётся в DOM.
   display:none некоторые боты распознают, off-screen — реже */
.ff-trap {
  position: absolute;
  left: -9999px; width: 1px; height: 1px;
  overflow: hidden;
}

.ff-submit { width: 100%; justify-content: center; }
.ff-submit:disabled { opacity: .6; cursor: default; }

.ff-status { margin-top: 10px; font-size: 13.5px; min-height: 1em; }
.ff-status.ok { color: var(--green); }
.ff-status.err { color: var(--red); }

.footer-bottom {
  margin-top: 30px; padding: 18px 0 10px;
  border-top: 1px solid var(--border);
  color: var(--dim); font-size: 12.5px;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--accent); }

@media (max-width: 860px) {
  .footer-cols { grid-template-columns: 1fr; gap: 28px; }
  .site-footer { margin-top: 48px; }
  .feedback-form { padding: 16px; }
  .ff-topics span { min-height: 36px; display: inline-flex; align-items: center; }
  .ff-field textarea, .ff-field input[type="text"] { font-size: 16px; }
}

/* ============ Поиск по курсу ============ */

.side-search {
  display: flex; align-items: center; gap: 9px;
  width: 100%; margin: 0 0 14px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  color: var(--muted);
  font-family: inherit; font-size: 13.5px;
  cursor: pointer; text-align: left;
  transition: border-color .15s, color .15s;
}
.side-search:hover { border-color: var(--accent); color: var(--text); }
.side-search .ss-icon { font-size: 16px; line-height: 1; }
.side-search .ss-label { flex: 1; }
.side-search .ss-kbd {
  font-family: var(--font-mono); font-size: 11px;
  padding: 2px 6px; border-radius: 5px;
  background: var(--surface-3); border: 1px solid var(--border-hi);
  color: var(--dim);
}

.search-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(5, 8, 12, .72);
  backdrop-filter: blur(4px);
  padding: 8vh 20px 20px;
}
.search-overlay.open { display: block; }

.search-box {
  max-width: 760px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 82vh;
  animation: viewIn .18s ease;
}

.search-input-row {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.search-icon { font-size: 20px; color: var(--dim); }
.search-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: 17px;
}
.search-input::placeholder { color: var(--dim); }
.search-input::-webkit-search-cancel-button { filter: invert(.6); }
.search-esc {
  font-family: var(--font-mono); font-size: 11px;
  padding: 3px 7px; border-radius: 5px;
  background: var(--surface-3); border: 1px solid var(--border-hi);
  color: var(--dim);
}

.search-filters {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
}
.sf {
  padding: 5px 12px; border-radius: 100px;
  background: none; border: 1px solid var(--border-hi);
  color: var(--muted); font-family: inherit; font-size: 12.5px;
  cursor: pointer; transition: all .15s;
}
.sf:hover { color: var(--text); border-color: var(--accent); }
.sf.active {
  background: var(--accent); border-color: var(--accent);
  color: #12161d; font-weight: 600;
}

.search-results { overflow-y: auto; flex: 1; }

.sr-item {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "type  title"
    ".     sub"
    ".     snippet";
  gap: 2px 10px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  border-left: 3px solid transparent;
  text-decoration: none; cursor: pointer;
}
.sr-item:hover, .sr-item.sel {
  background: var(--surface-2);
  border-left-color: var(--mod, var(--accent));
}
.sr-type {
  grid-area: type;
  font-family: var(--font-mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--mod, var(--accent));
  padding-top: 4px; white-space: nowrap;
}
.sr-title {
  grid-area: title;
  color: var(--text); font-weight: 600; font-size: 14.5px;
  line-height: 1.35;
}
.sr-sub {
  grid-area: sub;
  color: var(--dim); font-size: 12px;
  font-family: var(--font-mono);
}
.sr-snippet {
  grid-area: snippet;
  color: var(--muted); font-size: 13px; line-height: 1.5;
  margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.sr-item mark {
  background: rgba(255, 180, 84, .22);
  color: var(--accent);
  border-radius: 3px; padding: 0 2px;
}

.search-hint { padding: 30px 20px; text-align: center; color: var(--muted); }
.search-hint p { margin-bottom: 8px; font-size: 14px; }
.search-hint-ex { color: var(--dim); font-size: 13px; }
.search-hint-ex em {
  font-style: normal; font-family: var(--font-mono);
  color: var(--cyan); font-size: 12.5px;
}

.search-foot {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--dim);
}
.search-foot kbd {
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 2px 5px; margin-right: 3px; border-radius: 4px;
  background: var(--surface-3); border: 1px solid var(--border-hi);
}
.search-count { margin-left: auto; font-family: var(--font-mono); }

@media (max-width: 900px) {
  .search-overlay { padding: 0; }
  .search-box {
    max-width: none; max-height: 100vh; height: 100vh;
    border-radius: 0; border: none;
  }
  .search-input { font-size: 16px; }   /* против автозума в iOS */
  .search-input-row { padding: 14px 14px; }
  .search-filters { padding: 10px 14px; overflow-x: auto; flex-wrap: nowrap; }
  .sf { white-space: nowrap; min-height: 34px; }
  .sr-item { padding: 12px 14px; grid-template-columns: 1fr; grid-template-areas: "type" "title" "sub" "snippet"; }
  .search-foot { font-size: 11px; gap: 10px; }
  .search-foot span:not(.search-count) { display: none; }
}

/* ============ Мобильные устройства ============ */

/* Планшеты и узкие ноутбуки */
@media (max-width: 1024px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .mod-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  /* Контент занимает всю ширину: боковых полей на телефоне
     жалко, а читаемость обеспечивается длиной строки текста */
  .main {
    padding: 68px 16px 80px;
    max-width: none;
  }

  /* Типографика: на узком экране крупные кегли
     съедают экран и переносятся некрасиво */
  .hero h1 { font-size: clamp(26px, 7vw, 34px); }
  .hero p { font-size: 15.5px; }
  .lesson-body h1 { font-size: clamp(23px, 6.4vw, 30px); }
  .lesson-body h2 { font-size: 19px; margin: 26px 0 10px; }
  .lesson-body h3 { font-size: 16.5px; }
  .lesson-body { font-size: 16px; }
  .section-title { font-size: 15px; }

  /* Тач-цели: минимум 44px по высоте.
     Ниже этого попадать пальцем неудобно,
     и это отмечается в отчётах об удобстве */
  .btn,
  .q-opt,
  .cheat-tab,
  .nav-item,
  .task-check,
  .task-show,
  .continue-btn {
    min-height: 44px;
  }
  .btn { padding: 12px 18px; font-size: 14px; }
  .nav-item { padding: 11px 14px; }
  .cheat-tab { padding: 10px 16px; font-size: 13.5px; }

  /* Кнопка «Спросить ИИ» у блоков кода: была 23px,
     пальцем не попасть */
  .ai-ask {
    min-height: 40px;
    padding: 9px 14px;
    font-size: 13px;
  }

  /* Кнопки действий в задании — на всю ширину,
     в столбик: рядом они получаются слишком узкими */
  .task-actions { flex-direction: column; gap: 8px; }
  .task-actions .btn { width: 100%; justify-content: center; }

  /* Поля ввода: меньше 16px вызывают автозум в iOS
     при фокусе, и страница «прыгает» */
  input, textarea, select { font-size: 16px; }
  .task-answer { min-height: 140px; }

  /* Статистика на дашборде: три колонки не помещаются */
  .stats { grid-template-columns: 1fr; gap: 10px; margin: 24px 0 32px; }
  .stat { padding: 14px 16px; display: flex; align-items: baseline; gap: 12px; }
  .stat b { font-size: 26px; }
  .stat span { font-size: 13px; }

  /* Карточки модулей */
  .mod-card { padding: 16px; }
  .mod-card h3 { font-size: 16px; }

  /* Таблицы в уроках шире экрана — прокручиваем
     внутри контейнера, а не всю страницу */
  .lesson-body table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    font-size: 13.5px;
  }

  /* Код: уменьшаем кегль, чтобы влезало больше,
     и оставляем горизонтальную прокрутку внутри блока */
  pre.code {
    font-size: 12px;
    padding: 14px 12px;
    border-radius: 10px;
  }
  pre.code code { line-height: 1.55; }

  /* Длинные слова и адреса не должны рвать вёрстку */
  .lesson-body p,
  .lesson-body li,
  .callout,
  .task-text { overflow-wrap: anywhere; }

  /* Коллауты компактнее */
  .callout { padding: 14px 16px; font-size: 14.5px; }

  /* Хлебные крошки переносятся, а не сжимаются */
  .crumbs { flex-wrap: wrap; font-size: 12px; }

  /* Квиз */
  .q-opt { padding: 13px 15px; font-size: 14.5px; }
  .score-ring { width: 140px; height: 140px; }
  .quiz-result .btns { flex-direction: column; }
  .quiz-result .btns .btn { width: 100%; justify-content: center; }

  /* Бургер и плавающая кнопка сайдбара:
     увеличиваем зону нажатия */
  .burger, .sidebar-expand {
    width: 46px; height: 46px;
    display: grid; place-items: center;
    font-size: 20px;
  }

  /* Сайдбар почти на всю ширину: узкий выдвижной список
     на телефоне неудобен */
  .sidebar { width: min(88vw, 340px); min-width: 0; }

  /* Видео-карточки в одну колонку */
  .video-grid { grid-template-columns: 1fr; }
}

/* Узкие телефоны */
@media (max-width: 400px) {
  .main { padding: 64px 12px 72px; }
  pre.code { font-size: 11.5px; padding: 12px 10px; }
  .lesson-body h1 { font-size: 22px; }
  .hero h1 { font-size: 24px; }
  .cheat-tab { font-size: 12.5px; padding: 9px 12px; }
}

/* Уважение к системной настройке «уменьшить движение» */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============ Шпаргалки ============ */

.main:has(.cheat-grid) { max-width: 1500px; }

.cheat-tabs {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 20px;
}
.cheat-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 100px;
  border: 1px solid var(--border-hi); background: var(--surface);
  color: var(--muted); text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: color .15s, border-color .15s, background .15s;
}
.cheat-tab:hover { color: var(--text); border-color: var(--mod); }
.cheat-tab.active {
  color: #12161d; font-weight: 700;
  background: var(--mod); border-color: var(--mod);
}

.cheat-grid {
  columns: 3 340px;
  column-gap: 16px;
  margin-top: 18px;
}
@media (max-width: 900px) { .cheat-grid { columns: 1; } }

.cheat-card {
  break-inside: avoid;
  display: inline-block; width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
}
.cheat-card-title {
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 700;
  letter-spacing: 1.4px;
  color: #12161d;
  background: var(--mod, var(--accent));
  padding: 8px 14px;
  margin: 0;
}
.cheat-row {
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
}
.cheat-row:last-child { border-bottom: none; }
.cheat-row:hover { background: var(--surface-2); }
.cheat-label {
  font-size: 12.5px; color: var(--muted); line-height: 1.4;
}
.cheat-label::before { content: '→ '; color: var(--dim); }
.cheat-code {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55;
  color: #d5dde6; white-space: pre-wrap; word-break: break-word;
}

/* ============ Предрендер ============
   Разметка, которую отдаёт сервер до старта приложения. Её видят
   роботы и посетители без JS, а с рабочим JS она живёт доли секунды —
   поэтому оформление простое, но не «голый HTML». */

.pre-stage { margin: 34px 0 8px; }
.pre-stage > h2 {
  font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--dim); margin-bottom: 14px;
}
.pre-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.pre-card {
  display: block; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--mod, var(--accent));
  border-radius: var(--radius);
  text-decoration: none; color: inherit;
}
.pre-card:hover { border-color: var(--mod, var(--accent)); }
.pre-card-ico { font-size: 20px; }
.pre-card b { display: block; margin: 6px 0 4px; color: var(--text); font-size: 15px; }
.pre-card-note { color: var(--dim); font-size: 12px; font-family: var(--font-mono); }
.pre-card-desc { display: block; margin-top: 8px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }

.pre-mod { margin: 22px 0 26px; }
.pre-mod h3 { font-size: 17px; margin-bottom: 6px; }
.pre-mod h3 a { color: var(--text); text-decoration: none; }
.pre-mod h3 a:hover { color: var(--accent); }
.pre-mod > p { color: var(--muted); margin-bottom: 10px; }
.pre-meta { color: var(--dim); font-family: var(--font-mono); font-size: 12.5px; }

.pre-lessons { list-style: none; display: grid; gap: 4px; }
.pre-lessons.num { list-style: decimal; padding-left: 22px; }
.pre-lessons li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.pre-lessons a { color: var(--muted); text-decoration: none; }
.pre-lessons a:hover { color: var(--accent); }
.pre-lessons span { display: block; color: var(--dim); font-size: 12.5px; margin-top: 2px; }

.pre-nav {
  display: flex; justify-content: space-between; gap: 12px;
  margin: 32px 0 8px; padding-top: 18px; border-top: 1px solid var(--border);
}
.pre-nav a { color: var(--muted); text-decoration: none; font-size: 14px; }
.pre-nav a:hover { color: var(--accent); }

.pre-tasks { margin-top: 34px; }
.pre-task { margin: 18px 0; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.pre-task h3 { font-size: 14px; color: var(--accent); margin-bottom: 8px; }
.pre-task-body { color: var(--muted); line-height: 1.65; }
.pre-solution { margin-top: 12px; }
.pre-solution summary { cursor: pointer; color: var(--dim); font-size: 13px; }
.pre-note { color: var(--muted); font-size: 13.5px; margin-top: 8px; }

.pre-quiz { display: grid; gap: 18px; padding-left: 20px; }
.pre-quiz > li { padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.pre-q { color: var(--text); margin-bottom: 10px; }
.pre-opts { list-style: none; display: grid; gap: 6px; }
.pre-opts li { padding: 7px 11px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-size: 14px; }

.pre-cat { margin: 28px 0; }
.pre-terms dt { margin-top: 14px; font-weight: 700; color: var(--text); }
.pre-terms dt a { color: inherit; text-decoration: none; }
.pre-terms dt a:hover { color: var(--accent); }
.pre-terms dt i { color: var(--dim); font-weight: 400; font-size: 13px; }
.pre-terms dd { color: var(--muted); line-height: 1.6; margin-top: 3px; }
.pre-def { color: var(--muted); line-height: 1.7; font-size: 15.5px; }
.pre-related { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 18px; }
.pre-related a {
  display: inline-block; padding: 5px 11px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); text-decoration: none; font-size: 13px;
}
.pre-related a:hover { border-color: var(--accent); color: var(--accent); }

.pre-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 24px; }
.pre-tabs a {
  padding: 7px 13px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 13.5px;
}
.pre-tabs a[aria-current] { border-color: var(--accent); color: var(--accent); }

.pre-sheet { margin: 26px 0; }
.pre-sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin: 18px 0 8px; }
.pre-cheat-table { width: 100%; border-collapse: collapse; }
.pre-cheat-table th {
  text-align: left; vertical-align: top; width: 38%;
  padding: 7px 12px 7px 0; color: var(--muted); font-weight: 500; font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}
.pre-cheat-table td {
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 12.5px; color: #d5dde6;
  white-space: pre-wrap; word-break: break-word;
}

@media (max-width: 600px) {
  .pre-cheat-table th, .pre-cheat-table td { display: block; width: auto; border-bottom: none; }
  .pre-cheat-table td { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
}
