/* ========== Сброс и базовые стили ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: #1f2937;
  background: #f7f8fa;
  -webkit-font-smoothing: antialiased;
}

/* ========== Общий layout ========== */
#app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100vh;
}

/* ========== Сайдбар ========== */
#sidebar {
  background: #0f172a;
  color: #e2e8f0;
  overflow-y: auto;
  border-right: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
}
.brand {
  padding: 20px 20px 12px;
  border-bottom: 1px solid #1e293b;
}
.brand h1, .brand .brand-title {
  font-size: 20px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.3px;
}
.brand .subtitle {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}
.search-wrap { padding: 12px 14px; border-bottom: 1px solid #1e293b; }
#search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 13px;
  outline: none;
}
#search:focus { border-color: #3b82f6; }
#search::placeholder { color: #64748b; }

#nav { padding: 10px 0; flex: 1; }
.nav-category {
  padding: 12px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
}
.nav-item {
  display: block;
  padding: 8px 20px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.nav-item:hover { background: #1e293b; color: #f1f5f9; }
.nav-item.active {
  background: #1e293b;
  color: #60a5fa;
  border-left-color: #3b82f6;
  font-weight: 600;
}

/* ========== Контент ========== */
#content {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  min-width: 0;
}
.welcome {
  max-width: 760px;
  margin: 60px auto;
  padding: 0 40px;
  text-align: center;
}
.welcome h2 { font-size: 32px; margin-bottom: 8px; color: #0f172a; font-weight: 700; }
.welcome-tagline { color: #64748b; font-size: 16px; margin-bottom: 32px; }
.welcome p { color: #475569; margin-bottom: 10px; }
.welcome-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  text-align: left;
  margin: 24px 0;
}
.welcome-feature {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  color: #334155;
}
.welcome-icon { font-size: 20px; flex-shrink: 0; }
.welcome .hint {
  margin-top: 24px;
  padding: 14px 18px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1e40af;
  font-size: 14px;
  text-align: center;
}
/* ========== Learning paths ========== */
.learning-paths {
  margin-top: 28px;
  text-align: left;
}
.paths-title {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 16px;
}
.path-card {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 12px;
  background: #fff;
  border-left: 4px solid #94a3b8;
}
.path-card.path-analyst { border-left-color: #3b82f6; }
.path-card.path-ml { border-left-color: #10b981; }
.path-card.path-dl { border-left-color: #8b5cf6; }
.path-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.path-icon { font-size: 20px; }
.path-name { font-size: 16px; font-weight: 700; color: #0f172a; }
.path-desc { font-size: 13px; color: #64748b; margin-bottom: 10px; }
.path-steps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
}
.path-steps a {
  color: #3b82f6;
  cursor: pointer;
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f0f7ff;
  white-space: nowrap;
}
.path-steps a:hover { background: #dbeafe; text-decoration: underline; }
.path-arrow { color: #cbd5e1; font-size: 11px; }

.welcome-footer {
  margin-top: 28px;
  font-size: 14px;
  color: #94a3b8;
}
.welcome-footer a {
  color: #3b82f6;
  text-decoration: none;
  font-weight: 500;
}
.welcome-footer a:hover { text-decoration: underline; }
.welcome-footer span { margin: 0 8px; }

/* ========== Glossary inline links ========== */
.glossary-link {
  color: #dc2626;
  cursor: pointer;
  border-bottom: 1.5px dashed #f87171;
  text-decoration: none;
  font-weight: 600;
}
.glossary-link:hover {
  color: #991b1b;
  border-bottom-style: solid;
  background: #fef2f2;
}

/* ========== Prerequisites block ========== */
.prerequisites {
  margin-bottom: 18px;
  padding: 10px 16px;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
}
.prerequisites b { color: #78350f; }
.prerequisites a {
  color: #d97706;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.prerequisites a:hover { text-decoration: underline; }

.hidden { display: none !important; }

.topic-header {
  padding: 28px 40px 16px;
  background: white;
  border-bottom: 1px solid #e5e7eb;
}
.breadcrumb {
  font-size: 12px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}
#topic-title {
  font-size: 28px;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.4px;
}
.topic-summary {
  margin-top: 8px;
  color: #475569;
  font-size: 15px;
}

/* ========== Вкладки ========== */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 40px;
  background: white;
  border-bottom: 1px solid #e5e7eb;
  overflow-x: auto;
}
.tab {
  padding: 12px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #64748b;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
}
.tab:hover { color: #1e40af; }
.tab.active { color: #1e40af; border-bottom-color: #3b82f6; }

.tab-content {
  padding: 28px 40px 60px;
  max-width: 1100px;
  margin: 0 auto;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ========== Контент вкладок ========== */
.tab-pane h3 { font-size: 20px; margin: 24px 0 12px; color: #0f172a; }
.tab-pane h3:first-child { margin-top: 0; }
.tab-pane h4 { font-size: 16px; margin: 18px 0 8px; color: #1e293b; }
.tab-pane p { margin-bottom: 12px; color: #334155; }
.tab-pane ul, .tab-pane ol { margin: 8px 0 14px 24px; color: #334155; }
.tab-pane li { margin-bottom: 6px; }
.tab-pane code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'Consolas', 'Monaco', monospace;
  color: #be123c;
}
.tab-pane pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 13px;
  font-family: 'Consolas', 'Monaco', monospace;
}
.tab-pane pre code { background: transparent; color: inherit; padding: 0; }

.tab-pane table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
  font-size: 14px;
}
.tab-pane th, .tab-pane td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid #e5e7eb;
}
.tab-pane th { background: #f8fafc; font-weight: 600; color: #0f172a; }

.callout {
  border-left: 4px solid #3b82f6;
  background: #eff6ff;
  padding: 12px 16px;
  border-radius: 4px;
  margin: 14px 0;
  color: #1e3a8a;
  font-size: 14px;
}
.callout.warn { border-color: #f59e0b; background: #fffbeb; color: #78350f; }
.callout.tip { border-color: #10b981; background: #ecfdf5; color: #065f46; }

/* ========== Pros / Cons ========== */
.proscons { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 14px 0; }
.proscons > div { padding: 14px 18px; border-radius: 8px; }
.proscons .pros { background: #ecfdf5; border: 1px solid #a7f3d0; }
.proscons .cons { background: #fef2f2; border: 1px solid #fecaca; }
.proscons h4 { margin-top: 0; }
.proscons .pros h4 { color: #065f46; }
.proscons .cons h4 { color: #991b1b; }
.proscons ul { margin-left: 20px; }
.proscons .pros li { color: #064e3b; }
.proscons .cons li { color: #7f1d1d; }

/* ========== Симуляция ========== */
.sim-container {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 18px;
  margin: 14px 0;
}
.sim-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}
.sim-control { display: flex; flex-direction: column; gap: 6px; }
.sim-control label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  display: flex;
  justify-content: space-between;
}
.sim-control label span { color: #1e40af; font-variant-numeric: tabular-nums; }
.sim-control input[type="range"] { width: 100%; accent-color: #3b82f6; }
.sim-control input[type="number"], .sim-control select {
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  font-size: 13px;
  outline: none;
  background: white;
}
.sim-control input[type="number"]:focus, .sim-control select:focus { border-color: #3b82f6; }
.sim-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  background: #3b82f6;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
}
.btn:hover { background: #2563eb; }
.btn.secondary { background: #e2e8f0; color: #1e293b; }
.btn.secondary:hover { background: #cbd5e1; }

.sim-output {
  display: grid;
  gap: 14px;
}
.sim-chart-wrap {
  position: relative;
  height: 320px;
  background: #fafbfc;
  border-radius: 6px;
  padding: 8px;
}
.sim-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.stat-card {
  background: #f8fafc;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}
.stat-card .stat-label { font-size: 11px; text-transform: uppercase; color: #64748b; letter-spacing: 0.5px; }
.stat-card .stat-value { font-size: 18px; font-weight: 700; color: #0f172a; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ========== Math block ========== */
.math-block {
  background: #fafbfc;
  border: 1px solid #e5e7eb;
  padding: 14px 18px;
  border-radius: 6px;
  margin: 12px 0;
  overflow-x: auto;
}

/* ========== Example cards ========== */
.example-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px 18px;
  margin: 14px 0;
}
.example-card h4 { margin-top: 0; color: #1e40af; }
.example-card .example-data {
  background: #f8fafc;
  padding: 10px 12px;
  border-radius: 5px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  margin: 8px 0;
  color: #334155;
}

/* ========== Скроллбары ========== */
#sidebar::-webkit-scrollbar, #content::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-track { background: #0f172a; }
#sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
#content::-webkit-scrollbar-track { background: #f1f5f9; }
#content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ========== Canvas helpers ========== */
canvas.sim-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: white;
  border-radius: 4px;
}

/* ========== Intuition / analogy block ========== */
.intuition {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid #fcd34d;
  border-radius: 12px;
  padding: 18px 22px;
  margin: 8px 0 24px;
  position: relative;
  box-shadow: 0 2px 6px rgba(251, 191, 36, 0.12);
}
.intuition .intuition-title {
  font-size: 13px;
  font-weight: 700;
  color: #78350f;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}
.intuition p { color: #451a03; font-size: 15px; line-height: 1.65; margin-bottom: 10px; }
.intuition p:last-child { margin-bottom: 0; }
.intuition b, .intuition strong { color: #7c2d12; }

/* ========== Term with tooltip ========== */
.term {
  border-bottom: none;
  cursor: help;
  position: relative;
  color: #1e40af;
  font-weight: 500;
}
.term:hover { color: #1e3a8a; background: #dbeafe; }
.term:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  min-width: 240px;
  max-width: 360px;
  background: #0f172a;
  color: #f1f5f9;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  white-space: normal;
  border-bottom: none;
  pointer-events: none;
}
.term:hover::before {
  content: "";
  position: absolute;
  left: 10px;
  top: calc(100% + 2px);
  border: 6px solid transparent;
  border-bottom-color: #0f172a;
  z-index: 101;
  pointer-events: none;
}

/* ========== Deep dive collapsible ========== */
.deep-dive { border: 1px solid #e5e7eb; border-radius: 8px; margin: 16px 0; overflow: hidden; background: #fafbfc; }
.deep-dive summary { padding: 10px 16px; cursor: pointer; font-weight: 600; color: #3b82f6; font-size: 14px; user-select: none; background: #f8fafc; list-style: none; }
.deep-dive summary::before { content: "▸ "; display: inline-block; transition: transform 0.15s; margin-right: 4px; }
.deep-dive[open] summary::before { transform: rotate(90deg); }
.deep-dive summary::-webkit-details-marker { display: none; }
.deep-dive summary:hover { background: #eff6ff; }
.deep-dive .deep-dive-body { padding: 14px 18px; border-top: 1px solid #e5e7eb; }
.deep-dive .deep-dive-body > :last-child { margin-bottom: 0; }

/* ========== Key concept highlight ========== */
.key-concept { background: #f0f9ff; border: 1px solid #bae6fd; border-left: 4px solid #0ea5e9; padding: 14px 18px; border-radius: 6px; margin: 14px 0; }
.key-concept .kc-label { font-size: 11px; font-weight: 700; color: #0369a1; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 6px; }
.key-concept p { color: #0c4a6e; margin-bottom: 6px; }
.key-concept p:last-child { margin-bottom: 0; }

/* ========== Subtabs ========== */
.subtabs { display: flex; gap: 4px; padding: 0; margin: 0 0 20px; border-bottom: 1px solid #e5e7eb; overflow-x: auto; flex-wrap: wrap; }
.subtab { padding: 10px 14px; cursor: pointer; font-size: 13px; font-weight: 500; color: #64748b; border-bottom: 2px solid transparent; white-space: nowrap; transition: color 0.12s, border-color 0.12s, background 0.12s; border-radius: 6px 6px 0 0; }
.subtab:hover { color: #1e40af; background: #f8fafc; }
.subtab.active { color: #1e40af; border-bottom-color: #3b82f6; background: #eff6ff; font-weight: 600; }
.subtab-content > :first-child { margin-top: 0; }

/* ========== Illustration ========== */
.illustration { margin: 18px 0 22px; text-align: center; }
.illustration svg { max-width: 100% !important; width: 100%; height: auto; display: inline-block; }
.illustration .caption { font-size: 13px; color: #64748b; margin-top: 8px; font-style: italic; }
.illustration.bordered svg { border: 1px solid #e5e7eb; border-radius: 8px; padding: 14px; background: white; }

/* ========== Step-by-step examples ========== */
.example-problem { background: #eff6ff; border-left: 4px solid #3b82f6; padding: 14px 18px; border-radius: 4px; margin: 16px 0; }
.example-problem .problem-label { font-size: 11px; font-weight: 700; color: #1e40af; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 6px; }
.example-problem p:last-child { margin-bottom: 0; }
.example-data-table { margin: 14px 0; overflow-x: auto; }
.example-data-table table { font-size: 14px; min-width: 300px; }
.example-data-table th { background: #f1f5f9 !important; color: #334155; font-weight: 600; }

.step { margin: 18px 0; padding-left: 52px; position: relative; }
.step::before { content: attr(data-step); position: absolute; left: 0; top: 2px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; background: #3b82f6; color: white; border-radius: 50%; font-weight: 700; font-size: 15px; box-shadow: 0 1px 3px rgba(59, 130, 246, 0.35); }
.step h4 { margin: 0 0 8px 0; color: #1e293b; font-size: 16px; font-weight: 600; }
.step p { margin-bottom: 8px; }
.step p:last-child { margin-bottom: 0; }
.step .why { background: #fef9c3; border-left: 3px solid #eab308; padding: 8px 12px; margin: 10px 0; border-radius: 4px; font-size: 13px; color: #713f12; }
.step .why::before { content: "Почему так: "; font-weight: 700; color: #854d0e; }
.step .calc { background: #f8fafc; border: 1px solid #e2e8f0; padding: 10px 14px; margin: 10px 0; border-radius: 6px; font-family: 'Consolas', 'Monaco', monospace; font-size: 13px; overflow-x: auto; }

.answer-box { background: #ecfdf5; border: 1px solid #a7f3d0; border-left: 4px solid #10b981; padding: 14px 18px; border-radius: 6px; margin: 16px 0; }
.answer-box .answer-label { font-size: 11px; font-weight: 700; color: #047857; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 6px; }
.answer-box p:last-child { margin-bottom: 0; }

.lesson-box { background: #fdf4ff; border-left: 4px solid #a855f7; padding: 12px 16px; border-radius: 4px; margin: 16px 0; color: #581c87; font-size: 14px; }
.lesson-box::before { content: "💡 Что мы узнали: "; font-weight: 700; color: #6b21a8; }

/* ========== Burger + scrim (mobile) ========== */
.burger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 60;
  width: 42px;
  height: 42px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  cursor: pointer;
  padding: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.burger span {
  display: block;
  width: 20px;
  height: 2px;
  background: #0f172a;
  border-radius: 2px;
}
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 40;
}
body.drawer-open .scrim { display: block; }

/* ========== Prev / Next ========== */
.topic-prevnext {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid #e2e8f0;
}
.prevnext-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 18px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  text-decoration: none;
  color: #1e293b;
  transition: background 0.15s, border-color 0.15s;
}
.prevnext-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.prevnext-btn.next { text-align: right; }
.prevnext-label { font-size: 12px; color: #64748b; font-weight: 600; }
.prevnext-title { font-size: 15px; font-weight: 600; color: #0f172a; }

/* ========== Resume banner ========== */
.resume-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 20px;
  font-size: 14px;
  color: #1e3a8a;
}
.resume-banner b { color: #0f172a; }
.resume-btn {
  margin-left: auto;
  padding: 6px 12px;
  background: #3b82f6;
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}
.resume-btn:hover { background: #2563eb; }
.resume-close {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.resume-close:hover { color: #0f172a; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .burger { display: flex; }
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,0.2);
  }
  #sidebar.open { transform: translateX(0); }
  #content { padding-top: 60px; }
  .tab-content { padding: 20px 16px 60px; }
  .topic-prevnext { grid-template-columns: 1fr; }
}

/* ========== Quiz (тест) ========== */
.quiz-btn-sidebar {
  margin: 10px 14px 6px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: filter 0.15s, transform 0.05s;
}
.quiz-btn-sidebar:hover { filter: brightness(1.08); }
.quiz-btn-sidebar:active { transform: translateY(1px); }
.quiz-btn-sidebar .quiz-btn-icon { font-size: 18px; line-height: 1; }
.quiz-btn-sidebar .quiz-btn-label { flex: 1; }
.quiz-btn-sidebar .quiz-btn-meta {
  font-size: 10px;
  font-weight: 500;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.quiz-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.quiz-overlay.hidden { display: none; }
body.quiz-open { overflow: hidden; }

.quiz-card {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
}
.quiz-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid #f1f5f9;
  position: relative;
}
.quiz-header h3 { font-size: 20px; color: #0f172a; margin: 0; font-weight: 700; }
.quiz-crumb {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #64748b;
  margin-bottom: 4px;
  min-height: 14px;
}
.quiz-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: #f1f5f9;
  color: #475569;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s;
}
.quiz-close:hover { background: #e2e8f0; color: #0f172a; }
.quiz-progress {
  height: 4px;
  background: #f1f5f9;
}
.quiz-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #6366f1);
  transition: width 0.3s ease;
  width: 0%;
}
.quiz-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}
.quiz-footer {
  padding: 14px 22px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: #fafbfc;
}
.quiz-btn {
  padding: 10px 18px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, filter 0.12s;
}
.quiz-btn-primary {
  background: #3b82f6;
  color: #fff;
}
.quiz-btn-primary:hover:not(:disabled) { background: #2563eb; }
.quiz-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.quiz-btn-ghost {
  background: transparent;
  color: #64748b;
  border-color: #e2e8f0;
}
.quiz-btn-ghost:hover { background: #f1f5f9; color: #0f172a; }

/* Экран выбора */
.quiz-hint { color: #64748b; font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
.quiz-hint-inline { color: #94a3b8; font-size: 12px; }
.quiz-scope-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}
.quiz-scope {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.quiz-scope:hover { border-color: #cbd5e1; background: #f8fafc; }
.quiz-scope input[type="radio"] { margin: 0; accent-color: #3b82f6; }
.quiz-scope input[type="radio"]:checked ~ .quiz-scope-main { color: #1d4ed8; font-weight: 600; }
.quiz-scope:has(input:checked) { border-color: #3b82f6; background: #eff6ff; }
.quiz-scope-main { flex: 1; font-size: 14px; color: #1f2937; }
.quiz-scope-meta { font-size: 12px; color: #64748b; }
.quiz-scope-topic select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  color: #1f2937;
  font-family: inherit;
}
.quiz-count-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #475569;
  flex-wrap: wrap;
}
.quiz-count-row select {
  padding: 5px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-family: inherit;
}

/* Вопрос */
.quiz-prompt {
  font-size: 16px;
  color: #0f172a;
  line-height: 1.55;
  margin-bottom: 14px;
}
.quiz-prompt b { color: #0f172a; }
.quiz-prompt code {
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.quiz-figure {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 8px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}
.quiz-figure.hidden { display: none; }
.quiz-figure svg { max-width: 100%; height: auto; }

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  color: #1f2937;
  transition: border-color 0.12s, background 0.12s, transform 0.05s;
}
.quiz-option:hover { border-color: #cbd5e1; background: #f8fafc; }
.quiz-option.selected { border-color: #3b82f6; background: #eff6ff; }
.quiz-option.correct {
  border-color: #10b981;
  background: #ecfdf5;
}
.quiz-option.correct .quiz-option-marker::after { content: '✓'; color: #059669; }
.quiz-option.wrong {
  border-color: #ef4444;
  background: #fef2f2;
}
.quiz-option.wrong .quiz-option-marker::after { content: '✗'; color: #dc2626; }
.quiz-options[data-locked="1"] .quiz-option { cursor: default; }
.quiz-options[data-locked="1"] .quiz-option:hover {
  background: #fff;
  border-color: #e2e8f0;
}
.quiz-options[data-locked="1"] .quiz-option.correct:hover { background: #ecfdf5; border-color: #10b981; }
.quiz-options[data-locked="1"] .quiz-option.wrong:hover { background: #fef2f2; border-color: #ef4444; }
.quiz-option-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f1f5f9;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.quiz-option.selected .quiz-option-marker { background: #dbeafe; }
.quiz-option.correct .quiz-option-marker { background: #d1fae5; }
.quiz-option.wrong .quiz-option-marker { background: #fecaca; }
.quiz-option-text { flex: 1; line-height: 1.5; }

.quiz-explain {
  margin-top: 14px;
  padding: 12px 14px;
  background: #fefce8;
  border-left: 3px solid #eab308;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.55;
  color: #422006;
}
.quiz-explain.hidden { display: none; }
.quiz-explain-opt { margin-bottom: 8px; }
.quiz-explain-opt:last-child { margin-bottom: 0; }
.quiz-explain-general { color: #3f3f46; }
.quiz-explain b { color: #0f172a; }

/* Результат */
.quiz-result {
  text-align: center;
  padding: 10px 0 20px;
}
.quiz-score-big {
  font-size: 48px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1;
  margin-bottom: 4px;
}
.quiz-score-of { font-size: 24px; color: #94a3b8; font-weight: 500; }
.quiz-score-verdict {
  font-size: 14px;
  color: #64748b;
  margin-bottom: 14px;
}
.quiz-score-donut { display: inline-block; }
.quiz-wrong-list {
  margin-top: 8px;
  padding-top: 18px;
  border-top: 1px solid #f1f5f9;
}
.quiz-wrong-title {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 10px;
}
.quiz-wrong-item {
  padding: 8px 12px;
  background: #fef2f2;
  border-left: 3px solid #fca5a5;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 13px;
}
.quiz-wrong-q { color: #7f1d1d; margin-bottom: 4px; }
.quiz-wrong-link {
  color: #2563eb;
  cursor: pointer;
  font-weight: 500;
  font-size: 12px;
}
.quiz-wrong-link:hover { text-decoration: underline; }
.quiz-all-correct {
  text-align: center;
  padding: 14px;
  color: #065f46;
  background: #ecfdf5;
  border-radius: 8px;
  font-weight: 600;
}

/* Confusion matrix helper (из QuizUtil) */
.quiz-confusion {
  display: inline-block;
  font-size: 12px;
  color: #334155;
}
.quiz-confusion .qm-title { font-weight: 600; margin-bottom: 4px; text-align: center; }
.quiz-confusion table {
  border-collapse: collapse;
  background: #fff;
}
.quiz-confusion th, .quiz-confusion td {
  padding: 10px 16px;
  border: 1px solid #e2e8f0;
  text-align: center;
  min-width: 60px;
}
.quiz-confusion th { background: #f8fafc; font-weight: 600; font-size: 11px; color: #475569; }
.quiz-confusion .qm-tp { background: #d1fae5; color: #065f46; font-weight: 600; }
.quiz-confusion .qm-tn { background: #e0f2fe; color: #0c4a6e; font-weight: 600; }
.quiz-confusion .qm-fp { background: #fecaca; color: #7f1d1d; font-weight: 600; }
.quiz-confusion .qm-fn { background: #fed7aa; color: #7c2d12; font-weight: 600; }

@media (max-width: 640px) {
  .quiz-overlay { padding: 0; }
  .quiz-card { max-height: 100vh; border-radius: 0; }
  .quiz-body { padding: 16px; }
  .quiz-footer { padding: 12px 16px; }
  .quiz-score-big { font-size: 40px; }
  .quiz-scope-meta { font-size: 11px; }
}
