:root {
  /* фирменная палитра: только красный, серый, белый, чёрный */
  --bg: #f5f5f4;
  --surface: #ffffff;
  --text: #17171a;
  --text-muted: #6b6b6e;
  --border: #dedede;
  --accent: #c81e2c;
  --accent-hover: #a8121e;
  --accent-contrast: #ffffff;
  --ok-bg: #1c1c1e;
  --ok-text: #ffffff;
  --bad-bg: #c81e2c;
  --bad-text: #ffffff;
  --chip-bg: #ececec;
  --sidebar-bg: #111113;
  --sidebar-text: #d8d8da;
  --sidebar-text-muted: #8a8a8d;
  --sidebar-active-bg: #c81e2c;
  --sidebar-border: #2a2a2d;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1c1c1e;
    --text: #f2f2f2;
    --text-muted: #a3a3a6;
    --border: #333335;
    --accent: #e0424f;
    --accent-hover: #ef6a75;
    --accent-contrast: #17171a;
    --ok-bg: #2c2c2e;
    --ok-text: #ffffff;
    --bad-bg: #7a1620;
    --bad-text: #ffffff;
    --chip-bg: #29292b;
    --sidebar-bg: #0a0a0b;
    --sidebar-text: #d8d8da;
    --sidebar-text-muted: #77777a;
    --sidebar-active-bg: #e0424f;
    --sidebar-border: #232325;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #121212; --surface: #1c1c1e; --text: #f2f2f2; --text-muted: #a3a3a6;
  --border: #333335; --accent: #e0424f; --accent-hover: #ef6a75; --accent-contrast: #17171a;
  --ok-bg: #2c2c2e; --ok-text: #ffffff; --bad-bg: #7a1620; --bad-text: #ffffff; --chip-bg: #29292b;
  --sidebar-bg: #0a0a0b; --sidebar-text: #d8d8da; --sidebar-text-muted: #77777a;
  --sidebar-active-bg: #e0424f; --sidebar-border: #232325;
}
:root[data-theme="light"] {
  --bg: #f5f5f4; --surface: #ffffff; --text: #17171a; --text-muted: #6b6b6e;
  --border: #dedede; --accent: #c81e2c; --accent-hover: #a8121e; --accent-contrast: #ffffff;
  --ok-bg: #1c1c1e; --ok-text: #ffffff; --bad-bg: #c81e2c; --bad-text: #ffffff; --chip-bg: #ececec;
  --sidebar-bg: #111113; --sidebar-text: #d8d8da; --sidebar-text-muted: #8a8a8d;
  --sidebar-active-bg: #c81e2c; --sidebar-border: #2a2a2d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

body { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { font-weight: 700; font-size: 15px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.topbar-actions[hidden] { display: none; }
.track-label {
  padding: 4px 10px;
  background: var(--chip-bg);
  border-radius: 999px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 0;
  text-decoration: underline;
}
.link-btn:hover { color: var(--accent-hover); }

/* ---- Layout: sidebar + main ---- */
.layout {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 24px;
  padding: 24px 16px 64px;
}

.sidebar {
  flex: none;
  width: 260px;
  background: var(--sidebar-bg);
  border-radius: var(--radius);
  padding: 14px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}
.sidebar[hidden] { display: none; }
.sidebar-title {
  color: var(--sidebar-text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  padding: 4px 10px 10px;
}
.sidebar-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}
.sidebar-item:hover:not([disabled]) { background: var(--sidebar-border); }
.sidebar-item[disabled] {
  color: var(--sidebar-text-muted);
  cursor: default;
}
.sidebar-item.active {
  background: var(--sidebar-active-bg);
  color: #fff;
}
.sidebar-item .si-mark {
  flex: none;
  width: 18px;
  font-size: 12px;
  line-height: 1.4;
}

.app {
  flex: 1;
  min-width: 0;
}

@media (max-width: 860px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
    order: 2;
  }
  .app { order: 1; }
}

/* ---- Track select screen ---- */
.hero { text-align: center; padding: 24px 0 8px; }
.hero h1 { font-size: 24px; margin: 0 0 8px; }
.hero p { color: var(--text-muted); font-size: 15px; max-width: 520px; margin: 0 auto; }
.track-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 28px; }
@media (max-width: 560px) { .track-grid { grid-template-columns: 1fr; } }
.track-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, border-color 0.12s ease;
  color: var(--text);
  font: inherit;
}
.track-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.track-card h3 { margin: 0 0 8px; font-size: 17px; }
.track-card p { margin: 0; font-size: 13.5px; color: var(--text-muted); line-height: 1.45; }
.track-progress { margin-top: 12px; font-size: 12.5px; color: var(--accent); font-weight: 600; }

/* ---- Intro screen ---- */
.hero { position: relative; }
.intro-back {
  position: absolute;
  left: 0;
  top: 0;
}
.intro-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  max-width: 640px;
  margin: 28px auto 0;
}
.intro-card h2 { font-size: 16px; margin: 20px 0 10px; }
.intro-card h2:first-child { margin-top: 0; }
.intro-card p { font-size: 14.5px; line-height: 1.6; color: var(--text); margin: 0 0 10px; }
.intro-list {
  margin: 0 0 10px;
  padding-left: 20px;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
}
.intro-list li { margin-bottom: 8px; }
.intro-note {
  background: var(--chip-bg);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  margin: 18px 0 22px;
}
.intro-note a { color: var(--accent); font-weight: 600; }
.intro-link-pending { color: var(--text-muted); font-style: italic; }

@media (max-width: 560px) {
  .intro-back { position: static; display: block; margin-bottom: 10px; }
}

/* ---- Progress bar ---- */
.progress-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-size: 12.5px; color: var(--text-muted); }
.ft-timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); white-space: nowrap; }
.progress-bar { flex: 1; height: 6px; background: var(--chip-bg); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }

/* ---- Block content ---- */
.block-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.block-eyebrow {
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}
.block-card h2 { margin: 0 0 14px; font-size: 20px; }
.content-text { font-size: 15px; line-height: 1.65; color: var(--text); }
.content-text p { margin: 0 0 14px; }
.content-text p:last-child { margin-bottom: 0; }
.content-text strong { color: var(--text); font-weight: 700; }
.content-text code {
  background: var(--chip-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}

.learn-more {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.learn-more summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}
.learn-more summary::-webkit-details-marker { display: none; }
.learn-more summary::before { content: "Узнать больше →"; }
.learn-more[open] summary::before { content: "Узнать больше ↓"; }
.learn-more-links {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.learn-more-links a {
  font-size: 13px;
  color: var(--text-muted);
}
.learn-more-links a:hover { color: var(--accent); }

.block-actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; }

/* ---- Quiz (встроен под контентом того же блока) ---- */
.quiz-section { margin-top: 24px; }
.quiz-divider {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 24px 0;
}
.quiz-header { margin-bottom: 18px; }
.sys-badge {
  display: inline-block;
  background: var(--text);
  color: var(--surface);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
  padding: 3px 8px;
  margin-bottom: 8px;
}
.quiz-header .block-eyebrow { margin-bottom: 4px; }
.quiz-header h2 { margin: 0; font-size: 19px; }
.quiz-progress { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.question-title { font-size: 17px; font-weight: 700; margin: 0 0 8px; }
.question-scenario { font-size: 14.5px; color: var(--text-muted); line-height: 1.55; margin: 0 0 14px; }
.question-hint {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--chip-bg);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 16px;
  line-height: 1.5;
}
.question-hint b { color: var(--text); }

.hint-toggle {
  display: inline-block;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.hint-toggle:disabled {
  color: var(--text-muted);
  text-decoration: none;
  cursor: not-allowed;
}

.options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.option:hover:not([disabled]) { border-color: var(--accent); }
.option .opt-marker {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 1px;
  color: var(--accent-contrast);
}
.option.radio .opt-marker { border-radius: 999px; }
.option[disabled] { cursor: default; }
.option.selected { border-color: var(--accent); background: var(--chip-bg); }
.option.selected .opt-marker { border-color: var(--accent); background: var(--accent); color: #fff; }
.option.correct { border-color: var(--ok-bg); background: var(--chip-bg); }
.option.correct .opt-marker { border-color: var(--ok-bg); background: var(--ok-bg); color: var(--ok-text); }
.option.incorrect { border-color: var(--bad-bg); background: var(--chip-bg); }
.option.incorrect .opt-marker { border-color: var(--bad-bg); background: var(--bad-bg); color: var(--bad-text); }

.quiz-actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }

.btn {
  border: none;
  border-radius: 999px;
  padding: 11px 22px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: var(--chip-bg); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-dark { background: var(--ok-bg); color: var(--ok-text); }
.btn-dark:hover { opacity: 0.85; }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 10px; font-size: 14px; line-height: 1.55; }
.feedback.ok { background: var(--chip-bg); border: 1px solid var(--ok-bg); }
.feedback.ok .feedback-title { color: var(--ok-bg); font-weight: 700; }
.feedback.no { background: var(--chip-bg); border: 1px solid var(--bad-bg); }
.feedback.no .feedback-title { color: var(--bad-bg); font-weight: 700; }
.feedback .explain { color: var(--text); margin-top: 6px; }
.feedback .src { display: inline-block; margin-top: 8px; font-size: 12.5px; }
.feedback .src a { color: var(--text-muted); }
.feedback .src a:hover { color: var(--accent); }

/* ---- Completion screen ---- */
.done-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.done-card h2 { margin: 0 0 10px; }
.done-card p { color: var(--text-muted); margin: 0 0 20px; }
.done-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.struggle-list {
  text-align: left;
  background: var(--chip-bg);
  border-radius: 10px;
  padding: 16px;
  margin: 0 0 20px;
}
.struggle-title { font-size: 13.5px; font-weight: 700; margin-bottom: 10px; color: var(--text); }
.struggle-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.struggle-item:first-of-type { border-top: none; }
.struggle-item span:first-child { flex: 1; }
.struggle-count { color: var(--accent); font-size: 12.5px; white-space: nowrap; }
.struggle-item-fail .struggle-count { color: var(--bad-bg); font-weight: 700; }
.struggle-item-fail span:first-child { color: var(--bad-bg); }
.btn-sm { padding: 6px 14px; font-size: 13px; }

@media (max-width: 480px) {
  .block-card, .question-card, .done-card { padding: 18px; }
  .layout { padding: 16px 12px 48px; }
}

/* ---- Итоговый тест ---- */
.ft-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  max-width: 640px;
  margin: 0 auto;
}
.ft-card h2 { margin: 0 0 14px; font-size: 20px; }
.ft-rules {
  margin: 0 0 16px;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}
.ft-rules li { margin-bottom: 6px; }
.ft-last-result {
  background: var(--chip-bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  margin-bottom: 12px;
}
.ft-cooldown {
  background: var(--chip-bg);
  border: 1px solid var(--bad-bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--bad-bg);
  margin-bottom: 16px;
}
.ft-label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.ft-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  margin-bottom: 14px;
}
.ft-input:focus { outline: none; border-color: var(--accent); }
.ft-actions { display: flex; gap: 12px; }

.ft-score {
  font-size: 48px;
  font-weight: 800;
  text-align: center;
  margin: 8px 0 4px;
}
.ft-totals {
  text-align: center;
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.ft-verdict-pass, .ft-verdict-fail {
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 20px;
}
.ft-verdict-pass { color: var(--ok-bg); }
.ft-verdict-fail { color: var(--bad-bg); }
.ft-report-head p { color: var(--text-muted); font-size: 13.5px; line-height: 1.6; margin: 0 0 18px; }
.ft-manager-block {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.ft-hint-text { font-size: 12.5px; color: var(--text-muted); margin: 8px 0 0; }

@media print {
  .topbar, .sidebar, .no-print { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .printable-report {
    box-shadow: none;
    border: none;
    max-width: none;
    padding: 0;
  }
  body, .app { background: #fff; }
}
