/* ============================================================
   SimpleDU — дизайн-система
   Полное описание: DESIGN.md в корне репозитория.
   Все цвета и размеры — через CSS-переменные ниже.
   ============================================================ */

:root {
  /* Палитра */
  --bg: #faf9f6;            /* тёплый бумажный фон */
  --surface: #ffffff;       /* карточки */
  --surface-2: #f3f1ec;     /* вторичные поверхности, полосы */
  --ink: #1a1d29;           /* основной текст */
  --ink-soft: #5b6072;      /* вторичный текст */
  --line: #e6e2d9;          /* границы */

  --accent: #4f46e5;        /* индиго — основной акцент, ссылки, кнопки */
  --accent-soft: #eef2ff;   /* фон под акцентом */
  --teal: #0d9488;          /* второй акцент */
  --success: #16a34a;
  --success-soft: #ecfdf3;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;

  /* Палитра визуализаций (канвас читает эти переменные через IX.colors) */
  --viz-blue: #3b82f6;
  --viz-orange: #f59e0b;
  --viz-pink: #ec4899;
  --viz-green: #10b981;
  --viz-purple: #8b5cf6;
  --viz-grid: #e8e5dd;

  /* Геометрия */
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 304px;
  --content-max: 780px;
  --shadow: 0 1px 3px rgba(26,29,41,.06), 0 4px 16px rgba(26,29,41,.05);
  --shadow-lift: 0 2px 6px rgba(26,29,41,.08), 0 10px 28px rgba(26,29,41,.09);

  /* Анимация */
  --t-fast: 140ms cubic-bezier(.2,.7,.3,1);
  --t-med: 220ms cubic-bezier(.2,.7,.3,1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 16.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Сайдбар ---------- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: 40;
}
.sidebar-head { padding: 20px 18px 12px; border-bottom: 1px solid var(--line); }
.logo {
  display: block; font-size: 21px; font-weight: 800;
  text-decoration: none; letter-spacing: -.02em; margin-bottom: 14px;
  background: linear-gradient(90deg, var(--accent), var(--teal));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.nav-search {
  width: 100%; padding: 8px 12px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink); outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.nav-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.nav { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
.nav-section { margin-bottom: 4px; }
.nav-section-head {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 10px;
  font-size: 13.5px; font-weight: 700; color: var(--ink);
  background: none; border: none; cursor: pointer; border-radius: var(--radius-sm);
  font-family: inherit; text-align: left;
  transition: background var(--t-fast);
}
.nav-section-head:hover { background: var(--surface-2); }
.nav-section-head .chev { margin-left: auto; font-size: 11px; color: var(--ink-soft); transition: transform var(--t-med); }
.nav-section.open .chev { transform: rotate(90deg); }
.nav-section-count { font-size: 11px; color: var(--ink-soft); font-weight: 500; }
.nav-topics { display: none; padding-left: 6px; }
.nav-section.open .nav-topics { display: block; }
.nav-topic {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; margin: 1px 0;
  font-size: 14px; color: var(--ink-soft);
  text-decoration: none; border-radius: var(--radius-sm);
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-topic:hover { background: var(--surface-2); color: var(--ink); }
.nav-topic.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-topic .tick { margin-left: auto; font-size: 12px; color: var(--success); flex-shrink: 0; }
.nav-topic .tick.partial { color: var(--warn); }

.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--line); }
.progress-line { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--teal)); border-radius: 3px; transition: width 400ms cubic-bezier(.2,.7,.3,1); }
.progress-label { font-size: 12px; color: var(--ink-soft); margin-top: 6px; }

.nav-burger {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 60;
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
  font-size: 18px; cursor: pointer; box-shadow: var(--shadow);
}

/* ---------- Контент ---------- */
.content {
  margin-left: var(--sidebar-w);
  padding: 44px 40px 90px;
  min-height: 100vh;
}
.topic-wrap { max-width: var(--content-max); margin: 0 auto; animation: fadeUp 320ms cubic-bezier(.2,.7,.3,1); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.loading { color: var(--ink-soft); text-align: center; padding-top: 20vh; }

.crumbs { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; }
.crumbs a { color: var(--ink-soft); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

/* Типографика статей */
.topic-wrap h1 { font-size: 34px; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 14px; font-weight: 800; }
.topic-wrap h2 { font-size: 23px; letter-spacing: -.01em; margin: 40px 0 12px; font-weight: 750; }
.topic-wrap h3 { font-size: 18px; margin: 28px 0 8px; font-weight: 700; }
.topic-wrap p { margin: 0 0 14px; }
.topic-wrap a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color var(--t-fast); }
.topic-wrap a:hover { border-bottom-color: var(--accent); }
.topic-wrap ul, .topic-wrap ol { padding-left: 24px; margin: 0 0 14px; }
.topic-wrap li { margin-bottom: 6px; }
.topic-wrap strong { font-weight: 700; }
.topic-wrap code {
  font-family: var(--mono); font-size: .86em;
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 6px;
}
.topic-wrap pre {
  background: #14161f; color: #e6e8f0; border-radius: var(--radius-sm);
  padding: 16px 18px; overflow-x: auto; font-size: 13.5px; line-height: 1.55;
  margin: 0 0 16px;
}
.topic-wrap pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }

.lead { font-size: 18.5px; color: var(--ink-soft); margin-bottom: 24px !important; }

/* Формулы (без KaTeX — стилизованный HTML) */
.formula {
  font-family: Georgia, "Times New Roman", serif; font-style: italic;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 20px; margin: 16px 0; text-align: center; font-size: 18px;
  overflow-x: auto;
}
.formula sub, .formula sup { font-size: .7em; }
.fx { font-family: Georgia, serif; font-style: italic; } /* инлайн-формула */

/* Плашки */
.callout {
  border-radius: var(--radius-sm); padding: 14px 18px; margin: 16px 0;
  border: 1px solid; font-size: 15.5px;
}
.callout .callout-title { font-weight: 700; display: block; margin-bottom: 4px; }
.callout.idea { background: var(--accent-soft); border-color: #dfe3ff; }
.callout.warn { background: var(--warn-soft); border-color: #fde9c8; }
.callout.interview { background: var(--success-soft); border-color: #d3f2df; }

/* Таблицы */
.topic-wrap table { border-collapse: collapse; width: 100%; margin: 16px 0; font-size: 15px; }
.topic-wrap th, .topic-wrap td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; }
.topic-wrap th { background: var(--surface-2); font-weight: 700; }

/* ---------- Интерактив ---------- */
.ix {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin: 26px 0; overflow: hidden;
}
.ix-head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 14px 20px 0;
}
.ix-title { font-weight: 750; font-size: 16px; }
.ix-hint { font-size: 13px; color: var(--ink-soft); }
.ix-stage { padding: 12px 20px 4px; }
.ix-stage canvas { display: block; width: 100%; border-radius: var(--radius-sm); touch-action: none; }
.ix-controls {
  display: flex; flex-wrap: wrap; gap: 12px 22px; align-items: center;
  padding: 10px 20px 16px;
}
.ix-readout {
  padding: 0 20px 14px; font-size: 14px; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.ix-readout b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Слайдер */
.ix-slider { display: flex; flex-direction: column; gap: 2px; min-width: 170px; flex: 1; max-width: 260px; }
.ix-slider .lbl { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-soft); }
.ix-slider .lbl b { color: var(--ink); font-variant-numeric: tabular-nums; }
.ix-slider input[type=range] { width: 100%; accent-color: var(--accent); height: 26px; cursor: pointer; }

/* Кнопки */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 650;
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: #d8d3c6; }
.btn:active { transform: translateY(0) scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }

/* Переключатели-сегменты */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--ink-soft);
  border: none; background: none; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Тест ---------- */
.quiz {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin: 30px 0; padding: 24px 26px;
}
.quiz-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.quiz-head h2 { margin: 0 !important; font-size: 20px !important; }
.quiz-dots { display: flex; gap: 6px; }
.quiz-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); transition: background var(--t-med), transform var(--t-med); }
.quiz-dot.now { background: var(--accent); border-color: var(--accent); transform: scale(1.25); }
.quiz-dot.ok { background: var(--success); border-color: var(--success); }
.quiz-dot.bad { background: var(--danger); border-color: var(--danger); }

.quiz-q { font-size: 17px; font-weight: 650; margin: 14px 0 14px; line-height: 1.5; }
.quiz-opts { display: flex; flex-direction: column; gap: 9px; }
.quiz-opt {
  font-family: inherit; font-size: 15.5px; text-align: left; line-height: 1.45;
  padding: 12px 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.correct { border-color: var(--success); background: var(--success-soft); font-weight: 600; }
.quiz-opt.wrong { border-color: var(--danger); background: var(--danger-soft); animation: shake 320ms cubic-bezier(.36,.07,.19,.97); }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-3px); } 40%, 60% { transform: translateX(3px); } }

.quiz-explain {
  margin-top: 14px; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 14.5px; background: var(--surface-2); border: 1px solid var(--line);
  animation: fadeUp 240ms cubic-bezier(.2,.7,.3,1);
}
.quiz-explain b { display: block; margin-bottom: 2px; }
.quiz-actions { margin-top: 16px; display: flex; justify-content: flex-end; }

.quiz-result { text-align: center; padding: 18px 0 6px; animation: fadeUp 320ms; }
.quiz-result .big { font-size: 46px; }
.quiz-result .score { font-size: 22px; font-weight: 800; margin: 8px 0 4px; }
.quiz-result .note { color: var(--ink-soft); font-size: 14.5px; margin-bottom: 18px; }

/* ---------- Связанные темы и навигация ---------- */
.related { margin-top: 34px; }
.related h2 { font-size: 17px !important; margin-bottom: 10px !important; }
.related-list { display: flex; flex-wrap: wrap; gap: 8px; }
.related-list a {
  font-size: 14px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border: 1px solid #dfe3ff;
  padding: 6px 14px; border-radius: 999px; text-decoration: none;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.related-list a:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-bottom-color: transparent; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; }
.pager a {
  flex: 1; max-width: 48%;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; text-decoration: none; color: var(--ink);
  background: var(--surface); transition: box-shadow var(--t-fast), transform var(--t-fast);
}
.pager a:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); border-bottom-color: var(--line); }
.pager .dir { font-size: 12px; color: var(--ink-soft); display: block; }
.pager .ttl { font-weight: 650; font-size: 14.5px; }
.pager .next { text-align: right; margin-left: auto; }

/* ---------- Главная ---------- */
.home-hero { text-align: center; padding: 30px 0 10px; }
.home-hero h1 { font-size: 40px; margin-bottom: 10px; }
.home-hero p { color: var(--ink-soft); font-size: 18px; max-width: 560px; margin: 0 auto 30px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-top: 26px; }
.home-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; text-decoration: none; color: var(--ink);
  box-shadow: var(--shadow); transition: transform var(--t-med), box-shadow var(--t-med);
  display: block;
}
.home-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.home-card h3 { margin: 0 0 4px; font-size: 17px; }
.home-card .cnt { font-size: 13px; color: var(--ink-soft); }

/* ---------- Мобильная версия ---------- */
@media (max-width: 900px) {
  .nav-burger { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform var(--t-med); box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lift); }
  .content { margin-left: 0; padding: 70px 18px 70px; }
  .topic-wrap h1 { font-size: 27px; }
  .ix-controls { gap: 10px 14px; }
}
